-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
TownyBridge.java
146 lines (136 loc) · 5.9 KB
/
TownyBridge.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
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.properties.towny.TownyCuboidProperties;
import com.denizenscript.depenizen.bukkit.properties.towny.TownyLocationProperties;
import com.denizenscript.depenizen.bukkit.objects.towny.NationTag;
import com.denizenscript.depenizen.bukkit.objects.towny.TownTag;
import com.denizenscript.depenizen.bukkit.Bridge;
import com.denizenscript.depenizen.bukkit.properties.towny.TownyPlayerProperties;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.TownyUniverse;
import com.denizenscript.denizen.objects.CuboidTag;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizencore.events.ScriptEvent;
import com.denizenscript.denizencore.objects.ObjectFetcher;
import com.denizenscript.denizencore.tags.TagRunnable;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import com.denizenscript.denizencore.tags.ReplaceableTagEvent;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.tags.TagManager;
public class TownyBridge extends Bridge {
@Override
public void init() {
ObjectFetcher.registerWithObjectFetcher(TownTag.class, TownTag.tagProcessor);
ObjectFetcher.registerWithObjectFetcher(NationTag.class, NationTag.tagProcessor);
PropertyParser.registerProperty(TownyPlayerProperties.class, PlayerTag.class);
PropertyParser.registerProperty(TownyLocationProperties.class, LocationTag.class);
PropertyParser.registerProperty(TownyCuboidProperties.class, CuboidTag.class);
ScriptEvent.registerScriptEvent(PlayerEntersTownScriptEvent.class);
ScriptEvent.registerScriptEvent(PlayerExitsTownScriptEvent.class);
TagManager.registerTagHandler(new TagRunnable.RootForm() {
@Override
public void run(ReplaceableTagEvent event) {
townyTagEvent(event);
}
}, "towny");
TagManager.registerTagHandler(new TagRunnable.RootForm() {
@Override
public void run(ReplaceableTagEvent event) {
townTagEvent(event);
}
}, "town");
TagManager.registerTagHandler(new TagRunnable.RootForm() {
@Override
public void run(ReplaceableTagEvent event) {
nationTagEvent(event);
}
}, "nation");
}
public void townyTagEvent(ReplaceableTagEvent event) {
Attribute attribute = event.getAttributes().fulfill(1);
// <--[tag]
// @attribute <towny.list_towns[<world>]>
// @returns ListTag
// @plugin Depenizen, Towny
// @description
// Returns a list of all towns. Optionally specify a world name.
// -->
if (attribute.startsWith("list_towns")) {
ListTag towns = new ListTag();
if (attribute.hasParam()) {
try {
for (Town town : TownyAPI.getInstance().getDataSource().getWorld(attribute.getParam().replace("w@", "")).getTowns().values()) {
towns.addObject(new TownTag(town));
}
}
catch (NotRegisteredException e) {
attribute.echoError("World specified is not a registered towny world!");
return;
}
}
else {
for (Town town : TownyUniverse.getInstance().getTowns()) {
towns.addObject(new TownTag(town));
}
}
event.setReplacedObject(towns.getObjectAttribute(attribute.fulfill(1)));
}
}
public void townTagEvent(ReplaceableTagEvent event) {
Attribute attribute = event.getAttributes();
// <--[tag]
// @attribute <town[<name>]>
// @returns TownTag
// @plugin Depenizen, Towny
// @description
// Returns the town by the input name.
// -->
if (attribute.hasParam()) {
TownTag town;
if (TownTag.matches(attribute.getParam())) {
town = attribute.paramAsType(TownTag.class);
}
else {
attribute.echoError("Could not match '" + attribute.getParam() + "' to a valid town!");
return;
}
if (town != null) {
event.setReplacedObject(town.getObjectAttribute(attribute.fulfill(1)));
}
else {
attribute.echoError("Unknown town '" + attribute.getParam() + "' for town[] tag.");
}
}
}
public void nationTagEvent(ReplaceableTagEvent event) {
Attribute attribute = event.getAttributes();
// <--[tag]
// @attribute <nation[<name>]>
// @returns NationTag
// @plugin Depenizen, Towny
// @description
// Returns the nation by the input name.
// -->
if (attribute.hasParam()) {
NationTag nation;
if (NationTag.matches(attribute.getParam())) {
nation = attribute.paramAsType(NationTag.class);
}
else {
attribute.echoError("Could not match '" + attribute.getParam() + "' to a valid nation!");
return;
}
if (nation != null) {
event.setReplacedObject(nation.getObjectAttribute(attribute.fulfill(1)));
}
else {
attribute.echoError("Unknown nation '" + attribute.getParam() + "' for nation[] tag.");
}
}
}
}