diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/core/EquipCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/EquipCommand.java index ce3e918971..997fea0c4b 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/core/EquipCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/EquipCommand.java @@ -3,6 +3,8 @@ import java.util.HashMap; import java.util.Map; +import org.bukkit.entity.Player; + import net.aufdemrand.denizen.exceptions.CommandExecutionException; import net.aufdemrand.denizen.exceptions.InvalidArgumentsException; import net.aufdemrand.denizen.scripts.ScriptEntry; @@ -16,10 +18,13 @@ public class EquipCommand extends AbstractCommand{ + private enum TargetType { NPC, PLAYER } + @Override public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException { + TargetType targetType = TargetType.NPC; Map equipment = new HashMap(); for (String arg : scriptEntry.getArguments()) { @@ -39,9 +44,14 @@ else if (aH.matchesValueArg("LEGS, LEGGINGS", arg, ArgumentType.String)) { else if (aH.matchesValueArg("BOOTS", arg, ArgumentType.String)) { equipment.put("boots", getItem(arg)); } + else if (aH.matchesArg("PLAYER", arg)) { + targetType = TargetType.PLAYER; + dB.echoDebug("... will be equipped by the player!"); + } } - + scriptEntry.addObject("equipment", equipment); + scriptEntry.addObject("targetType", targetType); } @SuppressWarnings("unchecked") @@ -49,26 +59,58 @@ else if (aH.matchesValueArg("BOOTS", arg, ArgumentType.String)) { public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { - NPC npc = scriptEntry.getNPC().getCitizen(); Map equipment = (Map) scriptEntry.getObject("equipment"); + TargetType targetType = (TargetType) scriptEntry.getObject("targetType"); - if (!npc.hasTrait(Equipment.class)) npc.addTrait(Equipment.class); - Equipment trait = npc.getTrait(Equipment.class); + if (targetType.toString().equals("NPC")) { + + NPC npc = scriptEntry.getNPC().getCitizen(); + + if (npc != null) { - if (equipment.get("hand") != null) { - trait.set(0, equipment.get("hand").getItemStack()); - } - if (equipment.get("head") != null) { - trait.set(1, equipment.get("head").getItemStack()); - } - if (equipment.get("chest") != null) { - trait.set(2, equipment.get("chest").getItemStack()); - } - if (equipment.get("legs") != null) { - trait.set(3, equipment.get("legs").getItemStack()); + if (!npc.hasTrait(Equipment.class)) npc.addTrait(Equipment.class); + + Equipment trait = npc.getTrait(Equipment.class); + + if (equipment.get("hand") != null) { + trait.set(0, equipment.get("hand").getItemStack()); + } + if (equipment.get("head") != null) { + trait.set(1, equipment.get("head").getItemStack()); + } + if (equipment.get("chest") != null) { + trait.set(2, equipment.get("chest").getItemStack()); + } + if (equipment.get("legs") != null) { + trait.set(3, equipment.get("legs").getItemStack()); + } + if (equipment.get("boots") != null) { + trait.set(4, equipment.get("boots").getItemStack()); + } + } } - if (equipment.get("boots") != null) { - trait.set(4, equipment.get("boots").getItemStack()); + else { + + Player player = scriptEntry.getPlayer(); + + if (player != null) { + + if (equipment.get("hand") != null) { + player.getInventory().setItemInHand(equipment.get("hand").getItemStack()); + } + if (equipment.get("head") != null) { + player.getInventory().setHelmet(equipment.get("head").getItemStack()); + } + if (equipment.get("chest") != null) { + player.getInventory().setChestplate(equipment.get("chest").getItemStack()); + } + if (equipment.get("legs") != null) { + player.getInventory().setLeggings(equipment.get("legs").getItemStack()); + } + if (equipment.get("boots") != null) { + player.getInventory().setBoots(equipment.get("boots").getItemStack()); + } + } } } diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/core/FlyCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/FlyCommand.java index 35fd928297..faf2da0897 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/core/FlyCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/FlyCommand.java @@ -231,14 +231,6 @@ public void run() { destinations.remove(0); } } - - // Check if the entity has collided with something - // using the most basic possible calculation - - if (entity.getLocation().add(v3).getBlock().getType().toString().equals("AIR") == false) { - - flying = false; - } } else {