-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
PlayerFlyingScriptEvent.java
95 lines (82 loc) · 2.95 KB
/
PlayerFlyingScriptEvent.java
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.denizenscript.denizen.events.player;
import com.denizenscript.denizen.objects.dEntity;
import com.denizenscript.denizen.objects.dPlayer;
import com.denizenscript.denizen.BukkitScriptEntryData;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizencore.objects.ElementTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import com.denizenscript.denizencore.scripts.containers.ScriptContainer;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerToggleFlightEvent;
public class PlayerFlyingScriptEvent extends BukkitScriptEvent implements Listener {
// <--[event]
// @Events
// player toggles flying
// player starts flying
// player stops flying
//
// @Regex ^on player (toggles|starts|stops) flying$
// @Switch in <area>
//
// @Cancellable true
//
// @Triggers when a player starts or stops flying.
//
// @Context
// <context.state> returns an Element(Boolean) with a value of "true" if the player is now flying and "false" otherwise.
//
// -->
public PlayerFlyingScriptEvent() {
instance = this;
}
public static PlayerFlyingScriptEvent instance;
public Boolean state;
public PlayerToggleFlightEvent event;
@Override
public boolean couldMatch(ScriptContainer scriptContainer, String s) {
return CoreUtilities.getXthArg(2, CoreUtilities.toLowerCase(s)).equals("flying")
|| CoreUtilities.getXthArg(2, CoreUtilities.toLowerCase(s)).equals("flight");
}
@Override
public boolean matches(ScriptPath path) {
String cmd = path.eventArgLowerAt(1);
if (cmd.equals("starts") && !state) {
return false;
}
if (cmd.equals("stops") && state) {
return false;
}
return runInCheck(path, event.getPlayer().getLocation());
}
@Override
public String getName() {
return "PlayerFlying";
}
@Override
public boolean applyDetermination(ScriptContainer container, String determination) {
return super.applyDetermination(container, determination);
}
@Override
public ScriptEntryData getScriptEntryData() {
return new BukkitScriptEntryData(new dPlayer(event.getPlayer()), null);
}
@Override
public ObjectTag getContext(String name) {
if (name.equals("state")) {
return new ElementTag(state);
}
return super.getContext(name);
}
@EventHandler
public void onPlayerFlying(PlayerToggleFlightEvent event) {
if (dEntity.isNPC(event.getPlayer())) {
return;
}
state = event.isFlying();
this.event = event;
fire(event);
}
}