mSpigot-Parent/patches/api/0012-Riot-style-HCF-changes-for-better-QOL-Potion-related.patch

184 lines
5.2 KiB
Diff
Raw Normal View History

2023-07-21 05:34:25 +02:00
From 520669969c02c527fbcd06dc51a8c04e867cd670 Mon Sep 17 00:00:00 2001
From: virtualWinter <winter@catmc.club>
Date: Fri, 21 Jul 2023 06:19:50 +0300
Subject: [PATCH] Riot-style HCF changes for better QOL (Potion related part)
diff --git a/src/main/java/org/bukkit/event/entity/PotionEffectAddEvent.java b/src/main/java/org/bukkit/event/entity/PotionEffectAddEvent.java
new file mode 100644
index 00000000..6ac7dc75
--- /dev/null
+++ b/src/main/java/org/bukkit/event/entity/PotionEffectAddEvent.java
@@ -0,0 +1,40 @@
+package org.bukkit.event.entity;
+
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.potion.PotionEffect;
+
+import lombok.Getter;
+import lombok.Setter;
+
+
+public class PotionEffectAddEvent extends PotionEffectEvent implements Cancellable {
+
+ private static final HandlerList handlers = new HandlerList();
+
+ @Getter @Setter private boolean cancelled;
+ @Getter protected final EffectCause effectCause;
+
+ public PotionEffectAddEvent(LivingEntity entity, PotionEffect effect, EffectCause effectCause) {
+ super(entity, effect);
+ this.effectCause = effectCause;
+ }
+
+ @Override
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+
+ public enum EffectCause {
+ POTION_SPLASH,
+ BEACON,
+ WITHER_SKELETON,
+ PLUGIN,
+ UNKNOWN
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/bukkit/event/entity/PotionEffectEvent.java b/src/main/java/org/bukkit/event/entity/PotionEffectEvent.java
new file mode 100644
index 00000000..aefbc8f8
--- /dev/null
+++ b/src/main/java/org/bukkit/event/entity/PotionEffectEvent.java
@@ -0,0 +1,23 @@
+package org.bukkit.event.entity;
+
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.potion.PotionEffect;
+
+import lombok.Getter;
+
+public abstract class PotionEffectEvent extends EntityEvent {
+
+ @Getter private final PotionEffect effect;
+
+ public PotionEffectEvent(LivingEntity what, PotionEffect effect) {
+ super(what);
+ this.effect = effect;
+ }
+
+ @Override
+ public LivingEntity getEntity() {
+ return (LivingEntity) super.getEntity();
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/bukkit/event/entity/PotionEffectExpireEvent.java b/src/main/java/org/bukkit/event/entity/PotionEffectExpireEvent.java
new file mode 100644
index 00000000..2c1e7424
--- /dev/null
+++ b/src/main/java/org/bukkit/event/entity/PotionEffectExpireEvent.java
@@ -0,0 +1,30 @@
+package org.bukkit.event.entity;
+
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.potion.PotionEffect;
+
+import lombok.Getter;
+
+public class PotionEffectExpireEvent extends PotionEffectRemoveEvent {
+
+ @Getter private int duration = 0;
+
+ public PotionEffectExpireEvent(LivingEntity entity, PotionEffect effect) {
+ super(entity, effect);
+ }
+
+ public void setDuration(int duration) {
+ this.duration = Math.max(0, duration);
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return duration > 0;
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
+ this.duration = cancel ? Integer.MAX_VALUE : 0;
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/bukkit/event/entity/PotionEffectExtendEvent.java b/src/main/java/org/bukkit/event/entity/PotionEffectExtendEvent.java
new file mode 100644
index 00000000..bb25707a
--- /dev/null
+++ b/src/main/java/org/bukkit/event/entity/PotionEffectExtendEvent.java
@@ -0,0 +1,16 @@
+package org.bukkit.event.entity;
+
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.potion.PotionEffect;
+
+import lombok.Getter;
+
+public class PotionEffectExtendEvent extends PotionEffectAddEvent {
+
+ @Getter private final PotionEffect oldEffect;
+
+ public PotionEffectExtendEvent(LivingEntity entity, PotionEffect effect, PotionEffect oldEffect, EffectCause effectCause) {
+ super(entity, effect, effectCause);
+ this.oldEffect = oldEffect;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/bukkit/event/entity/PotionEffectRemoveEvent.java b/src/main/java/org/bukkit/event/entity/PotionEffectRemoveEvent.java
new file mode 100644
index 00000000..f2be18e7
--- /dev/null
+++ b/src/main/java/org/bukkit/event/entity/PotionEffectRemoveEvent.java
@@ -0,0 +1,30 @@
+package org.bukkit.event.entity;
+
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.potion.PotionEffect;
+
+import lombok.Getter;
+import lombok.Setter;
+
+public class PotionEffectRemoveEvent extends PotionEffectEvent implements Cancellable {
+
+ private static final HandlerList handlers = new HandlerList();
+
+ @Getter @Setter private boolean cancelled;
+
+ public PotionEffectRemoveEvent(LivingEntity entity, PotionEffect effect) {
+ super(entity, effect);
+ }
+
+ @Override
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+
+}
\ No newline at end of file
--
2.41.0.windows.1