/
FactionsPlayerNPCExtension.java
135 lines (117 loc) · 4.51 KB
/
FactionsPlayerNPCExtension.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
package net.gnomeffinway.depenizen.extensions.factions;
import com.massivecraft.factions.entity.UPlayer;
import com.massivecraft.factions.entity.UPlayerColl;
import com.massivecraft.factions.entity.UPlayerColls;
import net.aufdemrand.denizen.objects.Element;
import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dObject;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.tags.Attribute;
import net.aufdemrand.denizencore.utilities.debugging.dB;
import net.gnomeffinway.depenizen.extensions.dObjectExtension;
import net.gnomeffinway.depenizen.objects.dFaction;
public class FactionsPlayerNPCExtension extends dObjectExtension {
public static boolean describes(dObject obj) {
return obj instanceof dPlayer || obj instanceof dNPC;
}
public static FactionsPlayerNPCExtension getFrom(dObject obj) {
if (!describes(obj)) return null;
else return new FactionsPlayerNPCExtension(obj);
}
private FactionsPlayerNPCExtension(dObject obj) {
String name = obj instanceof dPlayer ? ((dPlayer) obj).getName()
: obj instanceof dNPC ? ((dNPC) obj).getName()
: null;
if (name == null) {
dB.echoError("Invalid dObject! Must be a dPlayer or dNPC!");
return;
}
for (UPlayerColl upc : UPlayerColls.get().getColls()) {
for (UPlayer up : upc.getAll())
if (up.getName().equalsIgnoreCase(name))
player = up;
}
if (player == null)
dB.echoError("No Factions player data found for '" + name + "'!");
}
UPlayer player = null;
@Override
public String getAttribute(Attribute attribute) {
if (attribute.startsWith("factions")) {
attribute = attribute.fulfill(1);
// <--[tag]
// @attribute <p@player.factions.power>
// @returns Element(Double)
// @description
// Returns the player's power level.
// @plugin Factions
// -->
// <--[tag]
// @attribute <n@npc.factions.power>
// @returns Element(Double)
// @description
// Returns the NPC's power level.
// @plugin Factions
// -->
if (attribute.startsWith("power")) {
return new Element(player.getPower()).getAttribute(attribute.fulfill(1));
}
else if (player.hasFaction()) {
// <--[tag]
// @attribute <p@player.factions.role>
// @returns Element
// @description
// Returns the player's role in their faction.
// @plugin Factions
// -->
// <--[tag]
// @attribute <n@npc.factions.role>
// @returns Element
// @description
// Returns the NPC's role in their faction.
// @plugin Factions
// -->
if (attribute.startsWith("role")) {
if (player.getRole() != null)
return new Element(player.getRole().toString()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.factions.title>
// @returns Element
// @description
// Returns the player's title.
// @plugin Factions
// -->
// <--[tag]
// @attribute <n@npc.factions.title>
// @returns Element
// @description
// Returns the NPC's title.
// @plugin Factions
// -->
else if (attribute.startsWith("title")) {
if (player.hasTitle())
return new Element(player.getTitle()).getAttribute(attribute.fulfill(1));
}
}
}
// <--[tag]
// @attribute <p@player.faction>
// @returns dFaction
// @description
// Returns the player's faction.
// @plugin Factions
// -->
// <--[tag]
// @attribute <n@npc.faction>
// @returns dFaction
// @description
// Returns the NPC's faction.
// @plugin Factions
// -->
else if (attribute.startsWith("faction")) {
return new dFaction(player.getFaction()).getAttribute(attribute.fulfill(1));
}
return null;
}
}