PaperMC/patches/api/0101-WitchThrowPotionEvent.patch

95 lines
2.7 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Wed, 16 May 2018 20:39:09 -0400
Subject: [PATCH] WitchThrowPotionEvent
Fired when a witch throws a potion at a player
diff --git a/src/main/java/com/destroystokyo/paper/event/entity/WitchThrowPotionEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/WitchThrowPotionEvent.java
2024-02-01 10:15:57 +01:00
new file mode 100644
index 0000000000000000000000000000000000000000..02395582b680f4baa3dc2251a8a79f41241b96ec
2024-02-01 10:15:57 +01:00
--- /dev/null
2021-06-11 14:02:28 +02:00
+++ b/src/main/java/com/destroystokyo/paper/event/entity/WitchThrowPotionEvent.java
@@ -0,0 +1,81 @@
2024-02-01 10:15:57 +01:00
+package com.destroystokyo.paper.event.entity;
+
2021-06-11 14:02:28 +02:00
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.entity.Witch;
2024-02-01 10:15:57 +01:00
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
2021-06-11 14:02:28 +02:00
+import org.bukkit.event.entity.EntityEvent;
+import org.bukkit.inventory.ItemStack;
2024-02-01 10:15:57 +01:00
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
2024-02-01 10:15:57 +01:00
+
2021-06-11 14:02:28 +02:00
+/**
+ * Fired when a witch throws a potion at a player
+ */
+@NullMarked
2021-06-11 14:02:28 +02:00
+public class WitchThrowPotionEvent extends EntityEvent implements Cancellable {
2024-02-01 10:15:57 +01:00
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
+ private final LivingEntity target;
+ private @Nullable ItemStack potion;
2024-02-01 10:15:57 +01:00
+ private boolean cancelled;
2021-06-11 14:02:28 +02:00
+
2024-02-01 10:15:57 +01:00
+ @ApiStatus.Internal
+ public WitchThrowPotionEvent(final Witch witch, final LivingEntity target, final @Nullable ItemStack potion) {
2021-06-11 14:02:28 +02:00
+ super(witch);
+ this.target = target;
+ this.potion = potion;
2024-02-01 10:15:57 +01:00
+ }
+
2021-06-11 14:02:28 +02:00
+ @Override
+ public Witch getEntity() {
+ return (Witch) super.getEntity();
+ }
+
+ /**
+ * @return The target of the potion
+ */
+ public LivingEntity getTarget() {
2024-02-01 10:15:57 +01:00
+ return this.target;
2021-06-11 14:02:28 +02:00
+ }
+
+ /**
+ * @return The potion the witch will throw at a player
+ */
+ public @Nullable ItemStack getPotion() {
2024-02-01 10:15:57 +01:00
+ return this.potion;
2021-06-11 14:02:28 +02:00
+ }
+
+ /**
+ * Sets the potion to be thrown at a player
2024-02-01 10:15:57 +01:00
+ *
2021-06-11 14:02:28 +02:00
+ * @param potion The potion
+ */
+ public void setPotion(final @Nullable ItemStack potion) {
2021-06-11 14:02:28 +02:00
+ this.potion = potion != null ? potion.clone() : null;
+ }
2024-02-01 10:15:57 +01:00
+
2021-06-11 14:02:28 +02:00
+ /**
2024-02-01 10:15:57 +01:00
+ * @return Event was cancelled or potion was {@code null}
2021-06-11 14:02:28 +02:00
+ */
2024-02-01 10:15:57 +01:00
+ @Override
+ public boolean isCancelled() {
+ return this.cancelled || this.potion == null;
+ }
+
+ @Override
+ public void setCancelled(final boolean cancel) {
2024-02-01 10:15:57 +01:00
+ this.cancelled = cancel;
+ }
+
+ @Override
+ public HandlerList getHandlers() {
+ return HANDLER_LIST;
+ }
+
+ public static HandlerList getHandlerList() {
+ return HANDLER_LIST;
+ }
+}