-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
DisguiseCommand.java
261 lines (229 loc) · 9.91 KB
/
DisguiseCommand.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
package com.denizenscript.depenizen.bukkit.commands.libsdisguises;
import com.denizenscript.denizencore.objects.Argument;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.disguisetypes.*;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.utilities.Utilities;
import com.denizenscript.denizencore.exceptions.InvalidArgumentsException;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.scripts.ScriptEntry;
import com.denizenscript.denizencore.scripts.commands.AbstractCommand;
import com.denizenscript.denizencore.utilities.debugging.Debug;
public class DisguiseCommand extends AbstractCommand {
public DisguiseCommand() {
setName("disguise");
setSyntax("disguise [remove/player/mob/misc] (type:<entity type>) (target:<entity>) (name:<text>) (baby:true/false) (id:<#>) (data:<#>) (self:true/false)");
setRequiredArguments(1, 6);
}
// <--[command]
// @Name disguise
// @Syntax disguise [remove/player/mob/misc] (type:<entity type>) (target:<entity>) (name:<text>) (baby:true/false) (id:<#>) (data:<#>) (self:true/false)
// @Group Depenizen
// @Plugin Depenizen, LibsDisguises
// @Required 1
// @Maximum 8
// @Short Disguises an entity as a different entity.
//
// @Description
// Disguises an entity using Lib's Disguises.
// This hides the true entity and replaces it with a fake entity as a disguise.
// The entity mimics the same actions and movement as the entity in a disguise.
//
// The required argument depends on the first argument:
// For 'mob':
// Specify an entity type.
// Optionally, specify if the mob is a baby or not (defaults to false).
// For 'player':
// Specify the player name.
// For 'misc':
// Specify a misc disguise type.
// Optionally, specify id and/or data. (Defaults to id:1 data:0).
//
// Removing a disguise shows the true entity again for all players.
// Only one disguise can be set per target, if another one is set, the previous disguise is removed.
// Optionally specify 'self:true' to hide the disguise from the target player, so they still see their normal player (defaults to false).
//
// @Tags
// <EntityTag.is_disguised>
// <EntityTag.disguise>
//
// @Usage
// Use to disguise the linked player as a different player named Bob.
// - disguise player name:Bob
//
// @Usage
// Use to disguise the linked player as a baby Zombie, which can only be seen by other players.
// - disguise mob type:ZOMBIE baby:true self:true
//
// @Usage
// Use to disguise the linked player as a Boat.
// - disguise misc type:Boat
//
// @Usage
// Use to disguise the linked player as a Sponge Block.
// - disguise misc type:Falling_Block id:19 data:0
//
// @Usage
// Use to remove the disguise from the linked player.
// - disguise remove
//
// @Usage
// Use to disguise an entity as a player named Bob.
// - disguise player target:<player.target> name:Bob
//
// @Usage
// Use to remove a disguise from an entity.
// - disguise remove target:<player.target>
//
// -->
private enum Action {REMOVE, MOB, PLAYER, MISC}
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry.getProcessedArgs()) {
if (!scriptEntry.hasObject("target")
&& arg.matchesPrefix("target")) {
scriptEntry.addObject("target", arg.asType(EntityTag.class));
}
else if (!scriptEntry.hasObject("name")
&& arg.matchesPrefix("name")) {
scriptEntry.addObject("name", arg.asElement());
}
else if (!scriptEntry.hasObject("type")
&& arg.matchesPrefix("type")) {
scriptEntry.addObject("type", arg.asElement());
}
else if (!scriptEntry.hasObject("id")
&& arg.matchesPrefix("id")) {
scriptEntry.addObject("id", arg.asElement());
}
else if (!scriptEntry.hasObject("data")
&& arg.matchesPrefix("data")) {
scriptEntry.addObject("data", arg.asElement());
}
else if (!scriptEntry.hasObject("baby")
&& arg.matchesPrefix("baby")) {
scriptEntry.addObject("baby", arg.asElement());
}
else if (!scriptEntry.hasObject("self")
&& arg.matchesPrefix("self")) {
scriptEntry.addObject("self", arg.asElement());
}
else if (!scriptEntry.hasObject("action")
&& arg.matchesEnum(Action.values())) {
scriptEntry.addObject("action", arg.asElement());
}
else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("action")) {
throw new InvalidArgumentsException("Action not specified! (remove/mob/player/misc)");
}
if (!scriptEntry.hasObject("baby")) {
scriptEntry.addObject("baby", new ElementTag(false));
}
if (!scriptEntry.hasObject("id")) {
scriptEntry.addObject("id", new ElementTag(1));
}
if (!scriptEntry.hasObject("data")) {
scriptEntry.addObject("data", new ElementTag(0));
}
if (!scriptEntry.hasObject("self")) {
scriptEntry.addObject("self", new ElementTag(false));
}
if (!scriptEntry.hasObject("target")) {
if (Utilities.entryHasPlayer(scriptEntry)) {
scriptEntry.addObject("target", Utilities.getEntryPlayer(scriptEntry).getDenizenEntity());
}
else {
throw new InvalidArgumentsException("This command does not have a player attached!");
}
}
}
@Override
public void execute(ScriptEntry scriptEntry) {
EntityTag target = scriptEntry.getObjectTag("target");
ElementTag type = scriptEntry.getObjectTag("type");
ElementTag name = scriptEntry.getObjectTag("name");
ElementTag action = scriptEntry.getObjectTag("action");
ElementTag id = scriptEntry.getObjectTag("id");
ElementTag data = scriptEntry.getObjectTag("data");
ElementTag baby = scriptEntry.getObjectTag("baby");
ElementTag self = scriptEntry.getObjectTag("self");
Debug.report(scriptEntry, getName(), action.debug()
+ (target != null ? target.debug() : "")
+ (type != null ? type.debug() : "")
+ (name != null ? name.debug() : "")
+ (id != null ? id.debug() : "")
+ (data != null ? data.debug() : "")
+ (baby != null ? baby.debug() : ""));
if (target == null) {
Debug.echoError(scriptEntry.getResidingQueue(), "Target not found!");
return;
}
if (baby == null) {
Debug.echoError(scriptEntry.getResidingQueue(), "Baby not specified!");
return;
}
if (action.asString().equalsIgnoreCase("remove")) {
DisguiseAPI.undisguiseToAll(target.getBukkitEntity());
}
else if (action.asString().equalsIgnoreCase("mob")) {
if (type == null) {
Debug.echoError(scriptEntry.getResidingQueue(), "Entity not specified!");
return;
}
MobDisguise mobDisguise = new MobDisguise(DisguiseType.valueOf(type.toString().toUpperCase()), !baby.asBoolean());
FlagWatcher watcher = mobDisguise.getWatcher();
if (name != null) {
watcher.setCustomNameVisible(true);
watcher.setCustomName(name.toString());
}
if (target.isPlayer() && self.asBoolean()) {
DisguiseAPI.disguiseIgnorePlayers(target.getBukkitEntity(), mobDisguise, target.getPlayer());
}
else {
DisguiseAPI.disguiseToAll(target.getBukkitEntity(), mobDisguise);
}
}
else if (action.asString().equalsIgnoreCase("player")) {
if (name == null) {
Debug.echoError(scriptEntry.getResidingQueue(), "Name not specified!");
return;
}
PlayerDisguise playerDisguise = new PlayerDisguise(name.toString());
if (target.isPlayer() && self.asBoolean()) {
DisguiseAPI.disguiseIgnorePlayers(target.getBukkitEntity(), playerDisguise, target.getPlayer());
}
else {
DisguiseAPI.disguiseToAll(target.getBukkitEntity(), playerDisguise);
}
}
else if (action.asString().equalsIgnoreCase("misc")) {
if (type == null) {
Debug.echoError(scriptEntry.getResidingQueue(), "Entity not specified!");
return;
}
if (id == null) {
Debug.echoError(scriptEntry.getResidingQueue(), "ID not specified!");
return;
}
if (data == null) {
Debug.echoError(scriptEntry.getResidingQueue(), "Data not specified!");
return;
}
MiscDisguise miscDisguise = new MiscDisguise(DisguiseType.valueOf(type.toString().toUpperCase()), id.asInt(), data.asInt());
FlagWatcher watcher = miscDisguise.getWatcher();
if (name != null) {
watcher.setCustomNameVisible(true);
watcher.setCustomName(name.toString());
}
if (target.isPlayer() && self.asBoolean()) {
DisguiseAPI.disguiseIgnorePlayers(target.getBukkitEntity(), miscDisguise, target.getPlayer());
}
else {
DisguiseAPI.disguiseToAll(target.getBukkitEntity(), miscDisguise);
}
}
}
}