-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
ViveCraftPlayerTag.java
180 lines (155 loc) · 5.59 KB
/
ViveCraftPlayerTag.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
package com.denizenscript.depenizen.bukkit.objects.vivecraft;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizencore.objects.Fetchable;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.tags.ObjectTagProcessor;
import com.denizenscript.denizencore.tags.TagContext;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.depenizen.bukkit.bridges.ViveCraftBridge;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.vivecraft.VSE;
import org.vivecraft.VivePlayer;
import java.util.UUID;
public class ViveCraftPlayerTag implements ObjectTag {
// <--[ObjectType]
// @name ViveCraftPlayerTag
// @prefix vivecraft
// @base ElementTag
// @format
// The identity format for ViveCraftPlayerTag is the UUID of the relevant player.
//
// @plugin Depenizen, ViveCraft
// @description
// A ViveCraftPlayerTag represents a player which is in VR.
//
// -->
public static ViveCraftPlayerTag valueOf(String uuid) {
return valueOf(uuid, null);
}
@Fetchable("vivecraft")
public static ViveCraftPlayerTag valueOf(String string, TagContext context) {
if (string == null) {
return null;
}
try {
string = string.replace("vivecraft@", "");
UUID uuid = UUID.fromString(string);
PlayerTag player = new PlayerTag(uuid);
if (!ViveCraftBridge.isViveCraftPlayer(player.getPlayerEntity())) {
return null;
}
return new ViveCraftPlayerTag(player.getPlayerEntity());
}
catch (Exception e) {
return null;
}
}
public static boolean matches(String string) {
return string.startsWith("vivecraft@");
}
public ViveCraftPlayerTag(Player player) {
if (VSE.isVive(player)) {
this.vivePlayer = ViveCraftBridge.getViveCraftPlayer(player);
this.player = player;
}
else {
Debug.echoError("ViceCraftPlayer referenced is null!");
}
}
public VivePlayer getVivePlayer() {
return vivePlayer;
}
public Player getPlayer() {
return player;
}
public Player player;
public VivePlayer vivePlayer;
private String prefix;
@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
return tagProcessor.getObjectAttribute(this, attribute);
}
@Override
public String getPrefix() {
return prefix;
}
@Override
public boolean isUnique() {
return true;
}
@Override
public String identify() {
return "vivecraft@" + player.getUniqueId();
}
@Override
public String identifySimple() {
return identify();
}
@Override
public String toString() {
return identify();
}
@Override
public ObjectTag setPrefix(String prefix) {
this.prefix = prefix;
return this;
}
public static ObjectTagProcessor<ViveCraftPlayerTag> tagProcessor = new ObjectTagProcessor<>();
public static void register() {
// <--[tag]
// @attribute <ViveCraftPlayerTag.active_hand>
// @returns ElementTag
// @description
// Returns the active hand of the ViveCraftPlayer. Returns either right or left.
// -->
tagProcessor.registerTag(ElementTag.class, "active_hand", (attribute, object) -> {
return new ElementTag(object.getPlayer().getMetadata("activehand").get(0).asString());
});
// <--[tag]
// @attribute <ViveCraftPlayerTag.is_seated>
// @returns ElementTag(Boolean)
// @description
// Returns whether the ViveCraftPlayer sits or not.
// -->
tagProcessor.registerTag(ElementTag.class, "is_seated", (attribute, object) -> {
return new ElementTag(object.getPlayer().getMetadata("seated").get(0).asBoolean());
});
// <--[tag]
// @attribute <ViveCraftPlayerTag.position[head/left/right]>
// @returns LocationTag
// @description
// Returns a LocationTag of the given position.
// -->
tagProcessor.registerTag(LocationTag.class, "position", (attribute, object) -> {
if (!attribute.hasParam()) {
attribute.echoError("ViveCraftPlayer.position[...] tag must have an input.");
return null;
}
Location location;
ElementTag type = attribute.paramAsType(ElementTag.class);
switch (type.toString()) {
case "head":
location = (Location) object.getPlayer().getMetadata("head.pos").get(0).value();
break;
case "left":
location = (Location) object.getPlayer().getMetadata("lefthand.pos").get(0).value();
break;
case "right":
location = (Location) object.getPlayer().getMetadata("righthand.pos").get(0).value();
break;
default:
attribute.echoError("Attribute must be 'head', 'left' or 'right'");
return null;
}
if (location == null) {
attribute.echoError("Location is not valid. Did a plugin overwrite the data?");
return null;
}
return new LocationTag(location);
});
}
}