-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
TownyPlayerExtension.java
71 lines (59 loc) · 2.25 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
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.dObject;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.tags.Attribute;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.gnomeffinway.depenizen.extensions.dObjectExtension;
import net.gnomeffinway.depenizen.objects.dNation;
import net.gnomeffinway.depenizen.objects.dTown;
public class TownyPlayerExtension extends dObjectExtension {
public static boolean describes(dObject pl) {
return pl instanceof dPlayer;
}
public static TownyPlayerExtension getFrom(dObject pl) {
if (!describes(pl)) return null;
else return new TownyPlayerExtension((dPlayer) pl);
}
private TownyPlayerExtension(dPlayer pl) { player = pl; }
dPlayer player = null;
@Override
public String getAttribute(Attribute attribute) {
// <--[tag]
// @attribute <p@player.town>
// @returns dTown
// @description
// Returns the player's town.
// @plugin Towny
// -->
if (attribute.startsWith("town")) {
try {
return new dTown(TownyUniverse.getDataSource().getResident(player.getName()).getTown())
.getAttribute(attribute.fulfill(1));
}
catch (NotRegisteredException ex) {
dB.echoError(player.getName() + " is not registered to a town!");
return "null";
}
}
// <--[tag]
// @attribute <p@player.nation>
// @returns dNation
// @description
// Returns the player's nation.
// @plugin Towny
// -->
if (attribute.startsWith("nation")) {
try {
return new dNation(TownyUniverse.getDataSource().getResident(player.getName()).getTown().getNation())
.getAttribute(attribute.fulfill(1));
}
catch (NotRegisteredException ex) {
dB.echoError(player.getName() + " is not registered to a nation!");
return "null";
}
}
return null;
}
}