-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
McMMOCommands.java
298 lines (254 loc) · 12.4 KB
/
McMMOCommands.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
package com.denizenscript.depenizen.bukkit.commands;
import com.gmail.nossr50.api.ExperienceAPI;
import com.gmail.nossr50.api.PartyAPI;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.database.DatabaseManagerFactory;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.party.PartyManager;
import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.aH;
import net.aufdemrand.denizencore.scripts.ScriptEntry;
import net.aufdemrand.denizencore.scripts.commands.AbstractCommand;
public class McMMOCommands extends AbstractCommand {
// <--[command]
// @Name mcMMO
// @Syntax mcmmo [add/remove/set] [levels/xp/xprate/vampirism/hardcore/leader] (skill:<skill>) (state:{toggle}/true/false) (qty:<#>) (party:<party>)
// @Group Depenizen
// @Plugin Depenizen, mcMMO
// @Required 1
// @Short Edits mcMMO information.
// @Description
// This command allows you to add or remove skill levels and experience for players, add or remove
// players to/from parties, set the level, xp, xprate, vampirism state, hardcore state of a player's
// skill, or set the leader of a party.
// @Tags
// <player.mcmmo. * >
// @Usage
// Use to add 5 levels to a player's skill.
// - mcmmo add levels skill:acrobatics qty:5
// @Usage
// Use to remove a player from a party.
// - mcmmo remove player:SerpentX party:SerpentPeople
// @Usage
// Use to set vampirism mode for a player's skill.
// - mcmmo set vampirism skill:woodcutting state:true
// -->
private enum Action {ADD, REMOVE, SET}
private enum State {TRUE, FALSE, TOGGLE}
private enum Type {XP, LEVELS, TOGGLE, XPRATE, LEADER, VAMPIRISM, HARDCORE}
public McMMOCommands() {
}
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
// Iterate through arguments
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("action")
&& arg.matchesEnum(Action.values())) {
scriptEntry.addObject("action", arg.asElement());
}
else if (!scriptEntry.hasObject("state")
&& arg.matchesPrefix("state")
&& arg.matchesEnum(State.values())) {
scriptEntry.addObject("state", arg.asElement());
}
else if (!scriptEntry.hasObject("party")
&& arg.matchesPrefix("party")) {
scriptEntry.addObject("party", arg.asElement());
}
else if (!scriptEntry.hasObject("skill")
&& arg.matchesPrefix("skill")) {
scriptEntry.addObject("skill", arg.asElement());
}
else if (!scriptEntry.hasObject("qty")
&& arg.matchesPrefix("q", "qty", "quantity")
&& arg.matchesPrimitive(aH.PrimitiveType.Double)) {
scriptEntry.addObject("qty", arg.asElement());
}
else if (!scriptEntry.hasObject("type")
&& arg.matchesEnum(Type.values())) {
scriptEntry.addObject("type", arg.asElement());
}
else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("action")) {
throw new InvalidArgumentsException("Must specify a valid action!");
}
if (!scriptEntry.hasObject("type")) {
throw new InvalidArgumentsException("Must specify a valid type!");
}
scriptEntry.defaultObject("state", new Element("TOGGLE"))
.defaultObject("qty", new Element(-1));
}
@Override
public void execute(ScriptEntry scriptEntry) {
BukkitScriptEntryData scriptEntryData = (BukkitScriptEntryData) scriptEntry.entryData;
// Get objects
Element action = scriptEntry.getElement("action");
Element state = scriptEntry.getElement("state");
Element type = scriptEntry.getElement("type");
Element qty = scriptEntry.getElement("qty");
Element party = scriptEntry.getElement("party");
Element skill = scriptEntry.getElement("skill");
dPlayer player = scriptEntryData.getPlayer();
// Report to dB
dB.report(scriptEntry, getName(), action.debug() + type.debug() + (state != null ? state.debug() : "") + qty.debug()
+ (party != null ? party.debug() : "") + (skill != null ? skill.debug() : ""));
switch (Action.valueOf(action.asString().toUpperCase())) {
case ADD: {
if (qty.asDouble() >= 0 && skill != null && player != null) {
switch (Type.valueOf(type.asString().toUpperCase())) {
case LEVELS: {
if (player.isOnline()) {
ExperienceAPI.addLevel(player.getPlayerEntity(), skill.asString(), qty.asInt());
}
else {
ExperienceAPI.addLevelOffline(player.getName(), skill.asString(), qty.asInt());
}
break;
}
case XP: {
if (player.isOnline()) {
ExperienceAPI.addRawXP(player.getPlayerEntity(), skill.asString(), qty.asFloat());
}
else {
ExperienceAPI.addRawXPOffline(player.getName(), skill.asString(), qty.asFloat());
}
}
}
}
else if (party != null && PartyManager.getParty(party.asString()) != null) {
PartyAPI.addToParty(player.getPlayerEntity(), party.asString());
}
break;
}
case REMOVE: {
if (qty.asDouble() >= 0 && skill != null && player != null) {
switch (Type.valueOf(type.asString().toUpperCase())) {
case LEVELS: {
if (player.isOnline()) {
ExperienceAPI.setLevel(player.getPlayerEntity(), skill.asString(), ExperienceAPI.getLevel(player.getPlayerEntity(), skill.asString()) - qty.asInt());
}
else {
ExperienceAPI.setLevelOffline(player.getName(), skill.asString(), ExperienceAPI.getLevelOffline(player.getName(), skill.asString()) - qty.asInt());
}
break;
}
case XP: {
if (player.isOnline()) {
ExperienceAPI.removeXP(player.getPlayerEntity(), skill.asString(), qty.asInt());
}
else {
ExperienceAPI.removeXPOffline(player.getName(), skill.asString(), qty.asInt());
}
break;
}
}
}
else if (player != null && player.isOnline() && party != null && PartyManager.getParty(party.asString()) != null) {
if (PartyAPI.getPartyLeader(party.asString()).equals(player.getName())) {
PartyManager.disbandParty(PartyManager.getParty(party.asString()));
}
else {
PartyAPI.removeFromParty(player.getPlayerEntity());
}
}
else if (player != null) {
DatabaseManagerFactory.getDatabaseManager().removeUser(player.getName());
}
break;
}
case SET: {
if (qty.asDouble() >= 0 && skill != null && player != null) {
switch (Type.valueOf(type.asString().toUpperCase())) {
case LEVELS: {
if (player.isOnline()) {
ExperienceAPI.setLevel(player.getPlayerEntity(), skill.asString(), qty.asInt());
}
else {
ExperienceAPI.setLevelOffline(player.getName(), skill.asString(), qty.asInt());
}
break;
}
case XP: {
if (player.isOnline()) {
ExperienceAPI.setXP(player.getPlayerEntity(), skill.asString(), qty.asInt());
}
else {
ExperienceAPI.setXPOffline(player.getName(), skill.asString(), qty.asInt());
}
break;
}
}
}
else {
switch (Type.valueOf(type.asString().toUpperCase())) {
case LEADER: {
if (party != null && PartyManager.getParty(party.asString()) != null) {
PartyAPI.setPartyLeader(party.asString(), player.getName());
}
break;
}
case XPRATE: {
if (qty.asInt() > 0) {
ExperienceConfig.getInstance().setExperienceGainsGlobalMultiplier(qty.asInt());
}
break;
}
case HARDCORE: {
if (skill == null) {
return;
}
SkillType skillType = SkillType.getSkill(skill.asString());
boolean isEnabled = Config.getInstance().getHardcoreStatLossEnabled(skillType);
switch (State.valueOf(state.asString().toUpperCase())) {
case TOGGLE: {
Config.getInstance().setHardcoreStatLossEnabled(skillType, !isEnabled);
break;
}
case TRUE: {
Config.getInstance().setHardcoreStatLossEnabled(skillType, true);
break;
}
case FALSE: {
Config.getInstance().setHardcoreStatLossEnabled(skillType, false);
break;
}
}
break;
}
case VAMPIRISM: {
if (skill == null) {
return;
}
SkillType skillType = SkillType.getSkill(skill.asString());
boolean isEnabled = Config.getInstance().getHardcoreVampirismEnabled(skillType);
switch (State.valueOf(state.asString().toUpperCase())) {
case TOGGLE: {
Config.getInstance().setHardcoreVampirismEnabled(skillType, !isEnabled);
break;
}
case TRUE: {
Config.getInstance().setHardcoreVampirismEnabled(skillType, true);
break;
}
case FALSE: {
Config.getInstance().setHardcoreVampirismEnabled(skillType, false);
break;
}
}
break;
}
}
}
break;
}
}
}
}