-
-
Notifications
You must be signed in to change notification settings - Fork 431
Expand file tree
/
Copy pathCondLeashWillDrop.java
More file actions
59 lines (50 loc) · 1.75 KB
/
CondLeashWillDrop.java
File metadata and controls
59 lines (50 loc) · 1.75 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
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.entity.EntityUnleashEvent;
import org.jetbrains.annotations.Nullable;
import ch.njol.skript.Skript;
import ch.njol.skript.doc.*;
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("Leash Will Drop")
@Description("Checks whether the leash item will drop during the leash detaching in an unleash event.")
@Example("""
on unleash:
if the leash will drop:
prevent the leash from dropping
else:
allow the leash to drop
""")
@Keywords("lead")
@Events("Leash / Unleash")
@Since("2.10")
public class CondLeashWillDrop extends Condition implements EventRestrictedSyntax {
static {
// TODO - remove this when Spigot support is dropped
if (Skript.methodExists(EntityUnleashEvent.class, "isDropLeash"))
Skript.registerCondition(CondLeashWillDrop.class, "[the] (lead|leash) [item] (will|not:(won't|will not)) (drop|be dropped)");
}
@Override
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
setNegated(parseResult.hasTag("not"));
return true;
}
@Override
public Class<? extends Event>[] supportedEvents() {
return CollectionUtils.array(EntityUnleashEvent.class);
}
@Override
public boolean check(Event event) {
if (!(event instanceof EntityUnleashEvent unleashEvent))
return false;
return unleashEvent.isDropLeash() ^ isNegated();
}
@Override
public String toString(@Nullable Event event, boolean debug) {
return "the leash will" + (isNegated() ? " not" : "") + " be dropped";
}
}