From 08af20f5adb08a1e6ec4f65c3881e78d0c47a839 Mon Sep 17 00:00:00 2001 From: Tofaa <82680183+Tofaa2@users.noreply.github.com> Date: Sun, 17 Dec 2023 18:30:11 +0300 Subject: [PATCH] fix metadata not being sent --- .../tofaa/entitylib/entity/WrapperEntity.java | 7 +++++ .../me/tofaa/entitylib/meta/EntityMeta.java | 27 ++++++++++--------- test-plugin/build.gradle | 5 ++-- .../me/tofaa/entitylib/TestEntityCommand.java | 19 +++++++++++-- 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/main/java/me/tofaa/entitylib/entity/WrapperEntity.java b/src/main/java/me/tofaa/entitylib/entity/WrapperEntity.java index d0838af..dfc28dc 100644 --- a/src/main/java/me/tofaa/entitylib/entity/WrapperEntity.java +++ b/src/main/java/me/tofaa/entitylib/entity/WrapperEntity.java @@ -31,6 +31,11 @@ public class WrapperEntity { this.meta = meta; } + public void refresh() { + if (!spawned) return; + sendPacketToViewers(meta.createPacket()); + } + public boolean spawn(Location location) { if (spawned) return false; this.location = location; @@ -48,6 +53,7 @@ public class WrapperEntity { Optional.empty() ) ); + sendPacketToViewers(meta.createPacket()); return true; } @@ -104,6 +110,7 @@ public class WrapperEntity { Optional.empty() ); EntityLib.sendPacket(uuid, packet); + EntityLib.sendPacket(uuid, meta.createPacket()); return true; } diff --git a/src/main/java/me/tofaa/entitylib/meta/EntityMeta.java b/src/main/java/me/tofaa/entitylib/meta/EntityMeta.java index f52d151..c69f81f 100644 --- a/src/main/java/me/tofaa/entitylib/meta/EntityMeta.java +++ b/src/main/java/me/tofaa/entitylib/meta/EntityMeta.java @@ -77,12 +77,25 @@ public class EntityMeta implements EntityMetadataProvider { } public Component getCustomName() { - return this.metadata.getIndex((byte) 2, null); + return this.metadata.getIndex(offset(OFFSET, 2), null); + } + + public void setCustomName(Component value) { + this.metadata.setIndex(offset(OFFSET, 2), EntityDataTypes.COMPONENT, GsonComponentSerializer.gson().serialize(value)); + } + + public boolean isCustomNameVisible() { + return this.metadata.getIndex(offset(OFFSET, 3), false); + } + + public void setCustomNameVisible(boolean value) { + this.metadata.setIndex(offset(OFFSET, 3), EntityDataTypes.BOOLEAN, value); } public boolean hasGlowingEffect() { return getMaskBit(OFFSET, HAS_GLOWING_EFFECT_BIT); } + public boolean isSwimming() { return getMaskBit(OFFSET, SWIMMING_BIT); } @@ -103,18 +116,6 @@ public class EntityMeta implements EntityMetadataProvider { setMaskBit(OFFSET, FLYING_WITH_ELYTRA_BIT, value); } - public void setCustomName(Component value) { - this.metadata.setIndex((byte) 2, EntityDataTypes.COMPONENT, GsonComponentSerializer.gson().serialize(value)); - } - - public boolean isCustomNameVisible() { - return this.metadata.getIndex((byte) 3, false); - } - - public void setCustomNameVisible(boolean value) { - this.metadata.setIndex((byte) 3, EntityDataTypes.BOOLEAN, value); - } - public boolean isSilent() { return this.metadata.getIndex((byte) 4, false); } diff --git a/test-plugin/build.gradle b/test-plugin/build.gradle index 0ee9a0d..1827dd3 100644 --- a/test-plugin/build.gradle +++ b/test-plugin/build.gradle @@ -1,7 +1,8 @@ plugins { id 'java' id 'com.github.johnrengelman.shadow' version '7.1.2' - + id("io.papermc.paperweight.userdev") version "1.5.11" + id 'xyz.jpenilla.run-paper' version '2.2.2' } group = 'me.tofaa.peentitymeta' @@ -24,7 +25,7 @@ repositories { } dependencies { - compileOnly('org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT') + paperweight.paperDevBundle("1.20.4-R0.1-SNAPSHOT") compileOnly('com.github.retrooper.packetevents:spigot:2.0.2') implementation project(':') } diff --git a/test-plugin/src/main/java/me/tofaa/entitylib/TestEntityCommand.java b/test-plugin/src/main/java/me/tofaa/entitylib/TestEntityCommand.java index d4fe719..722f01f 100644 --- a/test-plugin/src/main/java/me/tofaa/entitylib/TestEntityCommand.java +++ b/test-plugin/src/main/java/me/tofaa/entitylib/TestEntityCommand.java @@ -6,6 +6,8 @@ import io.github.retrooper.packetevents.util.SpigotConversionUtil; import me.tofaa.entitylib.entity.WrapperEntity; import me.tofaa.entitylib.entity.WrapperLivingEntity; import me.tofaa.entitylib.meta.EntityMeta; +import me.tofaa.entitylib.meta.other.ArmorStandMeta; +import net.kyori.adventure.text.Component; import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -25,7 +27,6 @@ public class TestEntityCommand implements CommandExecutor { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { if (!(sender instanceof Player)) return false; Player player = (Player) sender; - if (entity == null) { entity = (WrapperLivingEntity) EntityLib.createEntity(UUID.randomUUID(), EntityTypes.ZOMBIE); if (entity == null) { @@ -42,9 +43,23 @@ public class TestEntityCommand implements CommandExecutor { EntityMeta meta = entity.getMeta(); meta.setOnFire(!meta.isOnFire()); meta.setHasGlowingEffect(!meta.hasGlowingEffect()); + + meta.setCustomNameVisible(!meta.isCustomNameVisible()); + meta.setCustomName(Component.text("test")); + player.sendMessage("on fire: " + meta.isOnFire()); player.sendMessage("glowing: " + meta.hasGlowingEffect()); - player.sendMessage("viewers: " + entity.getViewers()); + + + WrapperEntity e = EntityLib.createEntity(UUID.randomUUID(), EntityTypes.ARMOR_STAND); + int entityId = e.getEntityId(); // You can set the entityId provider to change this, WrapperEntity#ID_PROVIDER + if (e == null) { + throw new RuntimeException("Error creating entity meta"); // Only happens if the entity meta is null/invalid. + } + ArmorStandMeta m = (ArmorStandMeta) e.getMeta(); + m.setInvisible(true); + e.spawn(new Location(1, 2, 3, 4, 5)); + e.addViewer(player.getUniqueId()); return false; }