per player hologram 1.19.3

This commit is contained in:
NK 2022-12-22 18:43:24 +00:00
parent 5b5502c0b4
commit 4d6b125774
2 changed files with 23 additions and 21 deletions

View file

@ -1,17 +1,18 @@
package me.night.nullvalkyrie.entities.holograms; package me.night.nullvalkyrie.entities.holograms;
import net.minecraft.network.chat.IChatBaseComponent; import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata; import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity; import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket;
import net.minecraft.network.syncher.DataWatcher; import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.DataWatcherObject; import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.DataWatcherRegistry; import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.EntityPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.PlayerConnection; import net.minecraft.server.network.ServerGamePacketListenerImpl;
import net.minecraft.world.entity.decoration.EntityArmorStand; import net.minecraft.world.entity.decoration.ArmorStand;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.List;
import java.util.Optional; import java.util.Optional;
public class PerPlayerHologram { public class PerPlayerHologram {
@ -23,15 +24,16 @@ public class PerPlayerHologram {
} }
} }
private void spawnLine(double y, Player player, String line) { private void spawnLine(double y, Player player, String line) {
EntityPlayer p = ((CraftPlayer) player).getHandle(); ServerPlayer p = ((CraftPlayer) player).getHandle();
EntityArmorStand stand = new EntityArmorStand(p.s, player.getLocation().getX(), y, player.getLocation().getZ()); ArmorStand stand = new ArmorStand(p.level, player.getLocation().getX(), y, player.getLocation().getZ());
stand.j(true); stand.setInvisible(true);
PlayerConnection connection = p.b; ServerGamePacketListenerImpl connection = p.connection;
connection.a(new PacketPlayOutSpawnEntity(stand)); connection.send(new ClientboundAddEntityPacket(stand));
DataWatcher watcher = stand.ai(); SynchedEntityData watcher = stand.getEntityData();
Optional<IChatBaseComponent> optional = Optional.of(IChatBaseComponent.a(line)); Optional<Component> optional = Optional.of(Component.nullToEmpty(line));
watcher.b(new DataWatcherObject<>(2, DataWatcherRegistry.f), optional); watcher.set(new EntityDataAccessor<>(2, EntityDataSerializers.OPTIONAL_COMPONENT), optional);
watcher.b(new DataWatcherObject<>(3, DataWatcherRegistry.i), true); watcher.set(new EntityDataAccessor<>(3, EntityDataSerializers.BOOLEAN), true);
connection.a(new PacketPlayOutEntityMetadata(stand.ae(), watcher, true)); List<SynchedEntityData.DataValue<?>> list = watcher.getNonDefaultValues();
connection.send(new ClientboundSetEntityDataPacket(stand.getBukkitEntity().getEntityId(), list));
} }
} }

View file

@ -36,6 +36,6 @@ public class InteractHologramEvent extends Event implements Cancellable {
public HandlerList getHandlers() { public HandlerList getHandlers() {
return HANDLERS; return HANDLERS;
} }
@SuppressWarnings("unused")
public static HandlerList getHandlerList() { return HANDLERS; } public static HandlerList getHandlerList() { return HANDLERS; }
} }