diff --git a/nms-patches/EntityIllagerWizard.patch b/nms-patches/EntityIllagerWizard.patch new file mode 100644 index 0000000000..71ae430e27 --- /dev/null +++ b/nms-patches/EntityIllagerWizard.patch @@ -0,0 +1,14 @@ +--- a/net/minecraft/server/EntityIllagerWizard.java ++++ b/net/minecraft/server/EntityIllagerWizard.java +@@ -145,6 +145,11 @@ + public void e() { + --this.b; + if (this.b == 0) { ++ // CraftBukkit start ++ if (!org.bukkit.craftbukkit.event.CraftEventFactory.handleEntitySpellCastEvent(EntityIllagerWizard.this, l())) { // PAIL rename getSpell ++ return; ++ } ++ // CraftBukkit end + this.j(); + EntityIllagerWizard.this.playSound(EntityIllagerWizard.this.getSoundCastSpell(), 1.0F, 1.0F); + } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftSpellcaster.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftSpellcaster.java index db1ba5b2cd..7f5c936b31 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftSpellcaster.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftSpellcaster.java @@ -23,13 +23,21 @@ public class CraftSpellcaster extends CraftIllager implements Spellcaster { @Override public Spell getSpell() { - return Spell.valueOf(getHandle().getSpell().name()); + return toBukkitSpell(getHandle().getSpell()); } @Override public void setSpell(Spell spell) { Preconditions.checkArgument(spell != null, "Use Spell.NONE"); - getHandle().setSpell(EntityIllagerWizard.Spell.a(spell.ordinal())); + getHandle().setSpell(toNMSSpell(spell)); + } + + public static Spell toBukkitSpell(EntityIllagerWizard.Spell spell) { + return Spell.valueOf(spell.name()); + } + + public static EntityIllagerWizard.Spell toNMSSpell(Spell spell) { + return EntityIllagerWizard.Spell.a(spell.ordinal()); } } diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index cc4e05bb52..2df4a51306 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -31,6 +31,7 @@ import net.minecraft.server.EntityFireworks; import net.minecraft.server.EntityGhast; import net.minecraft.server.EntityGolem; import net.minecraft.server.EntityHuman; +import net.minecraft.server.EntityIllagerWizard; import net.minecraft.server.EntityInsentient; import net.minecraft.server.EntityItem; import net.minecraft.server.EntityLiving; @@ -90,6 +91,7 @@ import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.craftbukkit.entity.CraftLivingEntity; import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.craftbukkit.entity.CraftRaider; +import org.bukkit.craftbukkit.entity.CraftSpellcaster; import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting; import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.craftbukkit.inventory.CraftMetaBook; @@ -114,6 +116,7 @@ import org.bukkit.entity.PigZombie; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.entity.Raider; +import org.bukkit.entity.Spellcaster; import org.bukkit.entity.Strider; import org.bukkit.entity.ThrownExpBottle; import org.bukkit.entity.ThrownPotion; @@ -148,6 +151,7 @@ import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.event.entity.CreeperPowerEvent; import org.bukkit.event.entity.EntityBreakDoorEvent; import org.bukkit.event.entity.EntityBreedEvent; +import org.bukkit.event.entity.EntitySpellCastEvent; import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityDamageByBlockEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -1588,4 +1592,10 @@ public class CraftEventFactory { StriderTemperatureChangeEvent event = new StriderTemperatureChangeEvent((Strider) strider.getBukkitEntity(), shivering); Bukkit.getPluginManager().callEvent(event); } + + public static boolean handleEntitySpellCastEvent(EntityIllagerWizard caster, EntityIllagerWizard.Spell spell) { + EntitySpellCastEvent event = new EntitySpellCastEvent((Spellcaster) caster.getBukkitEntity(), CraftSpellcaster.toBukkitSpell(spell)); + Bukkit.getPluginManager().callEvent(event); + return !event.isCancelled(); + } }