From 2e05530f363c190734c6cab15b5ff54c9f806ad6 Mon Sep 17 00:00:00 2001 From: Felipe Paschoal Bergamo <64669985+felipepasc@users.noreply.github.com> Date: Tue, 3 Jun 2025 18:37:58 -0300 Subject: [PATCH] Cleaned up the WrapperEntityPotionEffect class by removing --- .../java/me/tofaa/entitylib/APIConfig.java | 10 ---- .../me/tofaa/entitylib/meta/EntityMeta.java | 2 +- .../meta/display/TextDisplayMeta.java | 1 - .../wrapper/WrapperEntityPotionEffect.java | 55 +------------------ .../wrapper/WrapperLivingEntity.java | 9 +-- 5 files changed, 4 insertions(+), 73 deletions(-) diff --git a/api/src/main/java/me/tofaa/entitylib/APIConfig.java b/api/src/main/java/me/tofaa/entitylib/APIConfig.java index 5f59c05..4394618 100644 --- a/api/src/main/java/me/tofaa/entitylib/APIConfig.java +++ b/api/src/main/java/me/tofaa/entitylib/APIConfig.java @@ -13,7 +13,6 @@ public final class APIConfig { private boolean platformLogger = false; private boolean bstats = true; private boolean forceBundle = false; - private boolean ignoreServerVersionVerify = false; public APIConfig(PacketEventsAPI packetEvents) { this.packetEvents = packetEvents; @@ -54,11 +53,6 @@ public final class APIConfig { return this; } - public @NotNull APIConfig ignoreServerVersionVerify() { - this.ignoreServerVersionVerify = true; - return this; - } - public boolean isDebugMode() { return debugMode; } @@ -88,8 +82,4 @@ public final class APIConfig { && EntityLib.getOptionalApi().isPresent() && EntityLib.getOptionalApi().get().getPacketEvents().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_19_4); } - - public boolean shouldIgnoreServerVersionVerify() { - return ignoreServerVersionVerify; - } } diff --git a/api/src/main/java/me/tofaa/entitylib/meta/EntityMeta.java b/api/src/main/java/me/tofaa/entitylib/meta/EntityMeta.java index d6907af..8f99e4b 100644 --- a/api/src/main/java/me/tofaa/entitylib/meta/EntityMeta.java +++ b/api/src/main/java/me/tofaa/entitylib/meta/EntityMeta.java @@ -201,12 +201,12 @@ public class EntityMeta implements EntityMetadataProvider { } protected static void isVersionNewer(ServerVersion version) { - if (EntityLib.getApi().getSettings().shouldIgnoreServerVersionVerify()) return; if (EntityLib.getOptionalApi().isPresent()) { if (!EntityLib.getApi().getPacketEvents().getServerManager().getVersion().is(VersionComparison.NEWER_THAN, version)) { throw new InvalidVersionException("This method is only available for versions newer than " + version.name() + "."); } } + if (!PacketEvents.getAPI().getServerManager().getVersion().is(VersionComparison.NEWER_THAN, version)) { throw new InvalidVersionException("This method is only available for versions newer than " + version.name() + "."); } diff --git a/api/src/main/java/me/tofaa/entitylib/meta/display/TextDisplayMeta.java b/api/src/main/java/me/tofaa/entitylib/meta/display/TextDisplayMeta.java index 85ef64e..7fb8f71 100644 --- a/api/src/main/java/me/tofaa/entitylib/meta/display/TextDisplayMeta.java +++ b/api/src/main/java/me/tofaa/entitylib/meta/display/TextDisplayMeta.java @@ -19,7 +19,6 @@ public class TextDisplayMeta extends AbstractDisplayMeta { super(entityId, metadata); } - public Component getText() { return metadata.getIndex(OFFSET, Component.empty()); } diff --git a/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntityPotionEffect.java b/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntityPotionEffect.java index 50a2705..2d47629 100644 --- a/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntityPotionEffect.java +++ b/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntityPotionEffect.java @@ -4,19 +4,17 @@ import com.github.retrooper.packetevents.protocol.nbt.NBTCompound; import com.github.retrooper.packetevents.protocol.potion.PotionType; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityEffect; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerRemoveEntityEffect; -import me.tofaa.entitylib.tick.Tickable; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.concurrent.ConcurrentHashMap; -public class WrapperEntityPotionEffect implements Tickable { +public class WrapperEntityPotionEffect { private final WrapperLivingEntity entity; private final Map effects = new ConcurrentHashMap<>(); private boolean notifyChanges = true; - private boolean ticking = true; public WrapperEntityPotionEffect(WrapperLivingEntity entity) { this.entity = entity; @@ -134,16 +132,6 @@ public class WrapperEntityPotionEffect implements Tickable { boolean visible = effect.isVisible(); boolean icons = effect.hasIcons(); NBTCompound factorData = effect.getFactorData(); - long createdAt = effect.getCreatedAt(); - - int remainingDuration = duration; - if (duration != -1) { - long elapsedMillis = System.currentTimeMillis() - createdAt; - - int elapsedTicks = (int) (elapsedMillis / 50); - - remainingDuration = Math.max(duration - elapsedTicks, 0); - } int flags = 0; @@ -162,7 +150,7 @@ public class WrapperEntityPotionEffect implements Tickable { wrapperPlayServerEntityEffect.setEntityId(this.entity.getEntityId()); wrapperPlayServerEntityEffect.setPotionType(potionType); wrapperPlayServerEntityEffect.setEffectAmplifier(amplifier); - wrapperPlayServerEntityEffect.setEffectDurationTicks(remainingDuration); + wrapperPlayServerEntityEffect.setEffectDurationTicks(duration); wrapperPlayServerEntityEffect.setFactorData(factorData); return wrapperPlayServerEntityEffect; @@ -191,39 +179,6 @@ public class WrapperEntityPotionEffect implements Tickable { refresh(); } - @Override - public boolean isTicking() { - return this.ticking; - } - - @Override - public void setTicking(boolean ticking) { - this.ticking = ticking; - } - - @Override - public void tick(long time) { - Set toRemove = new HashSet<>(); - - this.effects.values().forEach(effect -> { - PotionType potionType = effect.getPotionType(); - - int duration = effect.getDuration(); - if (duration <= -1) return; // Infinity effect - - long createdAt = effect.getCreatedAt(); - - long elapsedMillis = time - createdAt; - - int elapsedTicks = (int) (elapsedMillis / 50); - - int remainingDuration = duration - elapsedTicks; - if (remainingDuration <= 0) toRemove.add(potionType); - }); - - toRemove.forEach(this::removePotionEffect); - } - public static class WrapperPotionEffect { private final PotionType potionType; private final int amplifier; @@ -232,7 +187,6 @@ public class WrapperEntityPotionEffect implements Tickable { private final boolean visible; private final boolean icons; private final @Nullable NBTCompound factorData; - private final long createdAt; private WrapperPotionEffect(PotionType potionType, int amplifier, int duration, boolean ambient, boolean visible, boolean icons, @Nullable NBTCompound factorData) { this.potionType = potionType; @@ -242,7 +196,6 @@ public class WrapperEntityPotionEffect implements Tickable { this.visible = visible; this.icons = icons; this.factorData = factorData; - this.createdAt = System.currentTimeMillis(); } public PotionType getPotionType() { @@ -272,9 +225,5 @@ public class WrapperEntityPotionEffect implements Tickable { public @Nullable NBTCompound getFactorData() { return factorData; } - - public long getCreatedAt() { - return createdAt; - } } } diff --git a/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperLivingEntity.java b/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperLivingEntity.java index 465f840..290e557 100644 --- a/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperLivingEntity.java +++ b/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperLivingEntity.java @@ -59,13 +59,6 @@ public class WrapperLivingEntity extends WrapperEntity { this.attributes.refresh(); } - @Override - public void tick(long time) { - this.potionEffect.tick(time); - - super.tick(time); - } - public WrapperEntityAttributes getAttributes() { return this.attributes; } @@ -83,7 +76,7 @@ public class WrapperLivingEntity extends WrapperEntity { packets.add(getAttributes().createPacket()); packets.add(getEquipment().createPacket()); - packets.addAll(this.potionEffect.createEffectPackets()); + packets.addAll(getPotionEffect().createEffectPackets()); return packets; }