From 4d6b12577444059e7586163c62b9711a5c476c23 Mon Sep 17 00:00:00 2001 From: NK Date: Thu, 22 Dec 2022 18:43:24 +0000 Subject: [PATCH] per player hologram 1.19.3 --- .../entities/holograms/PerPlayerHologram.java | 42 ++++++++++--------- .../events/custom/InteractHologramEvent.java | 2 +- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/main/java/me/night/nullvalkyrie/entities/holograms/PerPlayerHologram.java b/src/main/java/me/night/nullvalkyrie/entities/holograms/PerPlayerHologram.java index 4bfc98a..b4e2550 100644 --- a/src/main/java/me/night/nullvalkyrie/entities/holograms/PerPlayerHologram.java +++ b/src/main/java/me/night/nullvalkyrie/entities/holograms/PerPlayerHologram.java @@ -1,17 +1,18 @@ package me.night.nullvalkyrie.entities.holograms; -import net.minecraft.network.chat.IChatBaseComponent; -import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata; -import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.server.level.EntityPlayer; -import net.minecraft.server.network.PlayerConnection; -import net.minecraft.world.entity.decoration.EntityArmorStand; -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; +import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerGamePacketListenerImpl; +import net.minecraft.world.entity.decoration.ArmorStand; +import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; import org.bukkit.entity.Player; +import java.util.List; import java.util.Optional; public class PerPlayerHologram { @@ -23,15 +24,16 @@ public class PerPlayerHologram { } } private void spawnLine(double y, Player player, String line) { - EntityPlayer p = ((CraftPlayer) player).getHandle(); - EntityArmorStand stand = new EntityArmorStand(p.s, player.getLocation().getX(), y, player.getLocation().getZ()); - stand.j(true); - PlayerConnection connection = p.b; - connection.a(new PacketPlayOutSpawnEntity(stand)); - DataWatcher watcher = stand.ai(); - Optional optional = Optional.of(IChatBaseComponent.a(line)); - watcher.b(new DataWatcherObject<>(2, DataWatcherRegistry.f), optional); - watcher.b(new DataWatcherObject<>(3, DataWatcherRegistry.i), true); - connection.a(new PacketPlayOutEntityMetadata(stand.ae(), watcher, true)); + ServerPlayer p = ((CraftPlayer) player).getHandle(); + ArmorStand stand = new ArmorStand(p.level, player.getLocation().getX(), y, player.getLocation().getZ()); + stand.setInvisible(true); + ServerGamePacketListenerImpl connection = p.connection; + connection.send(new ClientboundAddEntityPacket(stand)); + SynchedEntityData watcher = stand.getEntityData(); + Optional optional = Optional.of(Component.nullToEmpty(line)); + watcher.set(new EntityDataAccessor<>(2, EntityDataSerializers.OPTIONAL_COMPONENT), optional); + watcher.set(new EntityDataAccessor<>(3, EntityDataSerializers.BOOLEAN), true); + List> list = watcher.getNonDefaultValues(); + connection.send(new ClientboundSetEntityDataPacket(stand.getBukkitEntity().getEntityId(), list)); } } diff --git a/src/main/java/me/night/nullvalkyrie/events/custom/InteractHologramEvent.java b/src/main/java/me/night/nullvalkyrie/events/custom/InteractHologramEvent.java index 6d8e275..f5d054d 100644 --- a/src/main/java/me/night/nullvalkyrie/events/custom/InteractHologramEvent.java +++ b/src/main/java/me/night/nullvalkyrie/events/custom/InteractHologramEvent.java @@ -36,6 +36,6 @@ public class InteractHologramEvent extends Event implements Cancellable { public HandlerList getHandlers() { return HANDLERS; } - + @SuppressWarnings("unused") public static HandlerList getHandlerList() { return HANDLERS; } }