Skip to content

Commit

Permalink
Add Region argument to Remove command.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcernat committed Jun 30, 2013
1 parent 3d4bb67 commit 1ae0da5
Showing 1 changed file with 26 additions and 5 deletions.
Expand Up @@ -8,9 +8,11 @@
import net.aufdemrand.denizen.exceptions.CommandExecutionException;
import net.aufdemrand.denizen.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.objects.aH.ArgumentType;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.depends.WorldGuardUtilities;

/**
* Safely removes an NPC.
Expand All @@ -24,39 +26,58 @@ public class RemoveCommand extends AbstractCommand {
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

EntityType entityType = null;
String region = null;

for (String arg : scriptEntry.getArguments()) {
if (aH.matchesEntityType(arg)) {
entityType = aH.getEntityTypeFrom(arg);
dB.echoDebug("...will remove all '%s'.", arg);
}
else if (aH.matchesValueArg("region", arg, ArgumentType.String)) {
region = aH.getStringFrom(arg);
dB.echoDebug("...in region " + region);
}
}

scriptEntry.addObject("entityType", entityType);
scriptEntry.addObject("region", region);
}

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

EntityType entityType = (EntityType) scriptEntry.getObject("entityType");
String region = (String) scriptEntry.getObject("region");

// If no entity type chosen, remove this NPC
// If no entity type or region chosen, remove this NPC

if (entityType == null) {
if (entityType == null && region == null) {

scriptEntry.getNPC().getCitizen().destroy();

dB.echoDebug("...have removed NPC '%s'.", String.valueOf(scriptEntry.getNPC().getCitizen().getId()));
}

// Else, remove all entities of this type from all worlds
// Else, remove regular entities

else {

for (World world: Bukkit.getWorlds()) {

for (Entity entity : world.getEntities()) {
if (entity.getType().equals(entityType)) {
if (region != null) {

if (WorldGuardUtilities.checkWGRegion(entity.getLocation(), region)) {

if (entityType == null) {
entity.remove();
}
else if (entity.getType().equals(entityType)) {
entity.remove();
}
}
}

else if (entity.getType().equals(entityType)) {

entity.remove();
}
Expand Down

0 comments on commit 1ae0da5

Please sign in to comment.