diff --git a/api/src/main/java/me/tofaa/entitylib/APIConfig.java b/api/src/main/java/me/tofaa/entitylib/APIConfig.java index 37cfad1..3cba7e7 100644 --- a/api/src/main/java/me/tofaa/entitylib/APIConfig.java +++ b/api/src/main/java/me/tofaa/entitylib/APIConfig.java @@ -1,6 +1,7 @@ package me.tofaa.entitylib; import com.github.retrooper.packetevents.PacketEventsAPI; +import com.github.retrooper.packetevents.manager.server.ServerVersion; import org.jetbrains.annotations.NotNull; public final class APIConfig { @@ -11,6 +12,7 @@ public final class APIConfig { private boolean tickTickables = false; private boolean platformLogger = false; private boolean bstats = true; + private boolean forceBundle = false; public APIConfig(PacketEventsAPI packetEvents) { this.packetEvents = packetEvents; @@ -26,6 +28,11 @@ public final class APIConfig { return this; } + public @NotNull APIConfig forceBundles() { + this.forceBundle = true; + return this; + } + public @NotNull APIConfig usePlatformLogger() { this.platformLogger = true; return this; @@ -70,4 +77,10 @@ public final class APIConfig { return bstats; } + public boolean shouldForceBundles() { + return this.forceBundle + && EntityLib.getOptionalApi().isPresent() + && EntityLib.getOptionalApi().get().getPacketEvents().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_19_4); + } + } diff --git a/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntity.java b/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntity.java index c4610dd..794f2fe 100644 --- a/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntity.java +++ b/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntity.java @@ -73,7 +73,7 @@ public class WrapperEntity implements Tickable { if (spawned) return false; this.location = location; this.spawned = true; - sendPacketToViewers( + sendPacketsToViewers( new WrapperPlayServerSpawnEntity( entityId, Optional.of(this.uuid), @@ -84,9 +84,12 @@ public class WrapperEntity implements Tickable { location.getYaw(), getObjectData(), createVeloPacket() - ) + ), + entityMeta.createPacket() ); - sendPacketToViewers(entityMeta.createPacket()); + if (this instanceof WrapperLivingEntity) { + sendPacketsToViewers(((WrapperLivingEntity)this).getAttributes().createPacket()); + } this.parent = parent; parent.addEntity(this); return true; @@ -196,6 +199,9 @@ public class WrapperEntity implements Tickable { sendPacket(uuid, createSpawnPacket()); sendPacket(uuid, entityMeta.createPacket()); sendPacket(uuid, createPassengerPacket()); + if (this instanceof WrapperLivingEntity) { + sendPacket(uuid, ((WrapperLivingEntity)this).getAttributes().createPacket()); + } } if (EntityLib.getApi().getSettings().isDebugMode()) { EntityLib.getPlatform().getLogger().info("Added viewer " + uuid + " to entity " + entityId); @@ -341,7 +347,6 @@ public class WrapperEntity implements Tickable { consumer.accept(entityMeta); } - public @NotNull UUID getUuid() { return uuid; } @@ -393,7 +398,7 @@ public class WrapperEntity implements Tickable { return viewerRules.get(index); } - private WrapperPlayServerEntityVelocity getVelocityPacket() { + public WrapperPlayServerEntityVelocity getVelocityPacket() { Vector3d velocity = this.velocity.multiply(8000.0f / 20.0f); return new WrapperPlayServerEntityVelocity(entityId, velocity); } @@ -441,12 +446,20 @@ public class WrapperEntity implements Tickable { public void refresh() { if (!spawned) return; - sendPacketToViewers(entityMeta.createPacket()); - sendPacketToViewers(createPassengerPacket()); + sendPacketsToViewers(entityMeta.createPacket(), createPassengerPacket()); } public void sendPacketToViewers(PacketWrapper packet) { - viewers.forEach(uuid -> sendPacket(uuid, packet)); + if (EntityLib.getApi().getSettings().shouldForceBundles()) { + viewers.forEach(uuid -> { + sendPacket(uuid, new WrapperPlayServerBundle()); + sendPacket(uuid, packet); + sendPacket(uuid, new WrapperPlayServerBundle()); + }); + } + else { + viewers.forEach(uuid -> sendPacket(uuid, packet)); + } } public void sendPacketsToViewers(PacketWrapper... wrappers) { diff --git a/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/Hologram.java b/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/Hologram.java index 2327d08..151772a 100644 --- a/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/Hologram.java +++ b/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/Hologram.java @@ -45,6 +45,8 @@ public interface Hologram { void setLine(int index, @Nullable Component line); + void removeLine(int index); + void addLine(@Nullable Component line); void addViewer(@NotNull UUID viewer); diff --git a/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/LegacyHologram.java b/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/LegacyHologram.java index 6cf847c..363b00d 100644 --- a/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/LegacyHologram.java +++ b/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/LegacyHologram.java @@ -110,6 +110,15 @@ final class LegacyHologram implements Hologram.Legacy { teleport(location); } + @Override + public void removeLine(int index) { + if (index < 0 || index >= lines.size()) { + return; + } + this.lines.get(index).remove(); + this.lines.remove(index); + } + @Override public void addLine(@Nullable Component line) { setLine(lines.size(), line); diff --git a/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/ModernHologram.java b/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/ModernHologram.java index 7391d1f..6d7d43f 100644 --- a/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/ModernHologram.java +++ b/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/ModernHologram.java @@ -89,6 +89,15 @@ final class ModernHologram implements Hologram.Modern { } } + @Override + public void removeLine(int index) { + if (index < 0 || index >= lines.size()) { + return; + } + this.lines.get(index).remove(); + this.lines.remove(index); + } + @Override public void addLine(@Nullable Component line) { setLine(lines.size(), line);