diff --git a/src/main/java/net/citizensnpcs/command/command/NPCCommands.java b/src/main/java/net/citizensnpcs/command/command/NPCCommands.java index f36908f82..b135510fa 100644 --- a/src/main/java/net/citizensnpcs/command/command/NPCCommands.java +++ b/src/main/java/net/citizensnpcs/command/command/NPCCommands.java @@ -28,6 +28,7 @@ import net.citizensnpcs.trait.VillagerProfession; import net.citizensnpcs.util.Messaging; import net.citizensnpcs.util.Paginator; import net.citizensnpcs.util.StringHelper; +import net.citizensnpcs.util.Util; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -36,6 +37,7 @@ import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.entity.Ageable; import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Villager.Profession; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -139,10 +141,14 @@ public class NPCCommands { } EntityType type = EntityType.PLAYER; if (args.hasValueFlag("type")) { - type = EntityType.fromName(args.getFlag("type")); + String inputType = args.getFlag("type"); + type = Util.matchEntityType(inputType); if (type == null) { - Messaging.sendError(player, "'" + args.getFlag("type") - + "' is not a valid mob type. Using default NPC."); + Messaging.sendError(player, "'" + inputType + + "' is not a valid mob type. Using default type."); + type = EntityType.PLAYER; + } else if (!LivingEntity.class.isAssignableFrom(type.getEntityClass())) { + Messaging.sendError(player, "'%s' is not a living entity type. Using default type."); type = EntityType.PLAYER; } } diff --git a/src/main/java/net/citizensnpcs/npc/ai/NPCHolder.java b/src/main/java/net/citizensnpcs/npc/ai/NPCHolder.java index e58e09b27..63c1a4b72 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/NPCHolder.java +++ b/src/main/java/net/citizensnpcs/npc/ai/NPCHolder.java @@ -4,8 +4,4 @@ import net.citizensnpcs.api.npc.NPC; public interface NPCHolder { public NPC getNPC(); - - boolean isPushable(); - - void setPushable(boolean pushable); } diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensBlazeNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensBlazeNPC.java index 2b2426ec8..780ab46f4 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensBlazeNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensBlazeNPC.java @@ -1,14 +1,17 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntityBlaze; import net.minecraft.server.PathfinderGoalSelector; import net.minecraft.server.World; import org.bukkit.entity.Blaze; +import org.bukkit.util.Vector; public class CitizensBlazeNPC extends CitizensMobNPC { @@ -24,8 +27,6 @@ public class CitizensBlazeNPC extends CitizensMobNPC { public static class EntityBlazeNPC extends EntityBlaze implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; - public EntityBlazeNPC(World world) { this(world, null); } @@ -41,7 +42,14 @@ public class CitizensBlazeNPC extends CitizensMobNPC { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -59,15 +67,5 @@ public class CitizensBlazeNPC extends CitizensMobNPC { public NPC getNPC() { return npc; } - - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensCaveSpiderNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensCaveSpiderNPC.java index 291514b13..047e018a2 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensCaveSpiderNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensCaveSpiderNPC.java @@ -1,14 +1,17 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntityCaveSpider; import net.minecraft.server.PathfinderGoalSelector; import net.minecraft.server.World; import org.bukkit.entity.CaveSpider; +import org.bukkit.util.Vector; public class CitizensCaveSpiderNPC extends CitizensMobNPC { @@ -24,8 +27,6 @@ public class CitizensCaveSpiderNPC extends CitizensMobNPC { public static class EntityCaveSpiderNPC extends EntityCaveSpider implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; - public EntityCaveSpiderNPC(World world, NPC npc) { super(world); this.npc = (CitizensNPC) npc; @@ -37,7 +38,14 @@ public class CitizensCaveSpiderNPC extends CitizensMobNPC { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -48,16 +56,6 @@ public class CitizensCaveSpiderNPC extends CitizensMobNPC { return npc; } - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } - @Override public void z_() { super.z_(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensChickenNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensChickenNPC.java index 72804d2f0..4f97e7c0e 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensChickenNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensChickenNPC.java @@ -1,14 +1,17 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntityChicken; import net.minecraft.server.PathfinderGoalSelector; import net.minecraft.server.World; import org.bukkit.entity.Chicken; +import org.bukkit.util.Vector; public class CitizensChickenNPC extends CitizensMobNPC { @@ -24,8 +27,6 @@ public class CitizensChickenNPC extends CitizensMobNPC { public static class EntityChickenNPC extends EntityChicken implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; - public EntityChickenNPC(World world) { this(world, null); } @@ -41,7 +42,14 @@ public class CitizensChickenNPC extends CitizensMobNPC { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -52,16 +60,6 @@ public class CitizensChickenNPC extends CitizensMobNPC { return npc; } - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } - @Override public void z_() { super.z_(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensCowNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensCowNPC.java index 07a9e0780..7d9740645 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensCowNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensCowNPC.java @@ -1,14 +1,17 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntityCow; import net.minecraft.server.PathfinderGoalSelector; import net.minecraft.server.World; import org.bukkit.entity.Cow; +import org.bukkit.util.Vector; public class CitizensCowNPC extends CitizensMobNPC { @@ -24,8 +27,6 @@ public class CitizensCowNPC extends CitizensMobNPC { public static class EntityCowNPC extends EntityCow implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; - public EntityCowNPC(World world) { this(world, null); } @@ -41,7 +42,14 @@ public class CitizensCowNPC extends CitizensMobNPC { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -52,16 +60,6 @@ public class CitizensCowNPC extends CitizensMobNPC { return npc; } - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } - @Override public void z_() { super.z_(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensCreeperNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensCreeperNPC.java index 9dbb49c0e..98c55342f 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensCreeperNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensCreeperNPC.java @@ -1,15 +1,18 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntityCreeper; import net.minecraft.server.EntityWeatherLighting; import net.minecraft.server.PathfinderGoalSelector; import net.minecraft.server.World; import org.bukkit.entity.Creeper; +import org.bukkit.util.Vector; public class CitizensCreeperNPC extends CitizensMobNPC { @@ -24,7 +27,6 @@ public class CitizensCreeperNPC extends CitizensMobNPC { public static class EntityCreeperNPC extends EntityCreeper implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; public EntityCreeperNPC(World world) { this(world, null); @@ -47,7 +49,14 @@ public class CitizensCreeperNPC extends CitizensMobNPC { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -58,16 +67,6 @@ public class CitizensCreeperNPC extends CitizensMobNPC { return npc; } - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } - @Override public void z_() { super.z_(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensEnderDragonNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensEnderDragonNPC.java index 0db6cb649..56a328744 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensEnderDragonNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensEnderDragonNPC.java @@ -1,14 +1,17 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntityEnderDragon; import net.minecraft.server.PathfinderGoalSelector; import net.minecraft.server.World; import org.bukkit.entity.EnderDragon; +import org.bukkit.util.Vector; public class CitizensEnderDragonNPC extends CitizensMobNPC { @@ -24,8 +27,6 @@ public class CitizensEnderDragonNPC extends CitizensMobNPC { public static class EntityEnderDragonNPC extends EntityEnderDragon implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; - public EntityEnderDragonNPC(World world, NPC npc) { super(world); this.npc = (CitizensNPC) npc; @@ -37,7 +38,14 @@ public class CitizensEnderDragonNPC extends CitizensMobNPC { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -62,14 +70,5 @@ public class CitizensEnderDragonNPC extends CitizensMobNPC { return npc; } - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } } } \ 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 23b897ba1..9125fbc4b 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensEndermanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensEndermanNPC.java @@ -1,5 +1,6 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.trait.trait.Equipment; import net.citizensnpcs.editor.Equipable; @@ -7,6 +8,7 @@ import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.Messaging; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntityEnderman; import net.minecraft.server.PathfinderGoalSelector; import net.minecraft.server.World; @@ -16,6 +18,7 @@ import org.bukkit.entity.Enderman; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.material.MaterialData; +import org.bukkit.util.Vector; public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable { @@ -62,8 +65,6 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable { public static class EntityEndermanNPC extends EntityEnderman implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; - public EntityEndermanNPC(World world) { this(world, null); } @@ -79,7 +80,14 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -104,14 +112,5 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable { return npc; } - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensGhastNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensGhastNPC.java index 59acfd42a..47411b820 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensGhastNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensGhastNPC.java @@ -1,14 +1,17 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntityGhast; import net.minecraft.server.PathfinderGoalSelector; import net.minecraft.server.World; import org.bukkit.entity.Ghast; +import org.bukkit.util.Vector; public class CitizensGhastNPC extends CitizensMobNPC { @@ -24,8 +27,6 @@ public class CitizensGhastNPC extends CitizensMobNPC { public static class EntityGhastNPC extends EntityGhast implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; - public EntityGhastNPC(World world) { this(world, null); } @@ -41,7 +42,14 @@ public class CitizensGhastNPC extends CitizensMobNPC { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -59,15 +67,5 @@ public class CitizensGhastNPC extends CitizensMobNPC { public NPC getNPC() { return npc; } - - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensGiantNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensGiantNPC.java index 4355b0b20..63b6cb53b 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensGiantNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensGiantNPC.java @@ -1,14 +1,17 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntityGiantZombie; import net.minecraft.server.PathfinderGoalSelector; import net.minecraft.server.World; import org.bukkit.entity.Giant; +import org.bukkit.util.Vector; public class CitizensGiantNPC extends CitizensMobNPC { @@ -24,8 +27,6 @@ public class CitizensGiantNPC extends CitizensMobNPC { public static class EntityGiantNPC extends EntityGiantZombie implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; - public EntityGiantNPC(World world, NPC npc) { super(world); this.npc = (CitizensNPC) npc; @@ -37,7 +38,14 @@ public class CitizensGiantNPC extends CitizensMobNPC { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -52,15 +60,5 @@ public class CitizensGiantNPC extends CitizensMobNPC { public NPC getNPC() { return npc; } - - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensIronGolemNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensIronGolemNPC.java index 147c763f9..dcf9600e5 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensIronGolemNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensIronGolemNPC.java @@ -1,14 +1,17 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntityIronGolem; import net.minecraft.server.PathfinderGoalSelector; import net.minecraft.server.World; import org.bukkit.entity.IronGolem; +import org.bukkit.util.Vector; public class CitizensIronGolemNPC extends CitizensMobNPC { @@ -24,8 +27,6 @@ public class CitizensIronGolemNPC extends CitizensMobNPC { public static class EntityIronGolemNPC extends EntityIronGolem implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; - public EntityIronGolemNPC(World world, NPC npc) { super(world); this.npc = (CitizensNPC) npc; @@ -37,7 +38,14 @@ public class CitizensIronGolemNPC extends CitizensMobNPC { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -48,16 +56,6 @@ public class CitizensIronGolemNPC extends CitizensMobNPC { return npc; } - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } - @Override public void z_() { super.z_(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensMagmaCubeNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensMagmaCubeNPC.java index f1bb23868..d950a1afa 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensMagmaCubeNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensMagmaCubeNPC.java @@ -1,14 +1,17 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntityMagmaCube; import net.minecraft.server.PathfinderGoalSelector; import net.minecraft.server.World; import org.bukkit.entity.MagmaCube; +import org.bukkit.util.Vector; public class CitizensMagmaCubeNPC extends CitizensMobNPC { @@ -24,8 +27,6 @@ public class CitizensMagmaCubeNPC extends CitizensMobNPC { public static class EntityMagmaCubeNPC extends EntityMagmaCube implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; - public EntityMagmaCubeNPC(World world) { this(world, null); } @@ -42,7 +43,14 @@ public class CitizensMagmaCubeNPC extends CitizensMobNPC { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -60,15 +68,5 @@ public class CitizensMagmaCubeNPC extends CitizensMobNPC { public NPC getNPC() { return npc; } - - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensMushroomCowNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensMushroomCowNPC.java index ba1830fff..b49475d2f 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensMushroomCowNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensMushroomCowNPC.java @@ -1,14 +1,17 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntityMushroomCow; import net.minecraft.server.PathfinderGoalSelector; import net.minecraft.server.World; import org.bukkit.entity.MushroomCow; +import org.bukkit.util.Vector; public class CitizensMushroomCowNPC extends CitizensMobNPC { @@ -24,8 +27,6 @@ public class CitizensMushroomCowNPC extends CitizensMobNPC { public static class EntityMushroomCowNPC extends EntityMushroomCow implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; - public EntityMushroomCowNPC(World world) { this(world, null); } @@ -41,7 +42,14 @@ public class CitizensMushroomCowNPC extends CitizensMobNPC { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -52,16 +60,6 @@ public class CitizensMushroomCowNPC extends CitizensMobNPC { return npc; } - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } - @Override public void z_() { super.z_(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensOcelotNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensOcelotNPC.java index 2e59acda2..618c1f13f 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensOcelotNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensOcelotNPC.java @@ -1,14 +1,17 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntityOcelot; import net.minecraft.server.PathfinderGoalSelector; import net.minecraft.server.World; import org.bukkit.entity.Ocelot; +import org.bukkit.util.Vector; public class CitizensOcelotNPC extends CitizensMobNPC { @@ -24,8 +27,6 @@ public class CitizensOcelotNPC extends CitizensMobNPC { public static class EntityOcelotNPC extends EntityOcelot implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; - public EntityOcelotNPC(World world) { this(world, null); } @@ -41,7 +42,14 @@ public class CitizensOcelotNPC extends CitizensMobNPC { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -52,16 +60,6 @@ public class CitizensOcelotNPC extends CitizensMobNPC { return npc; } - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } - @Override public void z_() { super.z_(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensPigNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensPigNPC.java index 2728596d0..5104d64f9 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensPigNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensPigNPC.java @@ -1,5 +1,6 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.editor.Equipable; import net.citizensnpcs.npc.CitizensMobNPC; @@ -8,6 +9,7 @@ import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.trait.Saddle; import net.citizensnpcs.util.Messaging; import net.citizensnpcs.util.StringHelper; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntityPig; import net.minecraft.server.EntityWeatherLighting; import net.minecraft.server.PathfinderGoalSelector; @@ -17,6 +19,7 @@ import org.bukkit.Material; import org.bukkit.entity.Pig; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.bukkit.util.Vector; public class CitizensPigNPC extends CitizensMobNPC implements Equipable { @@ -51,8 +54,6 @@ public class CitizensPigNPC extends CitizensMobNPC implements Equipable { public static class EntityPigNPC extends EntityPig implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; - public EntityPigNPC(World world) { this(world, null); } @@ -74,7 +75,14 @@ public class CitizensPigNPC extends CitizensMobNPC implements Equipable { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -85,16 +93,6 @@ public class CitizensPigNPC extends CitizensMobNPC implements Equipable { return npc; } - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } - @Override public void z_() { super.z_(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensPigZombieNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensPigZombieNPC.java index d57a235ac..69a99f888 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensPigZombieNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensPigZombieNPC.java @@ -1,14 +1,17 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntityPigZombie; import net.minecraft.server.PathfinderGoalSelector; import net.minecraft.server.World; import org.bukkit.entity.PigZombie; +import org.bukkit.util.Vector; public class CitizensPigZombieNPC extends CitizensMobNPC { @@ -24,8 +27,6 @@ public class CitizensPigZombieNPC extends CitizensMobNPC { public static class EntityPigZombieNPC extends EntityPigZombie implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; - public EntityPigZombieNPC(World world) { this(world, null); } @@ -41,7 +42,14 @@ public class CitizensPigZombieNPC extends CitizensMobNPC { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -60,14 +68,5 @@ public class CitizensPigZombieNPC extends CitizensMobNPC { return npc; } - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSheepNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSheepNPC.java index 86a687d9e..3992296a2 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSheepNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSheepNPC.java @@ -1,5 +1,6 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.editor.Equipable; import net.citizensnpcs.npc.CitizensMobNPC; @@ -9,6 +10,7 @@ import net.citizensnpcs.trait.Sheared; import net.citizensnpcs.trait.WoolColor; import net.citizensnpcs.util.Messaging; import net.citizensnpcs.util.StringHelper; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntitySheep; import net.minecraft.server.PathfinderGoalSelector; import net.minecraft.server.World; @@ -18,6 +20,7 @@ import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.entity.Sheep; import org.bukkit.inventory.ItemStack; +import org.bukkit.util.Vector; public class CitizensSheepNPC extends CitizensMobNPC implements Equipable { @@ -62,8 +65,6 @@ public class CitizensSheepNPC extends CitizensMobNPC implements Equipable { public static class EntitySheepNPC extends EntitySheep implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; - public EntitySheepNPC(World world) { this(world, null); } @@ -79,7 +80,14 @@ public class CitizensSheepNPC extends CitizensMobNPC implements Equipable { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -90,16 +98,6 @@ public class CitizensSheepNPC extends CitizensMobNPC implements Equipable { return npc; } - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } - @Override public void z_() { super.z_(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSilverfishNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSilverfishNPC.java index ba169c01e..4c0928991 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSilverfishNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSilverfishNPC.java @@ -1,14 +1,17 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntitySilverfish; import net.minecraft.server.PathfinderGoalSelector; import net.minecraft.server.World; import org.bukkit.entity.Silverfish; +import org.bukkit.util.Vector; public class CitizensSilverfishNPC extends CitizensMobNPC { @@ -24,8 +27,6 @@ public class CitizensSilverfishNPC extends CitizensMobNPC { public static class EntitySilverfishNPC extends EntitySilverfish implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; - public EntitySilverfishNPC(World world) { this(world, null); } @@ -41,7 +42,14 @@ public class CitizensSilverfishNPC extends CitizensMobNPC { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -52,16 +60,6 @@ public class CitizensSilverfishNPC extends CitizensMobNPC { return npc; } - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } - @Override public void z_() { super.z_(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSkeletonNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSkeletonNPC.java index 7e1cb7389..c94205215 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSkeletonNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSkeletonNPC.java @@ -1,14 +1,17 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntitySkeleton; import net.minecraft.server.PathfinderGoalSelector; import net.minecraft.server.World; import org.bukkit.entity.Skeleton; +import org.bukkit.util.Vector; public class CitizensSkeletonNPC extends CitizensMobNPC { @@ -24,8 +27,6 @@ public class CitizensSkeletonNPC extends CitizensMobNPC { public static class EntitySkeletonNPC extends EntitySkeleton implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; - public EntitySkeletonNPC(World world) { this(world, null); } @@ -41,7 +42,14 @@ public class CitizensSkeletonNPC extends CitizensMobNPC { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -52,16 +60,6 @@ public class CitizensSkeletonNPC extends CitizensMobNPC { return npc; } - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } - @Override public void z_() { super.z_(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSlimeNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSlimeNPC.java index a23835c4f..94c399d4e 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSlimeNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSlimeNPC.java @@ -1,14 +1,17 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntitySlime; import net.minecraft.server.PathfinderGoalSelector; import net.minecraft.server.World; import org.bukkit.entity.Slime; +import org.bukkit.util.Vector; public class CitizensSlimeNPC extends CitizensMobNPC { @@ -24,8 +27,6 @@ public class CitizensSlimeNPC extends CitizensMobNPC { public static class EntitySlimeNPC extends EntitySlime implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; - public EntitySlimeNPC(World world) { this(world, null); } @@ -42,7 +43,14 @@ public class CitizensSlimeNPC extends CitizensMobNPC { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -53,16 +61,6 @@ public class CitizensSlimeNPC extends CitizensMobNPC { return npc; } - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } - @Override public void z_() { super.z_(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSnowmanNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSnowmanNPC.java index e92982b9e..5a4e21b70 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSnowmanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSnowmanNPC.java @@ -1,14 +1,17 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntitySnowman; import net.minecraft.server.PathfinderGoalSelector; import net.minecraft.server.World; import org.bukkit.entity.Snowman; +import org.bukkit.util.Vector; public class CitizensSnowmanNPC extends CitizensMobNPC { @@ -24,8 +27,6 @@ public class CitizensSnowmanNPC extends CitizensMobNPC { public static class EntitySnowmanNPC extends EntitySnowman implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; - public EntitySnowmanNPC(World world, NPC npc) { super(world); this.npc = (CitizensNPC) npc; @@ -37,7 +38,14 @@ public class CitizensSnowmanNPC extends CitizensMobNPC { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -48,16 +56,6 @@ public class CitizensSnowmanNPC extends CitizensMobNPC { return npc; } - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } - @Override public void z_() { super.z_(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSpiderNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSpiderNPC.java index 2d568b48a..fa0c0a093 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSpiderNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSpiderNPC.java @@ -1,14 +1,17 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntitySpider; import net.minecraft.server.PathfinderGoalSelector; import net.minecraft.server.World; import org.bukkit.entity.Spider; +import org.bukkit.util.Vector; public class CitizensSpiderNPC extends CitizensMobNPC { @@ -24,8 +27,6 @@ public class CitizensSpiderNPC extends CitizensMobNPC { public static class EntitySpiderNPC extends EntitySpider implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; - public EntitySpiderNPC(World world) { this(world, null); } @@ -41,7 +42,14 @@ public class CitizensSpiderNPC extends CitizensMobNPC { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -52,16 +60,6 @@ public class CitizensSpiderNPC extends CitizensMobNPC { return npc; } - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } - @Override public void z_() { super.z_(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSquidNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSquidNPC.java index 355cc2d5b..5ca92b12d 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSquidNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSquidNPC.java @@ -1,14 +1,17 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntitySquid; import net.minecraft.server.PathfinderGoalSelector; import net.minecraft.server.World; import org.bukkit.entity.Squid; +import org.bukkit.util.Vector; public class CitizensSquidNPC extends CitizensMobNPC { @@ -24,8 +27,6 @@ public class CitizensSquidNPC extends CitizensMobNPC { public static class EntitySquidNPC extends EntitySquid implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; - public EntitySquidNPC(World world) { this(world, null); } @@ -41,7 +42,14 @@ public class CitizensSquidNPC extends CitizensMobNPC { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -60,14 +68,5 @@ public class CitizensSquidNPC extends CitizensMobNPC { return npc; } - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensVillagerNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensVillagerNPC.java index 7dc5e1acc..a37dbb0bd 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensVillagerNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensVillagerNPC.java @@ -1,14 +1,17 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntityVillager; import net.minecraft.server.PathfinderGoalSelector; import net.minecraft.server.World; import org.bukkit.entity.Villager; +import org.bukkit.util.Vector; public class CitizensVillagerNPC extends CitizensMobNPC { @@ -24,8 +27,6 @@ public class CitizensVillagerNPC extends CitizensMobNPC { public static class EntityVillagerNPC extends EntityVillager implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; - public EntityVillagerNPC(World world) { this(world, null); } @@ -41,7 +42,14 @@ public class CitizensVillagerNPC extends CitizensMobNPC { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -52,16 +60,6 @@ public class CitizensVillagerNPC extends CitizensMobNPC { return npc; } - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } - @Override public void z_() { super.z_(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensWolfNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensWolfNPC.java index 9204283cd..2b74801af 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensWolfNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensWolfNPC.java @@ -1,14 +1,17 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntityWolf; import net.minecraft.server.PathfinderGoalSelector; import net.minecraft.server.World; import org.bukkit.entity.Wolf; +import org.bukkit.util.Vector; public class CitizensWolfNPC extends CitizensMobNPC { @@ -24,8 +27,6 @@ public class CitizensWolfNPC extends CitizensMobNPC { public static class EntityWolfNPC extends EntityWolf implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; - public EntityWolfNPC(World world) { this(world, null); } @@ -41,7 +42,14 @@ public class CitizensWolfNPC extends CitizensMobNPC { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -52,16 +60,6 @@ public class CitizensWolfNPC extends CitizensMobNPC { return npc; } - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } - @Override public void z_() { super.z_(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensZombieNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensZombieNPC.java index 8982710db..342b3bb63 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensZombieNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensZombieNPC.java @@ -1,14 +1,17 @@ package net.citizensnpcs.npc.entity; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntityZombie; import net.minecraft.server.PathfinderGoalSelector; import net.minecraft.server.World; import org.bukkit.entity.Zombie; +import org.bukkit.util.Vector; public class CitizensZombieNPC extends CitizensMobNPC { @@ -24,8 +27,6 @@ public class CitizensZombieNPC extends CitizensMobNPC { public static class EntityZombieNPC extends EntityZombie implements NPCHolder { private final CitizensNPC npc; - private boolean pushable = false; - public EntityZombieNPC(World world) { this(world, null); } @@ -41,7 +42,14 @@ public class CitizensZombieNPC extends CitizensMobNPC { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -52,16 +60,6 @@ public class CitizensZombieNPC extends CitizensMobNPC { return npc; } - @Override - public boolean isPushable() { - return pushable; - } - - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } - @Override public void z_() { super.z_(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java index c1a74bba5..455f0d70c 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java @@ -2,12 +2,14 @@ package net.citizensnpcs.npc.entity; import java.io.IOException; +import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.network.NPCNetHandler; import net.citizensnpcs.npc.network.NPCNetworkManager; import net.citizensnpcs.npc.network.NPCSocket; +import net.citizensnpcs.util.Util; import net.minecraft.server.EntityPlayer; import net.minecraft.server.ItemInWorldManager; import net.minecraft.server.MinecraftServer; @@ -16,11 +18,11 @@ import net.minecraft.server.NetHandler; import net.minecraft.server.NetworkManager; import net.minecraft.server.World; +import org.bukkit.util.Vector; + public class EntityHumanNPC extends EntityPlayer implements NPCHolder { private CitizensNPC npc; - private boolean pushable = false; - public EntityHumanNPC(MinecraftServer minecraftServer, World world, String string, ItemInWorldManager itemInWorldManager, NPC npc) { super(minecraftServer, world, string, itemInWorldManager); @@ -46,7 +48,14 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder { @Override public void b_(double x, double y, double z) { - if (npc == null || pushable) + if (npc == null) { + super.b_(x, y, z); + return; + } + if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + NPCCollisionEvent event = Util.callCollisionEvent(npc, new Vector(x, y, z)); + if (!event.isCancelled()) super.b_(x, y, z); // when another entity collides, b_ is called to push the NPC // so we prevent b_ from doing anything. @@ -72,11 +81,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder { return npc; } - @Override - public boolean isPushable() { - return pushable; - } - private void moveOnCurrentHeading() { getControllerMove().c(); getControllerLook().a(); @@ -101,8 +105,4 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder { X = yaw; } - @Override - public void setPushable(boolean pushable) { - this.pushable = pushable; - } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/util/Util.java b/src/main/java/net/citizensnpcs/util/Util.java index 10ebf65a9..ca7dd035f 100644 --- a/src/main/java/net/citizensnpcs/util/Util.java +++ b/src/main/java/net/citizensnpcs/util/Util.java @@ -7,6 +7,8 @@ import java.util.Comparator; import java.util.Map; import net.citizensnpcs.Settings.Setting; +import net.citizensnpcs.api.event.NPCCollisionEvent; +import net.citizensnpcs.api.npc.NPC; import net.minecraft.server.Packet; import org.apache.commons.lang.Validate; @@ -15,7 +17,9 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; import com.google.common.base.Splitter; import com.google.common.collect.Maps; @@ -28,6 +32,12 @@ public class Util { private static final Map, Class> primitiveClassMap = Maps.newHashMap(); + public static NPCCollisionEvent callCollisionEvent(NPC npc, Vector vector) { + NPCCollisionEvent event = new NPCCollisionEvent(npc, vector); + Bukkit.getPluginManager().callEvent(event); + return event; + } + /** * Given a set of instantiation parameters, attempts to find a matching * constructor with the greatest number of matching class parameters and @@ -50,8 +60,9 @@ public class Util { } } - private static T createInstance0(Class clazz, Object[] params) throws InstantiationException, - IllegalAccessException, IllegalArgumentException, InvocationTargetException { + private static T createInstance0(Class clazz, Object[] params) + throws InstantiationException, IllegalAccessException, IllegalArgumentException, + InvocationTargetException { @SuppressWarnings("unchecked") Constructor[] constructors = (Constructor[]) clazz.getConstructors(); @@ -98,6 +109,20 @@ public class Util { } return false; } + + public static EntityType matchEntityType(String toMatch) { + EntityType type = EntityType.fromName(toMatch); + if (type != null) + return type; + for (EntityType check : EntityType.values()) { + if (check.name().matches(toMatch) || check.name().replace('_', '-').equals(toMatch)) { + type = check; + break; + } + } + return type; + } + private static boolean searchInterfaces(Class class1, Class class2) { for (Class test : class1.getInterfaces()) if (test == class2)