-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
TownyLocationExtension.java
54 lines (43 loc) · 1.69 KB
/
TownyLocationExtension.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
package net.gnomeffinway.depenizen.extensions.towny;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.TownyUniverse;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.objects.dObject;
import net.aufdemrand.denizen.tags.Attribute;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.gnomeffinway.depenizen.extensions.dObjectExtension;
import net.gnomeffinway.depenizen.objects.dTown;
public class TownyLocationExtension extends dObjectExtension {
public static boolean describes(dObject loc) {
return loc instanceof dLocation;
}
public static TownyLocationExtension getFrom(dObject loc) {
if (!describes(loc)) return null;
else return new TownyLocationExtension((dLocation) loc);
}
private TownyLocationExtension(dLocation loc) {
location = loc;
}
dLocation location = null;
@Override
public String getAttribute(Attribute attribute) {
// <--[tag]
// @attribute <l@location.town>
// @returns dTown
// @description
// Returns the town at the specified location.
// @plugin Depenizen, Towny
// -->
if (attribute.startsWith("town")) {
try {
return new dTown(TownyUniverse.getDataSource().getTown(TownyUniverse.getTownName(location)))
.getAttribute(attribute.fulfill(1));
}
catch (NotRegisteredException ex) {
if (!attribute.hasAlternative())
dB.echoError(location.identifySimple() + " is not registered to a town!");
}
}
return null;
}
}