From 35f9489280fa8f9ebc55e8e44a314ee621465ce2 Mon Sep 17 00:00:00 2001 From: DeidaraMC <117625071+DeidaraMC@users.noreply.github.com> Date: Mon, 15 Jan 2024 20:37:21 -0500 Subject: [PATCH] update: infinite potion duration support (#106) * upgrade: infinite potion duration * fix: no more aqgit --------- Co-authored-by: mworzala (cherry picked from commit bb4d925ec4211a268f95b4dcaec287f00df6f93c) --- src/main/java/net/minestom/server/entity/Entity.java | 4 +++- src/main/java/net/minestom/server/potion/Potion.java | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/minestom/server/entity/Entity.java b/src/main/java/net/minestom/server/entity/Entity.java index 0cc929cd2..db957dbf7 100644 --- a/src/main/java/net/minestom/server/entity/Entity.java +++ b/src/main/java/net/minestom/server/entity/Entity.java @@ -724,7 +724,9 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev final List effects = this.effects; if (effects.isEmpty()) return; effects.removeIf(timedPotion -> { - final long potionTime = (long) timedPotion.getPotion().duration() * MinecraftServer.TICK_MS; + long duration = timedPotion.getPotion().duration(); + if (duration == Potion.INFINITE_DURATION) return false; + final long potionTime = duration * MinecraftServer.TICK_MS; // Remove if the potion should be expired if (time >= timedPotion.getStartingTime() + potionTime) { // Send the packet that the potion should no longer be applied diff --git a/src/main/java/net/minestom/server/potion/Potion.java b/src/main/java/net/minestom/server/potion/Potion.java index 9fda569f6..6ad326aa0 100644 --- a/src/main/java/net/minestom/server/potion/Potion.java +++ b/src/main/java/net/minestom/server/potion/Potion.java @@ -48,6 +48,11 @@ public record Potion(@NotNull PotionEffect effect, byte amplifier, */ public static final byte ICON_FLAG = 0x04; + /** + * A duration constant which sets a Potion duration to infinite. + */ + public static final int INFINITE_DURATION = -1; + /** * Creates a new Potion with no flags. *