forked from SkriptLang/Skript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCondResourcePack.java
More file actions
68 lines (57 loc) · 2.24 KB
/
CondResourcePack.java
File metadata and controls
68 lines (57 loc) · 2.24 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
package ch.njol.skript.conditions;
import ch.njol.skript.lang.EventRestrictedSyntax;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.event.Event;
import org.bukkit.event.player.PlayerResourcePackStatusEvent;
import org.bukkit.event.player.PlayerResourcePackStatusEvent.Status;
import org.jetbrains.annotations.Nullable;
import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Events;
import ch.njol.skript.doc.Example;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Condition;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
@Name("Resource Pack")
@Description("Checks state of the resource pack in a <a href='#resource_pack_request_action'>resource pack request response</a> event.")
@Example("""
on resource pack response:
if the resource pack wasn't accepted:
kick the player due to "You have to install the resource pack to play in this server!"
""")
@Since("2.4")
@Events("resource pack request response")
public class CondResourcePack extends Condition implements EventRestrictedSyntax {
static {
Skript.registerCondition(CondResourcePack.class,
"[the] resource pack (was|is|has) [been] %resourcepackstate%",
"[the] resource pack (was|is|has)(n't| not) [been] %resourcepackstate%");
}
@SuppressWarnings("null")
private Expression<Status> states;
@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
states = (Expression<Status>) exprs[0];
setNegated(matchedPattern == 1);
return true;
}
@Override
public Class<? extends Event>[] supportedEvents() {
return CollectionUtils.array(PlayerResourcePackStatusEvent.class);
}
@Override
public boolean check(Event e) {
if (!(e instanceof PlayerResourcePackStatusEvent))
return isNegated();
Status state = ((PlayerResourcePackStatusEvent) e).getStatus();
return states.check(e, state::equals, isNegated());
}
@Override
public String toString(final @Nullable Event e, final boolean debug) {
return "resource pack was " + (isNegated() ? "not " : "") + states.toString(e, debug);
}
}