/
QuestsPlayerProperties.java
138 lines (119 loc) · 4.69 KB
/
QuestsPlayerProperties.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
package com.denizenscript.depenizen.bukkit.properties.quests;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.depenizen.bukkit.bridges.QuestsBridge;
import me.blackvein.quests.Quest;
import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.tags.Attribute;
public class QuestsPlayerProperties implements Property {
@Override
public String getPropertyString() {
return null;
}
@Override
public String getPropertyId() {
return "QuestsPlayer";
}
public static boolean describes(ObjectTag object) {
return object instanceof PlayerTag;
}
public static QuestsPlayerProperties getFrom(ObjectTag object) {
if (!describes(object)) {
return null;
}
else {
return new QuestsPlayerProperties((PlayerTag) object);
}
}
public static final String[] handledTags = new String[] {
"quests"
};
public static final String[] handledMechs = new String[] {
}; // None
private QuestsPlayerProperties(PlayerTag player) {
this.player = player;
}
public Quester getQuester() {
Quests quests = (Quests) QuestsBridge.instance.plugin;
// This would be Quests.getInstance() but the developers of Quests did a stupid and broke that method.
return quests.getQuester(player.getUUID());
}
PlayerTag player;
@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
if (attribute.startsWith("quests")) {
attribute = attribute.fulfill(1);
// <--[tag]
// @attribute <PlayerTag.quests.points>
// @returns ElementTag(Number)
// @plugin Depenizen, Quests
// @description
// Returns the number of quest points the player has.
// -->
if (attribute.startsWith("points")) {
if (getQuester().getBaseData().contains("quest-points")) {
return new ElementTag(getQuester().getBaseData().getInt("quest-points")).getAttribute(attribute.fulfill(1));
}
return new ElementTag("0").getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <PlayerTag.quests.completed_names>
// @returns ListTag
// @plugin Depenizen, Quests
// @description
// Returns the names of quests the player has completed.
// -->
if (attribute.startsWith("completed_names")) {
ListTag list = new ListTag(getQuester().getCompletedQuests().stream().map(Quest::getName));
return list.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <PlayerTag.quests.active_names>
// @returns ListTag
// @plugin Depenizen, Quests
// @description
// Returns the names of quests the player has active.
// -->
if (attribute.startsWith("active_names")) {
ListTag list = new ListTag();
for (Quest quest : getQuester().getCurrentQuests().keySet()) {
list.add(quest.getName());
}
return list.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <PlayerTag.quests.completed>
// @returns ElementTag(Number)
// @plugin Depenizen, Quests
// @description
// Returns the number of quests the player has completed.
// -->
else if (attribute.startsWith("completed")) {
return new ElementTag(getQuester().getCompletedQuests().size()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <PlayerTag.quests.active>
// @returns ElementTag(Number)
// @plugin Depenizen, Quests
// @description
// Returns the number of quests the player has active.
// -->
else if (attribute.startsWith("active")) {
return new ElementTag(getQuester().getCurrentQuests().size()).getAttribute(attribute.fulfill(1));
}
return null;
}
return null;
}
@Override
public void adjust(Mechanism mechanism) {
}
}