-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
PlayerClaimPlotScriptEvent.java
101 lines (89 loc) · 3.22 KB
/
PlayerClaimPlotScriptEvent.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
package com.denizenscript.depenizen.bukkit.events.plotsquared;
import com.denizenscript.depenizen.bukkit.objects.plotsquared.dPlotSquaredPlot;
import com.github.intellectualsites.plotsquared.bukkit.events.PlayerClaimPlotEvent;
import com.denizenscript.denizen.BukkitScriptEntryData;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizencore.objects.core.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;
public class PlayerClaimPlotScriptEvent extends BukkitScriptEvent implements Listener {
// <--[event]
// @Events
// plotsquared player claims plotsquaredplot
// plotsquared player claims <dplotsquaredplot>
//
// @Regex ^on plotsquared player [^\s]+ level changes( in ((notable (cuboid|ellipsoid))|([^\s]+)))?$
//
// @Cancellable true
//
// @Triggers when a player claims a plot.
//
// @Context
// <context.plot> returns the plot the player claimed.
// <context.auto> returns true if the plot was claimed automatic.
//
// @Plugin Depenizen, PlotSquared
//
// -->
public PlayerClaimPlotScriptEvent() {
instance = this;
}
public static PlayerClaimPlotScriptEvent instance;
public PlayerClaimPlotEvent event;
public PlayerTag player;
public dPlotSquaredPlot plot;
public ElementTag auto;
@Override
public boolean couldMatch(ScriptContainer scriptContainer, String s) {
String lower = CoreUtilities.toLowerCase(s);
return lower.startsWith("plotsquared player claims");
}
@Override
public boolean matches(ScriptPath path) {
String plotName = path.eventArgLowerAt(3);
if (plotName.equals("plotsquaredplot")) {
return true;
}
dPlotSquaredPlot dplot = dPlotSquaredPlot.valueOf(plotName);
return dplot != null && dplot.equals(plot);
}
@Override
public String getName() {
return "PlayerClaimPlotEvent";
}
@Override
public boolean applyDetermination(ScriptContainer container, String determination) {
return super.applyDetermination(container, determination);
}
@Override
public ScriptEntryData getScriptEntryData() {
return new BukkitScriptEntryData(player, null);
}
@Override
public ObjectTag getContext(String name) {
if (name.equals("plot")) {
return plot;
}
else if (name.equals("auto")) {
return auto;
}
return super.getContext(name);
}
@EventHandler
public void onPlotEnter(PlayerClaimPlotEvent event) {
if (EntityTag.isNPC(event.getPlayer())) {
return;
}
player = PlayerTag.mirrorBukkitPlayer(event.getPlayer());
plot = new dPlotSquaredPlot(event.getPlot());
auto = new ElementTag(event.wasAuto());
this.event = event;
fire(event);
}
}