-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
PVPArenaArena.java
141 lines (119 loc) · 3.9 KB
/
PVPArenaArena.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
package com.denizenscript.depenizen.bukkit.objects.pvparena;
import com.denizenscript.denizen.objects.dPlayer;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.tags.TagContext;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import net.slipcor.pvparena.arena.Arena;
import net.slipcor.pvparena.arena.ArenaPlayer;
import net.slipcor.pvparena.managers.ArenaManager;
public class PVPArenaArena implements ObjectTag {
String prefix = "PVPArena";
Arena arena = null;
public static boolean matches(String name) {
return valueOf(name) != null;
}
public static PVPArenaArena valueOf(String name) {
return valueOf(name, null);
}
public static PVPArenaArena valueOf(String name, TagContext context) {
name = name.replace("pvparena@", "");
Arena a = ArenaManager.getArenaByName(name);
if (a == null) {
return null;
}
return new PVPArenaArena(a);
}
public PVPArenaArena(Arena a) {
if (a != null) {
this.arena = a;
}
else {
Debug.echoError("Arena referenced is null");
}
}
public Arena getArena() {
return arena;
}
@Override
public String getPrefix() {
return prefix;
}
@Override
public ObjectTag 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 "PVPArena";
}
@Override
public String identify() {
return "pvparena@" + arena.getName();
}
@Override
public String identifySimple() {
return identify();
}
@Override
public String toString() {
return identify();
}
@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
// <--[tag]
// @attribute <pvparena@pvparena.name>
// @returns ElementTag
// @description
// Returns the name of the arena.
// @Plugin Depenizen, PVPArena
// -->
if (attribute.startsWith("name")) {
return new ElementTag(arena.getName()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <pvparena@pvparena.fighters>
// @returns ListTag(dPlayer)
// @description
// Returns a list of all fighters in the arena.
// @Plugin Depenizen, PvPArena
// -->
else if (attribute.startsWith("fighters")) {
ListTag fighters = new ListTag();
for (ArenaPlayer p : arena.getFighters()) {
fighters.add(new dPlayer(p.get()).identify());
}
return fighters.getAttribute(attribute.fulfill(1));
}
// NOTE: Deprecated.
if (attribute.startsWith("playercount") || attribute.startsWith("player_count")) {
return new ElementTag(arena.getFighters().size()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <pvparena@pvparena.type>
// @returns ElementTag
// @description
// Always returns 'PVPArena' for PVPArena objects. All objects fetchable by the Object Fetcher will return the
// type of object that is fulfilling this attribute.
// @Plugin Depenizen, PVPArena
// -->
else if (attribute.startsWith("type")) {
return new ElementTag("PVPArena").getAttribute(attribute.fulfill(1));
}
return new ElementTag(identify()).getAttribute(attribute);
}
}