diff --git a/src/main/java/net/citizensnpcs/command/CommandManager.java b/src/main/java/net/citizensnpcs/command/CommandManager.java index 519f32222..aea600359 100644 --- a/src/main/java/net/citizensnpcs/command/CommandManager.java +++ b/src/main/java/net/citizensnpcs/command/CommandManager.java @@ -117,7 +117,7 @@ public class CommandManager { types = EnumSet.allOf(EntityType.class); types.removeAll(Sets.newHashSet(cmdRequirements.excludedTypes())); - EntityType type = EntityType.valueOf(npc.getTrait(MobType.class).getType()); + EntityType type = npc.getTrait(MobType.class).getType(); if (!types.contains(type)) { throw new RequirementMissingException("The NPC cannot be the mob type '" + type.getName() + "' to use that command."); diff --git a/src/main/java/net/citizensnpcs/command/command/EditorCommands.java b/src/main/java/net/citizensnpcs/command/command/EditorCommands.java index d7501eadd..1b4e8c0b2 100644 --- a/src/main/java/net/citizensnpcs/command/command/EditorCommands.java +++ b/src/main/java/net/citizensnpcs/command/command/EditorCommands.java @@ -23,8 +23,8 @@ public class EditorCommands { min = 1, max = 1, permission = "npc.edit.equip") - @Requirements(selected = true, ownership = true, types = { EntityType.ENDERMAN, EntityType.PLAYER, EntityType.PIG, - EntityType.SHEEP }) + @Requirements(selected = true, ownership = true, types = { EntityType.ENDERMAN, EntityType.PLAYER, + EntityType.PIG, EntityType.SHEEP }) public void equip(CommandContext args, Player player, NPC npc) { Editor.enterOrLeave(player, new EquipmentEditor(player, npc)); } @@ -37,8 +37,8 @@ public class EditorCommands { min = 1, max = 1, permission = "npc.edit.path") - @Requirements(selected = true, ownership = true, excludedTypes = { EntityType.ENDER_DRAGON, EntityType.SQUID, - EntityType.GHAST, EntityType.BLAZE }) + @Requirements(selected = true, ownership = true, excludedTypes = { EntityType.BLAZE, + EntityType.ENDER_DRAGON, EntityType.GHAST, EntityType.SQUID }) public void path(CommandContext args, Player player, NPC npc) { Editor.enterOrLeave(player, npc.getTrait(Waypoints.class).getEditor(player)); } diff --git a/src/main/java/net/citizensnpcs/command/command/NPCCommands.java b/src/main/java/net/citizensnpcs/command/command/NPCCommands.java index b135510fa..8f39f2813 100644 --- a/src/main/java/net/citizensnpcs/command/command/NPCCommands.java +++ b/src/main/java/net/citizensnpcs/command/command/NPCCommands.java @@ -177,7 +177,7 @@ public class NPCCommands { // Initialize necessary traits if (!Setting.SERVER_OWNS_NPCS.asBoolean()) npc.getTrait(Owner.class).setOwner(player.getName()); - npc.getTrait(MobType.class).setType(type.toString()); + npc.getTrait(MobType.class).setType(type); npc.spawn(player.getLocation()); @@ -241,13 +241,13 @@ public class NPCCommands { } if (args.hasValueFlag("type")) { - String type = args.getFlag("type"); + EntityType type = Util.matchEntityType(args.getFlag("type")); - if (EntityType.fromName(type.replace('-', '_')) == null) + if (type == null) throw new CommandException("'" + type + "' is not a valid mob type."); for (NPC add : npcRegistry) { - if (!npcs.contains(add) && add.getTrait(MobType.class).getType().equalsIgnoreCase(type)) + if (!npcs.contains(add) && add.getTrait(MobType.class).getType() == type) npcs.add(add); } } diff --git a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java index 15d46b608..2bb0d323f 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java +++ b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java @@ -149,21 +149,24 @@ public class CitizensNavigator implements Navigator { } } - private static final float DEFAULT_SPEED = 0.7F; + private static final float DEFAULT_SPEED = 0.4F; private static final Map MOVEMENT_SPEEDS = Maps.newEnumMap(EntityType.class); private static Field PATHFINDING_RANGE; private static Field SPEED_FIELD; static { - MOVEMENT_SPEEDS.put(EntityType.IRON_GOLEM, 0.15F); + // constants taken from source code MOVEMENT_SPEEDS.put(EntityType.CHICKEN, 0.25F); MOVEMENT_SPEEDS.put(EntityType.COW, 0.2F); - MOVEMENT_SPEEDS.put(EntityType.SHEEP, 0.25F); - MOVEMENT_SPEEDS.put(EntityType.VILLAGER, 0.3F); - MOVEMENT_SPEEDS.put(EntityType.SNOWMAN, 0.25F); MOVEMENT_SPEEDS.put(EntityType.CREEPER, 0.3F); + MOVEMENT_SPEEDS.put(EntityType.IRON_GOLEM, 0.15F); + MOVEMENT_SPEEDS.put(EntityType.MUSHROOM_COW, 0.2F); + MOVEMENT_SPEEDS.put(EntityType.OCELOT, 0.23F); + MOVEMENT_SPEEDS.put(EntityType.SHEEP, 0.25F); + MOVEMENT_SPEEDS.put(EntityType.SNOWMAN, 0.25F); MOVEMENT_SPEEDS.put(EntityType.PIG, 0.27F); MOVEMENT_SPEEDS.put(EntityType.PLAYER, 1F); + MOVEMENT_SPEEDS.put(EntityType.VILLAGER, 0.3F); try { SPEED_FIELD = EntityLiving.class.getDeclaredField("bb"); SPEED_FIELD.setAccessible(true); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensCaveSpiderNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensCaveSpiderNPC.java index ffe47bc69..7de231337 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensCaveSpiderNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensCaveSpiderNPC.java @@ -59,6 +59,14 @@ public class CitizensCaveSpiderNPC extends CitizensMobNPC { Util.callCollisionEvent(npc, entity); } + @Override + public void d_() { + if (npc == null) + super.d_(); + else + npc.update(); + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensEndermanNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensEndermanNPC.java index 4aac0bbcd..402572397 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensEndermanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensEndermanNPC.java @@ -105,13 +105,13 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable { public void d_() { if (npc == null) super.d_(); + else + npc.update(); } @Override public void e() { - if (npc != null) - npc.update(); - else + if (npc == null) super.e(); } @@ -120,5 +120,9 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable { return npc; } + @Override + public void z_() { + + } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensMagmaCubeNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensMagmaCubeNPC.java index 30223b599..157f080e8 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensMagmaCubeNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensMagmaCubeNPC.java @@ -76,5 +76,12 @@ public class CitizensMagmaCubeNPC extends CitizensMobNPC { public NPC getNPC() { return npc; } + + @Override + public void z_() { + super.z_(); + if (npc != null) + npc.update(); + } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensPigZombieNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensPigZombieNPC.java index e95789d5b..f146cfacb 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensPigZombieNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensPigZombieNPC.java @@ -76,5 +76,11 @@ public class CitizensPigZombieNPC extends CitizensMobNPC { return npc; } + @Override + public void z_() { + super.z_(); + if (npc != null) + npc.update(); + } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSilverfishNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSilverfishNPC.java index dc07776f2..1c8eca3c9 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSilverfishNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSilverfishNPC.java @@ -63,6 +63,14 @@ public class CitizensSilverfishNPC extends CitizensMobNPC { Util.callCollisionEvent(npc, entity); } + @Override + public void d_() { + if (npc == null) + super.d_(); + else + npc.update(); + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSlimeNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSlimeNPC.java index a7b586c00..40e7c52e4 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSlimeNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSlimeNPC.java @@ -64,6 +64,14 @@ public class CitizensSlimeNPC extends CitizensMobNPC { Util.callCollisionEvent(npc, entity); } + @Override + public void d_() { + if (npc == null) + super.d_(); + else + npc.update(); + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSpiderNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSpiderNPC.java index 821594ae8..339a00da4 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSpiderNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSpiderNPC.java @@ -14,7 +14,6 @@ import org.bukkit.entity.Spider; import org.bukkit.util.Vector; public class CitizensSpiderNPC extends CitizensMobNPC { - public CitizensSpiderNPC(int id, String name) { super(id, name, EntitySpiderNPC.class); } @@ -63,6 +62,14 @@ public class CitizensSpiderNPC extends CitizensMobNPC { Util.callCollisionEvent(npc, entity); } + @Override + public void d_() { + if (npc == null) + super.d_(); + else + npc.update(); + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/trait/Controllable.java b/src/main/java/net/citizensnpcs/trait/Controllable.java index 11e77c988..3de66e324 100644 --- a/src/main/java/net/citizensnpcs/trait/Controllable.java +++ b/src/main/java/net/citizensnpcs/trait/Controllable.java @@ -2,7 +2,6 @@ package net.citizensnpcs.trait; import net.citizensnpcs.api.event.NPCRightClickEvent; import net.citizensnpcs.api.exception.NPCLoadException; -import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.util.DataKey; import net.minecraft.server.EntityLiving; @@ -18,7 +17,7 @@ import org.bukkit.event.player.PlayerInteractEvent; public class Controllable extends Trait implements Toggleable { private boolean enabled; - public Controllable(NPC npc) { + public Controllable() { super("controllable"); } @@ -54,13 +53,12 @@ public class Controllable extends Trait implements Toggleable { @EventHandler public void onRightClick(NPCRightClickEvent event) { - if (!npc.isSpawned() || !event.getNPC().equals(npc)) + if (!enabled || !npc.isSpawned() || !event.getNPC().equals(npc)) return; EntityPlayer handle = ((CraftPlayer) event.getClicker()).getHandle(); if (getHandle().passenger != null) { - if (getHandle().passenger == handle) { + if (getHandle().passenger == handle) event.getClicker().leaveVehicle(); - } return; } handle.setPassengerOf(getHandle()); @@ -68,7 +66,7 @@ public class Controllable extends Trait implements Toggleable { @Override public void run() { - if (!npc.isSpawned() || getHandle().passenger == null) + if (!enabled || !npc.isSpawned() || getHandle().passenger == null) return; EntityLiving handle = getHandle(); boolean onGround = handle.onGround; @@ -83,7 +81,10 @@ public class Controllable extends Trait implements Toggleable { @Override public boolean toggle() { - return (enabled = !enabled); + enabled = !enabled; + if (!enabled && getHandle().passenger != null) + getHandle().passenger.getBukkitEntity().leaveVehicle(); + return enabled; } private static final double AIR_SPEED = 1.5;