Cleaned up the WrapperEntityPotionEffect class by removing
This commit is contained in:
parent
9e7ecf310e
commit
2e05530f36
5 changed files with 4 additions and 73 deletions
|
@ -13,7 +13,6 @@ public final class APIConfig {
|
||||||
private boolean platformLogger = false;
|
private boolean platformLogger = false;
|
||||||
private boolean bstats = true;
|
private boolean bstats = true;
|
||||||
private boolean forceBundle = false;
|
private boolean forceBundle = false;
|
||||||
private boolean ignoreServerVersionVerify = false;
|
|
||||||
|
|
||||||
public APIConfig(PacketEventsAPI<?> packetEvents) {
|
public APIConfig(PacketEventsAPI<?> packetEvents) {
|
||||||
this.packetEvents = packetEvents;
|
this.packetEvents = packetEvents;
|
||||||
|
@ -54,11 +53,6 @@ public final class APIConfig {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull APIConfig ignoreServerVersionVerify() {
|
|
||||||
this.ignoreServerVersionVerify = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDebugMode() {
|
public boolean isDebugMode() {
|
||||||
return debugMode;
|
return debugMode;
|
||||||
}
|
}
|
||||||
|
@ -88,8 +82,4 @@ public final class APIConfig {
|
||||||
&& EntityLib.getOptionalApi().isPresent()
|
&& EntityLib.getOptionalApi().isPresent()
|
||||||
&& EntityLib.getOptionalApi().get().getPacketEvents().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_19_4);
|
&& EntityLib.getOptionalApi().get().getPacketEvents().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_19_4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldIgnoreServerVersionVerify() {
|
|
||||||
return ignoreServerVersionVerify;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,12 +201,12 @@ public class EntityMeta implements EntityMetadataProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void isVersionNewer(ServerVersion version) {
|
protected static void isVersionNewer(ServerVersion version) {
|
||||||
if (EntityLib.getApi().getSettings().shouldIgnoreServerVersionVerify()) return;
|
|
||||||
if (EntityLib.getOptionalApi().isPresent()) {
|
if (EntityLib.getOptionalApi().isPresent()) {
|
||||||
if (!EntityLib.getApi().getPacketEvents().getServerManager().getVersion().is(VersionComparison.NEWER_THAN, version)) {
|
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() + ".");
|
throw new InvalidVersionException("This method is only available for versions newer than " + version.name() + ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PacketEvents.getAPI().getServerManager().getVersion().is(VersionComparison.NEWER_THAN, version)) {
|
if (!PacketEvents.getAPI().getServerManager().getVersion().is(VersionComparison.NEWER_THAN, version)) {
|
||||||
throw new InvalidVersionException("This method is only available for versions newer than " + version.name() + ".");
|
throw new InvalidVersionException("This method is only available for versions newer than " + version.name() + ".");
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ public class TextDisplayMeta extends AbstractDisplayMeta {
|
||||||
super(entityId, metadata);
|
super(entityId, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Component getText() {
|
public Component getText() {
|
||||||
return metadata.getIndex(OFFSET, Component.empty());
|
return metadata.getIndex(OFFSET, Component.empty());
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.protocol.potion.PotionType;
|
||||||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityEffect;
|
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityEffect;
|
||||||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerRemoveEntityEffect;
|
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerRemoveEntityEffect;
|
||||||
import me.tofaa.entitylib.tick.Tickable;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class WrapperEntityPotionEffect implements Tickable {
|
public class WrapperEntityPotionEffect {
|
||||||
private final WrapperLivingEntity entity;
|
private final WrapperLivingEntity entity;
|
||||||
private final Map<PotionType, WrapperPotionEffect> effects = new ConcurrentHashMap<>();
|
private final Map<PotionType, WrapperPotionEffect> effects = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private boolean notifyChanges = true;
|
private boolean notifyChanges = true;
|
||||||
private boolean ticking = true;
|
|
||||||
|
|
||||||
public WrapperEntityPotionEffect(WrapperLivingEntity entity) {
|
public WrapperEntityPotionEffect(WrapperLivingEntity entity) {
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
|
@ -134,16 +132,6 @@ public class WrapperEntityPotionEffect implements Tickable {
|
||||||
boolean visible = effect.isVisible();
|
boolean visible = effect.isVisible();
|
||||||
boolean icons = effect.hasIcons();
|
boolean icons = effect.hasIcons();
|
||||||
NBTCompound factorData = effect.getFactorData();
|
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;
|
int flags = 0;
|
||||||
|
|
||||||
|
@ -162,7 +150,7 @@ public class WrapperEntityPotionEffect implements Tickable {
|
||||||
wrapperPlayServerEntityEffect.setEntityId(this.entity.getEntityId());
|
wrapperPlayServerEntityEffect.setEntityId(this.entity.getEntityId());
|
||||||
wrapperPlayServerEntityEffect.setPotionType(potionType);
|
wrapperPlayServerEntityEffect.setPotionType(potionType);
|
||||||
wrapperPlayServerEntityEffect.setEffectAmplifier(amplifier);
|
wrapperPlayServerEntityEffect.setEffectAmplifier(amplifier);
|
||||||
wrapperPlayServerEntityEffect.setEffectDurationTicks(remainingDuration);
|
wrapperPlayServerEntityEffect.setEffectDurationTicks(duration);
|
||||||
wrapperPlayServerEntityEffect.setFactorData(factorData);
|
wrapperPlayServerEntityEffect.setFactorData(factorData);
|
||||||
|
|
||||||
return wrapperPlayServerEntityEffect;
|
return wrapperPlayServerEntityEffect;
|
||||||
|
@ -191,39 +179,6 @@ public class WrapperEntityPotionEffect implements Tickable {
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isTicking() {
|
|
||||||
return this.ticking;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setTicking(boolean ticking) {
|
|
||||||
this.ticking = ticking;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick(long time) {
|
|
||||||
Set<PotionType> 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 {
|
public static class WrapperPotionEffect {
|
||||||
private final PotionType potionType;
|
private final PotionType potionType;
|
||||||
private final int amplifier;
|
private final int amplifier;
|
||||||
|
@ -232,7 +187,6 @@ public class WrapperEntityPotionEffect implements Tickable {
|
||||||
private final boolean visible;
|
private final boolean visible;
|
||||||
private final boolean icons;
|
private final boolean icons;
|
||||||
private final @Nullable NBTCompound factorData;
|
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) {
|
private WrapperPotionEffect(PotionType potionType, int amplifier, int duration, boolean ambient, boolean visible, boolean icons, @Nullable NBTCompound factorData) {
|
||||||
this.potionType = potionType;
|
this.potionType = potionType;
|
||||||
|
@ -242,7 +196,6 @@ public class WrapperEntityPotionEffect implements Tickable {
|
||||||
this.visible = visible;
|
this.visible = visible;
|
||||||
this.icons = icons;
|
this.icons = icons;
|
||||||
this.factorData = factorData;
|
this.factorData = factorData;
|
||||||
this.createdAt = System.currentTimeMillis();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PotionType getPotionType() {
|
public PotionType getPotionType() {
|
||||||
|
@ -272,9 +225,5 @@ public class WrapperEntityPotionEffect implements Tickable {
|
||||||
public @Nullable NBTCompound getFactorData() {
|
public @Nullable NBTCompound getFactorData() {
|
||||||
return factorData;
|
return factorData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getCreatedAt() {
|
|
||||||
return createdAt;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,13 +59,6 @@ public class WrapperLivingEntity extends WrapperEntity {
|
||||||
this.attributes.refresh();
|
this.attributes.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick(long time) {
|
|
||||||
this.potionEffect.tick(time);
|
|
||||||
|
|
||||||
super.tick(time);
|
|
||||||
}
|
|
||||||
|
|
||||||
public WrapperEntityAttributes getAttributes() {
|
public WrapperEntityAttributes getAttributes() {
|
||||||
return this.attributes;
|
return this.attributes;
|
||||||
}
|
}
|
||||||
|
@ -83,7 +76,7 @@ public class WrapperLivingEntity extends WrapperEntity {
|
||||||
|
|
||||||
packets.add(getAttributes().createPacket());
|
packets.add(getAttributes().createPacket());
|
||||||
packets.add(getEquipment().createPacket());
|
packets.add(getEquipment().createPacket());
|
||||||
packets.addAll(this.potionEffect.createEffectPackets());
|
packets.addAll(getPotionEffect().createEffectPackets());
|
||||||
|
|
||||||
return packets;
|
return packets;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue