-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
ViveMirrorCommand.java
84 lines (78 loc) · 3.38 KB
/
ViveMirrorCommand.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
package com.denizenscript.depenizen.bukkit.commands.vivecraft;
import com.denizenscript.denizen.objects.NPCTag;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizen.utilities.Utilities;
import com.denizenscript.denizencore.exceptions.InvalidArgumentsRuntimeException;
import com.denizenscript.denizencore.scripts.ScriptEntry;
import com.denizenscript.denizencore.scripts.commands.AbstractCommand;
import com.denizenscript.denizencore.scripts.commands.generator.*;
import com.denizenscript.depenizen.bukkit.bridges.ViveCraftBridge;
import com.denizenscript.depenizen.bukkit.objects.vivecraft.ViveCraftPlayerTag;
import org.bukkit.entity.Player;
import org.vivecraft.VSE;
import org.vivecraft.VivePlayer;
import java.util.Collections;
import java.util.List;
public class ViveMirrorCommand extends AbstractCommand {
public ViveMirrorCommand() {
setName("vivemirror");
setSyntax("vivemirror [<npc>] [mirror:<vivecraftplayer>] (targets:{player}/<player>|...)");
setRequiredArguments(2, 3);
autoCompile();
}
// <--[command]
// @Name ViveMirror
// @Syntax vivemirror [<npc>] [mirror:<vivecraftplayer>] (targets:{player}/<player>|...)
// @Required 2
// @Maximum 3
// @Short Mirrors a ViveCraftPlayers pose to the npc, once.
// @Group Depenizen
// @plugin Depenizen, ViveCraft
//
// @Tags
// None
//
// @Description
// Mirrors a ViveCraftPlayers pose to the npc, once.
//
// Ideally should run every tick.
//
// Specify a vivecraftplayer that will be mirrored to the NPC.
// Optionally, specify a list of targets to show the NPCs pose to (targets must be in VR to see the effect).
//
// @Usage
// Use to mirror the current players pose.
// - vivemirror <npc> mirror:<player.vivecraft>
//
// @Usage
// Use to show your dancing skills to other players.
// - vivemirror <npc> mirror:<player.vivecraft> targets:<server.online_players>
//
// -->
public static void autoExecute(ScriptEntry scriptEntry,
@ArgLinear @ArgName("npc") @ArgRaw NPCTag npc,
@ArgPrefixed @ArgName("mirror") ViveCraftPlayerTag mirror,
@ArgPrefixed @ArgName("targets") @ArgDefaultNull @ArgSubType(PlayerTag.class) List<PlayerTag> targets) {
if (!(npc.getEntity() instanceof Player)) {
throw new InvalidArgumentsRuntimeException("NPC must be a PLAYER type NPC.");
}
if (targets == null) {
if (!Utilities.entryHasPlayer(scriptEntry)) {
throw new InvalidArgumentsRuntimeException("Missing player input.");
}
targets = Collections.singletonList(Utilities.getEntryPlayer(scriptEntry));
}
VivePlayer vp = new VivePlayer((Player) npc.getLivingEntity());
VivePlayer copy = mirror.getVivePlayer();
vp.worldScale = copy.worldScale;
vp.heightScale = copy.heightScale;
vp.hmdData = copy.hmdData;
vp.controller0data = copy.controller0data;
vp.controller1data = copy.controller1data;
for (PlayerTag target : targets) {
if (ViveCraftBridge.isViveCraftPlayer(target.getPlayerEntity())) {
target.getPlayerEntity().sendPluginMessage(VSE.getPlugin(VSE.class), VSE.CHANNEL, vp.getUberPacket());
}
}
}
}