-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
OxygenCommand.java
127 lines (105 loc) · 4.49 KB
/
OxygenCommand.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
package com.denizenscript.denizen.scripts.commands.player;
import com.denizenscript.denizen.utilities.Utilities;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizencore.exceptions.InvalidArgumentsException;
import com.denizenscript.denizencore.objects.Argument;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.ArgumentHelper;
import com.denizenscript.denizencore.scripts.ScriptEntry;
import com.denizenscript.denizencore.scripts.commands.AbstractCommand;
public class OxygenCommand extends AbstractCommand {
// <--[command]
// @Name Oxygen
// @Syntax oxygen [<#>] (type:{remaining}/maximum) (mode:{set}/add/remove)
// @Required 1
// @Short Gives or takes breath from the player.
// @Group player
//
// @Description
// Used to add to, remove from or set the amount of current oxygen of a player. Also allows for the changing of the
// player's maximum oxygen level. Value is in ticks, so 30 equals to 1 bubble.
//
// @Tags
// <PlayerTag.oxygen>
// <PlayerTag.max_oxygen>
//
// @Usage
// Use to set the player's current oxygen level to 5 bubbles.
// - oxygen 150
//
// @Usage
// Use to add 1 bubble to the player's current oxygen level.
// - oxygen 30 mode:add
//
// @Usage
// Use to set the player's maximum oxygen level to 20 bubbles.
// - oxygen 600 type:maximum
// -->
public enum Type {MAXIMUM, REMAINING}
public enum Mode {SET, ADD, REMOVE}
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry.getProcessedArgs()) {
if (!scriptEntry.hasObject("type")
&& arg.matchesPrefix("type", "t")
&& arg.matchesEnum(Type.values())) {
scriptEntry.addObject("type", arg.asElement());
}
else if (!scriptEntry.hasObject("mode")
&& arg.matchesPrefix("mode", "m")
&& arg.matchesEnum(Mode.values())) {
scriptEntry.addObject("mode", arg.asElement());
}
else if (!scriptEntry.hasObject("amount")
&& arg.matchesInteger()) {
scriptEntry.addObject("amount", arg.asElement());
}
}
if (!Utilities.entryHasPlayer(scriptEntry) || !Utilities.getEntryPlayer(scriptEntry).isValid()) {
throw new InvalidArgumentsException("Must have player context!");
}
if (!scriptEntry.hasObject("amount")) {
throw new InvalidArgumentsException("Must specify a valid amount!");
}
scriptEntry.defaultObject("type", new ElementTag("REMAINING")).defaultObject("mode", new ElementTag("SET"));
}
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag type = scriptEntry.getElement("type");
ElementTag mode = scriptEntry.getElement("mode");
ElementTag amount = scriptEntry.getElement("amount");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), type.debug() + mode.debug() + amount.debug());
}
PlayerTag player = Utilities.getEntryPlayer(scriptEntry);
switch (Type.valueOf(type.asString().toUpperCase())) {
case MAXIMUM:
switch (Mode.valueOf(mode.asString().toUpperCase())) {
case SET:
player.setMaximumAir(amount.asInt());
break;
case ADD:
player.setMaximumAir(player.getMaximumAir() + amount.asInt());
break;
case REMOVE:
player.setMaximumAir(player.getMaximumAir() - amount.asInt());
break;
}
return;
case REMAINING:
switch (Mode.valueOf(mode.asString().toUpperCase())) {
case SET:
player.setRemainingAir(amount.asInt());
break;
case ADD:
player.setRemainingAir(player.getRemainingAir() + amount.asInt());
break;
case REMOVE:
player.setRemainingAir(player.getRemainingAir() - amount.asInt());
break;
}
return;
}
}
}