Skip to content

Commit

Permalink
Add Player argument to Equip command.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcernat committed Jun 11, 2013
1 parent 7f460e0 commit b5cf550
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 25 deletions.
Expand Up @@ -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;
Expand All @@ -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<String, dItem> equipment = new HashMap<String,dItem>();

for (String arg : scriptEntry.getArguments()) {
Expand All @@ -39,36 +44,73 @@ 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")
@Override
public void execute(ScriptEntry scriptEntry)
throws CommandExecutionException {

NPC npc = scriptEntry.getNPC().getCitizen();
Map<String, dItem> equipment = (Map<String, dItem>) 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());
}
}
}

}
Expand Down
Expand Up @@ -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 {

Expand Down

0 comments on commit b5cf550

Please sign in to comment.