-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
TownyPlayerExtension.java
175 lines (155 loc) · 6.16 KB
/
TownyPlayerExtension.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
package com.denizenscript.depenizen.bukkit.extensions.towny;
import com.denizenscript.depenizen.bukkit.extensions.dObjectExtension;
import com.denizenscript.depenizen.bukkit.objects.dNation;
import com.denizenscript.depenizen.bukkit.objects.dTown;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.TownyUniverse;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.dList;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.tags.Attribute;
public class TownyPlayerExtension extends dObjectExtension {
public static boolean describes(dObject object) {
return object instanceof dPlayer;
}
public static TownyPlayerExtension getFrom(dObject object) {
if (!describes(object)) {
return null;
}
else {
return new TownyPlayerExtension((dPlayer) object);
}
}
public static final String[] handledTags = new String[] {
"has_nation", "has_town", "mode_list", "nation_ranks", "nation", "town_ranks", "town"
};
public static final String[] handledMechs = new String[] {
}; // None
private TownyPlayerExtension(dPlayer player) {
this.player = player;
}
dPlayer player = null;
public Resident getResident() throws NotRegisteredException {
return TownyUniverse.getDataSource().getResident(player.getName());
}
@Override
public String getAttribute(Attribute attribute) {
try {
// <--[tag]
// @attribute <p@player.has_nation>
// @returns Element(Boolean)
// @description
// Returns whether the player is part of a nation.
// @Plugin DepenizenBukkit, Towny
// -->
if (attribute.startsWith("has_nation")) {
return new Element(getResident().hasNation()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.has_town>
// @returns Element(Boolean)
// @description
// Returns whether the player is part of a town.
// @Plugin DepenizenBukkit, Towny
// -->
if (attribute.startsWith("has_town")) {
return new Element(getResident().hasTown()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.mode_list>
// @returns dList(Element)
// @description
// Returns the player's towny modes as a list.
// @Plugin DepenizenBukkit, Towny
// -->
else if (attribute.startsWith("mode_list")) {
dList modes = new dList();
for (String mode : getResident().getModes()) {
modes.add(new Element(mode).identify());
}
return modes.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.nation_ranks>
// @returns dList(Element)
// @description
// Returns the player's nation ranks.
// @Plugin DepenizenBukkit, Towny
// -->
else if (attribute.startsWith("nation_ranks")) {
dList ranks = new dList();
for (String rank : getResident().getNationRanks()) {
ranks.add(new Element(rank).identify());
}
return ranks.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.nation>
// @returns dNation
// @description
// Returns the player's nation.
// @Plugin DepenizenBukkit, Towny
// -->
if (attribute.startsWith("nation")) {
try {
if (getResident().hasNation()) {
return new dNation(getResident().getTown().getNation()).getAttribute(attribute.fulfill(1));
}
else {
return null;
}
}
catch (NotRegisteredException e) {
if (!attribute.hasAlternative()) {
dB.echoError("'" + player.getName() + "' is not registered to a nation in Towny!");
}
}
}
// <--[tag]
// @attribute <p@player.town_ranks>
// @returns dList(Element)
// @description
// Returns the player's town ranks.
// @Plugin DepenizenBukkit, Towny
// -->
else if (attribute.startsWith("town_ranks")) {
dList ranks = new dList();
for (String rank : getResident().getTownRanks()) {
ranks.add(new Element(rank).identify());
}
return ranks.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.town>
// @returns dTown
// @description
// Returns the player's town.
// @Plugin DepenizenBukkit, Towny
// -->
if (attribute.startsWith("town")) {
try {
if (getResident().hasTown()) {
return new dTown(getResident().getTown()).getAttribute(attribute.fulfill(1));
}
else {
return null;
}
}
catch (NotRegisteredException e) {
if (!attribute.hasAlternative()) {
dB.echoError("'" + player.getName() + "' is not registered to a town in Towny!");
}
}
}
}
catch (NotRegisteredException e) {
if (!attribute.hasAlternative()) {
dB.echoError("'" + player.getName() + "' is not registered in Towny!");
}
}
return null;
}
}