diff --git a/src/main/java/net/citizensnpcs/Citizens.java b/src/main/java/net/citizensnpcs/Citizens.java index a9431cacf..730e59a74 100644 --- a/src/main/java/net/citizensnpcs/Citizens.java +++ b/src/main/java/net/citizensnpcs/Citizens.java @@ -236,19 +236,6 @@ public class Citizens extends JavaPlugin implements CitizensPlugin { } } - private void setupEconomy() { - try { - RegisteredServiceProvider provider = Bukkit.getServicesManager().getRegistration( - Economy.class); - if (provider != null && provider.getProvider() != null) { - Economy economy = provider.getProvider(); - Bukkit.getPluginManager().registerEvents(new PaymentListener(economy), this); - } - } catch (NoClassDefFoundError e) { - Messaging.log("Unable to use economy handling. Has Vault been enabled?"); - } - } - @Override public void onImplementationChanged() { Messaging.severe("Citizens implementation changed, disabling plugin."); @@ -293,6 +280,19 @@ public class Citizens extends JavaPlugin implements CitizensPlugin { }); } + private void setupEconomy() { + try { + RegisteredServiceProvider provider = Bukkit.getServicesManager().getRegistration( + Economy.class); + if (provider != null && provider.getProvider() != null) { + Economy economy = provider.getProvider(); + Bukkit.getPluginManager().registerEvents(new PaymentListener(economy), this); + } + } catch (NoClassDefFoundError e) { + Messaging.log("Unable to use economy handling. Has Vault been enabled?"); + } + } + private void setupScripting() { contextClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(getClassLoader()); diff --git a/src/main/java/net/citizensnpcs/EventListen.java b/src/main/java/net/citizensnpcs/EventListen.java index dfe40b5a8..dc774322e 100644 --- a/src/main/java/net/citizensnpcs/EventListen.java +++ b/src/main/java/net/citizensnpcs/EventListen.java @@ -288,11 +288,11 @@ public class EventListen implements Listener { } } + private static EventListen instance; + public static void add(Location loc, int id) { if (instance == null) return; instance.toRespawn.put(instance.toCoord(loc.getChunk()), id); } - - private static EventListen instance; } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/command/command/NPCCommands.java b/src/main/java/net/citizensnpcs/command/command/NPCCommands.java index 04e118673..fa9ef33dd 100644 --- a/src/main/java/net/citizensnpcs/command/command/NPCCommands.java +++ b/src/main/java/net/citizensnpcs/command/command/NPCCommands.java @@ -153,8 +153,11 @@ public class NPCCommands { from.save(key); copy.load(key); - if (copy.isSpawned() && sender instanceof Player) - copy.getBukkitEntity().teleport((Player) sender); + if (copy.isSpawned() && sender instanceof Player) { + Player player = (Player) sender; + copy.getBukkitEntity().teleport(player); + copy.getTrait(CurrentLocation.class).setLocation(player.getLocation()); + } Messaging.sendF(sender, ChatColor.GREEN + "%s has been copied.", StringHelper.wrap(npc.getName())); } diff --git a/src/main/java/net/citizensnpcs/editor/Equipable.java b/src/main/java/net/citizensnpcs/editor/Equipable.java index aece7ba46..9da2bc045 100644 --- a/src/main/java/net/citizensnpcs/editor/Equipable.java +++ b/src/main/java/net/citizensnpcs/editor/Equipable.java @@ -1,8 +1,8 @@ package net.citizensnpcs.editor; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; public interface Equipable { - - public void equip(Player equipper); + public void equip(Player equipper, ItemStack toEquip); } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/editor/EquipmentEditor.java b/src/main/java/net/citizensnpcs/editor/EquipmentEditor.java index 8423016da..938f89f5e 100644 --- a/src/main/java/net/citizensnpcs/editor/EquipmentEditor.java +++ b/src/main/java/net/citizensnpcs/editor/EquipmentEditor.java @@ -10,6 +10,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; public class EquipmentEditor extends Editor { private final NPC npc; @@ -44,7 +45,9 @@ public class EquipmentEditor extends Editor { return; if (npc instanceof Equipable) { - ((Equipable) npc).equip(event.getPlayer()); + ItemStack hand = event.getPlayer().getItemInHand(); + ((Equipable) npc).equip(event.getPlayer(), hand); + event.getPlayer().setItemInHand(hand.getAmount() > 0 ? hand : null); } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensEndermanNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensEndermanNPC.java index 73449ea62..f0003b136 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensEndermanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensEndermanNPC.java @@ -21,14 +21,12 @@ import org.bukkit.material.MaterialData; import org.bukkit.util.Vector; public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable { - public CitizensEndermanNPC(int id, String name) { super(id, name, EntityEndermanNPC.class); } @Override - public void equip(Player equipper) { - ItemStack hand = equipper.getItemInHand(); + public void equip(Player equipper, ItemStack hand) { if (!hand.getType().isBlock()) { Messaging.sendError(equipper, "Invalid block!"); return; @@ -47,11 +45,7 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable { ItemStack set = hand; if (set.getType() != Material.AIR) { - if (hand.getAmount() > 1) { - hand.setAmount(hand.getAmount() - 1); - } else - hand = null; - equipper.setItemInHand(hand); + hand.setAmount(hand.getAmount() - 1); set.setAmount(1); } getTrait(Equipment.class).set(0, set); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensHumanNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensHumanNPC.java index 1fa05fdf8..4529f91b2 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensHumanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensHumanNPC.java @@ -41,8 +41,7 @@ public class CitizensHumanNPC extends CitizensNPC implements Equipable { } @Override - public void equip(Player equipper) { - ItemStack hand = equipper.getItemInHand(); + public void equip(Player equipper, ItemStack hand) { Equipment trait = getTrait(Equipment.class); int slot = 0; Material type = hand == null ? Material.AIR : hand.getType(); @@ -105,11 +104,7 @@ public class CitizensHumanNPC extends CitizensNPC implements Equipable { clone.setAmount(1); trait.set(slot, clone); - if (hand.getAmount() > 1) - hand.setAmount(hand.getAmount() - 1); - else - hand = null; - equipper.setItemInHand(hand); + hand.setAmount(hand.getAmount() - 1); } } diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensPigNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensPigNPC.java index 653a0f7df..12d6958e4 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensPigNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensPigNPC.java @@ -28,21 +28,18 @@ public class CitizensPigNPC extends CitizensMobNPC implements Equipable { } @Override - public void equip(Player equipper) { - ItemStack hand = equipper.getItemInHand(); + public void equip(Player equipper, ItemStack hand) { if (hand.getType() == Material.SADDLE) { if (!getBukkitEntity().hasSaddle()) { getTrait(Saddle.class).toggle(); - equipper.setItemInHand(null); + hand.setAmount(0); Messaging.send(equipper, StringHelper.wrap(getName()) + " is now saddled."); } - } else { - if (getBukkitEntity().hasSaddle()) { - equipper.getWorld().dropItemNaturally(getBukkitEntity().getLocation(), - new ItemStack(Material.SADDLE, 1)); - getTrait(Saddle.class).toggle(); - Messaging.send(equipper, StringHelper.wrap(getName()) + " is no longer saddled."); - } + } else if (getBukkitEntity().hasSaddle()) { + equipper.getWorld().dropItemNaturally(getBukkitEntity().getLocation(), + new ItemStack(Material.SADDLE, 1)); + getTrait(Saddle.class).toggle(); + Messaging.send(equipper, StringHelper.wrap(getName()) + " is no longer saddled."); } } diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSheepNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSheepNPC.java index 67935b9e7..1b5c17d7f 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSheepNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSheepNPC.java @@ -29,8 +29,7 @@ public class CitizensSheepNPC extends CitizensMobNPC implements Equipable { } @Override - public void equip(Player equipper) { - ItemStack hand = equipper.getItemInHand(); + public void equip(Player equipper, ItemStack hand) { if (hand.getType() == Material.SHEARS) { Messaging.send(equipper, StringHelper.wrap(getName()) + " is " + (getTrait(Sheared.class).toggle() ? "now" : "no longer") + " sheared."); @@ -45,11 +44,7 @@ public class CitizensSheepNPC extends CitizensMobNPC implements Equipable { StringHelper.wrap(getName()) + " is now " + StringHelper.wrap(color.name().toLowerCase().replace("_", " ")) + "."); - if (hand.getAmount() > 1) - hand.setAmount(hand.getAmount() - 1); - else - hand = null; - equipper.setItemInHand(hand); + hand.setAmount(hand.getAmount() - 1); } else { getTrait(WoolColor.class).setColor(DyeColor.WHITE); Messaging.send(equipper, StringHelper.wrap(getName()) + " is now " + StringHelper.wrap("white") diff --git a/src/main/java/net/citizensnpcs/util/NMS.java b/src/main/java/net/citizensnpcs/util/NMS.java index 09168a5e9..bc2d10395 100644 --- a/src/main/java/net/citizensnpcs/util/NMS.java +++ b/src/main/java/net/citizensnpcs/util/NMS.java @@ -35,6 +35,10 @@ public class NMS { private static Field THREAD_STOPPER; + public static void attack(EntityLiving handle, EntityLiving target) { + handle.k(target); + } + public static void clearGoals(PathfinderGoalSelector... goalSelectors) { if (NMS.GOAL_FIELD == null || goalSelectors == null) return; @@ -76,6 +80,10 @@ public class NMS { } } + public static void look(ControllerLook controllerLook, EntityLiving handle, EntityLiving target) { + controllerLook.a(target, 10.0F, handle.bf()); + } + public static void registerEntityClass(Class clazz) { if (ENTITY_CLASS_TO_INT.containsKey(clazz)) return; @@ -160,12 +168,4 @@ public class NMS { } catch (Exception e) { } } - - public static void attack(EntityLiving handle, EntityLiving target) { - handle.k(target); - } - - public static void look(ControllerLook controllerLook, EntityLiving handle, EntityLiving target) { - controllerLook.a(target, 10.0F, handle.bf()); - } }