aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0308-Add-PufferFishStateChangeEvent.patch
blob: c3014534d3154205b8e3c25b897e3d4cdc4c9ea8 (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
91
92
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: HexedHero <6012891+HexedHero@users.noreply.github.com>
Date: Mon, 10 May 2021 16:58:38 +0100
Subject: [PATCH] Add PufferFishStateChangeEvent


diff --git a/src/main/java/io/papermc/paper/event/entity/PufferFishStateChangeEvent.java b/src/main/java/io/papermc/paper/event/entity/PufferFishStateChangeEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..3585457b21aca2a2f1779868a0fa91f8011ad3c9
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/entity/PufferFishStateChangeEvent.java
@@ -0,0 +1,80 @@
+package io.papermc.paper.event.entity;
+
+import org.bukkit.entity.PufferFish;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.entity.EntityEvent;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Called just before a {@link PufferFish} inflates or deflates.
+ */
+public class PufferFishStateChangeEvent extends EntityEvent implements Cancellable {
+    private static final HandlerList handlers = new HandlerList();
+    private boolean cancelled;
+    private int newPuffState;
+
+    public PufferFishStateChangeEvent(@NotNull PufferFish entity, int newPuffState) {
+        super(entity);
+        this.newPuffState = newPuffState;
+    }
+
+    @NotNull
+    @Override
+    public PufferFish getEntity() {
+        return (PufferFish) entity;
+    }
+
+    /**
+     * Get the <strong>new</strong> puff state of the {@link PufferFish}.
+     * <p>
+     * This is what the {@link PufferFish}'s new puff state will be after this event if it isn't cancelled.<br>
+     * Refer to {@link PufferFish#getPuffState()} to get the current puff state.
+     * @return The <strong>new</strong> puff state, 0 being not inflated, 1 being slightly inflated and 2 being fully inflated
+     */
+    public int getNewPuffState() {
+        return this.newPuffState;
+    }
+
+    /**
+     * Get if the {@link PufferFish} is going to inflate.
+     * @return If its going to inflate
+     */
+    public boolean isInflating() {
+        return getNewPuffState() > getEntity().getPuffState();
+    }
+
+    /**
+     * Get if the {@link PufferFish} is going to deflate.
+     * @return If its going to deflate
+     */
+    public boolean isDeflating() {
+        return getNewPuffState() < getEntity().getPuffState();
+    }
+
+    /**
+     * Set whether or not to cancel the {@link PufferFish} (in/de)flating.
+     *
+     * @param cancel true if you wish to cancel the (in/de)flation
+     */
+    @Override
+    public void setCancelled(boolean cancel) {
+        this.cancelled = cancel;
+    }
+
+    @Override
+    public boolean isCancelled() {
+        return cancelled;
+    }
+
+    @NotNull
+    @Override
+    public HandlerList getHandlers() {
+        return handlers;
+    }
+
+    @NotNull
+    public static HandlerList getHandlerList() {
+        return handlers;
+    }
+}