diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java index a80bfe58e7..d9297a1a01 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java @@ -191,7 +191,7 @@ public void registerCoreMembers() { "LOG", "log [] (type:severe/info/warning/fine/finer/finest) [file:]", 2); registerCoreMember(LookCommand.class, - "LOOK", "look (player/npc) []", 1); + "LOOK", "look (entity) [location] // Note: not specifying entity will default to attached NPC", 1); registerCoreMember(LookcloseCommand.class, "LOOKCLOSE", "lookclose [state:true/false]", 1); diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/LookCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/LookCommand.java index 5c3cf33859..3c5c8d709e 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/LookCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/LookCommand.java @@ -1,5 +1,10 @@ package net.aufdemrand.denizen.scripts.commands.entity; +import net.aufdemrand.denizen.objects.dEntity; +import net.aufdemrand.denizen.objects.dLocation; +import net.aufdemrand.denizen.objects.dNPC; +import net.citizensnpcs.api.CitizensAPI; +import net.citizensnpcs.api.trait.Trait; import org.bukkit.Location; import org.bukkit.entity.LivingEntity; @@ -22,134 +27,47 @@ public class LookCommand extends AbstractCommand { - // TODO: Finish - - /* LOOK [[DIRECTION]|[BOOKMARK]:'LOCATION BOOKMARK'|[CLOSE|AWAY]]*/ - - /* Arguments: [] - Required, () - Optional - * - * [Requires one of the below] - * DIRECTION - Valid Directions: UP DOWN LEFT RIGHT NORTH SOUTH EAST WEST BACK AT - * LOCATION BOOKMARK - gets Yaw/Pitch from a location bookmark. - * CLOSE/AWAY - toggles the NPC's LookClose trait - * - * Modifiers: - * (NPCID:#) Changes the Denizen to the Citizens2 NPCID - * (DURATION:#) Reverts to the previous head position after # amount of seconds. - */ - - private enum TargetType { NPC, PLAYER } - private enum Direction { UP, DOWN, LEFT, RIGHT, NORTH, SOUTH, EAST, WEST, BACK, AT, CLOSE, AWAY } - - + // look (e@entity) [l@location] // Note: not specifying entity will default to attached NPC @Override public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException { - - TargetType targetType = TargetType.NPC; - Integer duration = null; - Direction direction = null; - Location location = null; - - for (String arg : scriptEntry.getArguments()) { - - // If argument is a duration - if (aH.matchesDuration(arg)) { - duration = aH.getIntegerFrom(arg); - dB.echoDebug("...look duration set to '%s'.", arg); - } - - else if (aH.matchesArg("PLAYER", arg)) { - targetType = TargetType.PLAYER; - dB.echoDebug("... will affect the player!"); - } - - // If argument is a LOCATION modifier - else if (aH.matchesLocation(arg)) { - location = aH.getLocationFrom(arg); - dB.echoDebug("...location set"); - } - - // If argument is a Direction - else { - for (Direction thisDirection : Direction.values()) { - if (arg.toUpperCase().equals(thisDirection.name())) { - direction = Direction.valueOf(arg); - dB.echoDebug("...set look direction '%s'.", arg); - } - } - } - } - - // If TARGET is NPC/PLAYER and no NPC/PLAYER available, throw exception. - if (targetType == TargetType.PLAYER && scriptEntry.getPlayer() == null) throw new InvalidArgumentsException(Messages.ERROR_NO_PLAYER); - else if (targetType == TargetType.NPC && scriptEntry.getNPC() == null) throw new InvalidArgumentsException(Messages.ERROR_NO_NPCID); - scriptEntry.addObject("target", targetType) - .addObject("location", location); - } - - @Override - public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { - - TargetType target = (TargetType) scriptEntry.getObject("target"); - Location location = (Location) scriptEntry.getObject("location"); - LivingEntity entity = null; - - if (target.name().matches("NPC")) { - entity = scriptEntry.getNPC().getCitizen().getBukkitEntity(); - - // Turn off the NPC's lookclose - scriptEntry.getNPC().getCitizen().getTrait(LookClose.class).lookClose(false); - } - else { - entity = scriptEntry.getPlayer().getPlayerEntity(); - } - - if (location != null) { - Rotation.faceLocation(entity, location); - } - - - } + for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) { - - - /* - // MADE IT THIS FAR + if (!scriptEntry.hasObject("location") + && arg.matchesArgumentType(dLocation.class)) + scriptEntry.addObject("location", arg.asType(dLocation.class)); - if (theDenizen == null) { - aH.echoError("Seems this was sent from a TASK-type script. Must use NPCID:# to specify a Denizen NPC!"); - return false; - } + if (!scriptEntry.hasObject("entity") + && arg.matchesArgumentType(dEntity.class)) + scriptEntry.addObject("entity", arg.asType(dEntity.class)); - if (theLocation != null) { - look(theEntity, theDenizen, direction, duration, theLocation); - return true; - } + } - if (theEntity == null) theEntity = (LivingEntity) theEntry.getPlayer(); - if (direction != null) look(theEntity, theDenizen, direction, duration, theLocation); + if (!scriptEntry.hasObject("entity") + && scriptEntry.hasNPC() + && scriptEntry.getNPC().isSpawned()) + scriptEntry.addObject("entity", new dEntity(scriptEntry.getNPC().getEntity())); - return true; + if (!scriptEntry.hasObject("location") || !scriptEntry.hasObject("entity")) + throw new InvalidArgumentsException("Must specify a location and spawned entity!"); } + @Override + public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { + + dLocation loc = (dLocation) scriptEntry.getObject("location"); + dEntity ent = (dEntity) scriptEntry.getObject("entity"); - private void look(LivingEntity theEntity, dNPC theDenizen, Direction lookDir, Integer duration, Location lookLoc) { + dB.report(getName(), loc.debug() + ent.debug()); - Location restoreLocation = theDenizen.getEntity().getLocation(); - dNPC restoreDenizen = theDenizen; - Boolean restoreLookClose = theDenizen.isLookingClose(); - String lookWhere = "NOWHERE"; + Rotation.faceLocation(ent.getLivingEntity(), loc); - if (lookDir != null) lookWhere = lookDir.name(); + } - if (lookWhere.equals("CLOSE")) { - theDenizen.lookClose(true); - } - else if (lookWhere.equals("AWAY")) { - theDenizen.lookClose(false); - } + + + /* else if (lookWhere.equals("LEFT")) { theDenizen.lookClose(false); @@ -205,49 +123,6 @@ else if (lookWhere.equals("EAST")) { theDenizen.getHandle().az = theDenizen.getHandle().yaw; } - else if (lookWhere.equals("AT")) { - theDenizen.lookClose(false); - faceEntity(theDenizen.getEntity(), theEntity); - } - - else if (lookLoc != null) { - theDenizen.lookClose(false); - theDenizen.getHandle().pitch = lookLoc.getPitch(); - theDenizen.getHandle().yaw = lookLoc.getYaw(); - theDenizen.getHandle().az = theDenizen.getHandle().yaw; - } - - - // If duration is set... - - if (duration != null) { - - if (taskMap.containsKey(theDenizen.getCitizensEntity().getId())) { - try { - plugin.getServer().getScheduler().cancelTask(taskMap.get(theDenizen.getId())); - } catch (Exception e) { } - } - - aH.echoDebug("Setting delayed task: RESET LOOK"); - - taskMap.put(theDenizen.getCitizensEntity().getId(), plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new FourItemRunnable(restoreDenizen, restoreLocation, restoreLookClose, theDenizen.getLocation().getYaw()) { - @Override - public void run(dNPC denizen, Location location, Boolean lookClose, Float checkYaw) { - aH.echoDebug(ChatColor.YELLOW + "//DELAYED//" + ChatColor.WHITE + " Running delayed task: RESET LOOK."); - denizen.lookClose(lookClose); - - // if (denizen.getLocation().getYaw() == checkYaw) { - denizen.getHandle().yaw = location.getYaw(); - denizen.getHandle().pitch = location.getPitch(); - denizen.getHandle().az = denizen.getHandle().yaw; - // } - } - }, duration * 20)); - } - - - } - */ }