Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ViveCraftSpigotExtensions (#400)
* Add ViveCraftSpigotExtension * Cleanup * rename activehand -> active_hand * another minor cleanup * meta fix * fix typo * minor fixes (pr review #1) * fixes (pr review 2)
- Loading branch information
1 parent
8215daa
commit 3dfaca4
Showing
8 changed files
with
336 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/com/denizenscript/depenizen/bukkit/bridges/ViveCraftBridge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.denizenscript.depenizen.bukkit.bridges; | ||
|
||
import com.denizenscript.denizencore.DenizenCore; | ||
import com.denizenscript.denizencore.objects.ObjectFetcher; | ||
import com.denizenscript.depenizen.bukkit.Bridge; | ||
import com.denizenscript.depenizen.bukkit.commands.vivecraft.ViveMirrorCommand; | ||
import com.denizenscript.depenizen.bukkit.objects.vivecraft.ViveCraftPlayerTag; | ||
import com.denizenscript.depenizen.bukkit.properties.vivecraft.ViveCraftPlayerProperties; | ||
import org.bukkit.entity.Player; | ||
import org.vivecraft.VSE; | ||
import org.vivecraft.VivePlayer; | ||
|
||
public class ViveCraftBridge extends Bridge { | ||
|
||
@Override | ||
public void init() { | ||
ViveCraftPlayerProperties.register(); | ||
ObjectFetcher.registerWithObjectFetcher(ViveCraftPlayerTag.class, ViveCraftPlayerTag.tagProcessor); | ||
DenizenCore.commandRegistry.registerCommand(ViveMirrorCommand.class); | ||
} | ||
|
||
public static boolean isViveCraftPlayer(Player player) { | ||
return VSE.isVive(player); | ||
} | ||
|
||
public static VivePlayer getViveCraftPlayer(Player player) { | ||
return VSE.vivePlayers.get(player.getUniqueId()); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
src/main/java/com/denizenscript/depenizen/bukkit/commands/vivecraft/ViveMirrorCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
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.objects.core.ListTag; | ||
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.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 ViveCraft | ||
// | ||
// @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 ListTag 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 = new ListTag(); | ||
targets.addObject(Utilities.getEntryPlayer(scriptEntry)); | ||
} | ||
List<PlayerTag> players = targets.filter(PlayerTag.class, 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 : players) { | ||
if (ViveCraftBridge.isViveCraftPlayer(target.getPlayerEntity())) { | ||
target.getPlayerEntity().sendPluginMessage(VSE.getPlugin(VSE.class), VSE.CHANNEL, vp.getUberPacket()); | ||
} | ||
} | ||
} | ||
} |
180 changes: 180 additions & 0 deletions
180
src/main/java/com/denizenscript/depenizen/bukkit/objects/vivecraft/ViveCraftPlayerTag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 { | ||
|
||
// <--[ObjectTag] | ||
// @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 registerTags() { | ||
|
||
// <--[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); | ||
}); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...va/com/denizenscript/depenizen/bukkit/properties/vivecraft/ViveCraftPlayerProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.denizenscript.depenizen.bukkit.properties.vivecraft; | ||
|
||
import com.denizenscript.denizen.objects.PlayerTag; | ||
import com.denizenscript.denizencore.objects.core.ElementTag; | ||
import com.denizenscript.depenizen.bukkit.objects.vivecraft.ViveCraftPlayerTag; | ||
import org.vivecraft.VSE; | ||
|
||
public class ViveCraftPlayerProperties { | ||
|
||
public static void register() { | ||
|
||
// <--[tag] | ||
// @attribute <PlayerTag.is_vivecraft> | ||
// @returns ElementTag(Boolean) | ||
// @plugin Depenizen, ViveCraft | ||
// @description | ||
// Returns whether the player is running on VR or not. | ||
// --> | ||
PlayerTag.registerOnlineOnlyTag(ElementTag.class,"is_vivecraft", (attribute, object) -> { | ||
return new ElementTag(VSE.isVive(object.getPlayerEntity())); | ||
}); | ||
|
||
// <--[tag] | ||
// @attribute <PlayerTag.vivecraft> | ||
// @returns ViveCraftPlayerTag | ||
// @plugin Depenizen, ViveCraft | ||
// @description | ||
// Returns the ViveCraftPlayerTag for this player. | ||
// --> | ||
PlayerTag.registerOnlineOnlyTag(ViveCraftPlayerTag.class, "vivecraft", (attribute, object) -> { | ||
return new ViveCraftPlayerTag(object.getPlayerEntity()); | ||
}); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters