-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
TownySupport.java
119 lines (98 loc) · 4.39 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
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
package com.denizenscript.depenizen.bukkit.bridges;
import com.denizenscript.depenizen.bukkit.events.towny.PlayerEntersTownScriptEvent;
import com.denizenscript.depenizen.bukkit.events.towny.PlayerExitsTownScriptEvent;
import com.denizenscript.depenizen.bukkit.extensions.towny.TownyCuboidExtension;
import com.denizenscript.depenizen.bukkit.extensions.towny.TownyLocationExtension;
import com.denizenscript.depenizen.bukkit.objects.dNation;
import com.denizenscript.depenizen.bukkit.objects.dTown;
import com.denizenscript.depenizen.bukkit.support.Support;
import com.denizenscript.depenizen.bukkit.extensions.towny.TownyPlayerExtension;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownyUniverse;
import net.aufdemrand.denizen.objects.dCuboid;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizencore.objects.dList;
import net.aufdemrand.denizencore.tags.TagContext;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.tags.Attribute;
public class TownySupport extends Support {
public TownySupport() {
registerObjects(dTown.class, dNation.class);
registerProperty(TownyPlayerExtension.class, dPlayer.class);
registerProperty(TownyLocationExtension.class, dLocation.class);
registerProperty(TownyCuboidExtension.class, dCuboid.class);
registerScriptEvents(new PlayerEntersTownScriptEvent());
registerScriptEvents(new PlayerExitsTownScriptEvent());
registerAdditionalTags("towny", "town", "nation");
}
@Override
public String additionalTags(Attribute attribute, TagContext tagContext) {
if (attribute.startsWith("towny")) {
attribute = attribute.fulfill(1);
// <--[tag]
// @attribute <towny.list_towns[<world name>]>
// @returns dList(Element)
// @description
// Returns a list of all towns. Optionally specify a world name.
// @Plugin DepenizenBukkit, Towny
// -->
if (attribute.startsWith("list_towns")) {
dList towns = new dList();
if (attribute.hasContext(1)) {
try {
for (Town town : TownyUniverse.getDataSource().getWorld(attribute.getContext(1)).getTowns()) {
towns.add(new dTown(town).identify());
}
}
catch (NotRegisteredException e) {
dB.echoError("World specified is not a registered towny world!");
return null;
}
}
else {
for (Town town : TownyUniverse.getDataSource().getTowns()) {
towns.add(new dTown(town).identify());
}
}
return towns.getAttribute(attribute.fulfill(1));
}
}
else 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;
}
}