Included a bundles system, fixed entity attributes of an entity not being resent when respawned, implemented Hologram#removeLiner
This commit is contained in:
parent
47f47b5653
commit
1f4aeef600
5 changed files with 54 additions and 8 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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,13 +446,21 @@ 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) {
|
||||
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) {
|
||||
for (PacketWrapper<?> wrapper : wrappers) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue