/
BukkitScriptEvent.java
96 lines (86 loc) · 3.43 KB
/
BukkitScriptEvent.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
package net.aufdemrand.denizen.events;
import net.aufdemrand.denizen.objects.dCuboid;
import net.aufdemrand.denizen.objects.dEllipsoid;
import net.aufdemrand.denizen.objects.dItem;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.events.ScriptEvent;
import net.aufdemrand.denizencore.scripts.containers.ScriptContainer;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import org.bukkit.Location;
import java.util.List;
public abstract class BukkitScriptEvent extends ScriptEvent {
public boolean runInCheck(ScriptContainer scriptContainer, String s, String lower, Location location) {
List<String> data = CoreUtilities.split(lower, ' ');
int index;
for (index = 0; index < data.size(); index++) {
if (data.get(index).equals("in")) {
break;
}
}
if (index >= data.size()) {
// No 'in ...' specified
return true;
}
String it = CoreUtilities.getXthArg(index + 1, s);
if (it.equalsIgnoreCase("notable")) {
String subit = CoreUtilities.getXthArg(index + 2, lower);
if (subit.equalsIgnoreCase("cuboid")) {
return dCuboid.getNotableCuboidsContaining(location).size() > 0;
}
else if (subit.equalsIgnoreCase("ellipsoid")) {
return dEllipsoid.getNotableEllipsoidsContaining(location).size() > 0;
}
else {
dB.echoError("Invalid event 'IN ...' check [" + getName() + "] ('in notable ???'): '" + s + "' for " + scriptContainer.getName());
return false;
}
}
else if (dCuboid.matches(it)) {
dCuboid cuboid = dCuboid.valueOf(it);
return cuboid.isInsideCuboid(location);
}
else if (dEllipsoid.matches(it)) {
dEllipsoid ellipsoid = dEllipsoid.valueOf(it);
return ellipsoid.contains(location);
}
else {
dB.echoError("Invalid event 'IN ...' check [" + getName() + "] ('in ???'): '" + s + "' for " + scriptContainer.getName());
return false;
}
}
public boolean runWithCheck(ScriptContainer scriptContainer, String s, String lower, dItem held) {
String with = getSwitch(s, "with");
if (with != null) {
dItem it = dItem.valueOf(with);
if (it == null) {
dB.echoError("Invalid WITH item in " + getName() + " for '" + s + "' in " + scriptContainer.getName());
return false;
}
if (held == null || !tryItem(held, with)) {
return false;
}
}
return true;
}
public boolean tryItem(dItem item, String comparedto) {
item = new dItem(item.getItemStack().clone());
item.setAmount(1);
if (item.identifyNoIdentifier().equalsIgnoreCase(comparedto)) {
return true;
}
if (item.identifyMaterialNoIdentifier().equalsIgnoreCase(comparedto)) {
return true;
}
if (item.identifySimpleNoIdentifier().equalsIgnoreCase(comparedto)) {
return true;
}
item.setDurability((short) 0);
if (item.identifyNoIdentifier().equalsIgnoreCase(comparedto)) {
return true;
}
if (item.identifyMaterialNoIdentifier().equalsIgnoreCase(comparedto)) {
return true;
}
return false;
}
}