-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
MobArenaArena.java
248 lines (218 loc) · 7.88 KB
/
MobArenaArena.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
package net.gnomeffinway.depenizen.objects.mobarena;
import com.garbagemule.MobArena.MobArena;
import com.garbagemule.MobArena.framework.Arena;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.dList;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.tags.Attribute;
import net.aufdemrand.denizencore.tags.TagContext;
import net.aufdemrand.denizencore.utilities.debugging.dB;
import net.gnomeffinway.depenizen.support.Support;
import net.gnomeffinway.depenizen.support.plugins.MobArenaSupport;
import org.bukkit.entity.Player;
public class MobArenaArena implements dObject {
String prefix = "MobArena";
Arena arena = null;
static MobArena plugin = Support.getPlugin(MobArenaSupport.class);
public static MobArenaArena valueOf(String name) {
return valueOf(name, null);
}
public static MobArenaArena valueOf(String name, TagContext context) {
name = name.replace("mobarena@", "");
Arena arena = plugin.getArenaMaster().getArenaWithName(name);
if (arena == null) {
return null;
}
return new MobArenaArena(arena);
}
public static boolean matches(String name) {
return valueOf(name) != null;
}
public MobArenaArena(Arena arena) {
if (arena != null) {
this.arena = arena;
}
else {
dB.echoError("Arena referenced is null");
}
}
public Arena getArena() {
return arena;
}
@Override
public String getPrefix() {
return prefix;
}
@Override
public dObject 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 "MobArena";
}
@Override
public String identify() {
return "mobarena@" + arena.arenaName();
}
@Override
public String identifySimple() {
return identify();
}
@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
// <--[tag]
// @attribute <mobarena@mobarena.name>
// @returns Element
// @description
// Returns the name of the arena.
// @plugin Depenizen, MobArena
// -->
if (attribute.startsWith("name")) {
return new Element(arena.arenaName()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <mobarena@mobarena.is_running>
// @returns Element(Boolean)
// @description
// Returns whether the arena is running.
// @plugin Depenizen, MobArena
// -->
else if (attribute.startsWith("is_running")) {
return new Element(arena.isRunning()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <mobarena@mobarena.wave_count>
// @returns Element(Number)
// @description
// Returns the number of waves this arena has in total.
// @plugin Depenizen, MobArena
// -->
else if (attribute.startsWith("wave_count")) {
return new Element(arena.getWaveManager().getFinalWave())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <mobarena@mobarena.current_wave>
// @returns Element(Number)
// @description
// Returns the current wave number.
// NOTE: Requires the arena to be running.
// @plugin Depenizen, MobArena
// -->
else if (attribute.startsWith("current_wave") && arena.isRunning()) {
return new Element(arena.getWaveManager().getWaveNumber())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <mobarena@mobarena.wave_type>
// @returns Element
// @description
// Returns the type of the current wave.
// NOTE: Requires the arena to be running.
// @plugin Depenizen, MobArena
// -->
else if (attribute.startsWith("wave_type") && arena.isRunning()) {
return new Element(arena.getWaveManager().getCurrent().getType().toString())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <mobarena@mobarena.is_enabled>
// @returns Element(Boolean)
// @description
// Returns whether the arena is enabled.
// @plugin Depenizen, MobArena
// -->
else if (attribute.startsWith("is_enabled")) {
return new Element(arena.isEnabled()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <mobarena@mobarena.status>
// @returns Element
// @description
// Returns the status of the arena.
// Will return 'closed', 'open', or 'running'.
// @plugin Depenizen, MobArena
// -->
else if (attribute.startsWith("status")) {
if (!arena.isEnabled()) {
return new Element("closed").getAttribute(attribute.fulfill(1));
}
else if (!arena.isRunning()) {
return new Element("open").getAttribute(attribute.fulfill(1));
}
else {
return new Element("running").getAttribute(attribute.fulfill(1));
}
}
else if (attribute.startsWith("players")) {
// <--[tag]
// @attribute <mobarena@mobarena.players.in_arena>
// @returns dList(dPlayer)
// @description
// Returns a list of players in the arena.
// @plugin Depenizen, MobArena
// -->
if (attribute.getAttribute(2).startsWith("in_arena")) {
dList players = new dList();
for (Player p : arena.getPlayersInArena()) {
players.add(new dPlayer(p).identify());
}
return players.getAttribute(attribute.fulfill(2));
}
// <--[tag]
// @attribute <mobarena@mobarena.players.in_lobby>
// @returns dList(dPlayer)
// @description
// Returns a list of players in the lobby.
// @plugin Depenizen, MobArena
// -->
else if (attribute.startsWith("in_lobby")) {
dList players = new dList();
for (Player p : arena.getPlayersInLobby()) {
players.add(new dPlayer(p).identify());
}
return players.getAttribute(attribute.fulfill(2));
}
// <--[tag]
// @attribute <mobarena@mobarena.players>
// @returns dList(dPlayer)
// @description
// Returns a list of all players in the arena (including the lobby).
// @plugin Depenizen, MobArena
// -->
else {
dList players = new dList();
for (Player p : arena.getAllPlayers()) {
players.add(new dPlayer(p).identify());
}
return players.getAttribute(attribute.fulfill(1));
}
}
// <--[tag]
// @attribute <mobarena@mobarena.type>
// @returns Element
// @description
// Always returns 'MobArena' for MobArena objects. All objects fetchable by the Object Fetcher will return the
// type of object that is fulfilling this attribute.
// @plugin Depenizen, MobArena
// -->
else if (attribute.startsWith("type")) {
return new Element("MobArena").getAttribute(attribute.fulfill(1));
}
return new Element(identify()).getAttribute(attribute);
}
}