From abb84a380da9c3a5307324ed58d24a673cfb5413 Mon Sep 17 00:00:00 2001 From: Xenmai Date: Wed, 18 Oct 2017 20:02:16 +0200 Subject: [PATCH] Rotation arg for Teleport and Spawn --- .../commands/entity/SpawnCommand.java | 30 ++++++++++++++----- .../commands/entity/TeleportCommand.java | 27 +++++++++++++---- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/denizenscript/denizen2sponge/commands/entity/SpawnCommand.java b/src/main/java/com/denizenscript/denizen2sponge/commands/entity/SpawnCommand.java index 5b44bad..28b7da0 100644 --- a/src/main/java/com/denizenscript/denizen2sponge/commands/entity/SpawnCommand.java +++ b/src/main/java/com/denizenscript/denizen2sponge/commands/entity/SpawnCommand.java @@ -24,15 +24,16 @@ public class SpawnCommand extends AbstractCommand { // @Name spawn // @Arguments [map of properties] // @Short spawns a new entity. - // @Updated 2016/09/26 + // @Updated 2017/10/18 // @Group Entity // @Minimum 2 // @Maximum 3 + // @Named rotation (LocationTag) Sets the entity's rotation. // @Tag <[spawn_success]> (BooleanTag) returns whether the spawn passed. // @Tag <[spawn_entity]> (EntityTag) returns the entity that was spawned (only if the spawn passed). // @Description - // Spawns an entity at the specified location. Optionally, specify a MapTag of properties - // to spawn the entity with those values automatically set on it. + // Spawns an entity at the specified location. Optionally, specify rotation and a + // MapTag of properties to spawn the entity with those values automatically set on it. // Related information: <@link explanation Entity Types>entity types<@/link>. // @Example // # Spawns a sheep that feels the burn. @@ -88,11 +89,24 @@ public void execute(CommandQueue queue, CommandEntry entry) { } } } - if (queue.shouldShowGood()) { - queue.outGood("Spawning an entity of type " - + ColorSet.emphasis + entityType.getId() + ColorSet.good - + " with the following properties: " + ColorSet.emphasis + propertyMap.debug() - + " at location " + ColorSet.emphasis + locationTag.debug() + ColorSet.good + "..."); + if (entry.namedArgs.containsKey("rotation")) { + LocationTag rot = LocationTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "rotation")); + entity.setTransform(entity.getTransform().setRotation(rot.getInternal().toVector3d())); + if (queue.shouldShowGood()) { + queue.outGood("Spawning an entity of type " + ColorSet.emphasis + entityType.getId() + + ColorSet.good + " with the following properties: " + ColorSet.emphasis + + propertyMap.debug() + ColorSet.good + " at location " + ColorSet.emphasis + + locationTag.debug() + ColorSet.good + " and rotation " + ColorSet.emphasis + + rot.debug() + ColorSet.good + "..."); + } + } + else { + if (queue.shouldShowGood()) { + queue.outGood("Spawning an entity of type " + ColorSet.emphasis + entityType.getId() + + ColorSet.good + " with the following properties: " + ColorSet.emphasis + + propertyMap.debug() + ColorSet.good + " at location " + ColorSet.emphasis + + locationTag.debug() + ColorSet.good + "..."); + } } boolean passed = location.world.spawnEntity(entity); // TODO: "Cause" argument! diff --git a/src/main/java/com/denizenscript/denizen2sponge/commands/entity/TeleportCommand.java b/src/main/java/com/denizenscript/denizen2sponge/commands/entity/TeleportCommand.java index 0715b72..b77836d 100644 --- a/src/main/java/com/denizenscript/denizen2sponge/commands/entity/TeleportCommand.java +++ b/src/main/java/com/denizenscript/denizen2sponge/commands/entity/TeleportCommand.java @@ -13,12 +13,13 @@ public class TeleportCommand extends AbstractCommand { // @Name teleport // @Arguments // @Short teleports the entity to a location. - // @Updated 2016/09/05 + // @Updated 2017/10/18 // @Group Entity // @Minimum 2 // @Maximum 2 + // @Named rotation (LocationTag) Sets the entity's rotation. // @Description - // Teleports the entity to a location. + // Teleports the entity to a location. Optionally specify a rotation. // TODO: Explain more! // @Example // # This example teleports the player five blocks upward @@ -49,10 +50,24 @@ public int getMaximumArguments() { public void execute(CommandQueue queue, CommandEntry entry) { EntityTag ent = EntityTag.getFor(queue.error, entry.getArgumentObject(queue, 0)); LocationTag loc = LocationTag.getFor(queue.error, entry.getArgumentObject(queue, 1)); - if (queue.shouldShowGood()) { - queue.outGood("Teleporting " + ColorSet.emphasis + ent.debug() + ColorSet.good - + " to " + ColorSet.emphasis + loc.debug() + ColorSet.good + "!"); + if (entry.namedArgs.containsKey("rotation")) { + LocationTag rot = LocationTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "rotation")); + ent.getInternal().setTransform(ent.getInternal().getTransform() + .setLocation(loc.getInternal().toLocation()) + .setRotation(rot.getInternal().toVector3d())); // TODO: use the returned boolean? + if (queue.shouldShowGood()) { + queue.outGood("Teleporting " + ColorSet.emphasis + ent.debug() + ColorSet.good + + " to location " + ColorSet.emphasis + loc.debug() + ColorSet.good + + " and rotation " + ColorSet.emphasis + rot.debug() + "!"); + } } - ent.getInternal().setLocation(loc.getInternal().toLocation()); // TODO: use the returned boolean? + else { + ent.getInternal().setLocation(loc.getInternal().toLocation()); // TODO: use the returned boolean? + if (queue.shouldShowGood()) { + queue.outGood("Teleporting " + ColorSet.emphasis + ent.debug() + ColorSet.good + + " to location " + ColorSet.emphasis + loc.debug() + ColorSet.good + "!"); + } + } + } }