From fb5ac1851d49b3754ffac1e278641de29e94b776 Mon Sep 17 00:00:00 2001 From: NK Date: Sun, 18 Dec 2022 23:41:12 +0000 Subject: [PATCH] per player hologram --- .../nullvalkyrie/commands/BetaCommand.java | 4 +- .../entities/holograms/PerPlayerHologram.java | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 src/main/java/me/night/nullvalkyrie/entities/holograms/PerPlayerHologram.java diff --git a/src/main/java/me/night/nullvalkyrie/commands/BetaCommand.java b/src/main/java/me/night/nullvalkyrie/commands/BetaCommand.java index f35e52f..2b9497b 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/BetaCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/BetaCommand.java @@ -1,6 +1,5 @@ package me.night.nullvalkyrie.commands; -import me.night.nullvalkyrie.ui.inventory.LuckyDraw; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -18,8 +17,9 @@ public class BetaCommand extends Command { // CryptoMiner miner = new CryptoMiner(args[0], Material.DIAMOND_ORE, 1, 0.5, System.currentTimeMillis()); // miner.spawn(player, "https://textures.minecraft.net/texture/c09cc3c75bd13c59602040b5970f30dbc76825c0e817da815a65d76ab0e82198"); - new LuckyDraw().UI(player); +// new LuckyDraw().UI(player); } + } @Override diff --git a/src/main/java/me/night/nullvalkyrie/entities/holograms/PerPlayerHologram.java b/src/main/java/me/night/nullvalkyrie/entities/holograms/PerPlayerHologram.java new file mode 100644 index 0000000..04b63a7 --- /dev/null +++ b/src/main/java/me/night/nullvalkyrie/entities/holograms/PerPlayerHologram.java @@ -0,0 +1,38 @@ +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 org.bukkit.entity.Player; + +import java.util.Optional; + +public class PerPlayerHologram { + public PerPlayerHologram(Player player, String[] lines) { + double c = (lines.length) * 0.3 - 0.15; + for (String line : lines) { + spawnLine(player.getLocation().getY() + c, player, line); + c -= 0.3; + } + } + private void spawnLine(double y, Player player, String line) { + EntityPlayer splayer = ((CraftPlayer) player).getHandle(); + EntityArmorStand stand = new EntityArmorStand(splayer.s, player.getLocation().getX(), y, player.getLocation().getZ()); // creating armor stand by location and s(stands for nms world) + stand.j(true); // set invisible + PlayerConnection connection = splayer.b; //connection + connection.a(new PacketPlayOutSpawnEntity(stand)); // sending packet to spawn the armor stand + DataWatcher watcher = stand.ai(); // ai = getDataWatcher + Optional optional = Optional.of(IChatBaseComponent.a(line)); //according to wiki.vg, setting the custom name requires Optional if you are using mojang mappings, however i cant find out what a stands for, just find a method that returns ChatComponent which takes string as a parameter + watcher.b(new DataWatcherObject<>(2, DataWatcherRegistry.f), optional); // f = ChatComponent, here we putting the optional into the datawatcher + watcher.b(new DataWatcherObject<>(3, DataWatcherRegistry.i), true); // i = boolean, we setting show custom name to true + // watcher.b = set + connection.a(new PacketPlayOutEntityMetadata(stand.ae(), watcher, true)); // sending packet to update the metadata, ae=getEntityId + } +}