/
PlayerWalkScriptEvent.java
97 lines (85 loc) · 2.82 KB
/
PlayerWalkScriptEvent.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
96
97
package com.denizenscript.denizen.events.player;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
public class PlayerWalkScriptEvent extends BukkitScriptEvent implements Listener {
// <--[event]
// @Events
// player walks
//
// @Regex ^on player walks$
//
// @Group Player
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
//
// @Warning This event fires very very rapidly!
//
// @Cancellable true
//
// @Triggers when a player moves in the slightest.
//
// @Context
// <context.old_location> returns the location of where the player was.
// <context.new_location> returns the location of where the player is.
//
// @Player Always.
//
// -->
public PlayerWalkScriptEvent() {
instance = this;
}
public static PlayerWalkScriptEvent instance;
public LocationTag old_location;
public LocationTag new_location;
public PlayerMoveEvent event;
@Override
public boolean couldMatch(ScriptPath path) {
return path.eventLower.startsWith("player walks") && !path.eventArgLowerAt(2).equals("over");
}
@Override
public boolean matches(ScriptPath path) {
if (!runInCheck(path, old_location)) {
return false;
}
if (!runInCheck(path, new_location)) {
return false;
}
return super.matches(path);
}
@Override
public String getName() {
return "PlayerWalks";
}
@Override
public ScriptEntryData getScriptEntryData() {
return new BukkitScriptEntryData(PlayerTag.mirrorBukkitPlayer(event.getPlayer()), null);
}
@Override
public ObjectTag getContext(String name) {
if (name.equals("old_location")) {
return old_location;
}
else if (name.equals("new_location")) {
return new_location;
}
return super.getContext(name);
}
@EventHandler
public void onPlayerMoves(PlayerMoveEvent event) {
if (EntityTag.isNPC(event.getPlayer())) {
return;
}
old_location = new LocationTag(event.getFrom());
new_location = new LocationTag(event.getTo());
this.event = event;
fire(event);
}
}