-
-
Notifications
You must be signed in to change notification settings - Fork 432
Expand file tree
/
Copy pathCondWillHatch.java
More file actions
59 lines (51 loc) · 1.66 KB
/
CondWillHatch.java
File metadata and controls
59 lines (51 loc) · 1.66 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.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.EventRestrictedSyntax;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.event.Event;
import org.bukkit.event.player.PlayerEggThrowEvent;
import org.jetbrains.annotations.Nullable;
@Name("Egg Will Hatch")
@Description("Whether the egg will hatch in a Player Egg Throw event.")
@Example("""
on player egg throw:
if an entity won't hatch:
send "Better luck next time!" to the player
""")
@Events("Egg Throw")
@Since("2.7")
public class CondWillHatch extends Condition implements EventRestrictedSyntax {
static {
Skript.registerCondition(CondWillHatch.class,
"[the] egg (:will|will not|won't) hatch"
);
}
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
setNegated(!parseResult.hasTag("will"));
return true;
}
@Override
public Class<? extends Event>[] supportedEvents() {
return CollectionUtils.array(PlayerEggThrowEvent.class);
}
@Override
public boolean check(Event event) {
if (!(event instanceof PlayerEggThrowEvent))
return false;
return ((PlayerEggThrowEvent) event).isHatching() ^ isNegated();
}
@Override
public String toString(@Nullable Event event, boolean debug) {
return "the egg " + (isNegated() ? "will" : "will not") + " hatch";
}
}