-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
HeroesXPCommand.java
119 lines (99 loc) · 4.34 KB
/
HeroesXPCommand.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
package net.gnomeffinway.depenizen.commands.heroes;
import com.herocraftonline.heroes.characters.Hero;
import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizencore.exceptions.CommandExecutionException;
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;
import net.aufdemrand.denizencore.utilities.debugging.dB;
import net.gnomeffinway.depenizen.objects.heroes.HeroesClass;
import net.gnomeffinway.depenizen.objects.heroes.HeroesHero;
// <--[command]
// @Name HeroesXP
// @Syntax heroesxp [add/remove/set] [<heroesclass>] [quantity:<#.#>]
// @Group Depenizen
// @Plugin Depenizen, Heroes
// @Required 3
// @Stable stable
// @Short Manipulate Heroes' experience.
// @Author Fortifier42
// @Description
// This command allows you add, remove or set experience of a player's Hero.
// NOTE: Currently unable to change levels of Heroes' easily. (Maybe a TODO.)
// @Tags
// <player.heroes. * >
// @Usage
// Use to add 100 xp to the player's warrior class.
// - heroesxp add warrior quantity:100
// @Usage
// Use to remove 100 xp from the player's warrior class.
// - heroesxp remove heroesclass@warrior quantity:100
// @Usage
// Use to set the xp of the player's warrior class to 100.
// - heroesxp set heroesclass@warrior quantity:100
// @Usage
// Use to remove 10xp from another player's archer class.
// - heroesxp remove archer quantity:10 player:p@mcmonkey4eva
// -->
public class HeroesXPCommand extends AbstractCommand {
public enum Action {
ADD,
REMOVE,
SET
}
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
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("class")
&& arg.matchesArgumentType(HeroesClass.class)) {
scriptEntry.addObject("class", arg.asType(HeroesClass.class));
}
else if (!scriptEntry.hasObject("quantity")
&& arg.matchesPrefix("q", "qty", "quantity")
&& arg.matchesPrimitive(aH.PrimitiveType.Double)) {
scriptEntry.addObject("quantity", arg.asElement());
}
else {
arg.reportUnhandled();
}
}
if (!((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer()) {
throw new InvalidArgumentsException("This command must have a player attached!");
}
else if (!scriptEntry.hasObject("action")) {
throw new InvalidArgumentsException("Must specify a valid action!");
}
else if (!scriptEntry.hasObject("class")) {
throw new InvalidArgumentsException("Must specify a valid class!");
}
else if (!scriptEntry.hasObject("quantity")) {
throw new InvalidArgumentsException("Must specify a valid quantity!");
}
}
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
BukkitScriptEntryData scriptEntryData = (BukkitScriptEntryData) scriptEntry.entryData;
Element action = scriptEntry.getElement("action");
HeroesClass hclass = (HeroesClass) scriptEntry.getObject("class");
Element quantity = scriptEntry.getElement("quantity");
dPlayer player = scriptEntryData.getPlayer();
dB.report(scriptEntry, getName(),
action.debug() + hclass.debug() + quantity.debug());
Hero hero = new HeroesHero(player).getHero();
switch (Action.valueOf(action.asString().toUpperCase())) {
case ADD:
hero.addExp(quantity.asDouble(), hclass.getHeroClass(), player.getLocation());
case REMOVE:
hero.setExperience(hclass.getHeroClass(),
hero.getExperience(hclass.getHeroClass()) - quantity.asDouble());
case SET:
hero.setExperience(hclass.getHeroClass(), quantity.asDouble());
}
}
}