-
-
Notifications
You must be signed in to change notification settings - Fork 432
Expand file tree
/
Copy pathCondRespawnLocation.java
More file actions
64 lines (55 loc) · 2 KB
/
CondRespawnLocation.java
File metadata and controls
64 lines (55 loc) · 2 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
package ch.njol.skript.conditions;
import ch.njol.skript.Skript;
import ch.njol.skript.doc.Events;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Example;
import ch.njol.skript.doc.RequiredPlugins;
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.PlayerRespawnEvent;
import org.jetbrains.annotations.Nullable;
@Name("Is Bed/Anchor Spawn")
@Description("Checks what the respawn location of a player in the respawn event is.")
@Example("""
on respawn:
the respawn location is a bed
broadcast "%player% is respawning in their bed! So cozy!"
""")
@RequiredPlugins("Minecraft 1.16+")
@Since("2.7")
@Events("respawn")
public class CondRespawnLocation extends Condition implements EventRestrictedSyntax {
static {
Skript.registerCondition(CondRespawnLocation.class, "[the] respawn location (was|is)[1:(n'| no)t] [a] (:bed|respawn anchor)");
}
private boolean bedSpawn;
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
setNegated(parseResult.mark == 1);
bedSpawn = parseResult.hasTag("bed");
return true;
}
@Override
public Class<? extends Event>[] supportedEvents() {
return CollectionUtils.array(PlayerRespawnEvent.class);
}
@Override
public boolean check(Event event) {
if (event instanceof PlayerRespawnEvent) {
PlayerRespawnEvent respawnEvent = (PlayerRespawnEvent) event;
return (bedSpawn ? respawnEvent.isBedSpawn() : respawnEvent.isAnchorSpawn()) != isNegated();
}
return false;
}
@Override
public String toString(@Nullable Event event, boolean debug) {
return "the respawn location " + (isNegated() ? "isn't" : "is") + " a " + (bedSpawn ? "bed spawn" : "respawn anchor");
}
}