diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index e0b480af9..486944541 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -758,6 +758,22 @@ protect: # Monsters won't follow players. # permission essentials.protect.entitytarget.bypass disables this. entitytarget: false + # Prevent certain transformations. + transformation: + # Prevent creepers becoming charged when struck by lightning. + charged-creeper: false + # Prevent villagers becoming zombie villagers. + zombie-villager: false + # Prevent zombie villagers being cured. + villager: false + # Prevent villagers becoming witches when struck by lightning. + witch: false + # Prevent pigs becoming zombie pigmen when struck by lightning. + zombie-pigman: false + # Prevent zombies turning into drowneds, and husks turning into zombies. + drowned: false + # Prevent mooshrooms changing colour when struck by lightning. + mooshroom: false # Prevent the spawning of creatures. spawn: creeper: false diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java index 6081657a4..1f527f7d5 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java @@ -170,6 +170,29 @@ public class EssentialsProtectEntityListener implements Listener { } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onEntityTransform(final EntityTransformEvent event) { + final Entity entity = event.getEntity(); + final EntityTransformEvent.TransformReason reason = event.getTransformReason(); + if (reason == EntityTransformEvent.TransformReason.INFECTION && prot.getSettingBool(ProtectConfig.prevent_villager_infection)) { + event.setCancelled(true); + } else if (reason == EntityTransformEvent.TransformReason.CURED && prot.getSettingBool(ProtectConfig.prevent_villager_cure)) { + event.setCancelled(true); + } else if (reason == EntityTransformEvent.TransformReason.LIGHTNING) { + if (entity instanceof Villager && prot.getSettingBool(ProtectConfig.prevent_villager_to_witch)) { + event.setCancelled(true); + } else if (entity instanceof Pig && prot.getSettingBool(ProtectConfig.prevent_pig_transformation)) { + event.setCancelled(true); + } else if (entity instanceof Creeper && prot.getSettingBool(ProtectConfig.prevent_creeper_charge)) { + event.setCancelled(true); + } else if (entity instanceof MushroomCow && prot.getSettingBool(ProtectConfig.prevent_mooshroom_switching)) { + event.setCancelled(true); + } + } else if (reason == EntityTransformEvent.TransformReason.DROWNED && prot.getSettingBool(ProtectConfig.prevent_zombie_drowning)) { + event.setCancelled(true); + } + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onCreatureSpawn(final CreatureSpawnEvent event) { if (event.getEntity() instanceof Player) { diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java b/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java index 3d8e06cd7..cc088b85f 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java @@ -42,7 +42,14 @@ public enum ProtectConfig { prevent_villager_death("protect.prevent.villager-death", false), prevent_enderdragon_blockdmg("protect.prevent.enderdragon-blockdamage", true), prevent_entitytarget("protect.prevent.entitytarget", false), - enderdragon_fakeexplosions("protect.enderdragon-fakeexplosions", false); + enderdragon_fakeexplosions("protect.enderdragon-fakeexplosions", false), + prevent_creeper_charge("protect.prevent.transformation.charged-creeper", false), + prevent_villager_infection("protect.prevent.transformation.zombie-villager", false), + prevent_villager_cure("protect.prevent.transformation.villager", false), + prevent_villager_to_witch("protect.prevent.transformation.witch", false), + prevent_pig_transformation("protect.prevent.transformation.zombie-pigman", false), + prevent_zombie_drowning("protect.prevent.transformation.drowned", false), + prevent_mooshroom_switching("protect.prevent.transformation.mooshroom", false); private final String configName; private final String defValueString; private final boolean defValueBoolean;