-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathAttachCommand.java
More file actions
54 lines (47 loc) · 2.38 KB
/
AttachCommand.java
File metadata and controls
54 lines (47 loc) · 2.38 KB
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
package com.denizenscript.clientizen.scripts.commands;
import com.denizenscript.clientizen.objects.EntityTag;
import com.denizenscript.denizencore.exceptions.InvalidArgumentsRuntimeException;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.scripts.ScriptEntry;
import com.denizenscript.denizencore.scripts.commands.AbstractCommand;
import com.denizenscript.denizencore.scripts.commands.generator.ArgDefaultNull;
import com.denizenscript.denizencore.scripts.commands.generator.ArgLinear;
import com.denizenscript.denizencore.scripts.commands.generator.ArgName;
import com.denizenscript.denizencore.scripts.commands.generator.ArgPrefixed;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class AttachCommand extends AbstractCommand {
public record AttachData(boolean noShadow, boolean noAnimation) {}
public static Map<UUID, List<EntityTag>> attachMap = new HashMap<>();
public static Map<UUID, AttachData> attachedEntities = new HashMap<>();
public AttachCommand() {
setName("attach");
setSyntax("attach [<entity>|...] [to:<entity>] (cancel) (no_shadow) (no_animation)");
setRequiredArguments(2, 5);
isProcedural = false;
autoCompile();
}
public static void autoExecute(ScriptEntry scriptEntry,
@ArgLinear @ArgName("entities") ListTag attachingEntities,
@ArgDefaultNull @ArgPrefixed @ArgName("to") EntityTag toEntity,
@ArgName("cancel") boolean cancel,
@ArgName("no_shadow") boolean noShadow,
@ArgName("no_animation") boolean noAnimation) {
if (!cancel && toEntity == null) {
throw new InvalidArgumentsRuntimeException("Must specify an entity to attach to");
}
List<EntityTag> attaching = attachingEntities.filter(EntityTag.class, scriptEntry.context);
AttachData attachData = new AttachData(noShadow, noAnimation);
if (attachMap.containsKey(toEntity.uuid)) {
attachMap.get(toEntity.uuid).addAll(attaching);
}
else {
attachMap.put(toEntity.uuid, attaching);
}
for (EntityTag entityTag : attaching) {
attachedEntities.put(entityTag.uuid, attachData);
}
}
}