-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
BattleNightCommands.java
148 lines (114 loc) · 5 KB
/
BattleNightCommands.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
package com.morphanone.depenizenbukkit.commands;
import me.limebyte.battlenight.core.BattleNight;
import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.exceptions.CommandExecutionException;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizencore.objects.aH;
import net.aufdemrand.denizencore.scripts.ScriptEntry;
import net.aufdemrand.denizencore.scripts.commands.AbstractCommand;
public class BattleNightCommands extends AbstractCommand {
// <--[command]
// @Name BN
// @Syntax bn [add/kick/start/end]
// @Group Depenizen
// @Plugin Depenizen, BattleNight
// @Required 1
// @Stable stable
// @Short Adds/kicks player, starts/ends battle.
// @Author GnomeffinWay
// @Description
// With this command, you can add or kick players to/from the current battle. By default,
// this uses the player currently attached to the running Denizen queue. However, you can
// change the player by using Denizen's command-wide "player:" prefix. You can also use
// this command to start or end a battle.
// @Tags None
// @Usage
// Use to add the current player to a battle.
// - bn add
// @Usage
// Use to kick unattached player from a battle.
// - bn kick player:BlackCoyote
// @Usage
// Use to start a battle.
// - bn start
// @Usage
// Use to end a battle.
// - bn end
// -->
private enum Action {
ADD, KICK, START, END
}
@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", Action.valueOf(arg.getValue().toUpperCase()));
}
// The player:<name> argument is handled in Denizen automatically. No need to re-create it here
// It seems that spectator mode was removed in the latest version of BattleNight...
// Looks like they're going to find a better way to do it. Until then, let's just
// keep this code commented out.
/*
Allow - bn (spectator), which is more 0.9-like.
else if (!scriptEntry.hasObject("spectator")
&& arg.matches("spectator"))
scriptEntry.addObject("spectator", Element.TRUE);
// Keep old format for backwards compatibility
else if (!scriptEntry.hasObject("spectator")
&& arg.matchesPrefix("spectator")
&& arg.matchesPrimitive(aH.PrimitiveType.Boolean))
scriptEntry.addObject("spectator", arg.asElement());
*/
}
// Stash objects in scriptEntry for use in execute()
if (!scriptEntry.hasObject("action")) {
throw new InvalidArgumentsException("Must specify an action!");
}
// scriptEntry.defaultObject("spectator", Element.FALSE);
}
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
BukkitScriptEntryData scriptEntryData = (BukkitScriptEntryData) scriptEntry.getData();
// Get objects
Action action = (Action) scriptEntry.getObject("action");
dPlayer player = scriptEntryData.getPlayer();
// boolean spectator = scriptEntry.getElement("spectator").asBoolean();
// Report to dB
dB.report(scriptEntry, getName(),
aH.debugObj("NPC", scriptEntryData.getNPC().toString())
+ aH.debugObj("Action", action.toString())
// + aH.debugObj("Spectator", String.valueOf(spectator))
+ aH.debugObj("Player", player.getName()));
switch (action) {
case ADD: {
/*
if(spectator) {
BattleNight.instance.getAPI().getBattle().addPlayer(player.getPlayerEntity());
BattleNight.instance.getAPI().getBattle().toSpectator(player.getPlayerEntity(), true);
} else {
BattleNight.instance.getAPI().getBattle().addPlayer(player.getPlayerEntity());
}
*/
// Add the player
BattleNight.instance.getAPI().getBattle().addPlayer(player.getPlayerEntity());
return;
}
case KICK: {
BattleNight.instance.getAPI().getBattle().removePlayer(player.getPlayerEntity());
return;
}
case START: {
BattleNight.instance.getAPI().getBattle().start();
return;
}
case END: {
BattleNight.instance.getAPI().getBattle().stop();
return;
}
}
}
}