From b97e5124e416b0e491646d12aacb12c0c5f95d0f Mon Sep 17 00:00:00 2001 From: Aikar Date: Tue, 5 Jun 2018 22:48:27 -0400 Subject: [PATCH] WitchReadyPotionEvent Control what potion the witch readies to use --- .../0109-WitchReadyPotionEvent.patch | 87 +++++++++++++++++++ .../0301-WitchReadyPotionEvent.patch | 26 ++++++ 2 files changed, 113 insertions(+) create mode 100644 Spigot-API-Patches/0109-WitchReadyPotionEvent.patch create mode 100644 Spigot-Server-Patches/0301-WitchReadyPotionEvent.patch diff --git a/Spigot-API-Patches/0109-WitchReadyPotionEvent.patch b/Spigot-API-Patches/0109-WitchReadyPotionEvent.patch new file mode 100644 index 000000000..ca5606257 --- /dev/null +++ b/Spigot-API-Patches/0109-WitchReadyPotionEvent.patch @@ -0,0 +1,87 @@ +From 923b71da4ced8f00c0065473ee419aeb620114ef Mon Sep 17 00:00:00 2001 +From: Aikar +Date: Tue, 5 Jun 2018 22:47:08 -0400 +Subject: [PATCH] WitchReadyPotionEvent + +Control what potion the witch readies to use + +diff --git a/src/main/java/com/destroystokyo/paper/event/entity/WitchReadyPotionEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/WitchReadyPotionEvent.java +new file mode 100644 +index 00000000..5082662a +--- /dev/null ++++ b/src/main/java/com/destroystokyo/paper/event/entity/WitchReadyPotionEvent.java +@@ -0,0 +1,71 @@ ++package com.destroystokyo.paper.event.entity; ++ ++import org.bukkit.Material; ++import org.bukkit.entity.Witch; ++import org.bukkit.event.Cancellable; ++import org.bukkit.event.Event; ++import org.bukkit.event.HandlerList; ++import org.bukkit.event.entity.EntityEvent; ++import org.bukkit.inventory.ItemStack; ++ ++public class WitchReadyPotionEvent extends EntityEvent implements Cancellable { ++ private ItemStack potion; ++ ++ public WitchReadyPotionEvent(Witch witch, ItemStack potion) { ++ super(witch); ++ this.potion = potion; ++ } ++ ++ /** ++ * Fires thee event, returning the desired potion, or air of cancelled ++ */ ++ public static ItemStack process(Witch witch, ItemStack potion) { ++ WitchReadyPotionEvent event = new WitchReadyPotionEvent(witch, potion); ++ if (!event.callEvent() || event.getPotion() == null) { ++ return new ItemStack(Material.AIR); ++ } ++ return event.getPotion(); ++ } ++ ++ @Override ++ public Witch getEntity() { ++ return (Witch) super.getEntity(); ++ } ++ ++ /** ++ * Gets the potion the witch is readying to use ++ */ ++ public ItemStack getPotion() { ++ return potion; ++ } ++ ++ /** ++ * Sets the potion the which is going to hold and use ++ * @param potion The potion ++ */ ++ public void setPotion(ItemStack potion) { ++ this.potion = potion != null ? potion.clone() : null; ++ } ++ ++ private static final HandlerList handlers = new HandlerList(); ++ ++ public HandlerList getHandlers() { ++ return handlers; ++ } ++ ++ public static HandlerList getHandlerList() { ++ return handlers; ++ } ++ ++ private boolean cancelled = false; ++ ++ @Override ++ public boolean isCancelled() { ++ return cancelled; ++ } ++ ++ @Override ++ public void setCancelled(boolean cancel) { ++ cancelled = cancel; ++ } ++} +-- +2.17.1 + diff --git a/Spigot-Server-Patches/0301-WitchReadyPotionEvent.patch b/Spigot-Server-Patches/0301-WitchReadyPotionEvent.patch new file mode 100644 index 000000000..784ecb7f9 --- /dev/null +++ b/Spigot-Server-Patches/0301-WitchReadyPotionEvent.patch @@ -0,0 +1,26 @@ +From 2bbf05040bd95dea82d291401c46bfc0d5e95ae1 Mon Sep 17 00:00:00 2001 +From: Aikar +Date: Tue, 5 Jun 2018 22:47:26 -0400 +Subject: [PATCH] WitchReadyPotionEvent + + +diff --git a/src/main/java/net/minecraft/server/EntityWitch.java b/src/main/java/net/minecraft/server/EntityWitch.java +index bf029ad1c..035aa4a90 100644 +--- a/src/main/java/net/minecraft/server/EntityWitch.java ++++ b/src/main/java/net/minecraft/server/EntityWitch.java +@@ -104,7 +104,11 @@ public class EntityWitch extends EntityMonster implements IRangedEntity { + } + + if (potionregistry != null) { +- this.setSlot(EnumItemSlot.MAINHAND, PotionUtil.a(new ItemStack(Items.POTION), potionregistry)); ++ // Paper start ++ ItemStack potion = PotionUtil.a(new ItemStack(Items.POTION), potionregistry); ++ org.bukkit.inventory.ItemStack bukkitStack = com.destroystokyo.paper.event.entity.WitchReadyPotionEvent.process((org.bukkit.entity.Witch) this.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(potion)); ++ this.setSlot(EnumItemSlot.MAINHAND, org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(bukkitStack)); ++ // Paper end + this.bx = this.getItemInMainHand().m(); + this.a(true); + this.world.a((EntityHuman) null, this.locX, this.locY, this.locZ, SoundEffects.iz, this.bK(), 1.0F, 0.8F + this.random.nextFloat() * 0.4F); +-- +2.17.1 +