-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
dPlot.java
170 lines (141 loc) · 4.85 KB
/
dPlot.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package net.gnomeffinway.depenizen.objects;
import com.worldcretornica.plotme_core.Plot;
import com.worldcretornica.plotme_core.PlotId;
import com.worldcretornica.plotme_core.PlotMeCoreManager;
import com.worldcretornica.plotme_core.bukkit.api.BukkitWorld;
import net.aufdemrand.denizen.objects.dCuboid;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.objects.dWorld;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.Fetchable;
import net.aufdemrand.denizencore.objects.aH;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.tags.Attribute;
import net.aufdemrand.denizencore.tags.TagContext;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import java.util.List;
public class dPlot implements dObject {
/////////////////////
// OBJECT FETCHER
/////////////////
public static dPlot valueOf(String string) {
return valueOf(string, null);
}
@Fetchable("plot")
public static dPlot valueOf(String string, TagContext context) {
if (string == null) return null;
////////
// Match town name
string = string.replace("plot@", "");
try {
List<String> split = CoreUtilities.split(string, ',');
return new dPlot(PlotMeCoreManager.getInstance().getPlotById(
new PlotId(aH.getIntegerFrom(split.get(0)), aH.getIntegerFrom(split.get(1))),
new BukkitWorld(dWorld.valueOf(split.get(3)).getWorld())));
} catch (Throwable e) {
return null;
}
}
public static boolean matches(String arg) {
return arg.startsWith("plot@");
}
/////////////////////
// STATIC CONSTRUCTORS
/////////////////
Plot plot = null;
public dPlot(Plot pl) {
plot = pl;
}
/////////////////////
// dObject Methods
/////////////////
private String prefix = "Plot";
@Override
public String getPrefix() {
return prefix;
}
@Override
public dPlot setPrefix(String prefix) {
this.prefix = prefix;
return this;
}
@Override
public String debug() {
return (prefix + "='<A>" + identify() + "<G>' ");
}
@Override
public boolean isUnique() {
return true;
}
@Override
public String getObjectType() {
return "Plot";
}
@Override
public String identify() {
return "plot@" + plot.getId().getX() + "," + plot.getId().getZ() +"," + plot.getWorld().getName();
}
@Override
public String identifySimple() {
return identify();
}
@Override
public String getAttribute(Attribute attribute) {
// <--[tag]
// @attribute <plot@plot.id_x>
// @returns Element(Number)
// @description
// Returns the plot's X coordinate portion of its ID.
// @plugin Depenizen, PlotMe
// -->
if (attribute.startsWith("id_x")) {
return new Element(plot.getId().getX()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <plot@plot.id_z>
// @returns Element(Number)
// @description
// Returns the plot's Z coordinate portion of its ID.
// @plugin Depenizen, PlotMe
// -->
if (attribute.startsWith("id_z")) {
return new Element(plot.getId().getZ()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <plot@plot.world>
// @returns dWorld
// @description
// Returns the plot's world.
// @plugin Depenizen, PlotMe
// -->
if (attribute.startsWith("world")) {
return dWorld.valueOf(plot.getWorld().getName()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <plot@plot.owner>
// @returns dPlayer
// @description
// Returns the plot's owner.
// @plugin Depenizen, PlotMe
// -->
if (attribute.startsWith("owner")) {
return dPlayer.mirrorBukkitPlayer(Bukkit.getOfflinePlayer(plot.getOwnerId())).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <plot@plot.cuboid>
// @returns dCuboid
// @description
// Returns the plot's cuboid.
// @plugin Depenizen, PlotMe
// -->
if (attribute.startsWith("owner")) {
dWorld world = dWorld.valueOf(plot.getWorld().getName());
Location l1 = new Location(world.getWorld(), plot.getBottomX(), 0, plot.getBottomZ());
Location l2 = new Location(world.getWorld(), plot.getTopX(), 255, plot.getTopZ());
return new dCuboid(l1, l2).getAttribute(attribute.fulfill(1));
}
return new Element(identify()).getAttribute(attribute);
}
}