aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-API-Patches/0108-WitchReadyPotionEvent.patch
blob: e4383d111b2f7ade418a64d57a66598f7079336c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
From b07bf245ce402906a9d39ae8b21b386142509f7a Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
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 000000000..0e0c6da71
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/entity/WitchReadyPotionEvent.java
@@ -0,0 +1,74 @@
+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
+     * @param witch the witch whom is readying to use a potion
+     * @param potion the potion to be used
+     * @return The ItemStack to be used
+     */
+    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();
+    }
+
+    /**
+     * @return 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.18.0