From eb2428a5e509c1f54cdb813c063f2bfd01aaef1f Mon Sep 17 00:00:00 2001 From: Jeremy Schroeder Date: Tue, 9 Apr 2013 14:20:51 -0400 Subject: [PATCH] Fixes to NPCID: PLAYER: arguments, fixed to teleport command's 'target' argument. --- .../scripts/commands/CommandExecuter.java | 93 ++++++++++--------- .../commands/core/TeleportCommand.java | 19 ++-- .../denizen/utilities/arguments/dEntity.java | 4 - 3 files changed, 60 insertions(+), 56 deletions(-) diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandExecuter.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandExecuter.java index 55c99ebe5a..f490fe8485 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandExecuter.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandExecuter.java @@ -53,7 +53,8 @@ public boolean execute(ScriptEntry scriptEntry) { // Throw exception if arguments are required for this command, but not supplied. if (command.getOptions().REQUIRED_ARGS > scriptEntry.getArguments().size()) throw new InvalidArgumentsException(""); - if (scriptEntry.has_tags) { + if (scriptEntry.has_tags) + scriptEntry.setArguments(plugin.tagManager().fillArguments(scriptEntry.getArguments(), scriptEntry, true)); // Replace tags /* If using NPCID:# or PLAYER:Name arguments, these need to be changed out immediately because... * 1) Denizen/Player flags need the desired NPC/PLAYER before parseArgs's getFilledArguments() so that @@ -63,62 +64,64 @@ public boolean execute(ScriptEntry scriptEntry) { * here, instead of requiring each command to take care of the argument. */ - scriptEntry.setArguments(plugin.tagManager().fillArguments(scriptEntry.getArguments(), scriptEntry, true)); // Replace tags - List newArgs = new ArrayList(); - for (String arg : scriptEntry.getArguments()) { - String[] split = arg.split(":"); + List newArgs = new ArrayList(); + + for (String arg : scriptEntry.getArguments()) { + String[] split = arg.split(":"); - // Fill player/off-line player - if (aH.matchesValueArg("PLAYER", arg, aH.ArgumentType.String)) { - boolean foundNewPlayer = false; - dB.echoDebug("...replacing the linked Player."); - for (Player playa : Bukkit.getServer().getOnlinePlayers()) + // Fill player/off-line player + if (aH.matchesValueArg("PLAYER", arg, aH.ArgumentType.String)) { + boolean foundNewPlayer = false; + dB.echoDebug("...replacing the linked Player."); + for (Player playa : Bukkit.getServer().getOnlinePlayers()) + if (playa.getName().equalsIgnoreCase(split[1])) { + foundNewPlayer = true; + scriptEntry.setPlayer(playa); + } + if (foundNewPlayer) dB.echoDebug("...player set to '%s'.", split[1]); + else { + dB.echoDebug("This player is not online! Searching for offline player..."); + for (OfflinePlayer playa : Bukkit.getServer().getOfflinePlayers()) if (playa.getName().equalsIgnoreCase(split[1])) { + scriptEntry.setPlayer(null); + scriptEntry.setOfflinePlayer(playa); foundNewPlayer = true; - scriptEntry.setPlayer(playa); } - if (foundNewPlayer) dB.echoDebug("...player set to '%s'.", split[1]); - else { - dB.echoDebug("This player is not online! Searching for offline player..."); - for (OfflinePlayer playa : Bukkit.getServer().getOfflinePlayers()) - if (playa.getName().equalsIgnoreCase(split[1])) { - scriptEntry.setPlayer(null); - scriptEntry.setOfflinePlayer(playa); - foundNewPlayer = true; - } - } - if (foundNewPlayer) { - dB.echoDebug("Found an offline player.. linking."); - } - else { dB.echoError("Could not find a valid player!"); scriptEntry.setPlayer(null); } } - - // Fill Denizen with NPCID - else if (aH.matchesValueArg("NPCID", arg, aH.ArgumentType.String)) { - dB.echoDebug("...replacing the linked NPCID."); - try { - if (CitizensAPI.getNPCRegistry().getById(Integer.valueOf(split[1])) != null) - scriptEntry.setNPC(plugin.getNPCRegistry().getDenizen(CitizensAPI.getNPCRegistry().getById(Integer.valueOf(split[1])))); - dB.echoDebug("...NPC set to '%s'.", split[1]); - } catch (Exception e) { - dB.echoError("NPCID specified could not be matched to an NPC!"); - scriptEntry.setNPC(null); - } + if (foundNewPlayer) { + dB.echoDebug("Found an offline player.. linking."); } - else { - newArgs.add(arg); + else { dB.echoError("Could not find a valid player!"); scriptEntry.setPlayer(null); } + } + + // Fill Denizen with NPCID + else if (aH.matchesValueArg("NPCID", arg, aH.ArgumentType.String)) { + dB.echoDebug("...replacing the linked NPCID."); + try { + if (CitizensAPI.getNPCRegistry().getById(Integer.valueOf(split[1])) != null) + scriptEntry.setNPC(plugin.getNPCRegistry().getDenizen(CitizensAPI.getNPCRegistry().getById(Integer.valueOf(split[1])))); + dB.echoDebug("...NPC set to '%s'.", split[1]); + } catch (Exception e) { + dB.echoError("NPCID specified could not be matched to an NPC!"); + scriptEntry.setNPC(null); } } - // Add the arguments back to the scriptEntry. - scriptEntry.setArguments(newArgs); - // Now process non-instant tags. + else { + newArgs.add(arg); + } + } + // Add the arguments back to the scriptEntry. + scriptEntry.setArguments(newArgs); + + // Now process non-instant tags. + if (scriptEntry.has_tags) scriptEntry.setArguments(plugin.tagManager().fillArguments(scriptEntry.getArguments(), scriptEntry, false)); - // dBug the filled arguments - dB.echoDebug(ChatColor.AQUA + "+> " + ChatColor.DARK_GRAY + "Filled tags: " + scriptEntry.getArguments().toString()); - } + // dBug the filled arguments + dB.echoDebug(ChatColor.AQUA + "+> " + ChatColor.DARK_GRAY + "Filled tags: " + scriptEntry.getArguments().toString()); + // Parse the rest of the arguments for execution. command.parseArgs(scriptEntry); diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/core/TeleportCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/TeleportCommand.java index 6b814324af..42bd84ff8a 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/core/TeleportCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/TeleportCommand.java @@ -4,6 +4,7 @@ import net.aufdemrand.denizen.exceptions.InvalidArgumentsException; import net.aufdemrand.denizen.scripts.ScriptEntry; import net.aufdemrand.denizen.scripts.commands.AbstractCommand; +import net.aufdemrand.denizen.utilities.arguments.dEntity; import net.aufdemrand.denizen.utilities.arguments.dLocation; import net.aufdemrand.denizen.utilities.arguments.aH; import net.aufdemrand.denizen.utilities.arguments.aH.ArgumentType; @@ -94,12 +95,16 @@ else if (aH.matchesLocation(arg)) else if (aH.matchesValueArg("TARGETS, TARGET", arg, ArgumentType.Custom)) { teleportPlayer = false; for (String target : aH.getListFrom(arg)) { - if (CitizensAPI.getNPCRegistry().getNPC(aH.getLivingEntityFrom(target)) != null) { - teleportNPCs.add(CitizensAPI.getNPCRegistry().getNPC(aH.getLivingEntityFrom(target))); - continue; - } else if (aH.getLivingEntityFrom(target) != null && aH.getLivingEntityFrom(target) instanceof Player) { - teleportEntities.add(aH.getPlayerFrom(target)); - continue; + // Get entity + LivingEntity entity = dEntity.valueOf(target).getBukkitEntity(); + if (entity != null) { + if (CitizensAPI.getNPCRegistry().getNPC(entity) != null) { + teleportNPCs.add(CitizensAPI.getNPCRegistry().getNPC(entity)); + continue; + } else if (entity instanceof Player) { + teleportEntities.add(aH.getPlayerFrom(target)); + continue; + } } dB.echoError("Invalid TARGET '%s'!", target); } @@ -133,7 +138,7 @@ else if (aH.matchesValueArg("TARGETS, TARGET", arg, ArgumentType.Custom)) { * @param scriptEntry the ScriptEntry */ @SuppressWarnings("unchecked") - @Override + @Override public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { dLocation teleportLocation = (dLocation) scriptEntry.getObject("location"); diff --git a/src/main/java/net/aufdemrand/denizen/utilities/arguments/dEntity.java b/src/main/java/net/aufdemrand/denizen/utilities/arguments/dEntity.java index 79b4381380..41737c7047 100644 --- a/src/main/java/net/aufdemrand/denizen/utilities/arguments/dEntity.java +++ b/src/main/java/net/aufdemrand/denizen/utilities/arguments/dEntity.java @@ -95,7 +95,6 @@ public static dEntity valueOf(String string) { String entityGroup = m.group(1); String entityGroupUpper = entityGroup.toUpperCase(); - // TODO: Deprecate NPC./NPCID. if (entityGroupUpper.startsWith("N@")) { LivingEntity returnable = CitizensAPI.getNPCRegistry() .getById(Integer.valueOf(m.group(4))).getBukkitEntity(); @@ -104,7 +103,6 @@ public static dEntity valueOf(String string) { else dB.echoError("Invalid NPC! '" + entityGroup + "' could not be found. Has it been despawned or killed?"); } - // TODO: Deprecate PLAYER. else if (entityGroupUpper.startsWith("P@")) { LivingEntity returnable = aH.getPlayerFrom(m.group(4)); @@ -114,7 +112,6 @@ else if (entityGroupUpper.startsWith("P@")) { // Assume entity else { - if (aH.matchesInteger(m.group(4))) { int entityID = Integer.valueOf(m.group(4)); Entity entity = null; @@ -123,7 +120,6 @@ else if (entityGroupUpper.startsWith("P@")) { entity = ((CraftWorld) world).getHandle().getEntity(entityID); if (entity != null) break; } - if (entity != null) return new dEntity((LivingEntity) entity.getBukkitEntity()); } // Got this far? Invalid entity.