-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
FactionsPlayerNPCExtension.java
139 lines (121 loc) · 4.62 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
136
137
138
139
package net.gnomeffinway.depenizen.extensions.factions;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.entity.MPlayerColl;
import com.massivecraft.massivecore.util.IdUtil;
import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.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 object) {
return object instanceof dPlayer || object instanceof dNPC;
}
public static FactionsPlayerNPCExtension getFrom(dObject object) {
if (!describes(object)) {
return null;
}
else {
return new FactionsPlayerNPCExtension(object);
}
}
private FactionsPlayerNPCExtension(dObject object) {
String name = object instanceof dPlayer ? ((dPlayer) object).getName()
: object instanceof dNPC ? ((dNPC) object).getName()
: null;
if (name == null) {
dB.echoError("Invalid dObject! Must be a dPlayer or dNPC!");
return;
}
player = MPlayer.get(IdUtil.getId(name));
if (player == null) {
// Attempt to force NPCs into Factions
player = MPlayerColl.get().create(IdUtil.getId(name));
}
}
MPlayer 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 Depenizen, Factions
// -->
// <--[tag]
// @attribute <n@npc.factions.power>
// @returns Element(Double)
// @description
// Returns the NPC's power level.
// @plugin Depenizen, 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 Depenizen, Factions
// -->
// <--[tag]
// @attribute <n@npc.factions.role>
// @returns Element
// @description
// Returns the NPC's role in their faction.
// @plugin Depenizen, 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 Depenizen, Factions
// -->
// <--[tag]
// @attribute <n@npc.factions.title>
// @returns Element
// @description
// Returns the NPC's title.
// @plugin Depenizen, 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 Depenizen, Factions
// -->
// <--[tag]
// @attribute <n@npc.faction>
// @returns dFaction
// @description
// Returns the NPC's faction.
// @plugin Depenizen, Factions
// -->
else if (attribute.startsWith("faction")) {
return new dFaction(player.getFaction()).getAttribute(attribute.fulfill(1));
}
return null;
}
}