-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
GPClaimEnterEvent.java
131 lines (118 loc) · 4.29 KB
/
GPClaimEnterEvent.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package com.denizenscript.depenizen.bukkit.events.griefprevention;
import com.denizenscript.depenizen.bukkit.objects.griefprevention.GriefPreventionClaimTag;
import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
public class GPClaimEnterEvent extends BukkitScriptEvent implements Listener {
// TODO: in area?
// <--[event]
// @Events
// gp player enters <gpclaim>
// gp player exits <gpclaim>
// gp player enters gpclaim
// gp player exits gpclaim
//
// @Regex ^on gp player (enters|exits) [^\s]+$
//
// @Warning Cancelling this event will fire a similar event immediately after.
//
// @Cancellable true
//
// @Triggers when a player enters or exits a Grief Prevention claim.
//
// @Context
// <context.from> returns the block location moved from.
// <context.to> returns the block location moved to.
// <context.new_claim> returns the gpclaim being entered.
// <context.old_claim> returns the gpclaim being exited.
//
// @Plugin Depenizen, GriefPrevention
//
// @Player Always.
//
// @Group Depenizen
//
// -->
public GPClaimEnterEvent() {
instance = this;
}
public static GPClaimEnterEvent instance;
public LocationTag from;
public LocationTag to;
public GriefPreventionClaimTag new_claim;
public GriefPreventionClaimTag old_claim;
public PlayerMoveEvent event;
@Override
public boolean couldMatch(ScriptPath path) {
return path.eventLower.startsWith("gp player enters")
|| path.eventLower.startsWith("gp player exits");
}
@Override
public boolean matches(ScriptPath path) {
String direction = path.eventArgAt(2);
String claim_test = path.eventArgLowerAt(3);
// TODO: Wtf
if (direction.equals("enters") && new_claim != null) {
if (!(claim_test.equals("gpclaim") || claim_test.equals(CoreUtilities.toLowerCase(new_claim.simple())))) {
return false;
}
return super.matches(path);
}
else if (direction.equals("exits") && old_claim != null) {
if (!(claim_test.equals("gpclaim") || claim_test.equals(CoreUtilities.toLowerCase(old_claim.simple())))) {
return false;
}
return super.matches(path);
}
return false;
}
@Override
public String getName() {
return "GPClaimEnter";
}
@Override
public ScriptEntryData getScriptEntryData() {
// TODO: Store the player?
return new BukkitScriptEntryData(event != null ? new PlayerTag(event.getPlayer()) : null, null);
}
@Override
public ObjectTag getContext(String name) {
switch (name) {
case "to":
return to;
case "from":
return from;
case "old_claim":
return old_claim;
case "new_claim":
return new_claim;
}
return super.getContext(name);
}
@EventHandler
public void onPlayerEntersExitsGPClaim(PlayerMoveEvent event) {
if (LocationTag.isSameBlock(event.getFrom(), event.getTo())) {
return;
}
from = new LocationTag(event.getFrom());
to = new LocationTag(event.getTo());
Claim fclaim = GriefPrevention.instance.dataStore.getClaimAt(from, false, null);
Claim tclaim = GriefPrevention.instance.dataStore.getClaimAt(to, false, null);
if (tclaim == fclaim) {
return;
}
new_claim = tclaim == null ? null : new GriefPreventionClaimTag(tclaim);
old_claim = fclaim == null ? null : new GriefPreventionClaimTag(fclaim);
this.event = event;
fire(event);
}
}