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 385e3ca26e..a19958ac68 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java @@ -145,6 +145,9 @@ public void registerCoreMembers() { registerCoreMember(HealCommand.class, "HEAL", "heal (amt:#) (target:npc|{player})", 0); + registerCoreMember(HurtCommand.class, + "HURT", "hurt (amt:#) (target:npc|{player})", 0); + registerCoreMember(HealthCommand.class, "HEALTH", "health (toggle:true|false|toggle) (set_max:#)", 1); @@ -166,6 +169,9 @@ public void registerCoreMembers() { registerCoreMember(LookcloseCommand.class, "LOOKCLOSE", "lookclose [toggle:true|false]", 1); + registerCoreMember(MountCommand.class, + "MOUNT", "mount (cancel) (location:x,y,z,world) (target(s):[npc.#]|[player.name])", 0); + registerCoreMember(ModifyBlockCommand.class, "MODIFYBLOCK", "modifyblock [location:x,y,z,world] [material:data] (radius:#) (height:#) (depth:#)", 2); diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/core/FireworkCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/FireworkCommand.java index 9178c05b02..63452f7a09 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/core/FireworkCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/FireworkCommand.java @@ -48,9 +48,11 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException } else if (aH.matchesValueArg("type", arg, ArgumentType.String)) { + String typeArg = arg.split(":", 2)[1].toUpperCase(); + for (FireworkEffect.Type typeValue : FireworkEffect.Type.values()) { - if (arg.split(":", 2)[1].toUpperCase().matches(typeValue.name())) { + if (typeArg.matches(typeValue.name())) { type = typeValue; break; @@ -107,6 +109,7 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException scriptEntry.addObject("trail", trail); } + @SuppressWarnings("unchecked") @Override public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException { // Get objects diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/core/MountCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/MountCommand.java new file mode 100644 index 0000000000..b685ea55e9 --- /dev/null +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/MountCommand.java @@ -0,0 +1,162 @@ +package net.aufdemrand.denizen.scripts.commands.core; + +import net.aufdemrand.denizen.exceptions.CommandExecutionException; +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.aH; +import net.aufdemrand.denizen.utilities.arguments.dLocation; +import net.aufdemrand.denizen.utilities.arguments.aH.ArgumentType; +import net.aufdemrand.denizen.utilities.debugging.dB; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Mounts a player on the NPC if no targets are specified. + * If targets are specified, mount them on each other in order. + * + * @author David Cernat + */ + +public class MountCommand extends AbstractCommand { + + @Override + public void parseArgs(ScriptEntry scriptEntry) + throws InvalidArgumentsException { + + // + // List of entities to be teleported. + // + List entities = new ArrayList (); + + // + // Process the arguments. + // + Boolean dismount = false; + dLocation location = null; + + for (String arg : scriptEntry.getArguments()) { + + if (aH.matchesLocation(arg)) { + + location = aH.getLocationFrom(arg); + dB.echoDebug("...location set to '%s'.", arg); + } + else if (aH.matchesArg("cancel", arg)) { + dismount = true; + dB.echoDebug("...will dismount."); + } + else if (aH.matchesValueArg("TARGETS, TARGET", arg, ArgumentType.Custom)) { + + Entity entity = null; + + for (String target : aH.getListFrom(arg)) { + // Get entity + if (aH.matchesEntityType(target)) { + + dLocation entityLocation = null; + + // Cannot spawn an entity without a location, so go through possible locations + if (location != null) + entityLocation = location; + else if (scriptEntry.getPlayer() != null) + entityLocation = new dLocation(scriptEntry.getPlayer().getLocation()); + else if (scriptEntry.getNPC() != null) + entityLocation = new dLocation(scriptEntry.getNPC().getLocation()); + + if (entityLocation != null) { + EntityType entityType = aH.getEntityFrom(target); + + dB.echoApproval("Entity type is: " + entityType.name()); + dB.echoApproval("Entity location is: " + entityLocation.toString()); + + entity = entityLocation.getWorld().spawnEntity(entityLocation, entityType); + } + } + else { + entity = dEntity.valueOf(target).getBukkitEntity(); + } + + if (entity != null) { + entities.add(entity); + } + else { + dB.echoError("Invalid TARGET '%s'!", target); + } + } + } + + else throw new InvalidArgumentsException(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg); + } + + // If there are no targets, default to the player mounting this NPC + + if (entities.size() == 0) { + entities.add(scriptEntry.getPlayer()); + entities.add(scriptEntry.getNPC().getEntity()); + } + + // If there is only one target entity, there will be no one to mount + // it, so make this player mount it by adding him/her to the start + // of the list + + if (entities.size() == 1) { + + entities.add(0, scriptEntry.getPlayer()); + } + + // Store objects in ScriptEntry for use in execute() + scriptEntry.addObject("entities", entities); + scriptEntry.addObject("location", location); + scriptEntry.addObject("dismount", dismount); + } + + @SuppressWarnings("unchecked") + @Override + public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { + + List entities = (List) scriptEntry.getObject("entities"); + final dLocation location = (dLocation) scriptEntry.getObject("location"); + Boolean dismount = (Boolean) scriptEntry.getObject("dismount"); + + // Debug output + dB.echoApproval("Executing '" + getName() + "': " + + "Targets='" + entities.toString() + "'"); + + //Collections.reverse(entities); + + Entity lastEntity = null; + + for (Entity entity : entities) { + + if (dismount) { + + entity.leaveVehicle(); + } + else { + + if (lastEntity != null) { + // Because setPassenger() is a toggle, only use it if the new passenger + // is not already the current passenger + + if (entity.getPassenger() != lastEntity) { + lastEntity.teleport(entity.getLocation()); + entity.setPassenger(lastEntity); + } + } + + lastEntity = entity; + } + } + + if (location != null) { + lastEntity.teleport(location); + } + } +} diff --git a/src/main/java/net/aufdemrand/denizen/utilities/arguments/aH.java b/src/main/java/net/aufdemrand/denizen/utilities/arguments/aH.java index 40663bb2ee..c68d7495ec 100644 --- a/src/main/java/net/aufdemrand/denizen/utilities/arguments/aH.java +++ b/src/main/java/net/aufdemrand/denizen/utilities/arguments/aH.java @@ -661,7 +661,9 @@ public static ScriptQueue getQueueFrom(String arg) { public static String getStringFrom(String arg) { if (arg.split(":").length >= 2 && ((arg.indexOf(':') < arg.indexOf(' ') || arg.indexOf(' ') == -1))) - return arg.split(":", 2)[1]; + return arg.split(":", 2)[1]; + else if (arg.split("@").length >= 2) + return arg.split("@", 2)[1]; else return arg; } @@ -792,7 +794,7 @@ public static boolean matchesColor(String arg) { * */ public static boolean matchesEntityType(String arg) { - final Pattern matchesEntityPtrn = Pattern.compile("entity:(.+)", Pattern.CASE_INSENSITIVE); + final Pattern matchesEntityPtrn = Pattern.compile("(?:entity:|e@)(.+)", Pattern.CASE_INSENSITIVE); Matcher m = matchesEntityPtrn.matcher(arg); if (m.matches()) { String group = m.group(1).toUpperCase();