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;
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<IChatBaseComponent> 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<Component> optional = Optional.of(Component.nullToEmpty(line));
watcher.set(new EntityDataAccessor<>(2, EntityDataSerializers.OPTIONAL_COMPONENT), optional);
watcher.set(new EntityDataAccessor<>(3, EntityDataSerializers.BOOLEAN), 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() {
return HANDLERS;
}
@SuppressWarnings("unused")
public static HandlerList getHandlerList() { return HANDLERS; }
}