Skip to content

Commit

Permalink
Fixes to NPCID: PLAYER: arguments, fixed to teleport command's 'targe…
Browse files Browse the repository at this point in the history
…t' argument.
  • Loading branch information
aufdemrand committed Apr 9, 2013
1 parent d5356ff commit eb2428a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 56 deletions.
Expand Up @@ -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
Expand All @@ -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<String> newArgs = new ArrayList<String>();

for (String arg : scriptEntry.getArguments()) {
String[] split = arg.split(":");
List<String> newArgs = new ArrayList<String>();

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);
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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");
Expand Down
Expand Up @@ -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();
Expand All @@ -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));

Expand All @@ -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;
Expand All @@ -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.
Expand Down

0 comments on commit eb2428a

Please sign in to comment.