This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
/
VanishCommand.java
75 lines (67 loc) · 3.12 KB
/
VanishCommand.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
package com.denizenscript.denizen2sponge.commands.entity;
import com.denizenscript.denizen2core.commands.AbstractCommand;
import com.denizenscript.denizen2core.commands.CommandEntry;
import com.denizenscript.denizen2core.commands.CommandQueue;
import com.denizenscript.denizen2core.tags.objects.BooleanTag;
import com.denizenscript.denizen2core.utilities.debugging.ColorSet;
import com.denizenscript.denizen2sponge.tags.objects.EntityTag;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.entity.Entity;
public class VanishCommand extends AbstractCommand {
// <--[command]
// @Since 0.4.0
// @Name vanish
// @Arguments <entity> <state>
// @Short changes the vanish state of an entity.
// @Updated 2018/02/11
// @Group Entity
// @Minimum 2
// @Maximum 2
// @Named ignore_collisions (BooleanTag) Sets whether this vanished entity can collide with other entities.
// @Named untargetable (BooleanTag) Sets whether this vanished entity can be selected as a target.
// @Description
// Changes the vanish state of an entity. Vanished entities don't send packets to clients,
// but they can still affect collisions or target selection server-side. This can be adjusted
// with the "ignore_collisions" and "untargetable" named arguments.
// but update packets are still sent to the server and clients.
// Related commands: <@link command invisible>invisible<@/link>.
// @Example
// # Vanishes the player and makes it untargetable and uncollidable.
// - vanish <player> true --ignore_collisions true --untargetable true
// -->
@Override
public String getName() {
return "vanish";
}
@Override
public String getArguments() {
return "<entity> <state>";
}
@Override
public int getMinimumArguments() {
return 2;
}
@Override
public int getMaximumArguments() {
return 2;
}
@Override
public void execute(CommandQueue queue, CommandEntry entry) {
EntityTag entityTag = EntityTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
BooleanTag state = BooleanTag.getFor(queue.error, entry.getArgumentObject(queue, 1));
Entity entity = entityTag.getInternal();
entity.offer(Keys.VANISH, state.getInternal());
if (entry.namedArgs.containsKey("ignore_collisions")) {
BooleanTag bt = BooleanTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "ignore_collisions"));
entity.offer(Keys.VANISH_IGNORES_COLLISION, bt.getInternal());
}
if (entry.namedArgs.containsKey("untargetable")) {
BooleanTag bt = BooleanTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "untargetable"));
entity.offer(Keys.VANISH_PREVENTS_TARGETING, bt.getInternal());
}
if (queue.shouldShowGood()) {
queue.outGood("Setting vanish state of entity '" + ColorSet.emphasis + entityTag.debug()
+ ColorSet.good + "' to '" + ColorSet.emphasis + state.debug() + ColorSet.good + "'!");
}
}
}