-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
TownySupport.java
72 lines (54 loc) · 2.25 KB
/
TownySupport.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
package net.gnomeffinway.depenizen.support.plugins;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.tags.Attribute;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.gnomeffinway.depenizen.objects.dNation;
import net.gnomeffinway.depenizen.objects.dTown;
import net.gnomeffinway.depenizen.support.Support;
import net.gnomeffinway.depenizen.extensions.towny.TownyLocationExtension;
import net.gnomeffinway.depenizen.extensions.towny.TownyPlayerExtension;
public class TownySupport extends Support {
public TownySupport() {
registerObjects(dTown.class, dNation.class);
registerProperty(TownyPlayerExtension.class, dPlayer.class);
registerProperty(TownyLocationExtension.class, dLocation.class);
registerAdditionalTags("town", "nation");
}
@Override
public String additionalTags(Attribute attribute) {
if (attribute.startsWith("town")) {
dTown town = null;
if (attribute.hasContext(1)) {
if (dTown.matches(attribute.getContext(1))) {
town = dTown.valueOf(attribute.getContext(1));
} else {
dB.echoError("Could not match '" + attribute.getContext(1) + "' to a valid town!");
return null;
}
}
if (town == null) {
dB.echoError("Invalid or missing town!");
return null;
}
return town.getAttribute(attribute.fulfill(1));
}
else if (attribute.startsWith("nation")) {
dNation nation = null;
if (attribute.hasContext(1)) {
if (dNation.matches(attribute.getContext(1))) {
nation = dNation.valueOf(attribute.getContext(1));
} else {
dB.echoError("Could not match '" + attribute.getContext(1) + "' to a valid nation!");
return null;
}
}
if (nation == null) {
dB.echoError("Invalid or missing nation!");
return null;
}
return nation.getAttribute(attribute.fulfill(1));
}
return null;
}
}