-
-
Notifications
You must be signed in to change notification settings - Fork 432
Expand file tree
/
Copy pathEffHidePlayerFromServerList.java
More file actions
75 lines (63 loc) · 2.4 KB
/
EffHidePlayerFromServerList.java
File metadata and controls
75 lines (63 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package ch.njol.skript.effects;
import java.util.Arrays;
import java.util.Iterator;
import ch.njol.skript.lang.EventRestrictedSyntax;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.server.ServerListPingEvent;
import org.jetbrains.annotations.Nullable;
import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
import com.google.common.collect.Iterators;
import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Example;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
@Name("Hide Player from Server List")
@Description({"Hides a player from the <a href='#ExprHoverList'>hover list</a> " +
"and decreases the <a href='#ExprOnlinePlayersCount'>online players count</a> (only if the player count wasn't changed before)."})
@Example("""
on server list ping:
hide {vanished::*} from the server list
""")
@Since("2.3")
public class EffHidePlayerFromServerList extends Effect implements EventRestrictedSyntax {
static {
Skript.registerEffect(EffHidePlayerFromServerList.class,
"hide %players% (in|on|from) [the] server list",
"hide %players%'[s] info[rmation] (in|on|from) [the] server list");
}
@SuppressWarnings("null")
private Expression<Player> players;
@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
if (isDelayed == Kleenean.TRUE) {
Skript.error("Can't hide players from the server list anymore after the server list ping event has already passed");
return false;
}
players = (Expression<Player>) exprs[0];
return true;
}
@Override
public Class<? extends Event>[] supportedEvents() {
return CollectionUtils.array(ServerListPingEvent.class, PaperServerListPingEvent.class);
}
@Override
@SuppressWarnings("removal")
protected void execute(Event e) {
if (!(e instanceof ServerListPingEvent))
return;
Iterator<Player> it = ((ServerListPingEvent) e).iterator();
Iterators.removeAll(it, Arrays.asList(players.getArray(e)));
}
@Override
public String toString(@Nullable Event e, boolean debug) {
return "hide " + players.toString(e, debug) + " from the server list";
}
}