From 3c1d46398d331798f445fcf80c2c05292c52f326 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 28 Dec 2024 12:26:12 +0100 Subject: [PATCH 1/8] Add RDisplay, RBlockDisplay, RItemDisplay, RTextDisplay --- .../src/de/steamwar/entity/RBlockDisplay.java | 30 ++++ .../src/de/steamwar/entity/RDisplay.java | 154 ++++++++++++++++++ .../src/de/steamwar/entity/REntity.java | 2 +- .../src/de/steamwar/entity/RItemDisplay.java | 41 +++++ .../src/de/steamwar/entity/RTextDisplay.java | 116 +++++++++++++ 5 files changed, 342 insertions(+), 1 deletion(-) create mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java create mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java create mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java create mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java new file mode 100644 index 00000000..a349e8c0 --- /dev/null +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java @@ -0,0 +1,30 @@ +package de.steamwar.entity; + +import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.core.BountifulWrapper; +import de.steamwar.core.Core; +import lombok.Getter; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.data.BlockData; +import org.bukkit.entity.EntityType; + +public class RBlockDisplay extends RDisplay { + + @Getter + private BlockData block = Material.AIR.createBlockData(); + + public RBlockDisplay(REntityServer server, Location location) { + super(server, EntityType.BLOCK_DISPLAY, location); + } + + private static final Class iBlockDataClass = Reflection.getClass("{nms.world}.level.block.state.IBlockData"); + private static final Reflection.MethodInvoker getState = Reflection.getTypedMethod(Reflection.getClass("{obc}.block.data.CraftBlockData"), "getState", iBlockDataClass); + private static final Object blockWatcher = BountifulWrapper.impl.getDataWatcherObject(23, iBlockDataClass); + public void setBlock(BlockData block) { + this.block = block; + if (Core.getVersion() >= 20) { + server.updateEntity(this, getDataWatcherPacket(blockWatcher, getState.invoke(block))); + } + } +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java new file mode 100644 index 00000000..2cc86492 --- /dev/null +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java @@ -0,0 +1,154 @@ +package de.steamwar.entity; + +import de.steamwar.core.BountifulWrapper; +import de.steamwar.core.Core; +import lombok.Getter; +import lombok.NonNull; +import org.bukkit.Color; +import org.bukkit.Location; +import org.bukkit.entity.Display; +import org.bukkit.entity.EntityType; +import org.bukkit.util.Transformation; +import org.joml.Quaternionf; +import org.joml.Vector3f; + +public class RDisplay extends REntity { + + @Getter + private Transformation transform = new Transformation(new Vector3f(), new Quaternionf(0, 0, 0, 1), new Vector3f(1, 1, 1), new Quaternionf(0, 0, 0, 1)); + + @Getter + private int interpolationDuration = 0; + + @Getter + private float viewRange = 1.0F; + + @Getter + private float shadowRadius = 0.0F; + + @Getter + private float shadowStrength = 1.0F; + + @Getter + private float displayWidth = 0.0F; + + @Getter + private float displayHeight = 0.0F; + + @Getter + private int interpolationDelay = 0; + + @Getter + private Display.Billboard billboard = Display.Billboard.FIXED; + + @Getter + private Color glowColorOverride = null; + + @Getter + private Display.Brightness brightness = null; + + protected RDisplay(REntityServer server, EntityType entityType, Location location) { + super(server, entityType, location); + } + + private static final Object translationWatcher = BountifulWrapper.impl.getDataWatcherObject(10, Vector3f.class); + private static final Object leftRotationWatcher = BountifulWrapper.impl.getDataWatcherObject(12, Quaternionf.class); + private static final Object scaleWatcher = BountifulWrapper.impl.getDataWatcherObject(11, Vector3f.class); + private static final Object rightRotationWatcher = BountifulWrapper.impl.getDataWatcherObject(13, Quaternionf.class); + public void setTransform(@NonNull Transformation transform) { + this.transform = transform; + if (Core.getVersion() >= 20) { + server.updateEntity(this, getDataWatcherPacket(translationWatcher, transform.getTranslation())); + server.updateEntity(this, getDataWatcherPacket(leftRotationWatcher, transform.getLeftRotation())); + server.updateEntity(this, getDataWatcherPacket(scaleWatcher, transform.getScale())); + server.updateEntity(this, getDataWatcherPacket(rightRotationWatcher, transform.getRightRotation())); + } + } + + private static final Object transformationInterpolationDurationWatcher = BountifulWrapper.impl.getDataWatcherObject(9, Integer.class); + private static final Object positionOrRotationInterpolationDurationWatcher = BountifulWrapper.impl.getDataWatcherObject(10, Integer.class); + public void setInterpolationDuration(int interpolationDuration) { + this.interpolationDuration = interpolationDuration; + if (Core.getVersion() >= 20) { + server.updateEntity(this, getDataWatcherPacket(transformationInterpolationDurationWatcher, interpolationDuration)); + server.updateEntity(this, getDataWatcherPacket(positionOrRotationInterpolationDurationWatcher, interpolationDuration)); + } + } + + private static final Object viewRangeWatcher = BountifulWrapper.impl.getDataWatcherObject(17, Float.class); + public void setViewRange(float viewRange) { + this.viewRange = viewRange; + if (Core.getVersion() >= 20) { + server.updateEntity(this, getDataWatcherPacket(viewRangeWatcher, viewRange)); + } + } + + private static final Object shadowRadiusWatcher = BountifulWrapper.impl.getDataWatcherObject(18, Float.class); + public void setShadowRadius(float shadowRadius) { + this.shadowRadius = shadowRadius; + if (Core.getVersion() >= 20) { + server.updateEntity(this, getDataWatcherPacket(shadowRadiusWatcher, shadowRadius)); + } + } + + private static final Object shadowStrengthWatcher = BountifulWrapper.impl.getDataWatcherObject(19, Float.class); + public void setShadowStrength(float shadowStrength) { + this.shadowStrength = shadowStrength; + if (Core.getVersion() >= 20) { + server.updateEntity(this, getDataWatcherPacket(shadowStrengthWatcher, shadowStrength)); + } + } + + private static final Object displayWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(20, Float.class); + public void setDisplayWidth(float displayWidth) { + this.displayWidth = displayWidth; + if (Core.getVersion() >= 20) { + server.updateEntity(this, getDataWatcherPacket(displayWidthWatcher, displayWidth)); + } + } + + private static final Object displayHeightWatcher = BountifulWrapper.impl.getDataWatcherObject(21, Float.class); + public void setDisplayHeight(float displayHeight) { + this.displayHeight = displayHeight; + if (Core.getVersion() >= 20) { + server.updateEntity(this, getDataWatcherPacket(displayHeightWatcher, displayHeight)); + } + } + + private static final Object interpolationDelayWatcher = BountifulWrapper.impl.getDataWatcherObject(22, Integer.class); + public void setInterpolationDelay(int interpolationDelay) { + this.interpolationDelay = interpolationDelay; + if (Core.getVersion() >= 20) { + server.updateEntity(this, getDataWatcherPacket(interpolationDelayWatcher, interpolationDelay)); + } + } + + private static final Object billboardWatcher = BountifulWrapper.impl.getDataWatcherObject(15, Byte.class); + public void setBillboard(Display.Billboard billboard) { + this.billboard = billboard; + if (Core.getVersion() >= 20) { + server.updateEntity(this, getDataWatcherPacket(billboardWatcher, (byte) billboard.ordinal())); + } + } + + private static final Object glowColorOverrideWatcher = BountifulWrapper.impl.getDataWatcherObject(3, Integer.class); + public void setGlowColorOverride(Color glowColorOverride) { + this.glowColorOverride = glowColorOverride; + if (Core.getVersion() >= 20) { + server.updateEntity(this, getDataWatcherPacket(glowColorOverrideWatcher, glowColorOverride == null ? -1 : glowColorOverride.asARGB())); + } + } + + private static final Object brightnessWatcher = BountifulWrapper.impl.getDataWatcherObject(16, Integer.class); + public void setBrightness(Display.Brightness brightness) { + this.brightness = brightness; + if (Core.getVersion() >= 20) { + if (brightness == null) { + server.updateEntity(this, getDataWatcherPacket(brightnessWatcher, -1)); + } else { + int brightnessData = brightness.getBlockLight() << 4 | brightness.getSkyLight() << 20; + server.updateEntity(this, getDataWatcherPacket(brightnessWatcher, brightnessData)); + } + } + } +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java index e7ecb1a8..66c13c40 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -45,7 +45,7 @@ public class REntity { private static int entityIdCounter = -1; private static final Random random = new Random(); - private final REntityServer server; + protected final REntityServer server; private final EntityType entityType; @Getter protected final int entityId; diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java new file mode 100644 index 00000000..c45db756 --- /dev/null +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java @@ -0,0 +1,41 @@ +package de.steamwar.entity; + +import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.core.BountifulWrapper; +import de.steamwar.core.Core; +import lombok.Getter; +import org.bukkit.Location; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.ItemDisplay; +import org.bukkit.inventory.ItemStack; + +public class RItemDisplay extends RDisplay { + + @Getter + private ItemStack itemStack; + + @Getter + private ItemDisplay.ItemDisplayTransform itemDisplayTransform; + + public RItemDisplay(REntityServer server, Location location) { + super(server, EntityType.ITEM_DISPLAY, location); + } + + private static final Class itemStackClass = Reflection.getClass("{nms.world}.item.ItemStack"); + private static final Reflection.MethodInvoker asNMSCopy = Reflection.getTypedMethod(Reflection.getClass("{obc}.inventory.CraftItemStack"), "asNMSCopy", itemStackClass); + private static final Object itemStackWatcher = BountifulWrapper.impl.getDataWatcherObject(23, itemStackClass); + public void setItemStack(ItemStack itemStack) { + this.itemStack = itemStack; + if (Core.getVersion() >= 20) { + server.updateEntity(this, getDataWatcherPacket(itemStackWatcher, asNMSCopy.invoke(itemStack))); + } + } + + private static final Object itemDisplayTransformWatcher = BountifulWrapper.impl.getDataWatcherObject(24, Byte.class); + public void setItemDisplayTransform(ItemDisplay.ItemDisplayTransform itemDisplayTransform) { + this.itemDisplayTransform = itemDisplayTransform; + if (Core.getVersion() >= 20) { + server.updateEntity(this, getDataWatcherPacket(itemDisplayTransformWatcher, (byte) itemDisplayTransform.ordinal())); + } + } +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java new file mode 100644 index 00000000..459dd9e8 --- /dev/null +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java @@ -0,0 +1,116 @@ +package de.steamwar.entity; + +import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.core.BountifulWrapper; +import de.steamwar.core.ChatWrapper; +import de.steamwar.core.Core; +import lombok.Getter; +import org.bukkit.Location; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.TextDisplay; + +public class RTextDisplay extends RDisplay { + + @Getter + private String text = ""; + + @Getter + private int lineWidth = 200; + + @Getter + private byte textOpacity = (byte) -1; + + @Getter + private boolean shadowed = false; + + @Getter + private boolean seeThrough = false; + + @Getter + private boolean defaultBackground = false; + + @Getter + private TextDisplay.TextAlignment alignment = TextDisplay.TextAlignment.CENTER; + + public RTextDisplay(REntityServer server, Location location) { + super(server, EntityType.TEXT_DISPLAY, location); + } + + private static final Class iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent"); + private static final Object textWatcher = BountifulWrapper.impl.getDataWatcherObject(23, iChatBaseComponent); + public void setText(String text) { + this.text = text; + if (Core.getVersion() >= 20) { + server.updateEntity(this, getDataWatcherPacket(textWatcher, ChatWrapper.impl.stringToChatComponent(text))); + } + } + + private static final Object lineWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(24, Integer.class); + public void setLineWidth(int lineWidth) { + this.lineWidth = lineWidth; + if (Core.getVersion() >= 20) { + server.updateEntity(this, getDataWatcherPacket(lineWidthWatcher, lineWidth)); + } + } + + private static final Object textOpacityWatcher = BountifulWrapper.impl.getDataWatcherObject(26, Byte.class); + public void setTextOpacity(byte textOpacity) { + this.textOpacity = textOpacity; + if (Core.getVersion() >= 20) { + server.updateEntity(this, getDataWatcherPacket(textOpacityWatcher, textOpacity)); + } + } + + private static final Object textStatusWatcher = BountifulWrapper.impl.getDataWatcherObject(27, Byte.class); + + public void setShadowed(boolean shadowed) { + this.shadowed = shadowed; + if (Core.getVersion() >= 20) { + server.updateEntity(this, getDataWatcherPacket(textStatusWatcher, getTextStatus())); + } + } + + public void setSeeThrough(boolean seeThrough) { + this.seeThrough = seeThrough; + if (Core.getVersion() >= 20) { + server.updateEntity(this, getDataWatcherPacket(textStatusWatcher, getTextStatus())); + } + } + + public void setDefaultBackground(boolean defaultBackground) { + this.defaultBackground = defaultBackground; + if (Core.getVersion() >= 20) { + server.updateEntity(this, getDataWatcherPacket(textStatusWatcher, getTextStatus())); + } + } + + public void setAlignment(TextDisplay.TextAlignment alignment) { + this.alignment = alignment; + if (Core.getVersion() >= 20) { + server.updateEntity(this, getDataWatcherPacket(textStatusWatcher, getTextStatus())); + } + } + + private byte getTextStatus() { + byte status = 0; + + if (shadowed) { + status |= 0x01; + } + if (seeThrough) { + status |= 0x02; + } + if (defaultBackground) { + status |= 0x04; + } + if (alignment == TextDisplay.TextAlignment.CENTER) { + // Do nothing + } else if (alignment == TextDisplay.TextAlignment.LEFT) { + status |= 0x08; + } else if (alignment == TextDisplay.TextAlignment.RIGHT) { + status |= 0x0F; + } + + return status; + } +} From 33f41869b601c056c5430a2b24cc050b4d845db2 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 28 Dec 2024 16:08:50 +0100 Subject: [PATCH 2/8] Fix packets --- .../src/de/steamwar/entity/RBlockDisplay.java | 4 +-- .../src/de/steamwar/entity/RDisplay.java | 36 +++++++------------ .../src/de/steamwar/entity/RItemDisplay.java | 11 +++--- .../src/de/steamwar/entity/RTextDisplay.java | 16 +++------ 4 files changed, 25 insertions(+), 42 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java index a349e8c0..6dbb8fb2 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java @@ -9,9 +9,9 @@ import org.bukkit.Material; import org.bukkit.block.data.BlockData; import org.bukkit.entity.EntityType; +@Getter public class RBlockDisplay extends RDisplay { - @Getter private BlockData block = Material.AIR.createBlockData(); public RBlockDisplay(REntityServer server, Location location) { @@ -20,7 +20,7 @@ public class RBlockDisplay extends RDisplay { private static final Class iBlockDataClass = Reflection.getClass("{nms.world}.level.block.state.IBlockData"); private static final Reflection.MethodInvoker getState = Reflection.getTypedMethod(Reflection.getClass("{obc}.block.data.CraftBlockData"), "getState", iBlockDataClass); - private static final Object blockWatcher = BountifulWrapper.impl.getDataWatcherObject(23, iBlockDataClass); + private static final Object blockWatcher = BountifulWrapper.impl.getDataWatcherObject(22, iBlockDataClass); public void setBlock(BlockData block) { this.block = block; if (Core.getVersion() >= 20) { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java index 2cc86492..39a8615a 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java @@ -12,39 +12,29 @@ import org.bukkit.util.Transformation; import org.joml.Quaternionf; import org.joml.Vector3f; -public class RDisplay extends REntity { +@Getter +public abstract class RDisplay extends REntity { - @Getter private Transformation transform = new Transformation(new Vector3f(), new Quaternionf(0, 0, 0, 1), new Vector3f(1, 1, 1), new Quaternionf(0, 0, 0, 1)); - @Getter private int interpolationDuration = 0; - @Getter private float viewRange = 1.0F; - @Getter private float shadowRadius = 0.0F; - @Getter private float shadowStrength = 1.0F; - @Getter private float displayWidth = 0.0F; - @Getter private float displayHeight = 0.0F; - @Getter private int interpolationDelay = 0; - @Getter private Display.Billboard billboard = Display.Billboard.FIXED; - @Getter private Color glowColorOverride = null; - @Getter private Display.Brightness brightness = null; protected RDisplay(REntityServer server, EntityType entityType, Location location) { @@ -65,8 +55,8 @@ public class RDisplay extends REntity { } } - private static final Object transformationInterpolationDurationWatcher = BountifulWrapper.impl.getDataWatcherObject(9, Integer.class); - private static final Object positionOrRotationInterpolationDurationWatcher = BountifulWrapper.impl.getDataWatcherObject(10, Integer.class); + private static final Object transformationInterpolationDurationWatcher = BountifulWrapper.impl.getDataWatcherObject(8, Integer.class); + private static final Object positionOrRotationInterpolationDurationWatcher = BountifulWrapper.impl.getDataWatcherObject(9, Integer.class); public void setInterpolationDuration(int interpolationDuration) { this.interpolationDuration = interpolationDuration; if (Core.getVersion() >= 20) { @@ -75,7 +65,7 @@ public class RDisplay extends REntity { } } - private static final Object viewRangeWatcher = BountifulWrapper.impl.getDataWatcherObject(17, Float.class); + private static final Object viewRangeWatcher = BountifulWrapper.impl.getDataWatcherObject(16, Float.class); public void setViewRange(float viewRange) { this.viewRange = viewRange; if (Core.getVersion() >= 20) { @@ -83,7 +73,7 @@ public class RDisplay extends REntity { } } - private static final Object shadowRadiusWatcher = BountifulWrapper.impl.getDataWatcherObject(18, Float.class); + private static final Object shadowRadiusWatcher = BountifulWrapper.impl.getDataWatcherObject(17, Float.class); public void setShadowRadius(float shadowRadius) { this.shadowRadius = shadowRadius; if (Core.getVersion() >= 20) { @@ -91,7 +81,7 @@ public class RDisplay extends REntity { } } - private static final Object shadowStrengthWatcher = BountifulWrapper.impl.getDataWatcherObject(19, Float.class); + private static final Object shadowStrengthWatcher = BountifulWrapper.impl.getDataWatcherObject(18, Float.class); public void setShadowStrength(float shadowStrength) { this.shadowStrength = shadowStrength; if (Core.getVersion() >= 20) { @@ -99,7 +89,7 @@ public class RDisplay extends REntity { } } - private static final Object displayWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(20, Float.class); + private static final Object displayWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(19, Float.class); public void setDisplayWidth(float displayWidth) { this.displayWidth = displayWidth; if (Core.getVersion() >= 20) { @@ -107,7 +97,7 @@ public class RDisplay extends REntity { } } - private static final Object displayHeightWatcher = BountifulWrapper.impl.getDataWatcherObject(21, Float.class); + private static final Object displayHeightWatcher = BountifulWrapper.impl.getDataWatcherObject(20, Float.class); public void setDisplayHeight(float displayHeight) { this.displayHeight = displayHeight; if (Core.getVersion() >= 20) { @@ -115,7 +105,7 @@ public class RDisplay extends REntity { } } - private static final Object interpolationDelayWatcher = BountifulWrapper.impl.getDataWatcherObject(22, Integer.class); + private static final Object interpolationDelayWatcher = BountifulWrapper.impl.getDataWatcherObject(7, Integer.class); public void setInterpolationDelay(int interpolationDelay) { this.interpolationDelay = interpolationDelay; if (Core.getVersion() >= 20) { @@ -123,7 +113,7 @@ public class RDisplay extends REntity { } } - private static final Object billboardWatcher = BountifulWrapper.impl.getDataWatcherObject(15, Byte.class); + private static final Object billboardWatcher = BountifulWrapper.impl.getDataWatcherObject(14, Byte.class); public void setBillboard(Display.Billboard billboard) { this.billboard = billboard; if (Core.getVersion() >= 20) { @@ -131,7 +121,7 @@ public class RDisplay extends REntity { } } - private static final Object glowColorOverrideWatcher = BountifulWrapper.impl.getDataWatcherObject(3, Integer.class); + private static final Object glowColorOverrideWatcher = BountifulWrapper.impl.getDataWatcherObject(21, Integer.class); public void setGlowColorOverride(Color glowColorOverride) { this.glowColorOverride = glowColorOverride; if (Core.getVersion() >= 20) { @@ -139,7 +129,7 @@ public class RDisplay extends REntity { } } - private static final Object brightnessWatcher = BountifulWrapper.impl.getDataWatcherObject(16, Integer.class); + private static final Object brightnessWatcher = BountifulWrapper.impl.getDataWatcherObject(15, Integer.class); public void setBrightness(Display.Brightness brightness) { this.brightness = brightness; if (Core.getVersion() >= 20) { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java index c45db756..0f546957 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java @@ -9,12 +9,11 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.ItemDisplay; import org.bukkit.inventory.ItemStack; +@Getter public class RItemDisplay extends RDisplay { - @Getter private ItemStack itemStack; - @Getter private ItemDisplay.ItemDisplayTransform itemDisplayTransform; public RItemDisplay(REntityServer server, Location location) { @@ -22,16 +21,16 @@ public class RItemDisplay extends RDisplay { } private static final Class itemStackClass = Reflection.getClass("{nms.world}.item.ItemStack"); - private static final Reflection.MethodInvoker asNMSCopy = Reflection.getTypedMethod(Reflection.getClass("{obc}.inventory.CraftItemStack"), "asNMSCopy", itemStackClass); - private static final Object itemStackWatcher = BountifulWrapper.impl.getDataWatcherObject(23, itemStackClass); + private static final Reflection.MethodInvoker asNMSCopy = Reflection.getTypedMethod(Reflection.getClass("{obc}.inventory.CraftItemStack"), "asNMSCopy", itemStackClass, ItemStack.class); + private static final Object itemStackWatcher = BountifulWrapper.impl.getDataWatcherObject(22, itemStackClass); public void setItemStack(ItemStack itemStack) { this.itemStack = itemStack; if (Core.getVersion() >= 20) { - server.updateEntity(this, getDataWatcherPacket(itemStackWatcher, asNMSCopy.invoke(itemStack))); + server.updateEntity(this, getDataWatcherPacket(itemStackWatcher, asNMSCopy.invoke(null, itemStack))); } } - private static final Object itemDisplayTransformWatcher = BountifulWrapper.impl.getDataWatcherObject(24, Byte.class); + private static final Object itemDisplayTransformWatcher = BountifulWrapper.impl.getDataWatcherObject(23, Byte.class); public void setItemDisplayTransform(ItemDisplay.ItemDisplayTransform itemDisplayTransform) { this.itemDisplayTransform = itemDisplayTransform; if (Core.getVersion() >= 20) { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java index 459dd9e8..49136d19 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java @@ -9,27 +9,21 @@ import org.bukkit.Location; import org.bukkit.entity.EntityType; import org.bukkit.entity.TextDisplay; +@Getter public class RTextDisplay extends RDisplay { - @Getter private String text = ""; - @Getter private int lineWidth = 200; - @Getter private byte textOpacity = (byte) -1; - @Getter private boolean shadowed = false; - @Getter private boolean seeThrough = false; - @Getter private boolean defaultBackground = false; - @Getter private TextDisplay.TextAlignment alignment = TextDisplay.TextAlignment.CENTER; public RTextDisplay(REntityServer server, Location location) { @@ -37,7 +31,7 @@ public class RTextDisplay extends RDisplay { } private static final Class iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent"); - private static final Object textWatcher = BountifulWrapper.impl.getDataWatcherObject(23, iChatBaseComponent); + private static final Object textWatcher = BountifulWrapper.impl.getDataWatcherObject(22, iChatBaseComponent); public void setText(String text) { this.text = text; if (Core.getVersion() >= 20) { @@ -45,7 +39,7 @@ public class RTextDisplay extends RDisplay { } } - private static final Object lineWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(24, Integer.class); + private static final Object lineWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(23, Integer.class); public void setLineWidth(int lineWidth) { this.lineWidth = lineWidth; if (Core.getVersion() >= 20) { @@ -53,7 +47,7 @@ public class RTextDisplay extends RDisplay { } } - private static final Object textOpacityWatcher = BountifulWrapper.impl.getDataWatcherObject(26, Byte.class); + private static final Object textOpacityWatcher = BountifulWrapper.impl.getDataWatcherObject(25, Byte.class); public void setTextOpacity(byte textOpacity) { this.textOpacity = textOpacity; if (Core.getVersion() >= 20) { @@ -61,7 +55,7 @@ public class RTextDisplay extends RDisplay { } } - private static final Object textStatusWatcher = BountifulWrapper.impl.getDataWatcherObject(27, Byte.class); + private static final Object textStatusWatcher = BountifulWrapper.impl.getDataWatcherObject(26, Byte.class); public void setShadowed(boolean shadowed) { this.shadowed = shadowed; From 3c848389c92c49ac391253e03634c9189cc9423e Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 28 Dec 2024 16:28:56 +0100 Subject: [PATCH 3/8] Update structure --- .../src/de/steamwar/entity/RBlockDisplay.java | 20 ++- .../src/de/steamwar/entity/RDisplay.java | 148 +++++++++++++----- .../src/de/steamwar/entity/RItemDisplay.java | 27 +++- .../src/de/steamwar/entity/RTextDisplay.java | 60 ++++--- 4 files changed, 184 insertions(+), 71 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java index 6dbb8fb2..53753962 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java @@ -9,6 +9,8 @@ import org.bukkit.Material; import org.bukkit.block.data.BlockData; import org.bukkit.entity.EntityType; +import java.util.function.Consumer; + @Getter public class RBlockDisplay extends RDisplay { @@ -18,13 +20,23 @@ public class RBlockDisplay extends RDisplay { super(server, EntityType.BLOCK_DISPLAY, location); } - private static final Class iBlockDataClass = Reflection.getClass("{nms.world}.level.block.state.IBlockData"); - private static final Reflection.MethodInvoker getState = Reflection.getTypedMethod(Reflection.getClass("{obc}.block.data.CraftBlockData"), "getState", iBlockDataClass); - private static final Object blockWatcher = BountifulWrapper.impl.getDataWatcherObject(22, iBlockDataClass); + @Override + protected void postSpawn(Consumer packetSink) { + super.postSpawn(packetSink); + sendBlock(packetSink); + } + public void setBlock(BlockData block) { this.block = block; if (Core.getVersion() >= 20) { - server.updateEntity(this, getDataWatcherPacket(blockWatcher, getState.invoke(block))); + sendBlock(o -> server.updateEntity(this, o)); } } + + private static final Class iBlockDataClass = Reflection.getClass("{nms.world}.level.block.state.IBlockData"); + private static final Reflection.MethodInvoker getState = Reflection.getTypedMethod(Reflection.getClass("{obc}.block.data.CraftBlockData"), "getState", iBlockDataClass); + private static final Object blockWatcher = BountifulWrapper.impl.getDataWatcherObject(22, iBlockDataClass); + private void sendBlock(Consumer packetSink) { + packetSink.accept(getDataWatcherPacket(blockWatcher, getState.invoke(block))); + } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java index 39a8615a..a8819859 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java @@ -12,6 +12,8 @@ import org.bukkit.util.Transformation; import org.joml.Quaternionf; import org.joml.Vector3f; +import java.util.function.Consumer; + @Getter public abstract class RDisplay extends REntity { @@ -41,104 +43,164 @@ public abstract class RDisplay extends REntity { super(server, entityType, location); } + @Override + protected void postSpawn(Consumer packetSink) { + super.postSpawn(packetSink); + sendTransform(packetSink); + sendInterpolationDuration(packetSink); + sendViewRange(packetSink); + sendShadowRadius(packetSink); + sendShadowStrength(packetSink); + sendDisplayWidth(packetSink); + sendDisplayHeight(packetSink); + sendInterpolationDelay(packetSink); + sendBillboard(packetSink); + sendGlowColorOverride(packetSink); + sendBrightness(packetSink); + } + + public void setTransform(@NonNull Transformation transform) { + this.transform = transform; + if (Core.getVersion() >= 20) { + sendTransform(o -> server.updateEntity(this, o)); + } + } + private static final Object translationWatcher = BountifulWrapper.impl.getDataWatcherObject(10, Vector3f.class); private static final Object leftRotationWatcher = BountifulWrapper.impl.getDataWatcherObject(12, Quaternionf.class); private static final Object scaleWatcher = BountifulWrapper.impl.getDataWatcherObject(11, Vector3f.class); private static final Object rightRotationWatcher = BountifulWrapper.impl.getDataWatcherObject(13, Quaternionf.class); - public void setTransform(@NonNull Transformation transform) { - this.transform = transform; + private void sendTransform(Consumer packetSink) { + packetSink.accept(getDataWatcherPacket(translationWatcher, transform.getTranslation())); + packetSink.accept(getDataWatcherPacket(leftRotationWatcher, transform.getLeftRotation())); + packetSink.accept(getDataWatcherPacket(scaleWatcher, transform.getScale())); + packetSink.accept(getDataWatcherPacket(rightRotationWatcher, transform.getRightRotation())); + } + + public void setInterpolationDuration(int interpolationDuration) { + this.interpolationDuration = interpolationDuration; if (Core.getVersion() >= 20) { - server.updateEntity(this, getDataWatcherPacket(translationWatcher, transform.getTranslation())); - server.updateEntity(this, getDataWatcherPacket(leftRotationWatcher, transform.getLeftRotation())); - server.updateEntity(this, getDataWatcherPacket(scaleWatcher, transform.getScale())); - server.updateEntity(this, getDataWatcherPacket(rightRotationWatcher, transform.getRightRotation())); + sendInterpolationDuration(o -> server.updateEntity(this, o)); } } private static final Object transformationInterpolationDurationWatcher = BountifulWrapper.impl.getDataWatcherObject(8, Integer.class); private static final Object positionOrRotationInterpolationDurationWatcher = BountifulWrapper.impl.getDataWatcherObject(9, Integer.class); - public void setInterpolationDuration(int interpolationDuration) { - this.interpolationDuration = interpolationDuration; + private void sendInterpolationDuration(Consumer packetSink) { + packetSink.accept(getDataWatcherPacket(transformationInterpolationDurationWatcher, interpolationDuration)); + packetSink.accept(getDataWatcherPacket(positionOrRotationInterpolationDurationWatcher, interpolationDuration)); + } + + public void setViewRange(float viewRange) { + this.viewRange = viewRange; if (Core.getVersion() >= 20) { - server.updateEntity(this, getDataWatcherPacket(transformationInterpolationDurationWatcher, interpolationDuration)); - server.updateEntity(this, getDataWatcherPacket(positionOrRotationInterpolationDurationWatcher, interpolationDuration)); + sendViewRange(o -> server.updateEntity(this, o)); } } private static final Object viewRangeWatcher = BountifulWrapper.impl.getDataWatcherObject(16, Float.class); - public void setViewRange(float viewRange) { - this.viewRange = viewRange; + private void sendViewRange(Consumer packetSink) { + packetSink.accept(getDataWatcherPacket(viewRangeWatcher, viewRange)); + } + + public void setShadowRadius(float shadowRadius) { + this.shadowRadius = shadowRadius; if (Core.getVersion() >= 20) { - server.updateEntity(this, getDataWatcherPacket(viewRangeWatcher, viewRange)); + sendShadowRadius(o -> server.updateEntity(this, o)); } } private static final Object shadowRadiusWatcher = BountifulWrapper.impl.getDataWatcherObject(17, Float.class); - public void setShadowRadius(float shadowRadius) { - this.shadowRadius = shadowRadius; + private void sendShadowRadius(Consumer packetSink) { + packetSink.accept(getDataWatcherPacket(shadowRadiusWatcher, shadowRadius)); + } + + public void setShadowStrength(float shadowStrength) { + this.shadowStrength = shadowStrength; if (Core.getVersion() >= 20) { - server.updateEntity(this, getDataWatcherPacket(shadowRadiusWatcher, shadowRadius)); + sendShadowStrength(o -> server.updateEntity(this, o)); } } private static final Object shadowStrengthWatcher = BountifulWrapper.impl.getDataWatcherObject(18, Float.class); - public void setShadowStrength(float shadowStrength) { - this.shadowStrength = shadowStrength; + private void sendShadowStrength(Consumer packetSink) { + packetSink.accept(getDataWatcherPacket(shadowStrengthWatcher, shadowStrength)); + } + + public void setDisplayWidth(float displayWidth) { + this.displayWidth = displayWidth; if (Core.getVersion() >= 20) { - server.updateEntity(this, getDataWatcherPacket(shadowStrengthWatcher, shadowStrength)); + sendDisplayWidth(o -> server.updateEntity(this, o)); } } private static final Object displayWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(19, Float.class); - public void setDisplayWidth(float displayWidth) { - this.displayWidth = displayWidth; + private void sendDisplayWidth(Consumer packetSink) { + packetSink.accept(getDataWatcherPacket(displayWidthWatcher, displayWidth)); + } + + public void setDisplayHeight(float displayHeight) { + this.displayHeight = displayHeight; if (Core.getVersion() >= 20) { - server.updateEntity(this, getDataWatcherPacket(displayWidthWatcher, displayWidth)); + sendDisplayHeight(o -> server.updateEntity(this, o)); } } private static final Object displayHeightWatcher = BountifulWrapper.impl.getDataWatcherObject(20, Float.class); - public void setDisplayHeight(float displayHeight) { - this.displayHeight = displayHeight; + private void sendDisplayHeight(Consumer packetSink) { + packetSink.accept(getDataWatcherPacket(displayHeightWatcher, displayHeight)); + } + + public void setInterpolationDelay(int interpolationDelay) { + this.interpolationDelay = interpolationDelay; if (Core.getVersion() >= 20) { - server.updateEntity(this, getDataWatcherPacket(displayHeightWatcher, displayHeight)); + sendInterpolationDelay(o -> server.updateEntity(this, o)); } } private static final Object interpolationDelayWatcher = BountifulWrapper.impl.getDataWatcherObject(7, Integer.class); - public void setInterpolationDelay(int interpolationDelay) { - this.interpolationDelay = interpolationDelay; + private void sendInterpolationDelay(Consumer packetSink) { + packetSink.accept(getDataWatcherPacket(interpolationDelayWatcher, interpolationDelay)); + } + + public void setBillboard(Display.Billboard billboard) { + this.billboard = billboard; if (Core.getVersion() >= 20) { - server.updateEntity(this, getDataWatcherPacket(interpolationDelayWatcher, interpolationDelay)); + sendBillboard(o -> server.updateEntity(this, o)); } } private static final Object billboardWatcher = BountifulWrapper.impl.getDataWatcherObject(14, Byte.class); - public void setBillboard(Display.Billboard billboard) { - this.billboard = billboard; + private void sendBillboard(Consumer packetSink) { + packetSink.accept(getDataWatcherPacket(billboardWatcher, (byte) billboard.ordinal())); + } + + public void setGlowColorOverride(Color glowColorOverride) { + this.glowColorOverride = glowColorOverride; if (Core.getVersion() >= 20) { - server.updateEntity(this, getDataWatcherPacket(billboardWatcher, (byte) billboard.ordinal())); + sendGlowColorOverride(o -> server.updateEntity(this, o)); } } private static final Object glowColorOverrideWatcher = BountifulWrapper.impl.getDataWatcherObject(21, Integer.class); - public void setGlowColorOverride(Color glowColorOverride) { - this.glowColorOverride = glowColorOverride; + private void sendGlowColorOverride(Consumer packetSink) { + packetSink.accept(getDataWatcherPacket(glowColorOverrideWatcher, glowColorOverride)); + } + + public void setBrightness(Display.Brightness brightness) { + this.brightness = brightness; if (Core.getVersion() >= 20) { - server.updateEntity(this, getDataWatcherPacket(glowColorOverrideWatcher, glowColorOverride == null ? -1 : glowColorOverride.asARGB())); + sendBrightness(o -> server.updateEntity(this, o)); } } private static final Object brightnessWatcher = BountifulWrapper.impl.getDataWatcherObject(15, Integer.class); - public void setBrightness(Display.Brightness brightness) { - this.brightness = brightness; - if (Core.getVersion() >= 20) { - if (brightness == null) { - server.updateEntity(this, getDataWatcherPacket(brightnessWatcher, -1)); - } else { - int brightnessData = brightness.getBlockLight() << 4 | brightness.getSkyLight() << 20; - server.updateEntity(this, getDataWatcherPacket(brightnessWatcher, brightnessData)); - } + private void sendBrightness(Consumer packetSink) { + if (brightness == null) { + packetSink.accept(getDataWatcherPacket(brightnessWatcher, -1)); + } else { + int brightnessData = brightness.getBlockLight() << 4 | brightness.getSkyLight() << 20; + packetSink.accept(getDataWatcherPacket(brightnessWatcher, brightnessData)); } } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java index 0f546957..5b0f10bd 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java @@ -9,6 +9,8 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.ItemDisplay; import org.bukkit.inventory.ItemStack; +import java.util.function.Consumer; + @Getter public class RItemDisplay extends RDisplay { @@ -20,21 +22,36 @@ public class RItemDisplay extends RDisplay { super(server, EntityType.ITEM_DISPLAY, location); } - private static final Class itemStackClass = Reflection.getClass("{nms.world}.item.ItemStack"); - private static final Reflection.MethodInvoker asNMSCopy = Reflection.getTypedMethod(Reflection.getClass("{obc}.inventory.CraftItemStack"), "asNMSCopy", itemStackClass, ItemStack.class); - private static final Object itemStackWatcher = BountifulWrapper.impl.getDataWatcherObject(22, itemStackClass); + @Override + protected void postSpawn(Consumer packetSink) { + super.postSpawn(packetSink); + sendItemStack(packetSink); + sendItemDisplayTransform(packetSink); + } + public void setItemStack(ItemStack itemStack) { this.itemStack = itemStack; if (Core.getVersion() >= 20) { - server.updateEntity(this, getDataWatcherPacket(itemStackWatcher, asNMSCopy.invoke(null, itemStack))); + sendItemStack(o -> server.updateEntity(this, o)); } } + private static final Class itemStackClass = Reflection.getClass("{nms.world}.item.ItemStack"); + private static final Reflection.MethodInvoker asNMSCopy = Reflection.getTypedMethod(Reflection.getClass("{obc}.inventory.CraftItemStack"), "asNMSCopy", itemStackClass, ItemStack.class); + private static final Object itemStackWatcher = BountifulWrapper.impl.getDataWatcherObject(22, itemStackClass); + private void sendItemStack(Consumer packetSink) { + packetSink.accept(getDataWatcherPacket(itemStackWatcher, asNMSCopy.invoke(null, itemStack))); + } + private static final Object itemDisplayTransformWatcher = BountifulWrapper.impl.getDataWatcherObject(23, Byte.class); public void setItemDisplayTransform(ItemDisplay.ItemDisplayTransform itemDisplayTransform) { this.itemDisplayTransform = itemDisplayTransform; if (Core.getVersion() >= 20) { - server.updateEntity(this, getDataWatcherPacket(itemDisplayTransformWatcher, (byte) itemDisplayTransform.ordinal())); + sendItemDisplayTransform(o -> server.updateEntity(this, o)); } } + + private void sendItemDisplayTransform(Consumer packetSink) { + packetSink.accept(getDataWatcherPacket(itemDisplayTransformWatcher, (byte) itemDisplayTransform.ordinal())); + } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java index 49136d19..65e3dc2f 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java @@ -9,6 +9,8 @@ import org.bukkit.Location; import org.bukkit.entity.EntityType; import org.bukkit.entity.TextDisplay; +import java.util.function.Consumer; + @Getter public class RTextDisplay extends RDisplay { @@ -30,62 +32,82 @@ public class RTextDisplay extends RDisplay { super(server, EntityType.TEXT_DISPLAY, location); } - private static final Class iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent"); - private static final Object textWatcher = BountifulWrapper.impl.getDataWatcherObject(22, iChatBaseComponent); + @Override + protected void postSpawn(Consumer packetSink) { + super.postSpawn(packetSink); + sendText(packetSink); + sendLineWidth(packetSink); + sendTextOpacity(packetSink); + sendTextStatus(packetSink); + } + public void setText(String text) { this.text = text; if (Core.getVersion() >= 20) { - server.updateEntity(this, getDataWatcherPacket(textWatcher, ChatWrapper.impl.stringToChatComponent(text))); + sendText(o -> server.updateEntity(this, o)); + } + } + + private static final Class iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent"); + private static final Object textWatcher = BountifulWrapper.impl.getDataWatcherObject(22, iChatBaseComponent); + private void sendText(Consumer packetSink) { + packetSink.accept(getDataWatcherPacket(textWatcher, ChatWrapper.impl.stringToChatComponent(text))); + } + + public void setLineWidth(int lineWidth) { + this.lineWidth = lineWidth; + if (Core.getVersion() >= 20) { + sendLineWidth(o -> server.updateEntity(this, o)); } } private static final Object lineWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(23, Integer.class); - public void setLineWidth(int lineWidth) { - this.lineWidth = lineWidth; + private void sendLineWidth(Consumer packetSink) { + packetSink.accept(getDataWatcherPacket(lineWidthWatcher, lineWidth)); + } + + public void setTextOpacity(byte textOpacity) { + this.textOpacity = textOpacity; if (Core.getVersion() >= 20) { - server.updateEntity(this, getDataWatcherPacket(lineWidthWatcher, lineWidth)); + sendTextOpacity(o -> server.updateEntity(this, o)); } } private static final Object textOpacityWatcher = BountifulWrapper.impl.getDataWatcherObject(25, Byte.class); - public void setTextOpacity(byte textOpacity) { - this.textOpacity = textOpacity; - if (Core.getVersion() >= 20) { - server.updateEntity(this, getDataWatcherPacket(textOpacityWatcher, textOpacity)); - } + private void sendTextOpacity(Consumer packetSink) { + packetSink.accept(getDataWatcherPacket(textOpacityWatcher, textOpacity)); } - private static final Object textStatusWatcher = BountifulWrapper.impl.getDataWatcherObject(26, Byte.class); - public void setShadowed(boolean shadowed) { this.shadowed = shadowed; if (Core.getVersion() >= 20) { - server.updateEntity(this, getDataWatcherPacket(textStatusWatcher, getTextStatus())); + sendTextStatus(o -> server.updateEntity(this, o)); } } public void setSeeThrough(boolean seeThrough) { this.seeThrough = seeThrough; if (Core.getVersion() >= 20) { - server.updateEntity(this, getDataWatcherPacket(textStatusWatcher, getTextStatus())); + sendTextStatus(o -> server.updateEntity(this, o)); } } public void setDefaultBackground(boolean defaultBackground) { this.defaultBackground = defaultBackground; if (Core.getVersion() >= 20) { - server.updateEntity(this, getDataWatcherPacket(textStatusWatcher, getTextStatus())); + sendTextStatus(o -> server.updateEntity(this, o)); } } public void setAlignment(TextDisplay.TextAlignment alignment) { this.alignment = alignment; if (Core.getVersion() >= 20) { - server.updateEntity(this, getDataWatcherPacket(textStatusWatcher, getTextStatus())); + sendTextStatus(o -> server.updateEntity(this, o)); } } - private byte getTextStatus() { + private static final Object textStatusWatcher = BountifulWrapper.impl.getDataWatcherObject(26, Byte.class); + private void sendTextStatus(Consumer packetSink) { byte status = 0; if (shadowed) { @@ -105,6 +127,6 @@ public class RTextDisplay extends RDisplay { status |= 0x0F; } - return status; + packetSink.accept(getDataWatcherPacket(textStatusWatcher, status)); } } From 1f65121c680e345394d9665a5857981d00d01f2b Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 1 Jan 2025 13:06:26 +0100 Subject: [PATCH 4/8] Fixup postSpawn because of NPE/Not Initialized Exception --- .../src/de/steamwar/entity/RBlockDisplay.java | 5 +++- .../src/de/steamwar/entity/RDisplay.java | 25 +++++++++++-------- .../src/de/steamwar/entity/RItemDisplay.java | 7 ++++-- .../src/de/steamwar/entity/RTextDisplay.java | 11 +++++--- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java index 53753962..9041a232 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java @@ -4,6 +4,7 @@ import com.comphenix.tinyprotocol.Reflection; import de.steamwar.core.BountifulWrapper; import de.steamwar.core.Core; import lombok.Getter; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.data.BlockData; @@ -23,7 +24,9 @@ public class RBlockDisplay extends RDisplay { @Override protected void postSpawn(Consumer packetSink) { super.postSpawn(packetSink); - sendBlock(packetSink); + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { + sendBlock(packetSink); + }, 0); } public void setBlock(BlockData block) { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java index a8819859..49186a0c 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java @@ -4,6 +4,7 @@ import de.steamwar.core.BountifulWrapper; import de.steamwar.core.Core; import lombok.Getter; import lombok.NonNull; +import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.entity.Display; @@ -46,17 +47,19 @@ public abstract class RDisplay extends REntity { @Override protected void postSpawn(Consumer packetSink) { super.postSpawn(packetSink); - sendTransform(packetSink); - sendInterpolationDuration(packetSink); - sendViewRange(packetSink); - sendShadowRadius(packetSink); - sendShadowStrength(packetSink); - sendDisplayWidth(packetSink); - sendDisplayHeight(packetSink); - sendInterpolationDelay(packetSink); - sendBillboard(packetSink); - sendGlowColorOverride(packetSink); - sendBrightness(packetSink); + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { + sendTransform(packetSink); + sendInterpolationDuration(packetSink); + sendViewRange(packetSink); + sendShadowRadius(packetSink); + sendShadowStrength(packetSink); + sendDisplayWidth(packetSink); + sendDisplayHeight(packetSink); + sendInterpolationDelay(packetSink); + sendBillboard(packetSink); + sendGlowColorOverride(packetSink); + sendBrightness(packetSink); + }, 0); } public void setTransform(@NonNull Transformation transform) { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java index 5b0f10bd..4c290fa7 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java @@ -4,6 +4,7 @@ import com.comphenix.tinyprotocol.Reflection; import de.steamwar.core.BountifulWrapper; import de.steamwar.core.Core; import lombok.Getter; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.EntityType; import org.bukkit.entity.ItemDisplay; @@ -25,8 +26,10 @@ public class RItemDisplay extends RDisplay { @Override protected void postSpawn(Consumer packetSink) { super.postSpawn(packetSink); - sendItemStack(packetSink); - sendItemDisplayTransform(packetSink); + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { + sendItemStack(packetSink); + sendItemDisplayTransform(packetSink); + }, 0); } public void setItemStack(ItemStack itemStack) { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java index 65e3dc2f..d5c459ae 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java @@ -5,6 +5,7 @@ import de.steamwar.core.BountifulWrapper; import de.steamwar.core.ChatWrapper; import de.steamwar.core.Core; import lombok.Getter; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.EntityType; import org.bukkit.entity.TextDisplay; @@ -35,10 +36,12 @@ public class RTextDisplay extends RDisplay { @Override protected void postSpawn(Consumer packetSink) { super.postSpawn(packetSink); - sendText(packetSink); - sendLineWidth(packetSink); - sendTextOpacity(packetSink); - sendTextStatus(packetSink); + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { + sendText(packetSink); + sendLineWidth(packetSink); + sendTextOpacity(packetSink); + sendTextStatus(packetSink); + }, 0); } public void setText(String text) { From 82c73f936795982388a89da1c9cc01d5c3214203 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 8 Jan 2025 12:24:17 +0100 Subject: [PATCH 5/8] Fix packet count to at most 2 for the display entities at spawn --- .../src/de/steamwar/entity/RBlockDisplay.java | 24 ++- .../src/de/steamwar/entity/RDisplay.java | 158 +++++++++--------- .../src/de/steamwar/entity/RItemDisplay.java | 35 ++-- .../src/de/steamwar/entity/RTextDisplay.java | 60 +++---- 4 files changed, 131 insertions(+), 146 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java index 9041a232..9e9c3c42 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java @@ -1,21 +1,22 @@ package de.steamwar.entity; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.core.BountifulWrapper; -import de.steamwar.core.Core; import lombok.Getter; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.data.BlockData; import org.bukkit.entity.EntityType; +import java.util.function.BiConsumer; import java.util.function.Consumer; @Getter public class RBlockDisplay extends RDisplay { - private BlockData block = Material.AIR.createBlockData(); + public static final BlockData DEFAULT_BLOCK = Material.AIR.createBlockData(); + + private BlockData block = DEFAULT_BLOCK; public RBlockDisplay(REntityServer server, Location location) { super(server, EntityType.BLOCK_DISPLAY, location); @@ -24,22 +25,19 @@ public class RBlockDisplay extends RDisplay { @Override protected void postSpawn(Consumer packetSink) { super.postSpawn(packetSink); - Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { - sendBlock(packetSink); - }, 0); + sendPacket(packetSink, this::getBlock); } public void setBlock(BlockData block) { this.block = block; - if (Core.getVersion() >= 20) { - sendBlock(o -> server.updateEntity(this, o)); - } + sendPacket(updatePacketSink, this::getBlock); } private static final Class iBlockDataClass = Reflection.getClass("{nms.world}.level.block.state.IBlockData"); - private static final Reflection.MethodInvoker getState = Reflection.getTypedMethod(Reflection.getClass("{obc}.block.data.CraftBlockData"), "getState", iBlockDataClass); + private static final Reflection.Method getState = Reflection.getTypedMethod(Reflection.getClass("{obc}.block.data.CraftBlockData"), "getState", iBlockDataClass); private static final Object blockWatcher = BountifulWrapper.impl.getDataWatcherObject(22, iBlockDataClass); - private void sendBlock(Consumer packetSink) { - packetSink.accept(getDataWatcherPacket(blockWatcher, getState.invoke(block))); + private void getBlock(BiConsumer packetSink) { + if (block.getAsString(true).equals(DEFAULT_BLOCK.getAsString(true))) return; + packetSink.accept(blockWatcher, getState.invoke(block)); } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java index 49186a0c..216103d9 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java @@ -13,12 +13,18 @@ import org.bukkit.util.Transformation; import org.joml.Quaternionf; import org.joml.Vector3f; +import java.util.ArrayList; +import java.util.List; +import java.util.function.BiConsumer; import java.util.function.Consumer; @Getter public abstract class RDisplay extends REntity { - private Transformation transform = new Transformation(new Vector3f(), new Quaternionf(0, 0, 0, 1), new Vector3f(1, 1, 1), new Quaternionf(0, 0, 0, 1)); + protected final Consumer updatePacketSink = o -> server.updateEntity(this, o); + + public static final Transformation DEFAULT_TRANSFORM = new Transformation(new Vector3f(), new Quaternionf(0, 0, 0, 1), new Vector3f(1, 1, 1), new Quaternionf(0, 0, 0, 1)); + private Transformation transform = DEFAULT_TRANSFORM; private int interpolationDuration = 0; @@ -41,169 +47,171 @@ public abstract class RDisplay extends REntity { private Display.Brightness brightness = null; protected RDisplay(REntityServer server, EntityType entityType, Location location) { - super(server, entityType, location); + super(server, entityType, location, 0); + Bukkit.getScheduler().runTask(Core.getInstance(), () -> server.addEntity(this)); } @Override protected void postSpawn(Consumer packetSink) { super.postSpawn(packetSink); - Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { - sendTransform(packetSink); - sendInterpolationDuration(packetSink); - sendViewRange(packetSink); - sendShadowRadius(packetSink); - sendShadowStrength(packetSink); - sendDisplayWidth(packetSink); - sendDisplayHeight(packetSink); - sendInterpolationDelay(packetSink); - sendBillboard(packetSink); - sendGlowColorOverride(packetSink); - sendBrightness(packetSink); - }, 0); + sendPacket(packetSink, + this::getTransformData, + this::getInterpolationDuration, + this::getViewRange, + this::getShadowRadius, + this::getShadowStrength, + this::getDisplayWidth, + this::getDisplayHeight, + this::getInterpolationDelay, + this::getBillboard, + this::getGlowColorOverride, + this::getBrightness + ); + } + + @SafeVarargs + protected final void sendPacket(Consumer packetSink, Consumer>... dataSinkSinks) { + List keyValueData = new ArrayList<>(); + for (Consumer> dataSinkSink : dataSinkSinks) { + dataSinkSink.accept((dataWatcher, value) -> { + keyValueData.add(dataWatcher); + keyValueData.add(value); + }); + } + if (keyValueData.isEmpty()) return; + packetSink.accept(getDataWatcherPacket(keyValueData.toArray())); } public void setTransform(@NonNull Transformation transform) { this.transform = transform; - if (Core.getVersion() >= 20) { - sendTransform(o -> server.updateEntity(this, o)); - } + sendPacket(updatePacketSink, this::getTransformData); } private static final Object translationWatcher = BountifulWrapper.impl.getDataWatcherObject(10, Vector3f.class); private static final Object leftRotationWatcher = BountifulWrapper.impl.getDataWatcherObject(12, Quaternionf.class); private static final Object scaleWatcher = BountifulWrapper.impl.getDataWatcherObject(11, Vector3f.class); private static final Object rightRotationWatcher = BountifulWrapper.impl.getDataWatcherObject(13, Quaternionf.class); - private void sendTransform(Consumer packetSink) { - packetSink.accept(getDataWatcherPacket(translationWatcher, transform.getTranslation())); - packetSink.accept(getDataWatcherPacket(leftRotationWatcher, transform.getLeftRotation())); - packetSink.accept(getDataWatcherPacket(scaleWatcher, transform.getScale())); - packetSink.accept(getDataWatcherPacket(rightRotationWatcher, transform.getRightRotation())); + private void getTransformData(BiConsumer dataSink) { + if (transform.equals(DEFAULT_TRANSFORM)) return; + dataSink.accept(translationWatcher, transform.getTranslation()); + dataSink.accept(leftRotationWatcher, transform.getLeftRotation()); + dataSink.accept(scaleWatcher, transform.getScale()); + dataSink.accept(rightRotationWatcher, transform.getRightRotation()); } public void setInterpolationDuration(int interpolationDuration) { this.interpolationDuration = interpolationDuration; - if (Core.getVersion() >= 20) { - sendInterpolationDuration(o -> server.updateEntity(this, o)); - } + sendPacket(updatePacketSink, this::getInterpolationDuration); } private static final Object transformationInterpolationDurationWatcher = BountifulWrapper.impl.getDataWatcherObject(8, Integer.class); private static final Object positionOrRotationInterpolationDurationWatcher = BountifulWrapper.impl.getDataWatcherObject(9, Integer.class); - private void sendInterpolationDuration(Consumer packetSink) { - packetSink.accept(getDataWatcherPacket(transformationInterpolationDurationWatcher, interpolationDuration)); - packetSink.accept(getDataWatcherPacket(positionOrRotationInterpolationDurationWatcher, interpolationDuration)); + private void getInterpolationDuration(BiConsumer packetSink) { + if (interpolationDelay == 0) return; + packetSink.accept(transformationInterpolationDurationWatcher, interpolationDuration); + packetSink.accept(positionOrRotationInterpolationDurationWatcher, interpolationDuration); } public void setViewRange(float viewRange) { this.viewRange = viewRange; - if (Core.getVersion() >= 20) { - sendViewRange(o -> server.updateEntity(this, o)); - } + sendPacket(updatePacketSink, this::getViewRange); } private static final Object viewRangeWatcher = BountifulWrapper.impl.getDataWatcherObject(16, Float.class); - private void sendViewRange(Consumer packetSink) { - packetSink.accept(getDataWatcherPacket(viewRangeWatcher, viewRange)); + private void getViewRange(BiConsumer packetSink) { + if (viewRange == 1.0F) return; + packetSink.accept(viewRangeWatcher, viewRange); } public void setShadowRadius(float shadowRadius) { this.shadowRadius = shadowRadius; - if (Core.getVersion() >= 20) { - sendShadowRadius(o -> server.updateEntity(this, o)); - } + sendPacket(updatePacketSink, this::getShadowRadius); } private static final Object shadowRadiusWatcher = BountifulWrapper.impl.getDataWatcherObject(17, Float.class); - private void sendShadowRadius(Consumer packetSink) { - packetSink.accept(getDataWatcherPacket(shadowRadiusWatcher, shadowRadius)); + private void getShadowRadius(BiConsumer packetSink) { + if (shadowRadius == 1.0F) return; + packetSink.accept(shadowRadiusWatcher, shadowRadius); } public void setShadowStrength(float shadowStrength) { this.shadowStrength = shadowStrength; - if (Core.getVersion() >= 20) { - sendShadowStrength(o -> server.updateEntity(this, o)); - } + sendPacket(updatePacketSink, this::getShadowStrength); } private static final Object shadowStrengthWatcher = BountifulWrapper.impl.getDataWatcherObject(18, Float.class); - private void sendShadowStrength(Consumer packetSink) { - packetSink.accept(getDataWatcherPacket(shadowStrengthWatcher, shadowStrength)); + private void getShadowStrength(BiConsumer packetSink) { + if (shadowStrength == 1.0F) return; + packetSink.accept(shadowStrengthWatcher, shadowStrength); } public void setDisplayWidth(float displayWidth) { this.displayWidth = displayWidth; - if (Core.getVersion() >= 20) { - sendDisplayWidth(o -> server.updateEntity(this, o)); - } + sendPacket(updatePacketSink, this::getDisplayWidth); } private static final Object displayWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(19, Float.class); - private void sendDisplayWidth(Consumer packetSink) { - packetSink.accept(getDataWatcherPacket(displayWidthWatcher, displayWidth)); + private void getDisplayWidth(BiConsumer packetSink) { + if (displayWidth == 0.0F) return; + packetSink.accept(displayWidthWatcher, displayWidth); } public void setDisplayHeight(float displayHeight) { this.displayHeight = displayHeight; - if (Core.getVersion() >= 20) { - sendDisplayHeight(o -> server.updateEntity(this, o)); - } + sendPacket(updatePacketSink, this::getDisplayHeight); } private static final Object displayHeightWatcher = BountifulWrapper.impl.getDataWatcherObject(20, Float.class); - private void sendDisplayHeight(Consumer packetSink) { - packetSink.accept(getDataWatcherPacket(displayHeightWatcher, displayHeight)); + private void getDisplayHeight(BiConsumer packetSink) { + if (displayHeight == 0.0F) return; + packetSink.accept(displayHeightWatcher, displayHeight); } public void setInterpolationDelay(int interpolationDelay) { this.interpolationDelay = interpolationDelay; - if (Core.getVersion() >= 20) { - sendInterpolationDelay(o -> server.updateEntity(this, o)); - } + sendPacket(updatePacketSink, this::getInterpolationDelay); } private static final Object interpolationDelayWatcher = BountifulWrapper.impl.getDataWatcherObject(7, Integer.class); - private void sendInterpolationDelay(Consumer packetSink) { - packetSink.accept(getDataWatcherPacket(interpolationDelayWatcher, interpolationDelay)); + private void getInterpolationDelay(BiConsumer packetSink) { + if (interpolationDelay == 0) return; + packetSink.accept(interpolationDelayWatcher, interpolationDelay); } public void setBillboard(Display.Billboard billboard) { this.billboard = billboard; - if (Core.getVersion() >= 20) { - sendBillboard(o -> server.updateEntity(this, o)); - } + sendPacket(updatePacketSink, this::getBillboard); } private static final Object billboardWatcher = BountifulWrapper.impl.getDataWatcherObject(14, Byte.class); - private void sendBillboard(Consumer packetSink) { - packetSink.accept(getDataWatcherPacket(billboardWatcher, (byte) billboard.ordinal())); + private void getBillboard(BiConsumer packetSink) { + if (billboard == Display.Billboard.FIXED) return; + packetSink.accept(billboardWatcher, (byte) billboard.ordinal()); } public void setGlowColorOverride(Color glowColorOverride) { this.glowColorOverride = glowColorOverride; - if (Core.getVersion() >= 20) { - sendGlowColorOverride(o -> server.updateEntity(this, o)); - } + sendPacket(updatePacketSink, this::getGlowColorOverride); } private static final Object glowColorOverrideWatcher = BountifulWrapper.impl.getDataWatcherObject(21, Integer.class); - private void sendGlowColorOverride(Consumer packetSink) { - packetSink.accept(getDataWatcherPacket(glowColorOverrideWatcher, glowColorOverride)); + private void getGlowColorOverride(BiConsumer packetSink) { + if (glowColorOverride == null) return; + packetSink.accept(glowColorOverrideWatcher, glowColorOverride); } public void setBrightness(Display.Brightness brightness) { this.brightness = brightness; - if (Core.getVersion() >= 20) { - sendBrightness(o -> server.updateEntity(this, o)); - } + sendPacket(updatePacketSink, this::getBrightness); } private static final Object brightnessWatcher = BountifulWrapper.impl.getDataWatcherObject(15, Integer.class); - private void sendBrightness(Consumer packetSink) { + private void getBrightness(BiConsumer packetSink) { if (brightness == null) { - packetSink.accept(getDataWatcherPacket(brightnessWatcher, -1)); + packetSink.accept(brightnessWatcher, -1); // TODO: Potentially not needed, need to test/investigate } else { int brightnessData = brightness.getBlockLight() << 4 | brightness.getSkyLight() << 20; - packetSink.accept(getDataWatcherPacket(brightnessWatcher, brightnessData)); + packetSink.accept(brightnessWatcher, brightnessData); } } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java index 4c290fa7..4428df86 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java @@ -1,23 +1,25 @@ package de.steamwar.entity; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.core.BountifulWrapper; -import de.steamwar.core.Core; import lombok.Getter; -import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.entity.ItemDisplay; import org.bukkit.inventory.ItemStack; +import java.util.function.BiConsumer; import java.util.function.Consumer; @Getter public class RItemDisplay extends RDisplay { - private ItemStack itemStack; + public static final ItemStack DEFAULT_ITEM_STACK = new ItemStack(Material.AIR); - private ItemDisplay.ItemDisplayTransform itemDisplayTransform; + private ItemStack itemStack = DEFAULT_ITEM_STACK; + + private ItemDisplay.ItemDisplayTransform itemDisplayTransform = ItemDisplay.ItemDisplayTransform.NONE; public RItemDisplay(REntityServer server, Location location) { super(server, EntityType.ITEM_DISPLAY, location); @@ -26,35 +28,28 @@ public class RItemDisplay extends RDisplay { @Override protected void postSpawn(Consumer packetSink) { super.postSpawn(packetSink); - Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { - sendItemStack(packetSink); - sendItemDisplayTransform(packetSink); - }, 0); + sendPacket(packetSink, this::getItemStack, this::getItemDisplayTransform); } public void setItemStack(ItemStack itemStack) { this.itemStack = itemStack; - if (Core.getVersion() >= 20) { - sendItemStack(o -> server.updateEntity(this, o)); - } + sendPacket(updatePacketSink, this::getItemStack); } private static final Class itemStackClass = Reflection.getClass("{nms.world}.item.ItemStack"); - private static final Reflection.MethodInvoker asNMSCopy = Reflection.getTypedMethod(Reflection.getClass("{obc}.inventory.CraftItemStack"), "asNMSCopy", itemStackClass, ItemStack.class); + private static final Reflection.Method asNMSCopy = Reflection.getTypedMethod(Reflection.getClass("{obc}.inventory.CraftItemStack"), "asNMSCopy", itemStackClass, ItemStack.class); private static final Object itemStackWatcher = BountifulWrapper.impl.getDataWatcherObject(22, itemStackClass); - private void sendItemStack(Consumer packetSink) { - packetSink.accept(getDataWatcherPacket(itemStackWatcher, asNMSCopy.invoke(null, itemStack))); + private void getItemStack(BiConsumer packetSink) { + packetSink.accept(itemStackWatcher, asNMSCopy.invoke(null, itemStack)); } private static final Object itemDisplayTransformWatcher = BountifulWrapper.impl.getDataWatcherObject(23, Byte.class); public void setItemDisplayTransform(ItemDisplay.ItemDisplayTransform itemDisplayTransform) { this.itemDisplayTransform = itemDisplayTransform; - if (Core.getVersion() >= 20) { - sendItemDisplayTransform(o -> server.updateEntity(this, o)); - } + sendPacket(updatePacketSink, this::getItemDisplayTransform); } - private void sendItemDisplayTransform(Consumer packetSink) { - packetSink.accept(getDataWatcherPacket(itemDisplayTransformWatcher, (byte) itemDisplayTransform.ordinal())); + private void getItemDisplayTransform(BiConsumer packetSink) { + packetSink.accept(itemDisplayTransformWatcher, (byte) itemDisplayTransform.ordinal()); } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java index d5c459ae..f8c7db3c 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java @@ -1,15 +1,14 @@ package de.steamwar.entity; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.core.BountifulWrapper; import de.steamwar.core.ChatWrapper; -import de.steamwar.core.Core; import lombok.Getter; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.EntityType; import org.bukkit.entity.TextDisplay; +import java.util.function.BiConsumer; import java.util.function.Consumer; @Getter @@ -36,81 +35,65 @@ public class RTextDisplay extends RDisplay { @Override protected void postSpawn(Consumer packetSink) { super.postSpawn(packetSink); - Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { - sendText(packetSink); - sendLineWidth(packetSink); - sendTextOpacity(packetSink); - sendTextStatus(packetSink); - }, 0); + sendPacket(packetSink, this::getText, this::getLineWidth, this::getTextOpacity, this::getTextStatus); } public void setText(String text) { this.text = text; - if (Core.getVersion() >= 20) { - sendText(o -> server.updateEntity(this, o)); - } + sendPacket(updatePacketSink, this::getText); } private static final Class iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent"); private static final Object textWatcher = BountifulWrapper.impl.getDataWatcherObject(22, iChatBaseComponent); - private void sendText(Consumer packetSink) { - packetSink.accept(getDataWatcherPacket(textWatcher, ChatWrapper.impl.stringToChatComponent(text))); + private void getText(BiConsumer packetSink) { + if (text.isEmpty()) return; + packetSink.accept(textWatcher, ChatWrapper.impl.stringToChatComponent(text)); } public void setLineWidth(int lineWidth) { this.lineWidth = lineWidth; - if (Core.getVersion() >= 20) { - sendLineWidth(o -> server.updateEntity(this, o)); - } + sendPacket(updatePacketSink, this::getLineWidth); } private static final Object lineWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(23, Integer.class); - private void sendLineWidth(Consumer packetSink) { - packetSink.accept(getDataWatcherPacket(lineWidthWatcher, lineWidth)); + private void getLineWidth(BiConsumer packetSink) { + if (lineWidth == 200) return; + packetSink.accept(lineWidthWatcher, lineWidth); } public void setTextOpacity(byte textOpacity) { this.textOpacity = textOpacity; - if (Core.getVersion() >= 20) { - sendTextOpacity(o -> server.updateEntity(this, o)); - } + sendPacket(updatePacketSink, this::getTextOpacity); } private static final Object textOpacityWatcher = BountifulWrapper.impl.getDataWatcherObject(25, Byte.class); - private void sendTextOpacity(Consumer packetSink) { - packetSink.accept(getDataWatcherPacket(textOpacityWatcher, textOpacity)); + private void getTextOpacity(BiConsumer packetSink) { + if (textOpacity == (byte) -1) return; + packetSink.accept(textOpacityWatcher, textOpacity); } public void setShadowed(boolean shadowed) { this.shadowed = shadowed; - if (Core.getVersion() >= 20) { - sendTextStatus(o -> server.updateEntity(this, o)); - } + sendPacket(updatePacketSink, this::getTextStatus); } public void setSeeThrough(boolean seeThrough) { this.seeThrough = seeThrough; - if (Core.getVersion() >= 20) { - sendTextStatus(o -> server.updateEntity(this, o)); - } + sendPacket(updatePacketSink, this::getTextStatus); } public void setDefaultBackground(boolean defaultBackground) { this.defaultBackground = defaultBackground; - if (Core.getVersion() >= 20) { - sendTextStatus(o -> server.updateEntity(this, o)); - } + sendPacket(updatePacketSink, this::getTextStatus); } public void setAlignment(TextDisplay.TextAlignment alignment) { this.alignment = alignment; - if (Core.getVersion() >= 20) { - sendTextStatus(o -> server.updateEntity(this, o)); - } + sendPacket(updatePacketSink, this::getTextStatus); } private static final Object textStatusWatcher = BountifulWrapper.impl.getDataWatcherObject(26, Byte.class); - private void sendTextStatus(Consumer packetSink) { + private void getTextStatus(BiConsumer packetSink) { byte status = 0; if (shadowed) { @@ -130,6 +113,7 @@ public class RTextDisplay extends RDisplay { status |= 0x0F; } - packetSink.accept(getDataWatcherPacket(textStatusWatcher, status)); + if (status == 0) return; + packetSink.accept(textStatusWatcher, status); } } From e418109ab70a493230a9cb6b0cd0c1f87b63428e Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 8 Jan 2025 16:27:18 +0100 Subject: [PATCH 6/8] Reduce spawn packets to 0 if everything is default --- .../src/de/steamwar/entity/RBlockDisplay.java | 8 ++- .../src/de/steamwar/entity/RDisplay.java | 56 +++++++++---------- .../src/de/steamwar/entity/REntity.java | 2 +- .../src/de/steamwar/entity/RItemDisplay.java | 16 +++--- .../src/de/steamwar/entity/RTextDisplay.java | 24 +++++--- 5 files changed, 57 insertions(+), 49 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java index 9e9c3c42..a134dea7 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java @@ -16,10 +16,12 @@ public class RBlockDisplay extends RDisplay { public static final BlockData DEFAULT_BLOCK = Material.AIR.createBlockData(); - private BlockData block = DEFAULT_BLOCK; + private BlockData block; public RBlockDisplay(REntityServer server, Location location) { super(server, EntityType.BLOCK_DISPLAY, location); + this.block = DEFAULT_BLOCK; + server.addEntity(this); } @Override @@ -33,8 +35,8 @@ public class RBlockDisplay extends RDisplay { sendPacket(updatePacketSink, this::getBlock); } - private static final Class iBlockDataClass = Reflection.getClass("{nms.world}.level.block.state.IBlockData"); - private static final Reflection.Method getState = Reflection.getTypedMethod(Reflection.getClass("{obc}.block.data.CraftBlockData"), "getState", iBlockDataClass); + private static final Class iBlockDataClass = Reflection.getClass("net.minecraft.world.level.block.state.BlockState"); + private static final Reflection.Method getState = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.block.data.CraftBlockData"), "getState", iBlockDataClass); private static final Object blockWatcher = BountifulWrapper.impl.getDataWatcherObject(22, iBlockDataClass); private void getBlock(BiConsumer packetSink) { if (block.getAsString(true).equals(DEFAULT_BLOCK.getAsString(true))) return; diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java index 216103d9..077be91f 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java @@ -1,10 +1,8 @@ package de.steamwar.entity; import de.steamwar.core.BountifulWrapper; -import de.steamwar.core.Core; import lombok.Getter; import lombok.NonNull; -import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.entity.Display; @@ -24,31 +22,32 @@ public abstract class RDisplay extends REntity { protected final Consumer updatePacketSink = o -> server.updateEntity(this, o); public static final Transformation DEFAULT_TRANSFORM = new Transformation(new Vector3f(), new Quaternionf(0, 0, 0, 1), new Vector3f(1, 1, 1), new Quaternionf(0, 0, 0, 1)); - private Transformation transform = DEFAULT_TRANSFORM; - private int interpolationDuration = 0; - - private float viewRange = 1.0F; - - private float shadowRadius = 0.0F; - - private float shadowStrength = 1.0F; - - private float displayWidth = 0.0F; - - private float displayHeight = 0.0F; - - private int interpolationDelay = 0; - - private Display.Billboard billboard = Display.Billboard.FIXED; - - private Color glowColorOverride = null; - - private Display.Brightness brightness = null; + private Transformation transform; + private int interpolationDuration; + private float viewRange; + private float shadowRadius; + private float shadowStrength; + private float displayWidth; + private float displayHeight; + private int interpolationDelay; + private Display.Billboard billboard; + private Color glowColorOverride; + private Display.Brightness brightness; protected RDisplay(REntityServer server, EntityType entityType, Location location) { super(server, entityType, location, 0); - Bukkit.getScheduler().runTask(Core.getInstance(), () -> server.addEntity(this)); + this.transform = DEFAULT_TRANSFORM; + this.interpolationDuration = 0; + this.viewRange = 1.0F; + this.shadowRadius = 0.0F; + this.shadowStrength = 1.0F; + this.displayWidth = 0.0F; + this.displayHeight = 0.0F; + this.interpolationDelay = 0; + this.billboard = Display.Billboard.FIXED; + this.glowColorOverride = null; + this.brightness = null; } @Override @@ -130,7 +129,7 @@ public abstract class RDisplay extends REntity { private static final Object shadowRadiusWatcher = BountifulWrapper.impl.getDataWatcherObject(17, Float.class); private void getShadowRadius(BiConsumer packetSink) { - if (shadowRadius == 1.0F) return; + if (shadowRadius == 0.0F) return; packetSink.accept(shadowRadiusWatcher, shadowRadius); } @@ -207,11 +206,8 @@ public abstract class RDisplay extends REntity { private static final Object brightnessWatcher = BountifulWrapper.impl.getDataWatcherObject(15, Integer.class); private void getBrightness(BiConsumer packetSink) { - if (brightness == null) { - packetSink.accept(brightnessWatcher, -1); // TODO: Potentially not needed, need to test/investigate - } else { - int brightnessData = brightness.getBlockLight() << 4 | brightness.getSkyLight() << 20; - packetSink.accept(brightnessWatcher, brightnessData); - } + if (brightness == null) return; + int brightnessData = brightness.getBlockLight() << 4 | brightness.getSkyLight() << 20; + packetSink.accept(brightnessWatcher, brightnessData); } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 66c13c40..0c02a889 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -441,7 +441,7 @@ public class REntity { private static final Reflection.Field equipmentEntity = Reflection.getField(ProtocolWrapper.equipmentPacket, int.class, 0); private static final Class craftItemStack = Reflection.getClass("org.bukkit.craftbukkit.inventory.CraftItemStack"); - private static final Reflection.Method asNMSCopy = Reflection.getTypedMethod(REntity.craftItemStack, "asNMSCopy", ProtocolWrapper.itemStack, ItemStack.class); + protected static final Reflection.Method asNMSCopy = Reflection.getTypedMethod(REntity.craftItemStack, "asNMSCopy", ProtocolWrapper.itemStack, ItemStack.class); protected Object getEquipmentPacket(Object slot, ItemStack stack){ Object packet = Reflection.newInstance(ProtocolWrapper.equipmentPacket); equipmentEntity.set(packet, entityId); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java index 4428df86..0b2a8d89 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java @@ -1,7 +1,7 @@ package de.steamwar.entity; -import de.steamwar.Reflection; import de.steamwar.core.BountifulWrapper; +import de.steamwar.core.ProtocolWrapper; import lombok.Getter; import org.bukkit.Location; import org.bukkit.Material; @@ -17,12 +17,14 @@ public class RItemDisplay extends RDisplay { public static final ItemStack DEFAULT_ITEM_STACK = new ItemStack(Material.AIR); - private ItemStack itemStack = DEFAULT_ITEM_STACK; - - private ItemDisplay.ItemDisplayTransform itemDisplayTransform = ItemDisplay.ItemDisplayTransform.NONE; + private ItemStack itemStack; + private ItemDisplay.ItemDisplayTransform itemDisplayTransform; public RItemDisplay(REntityServer server, Location location) { super(server, EntityType.ITEM_DISPLAY, location); + this.itemStack = DEFAULT_ITEM_STACK; + this.itemDisplayTransform = ItemDisplay.ItemDisplayTransform.NONE; + server.addEntity(this); } @Override @@ -36,10 +38,9 @@ public class RItemDisplay extends RDisplay { sendPacket(updatePacketSink, this::getItemStack); } - private static final Class itemStackClass = Reflection.getClass("{nms.world}.item.ItemStack"); - private static final Reflection.Method asNMSCopy = Reflection.getTypedMethod(Reflection.getClass("{obc}.inventory.CraftItemStack"), "asNMSCopy", itemStackClass, ItemStack.class); - private static final Object itemStackWatcher = BountifulWrapper.impl.getDataWatcherObject(22, itemStackClass); + private static final Object itemStackWatcher = BountifulWrapper.impl.getDataWatcherObject(22, ProtocolWrapper.itemStack); private void getItemStack(BiConsumer packetSink) { + if (itemStack.equals(DEFAULT_ITEM_STACK)) return; packetSink.accept(itemStackWatcher, asNMSCopy.invoke(null, itemStack)); } @@ -50,6 +51,7 @@ public class RItemDisplay extends RDisplay { } private void getItemDisplayTransform(BiConsumer packetSink) { + if (itemDisplayTransform == ItemDisplay.ItemDisplayTransform.NONE) return; packetSink.accept(itemDisplayTransformWatcher, (byte) itemDisplayTransform.ordinal()); } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java index f8c7db3c..1720096d 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java @@ -14,22 +14,30 @@ import java.util.function.Consumer; @Getter public class RTextDisplay extends RDisplay { - private String text = ""; + private String text; - private int lineWidth = 200; + private int lineWidth; - private byte textOpacity = (byte) -1; + private byte textOpacity; - private boolean shadowed = false; + private boolean shadowed; - private boolean seeThrough = false; + private boolean seeThrough; - private boolean defaultBackground = false; + private boolean defaultBackground; - private TextDisplay.TextAlignment alignment = TextDisplay.TextAlignment.CENTER; + private TextDisplay.TextAlignment alignment; public RTextDisplay(REntityServer server, Location location) { super(server, EntityType.TEXT_DISPLAY, location); + this.text = ""; + this.lineWidth = 200; + this.textOpacity = (byte) -1; + this.shadowed = false; + this.seeThrough = false; + this.defaultBackground = false; + this.alignment = TextDisplay.TextAlignment.CENTER; + server.addEntity(this); } @Override @@ -43,7 +51,7 @@ public class RTextDisplay extends RDisplay { sendPacket(updatePacketSink, this::getText); } - private static final Class iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent"); + private static final Class iChatBaseComponent = Reflection.getClass("net.minecraft.network.chat.Component"); private static final Object textWatcher = BountifulWrapper.impl.getDataWatcherObject(22, iChatBaseComponent); private void getText(BiConsumer packetSink) { if (text.isEmpty()) return; From bfdf6471d2844bcd24e8b90debc87ce55e899849 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 8 Jan 2025 16:52:24 +0100 Subject: [PATCH 7/8] Cleanup things and fix setting back to default --- .../src/de/steamwar/entity/RBlockDisplay.java | 7 +- .../src/de/steamwar/entity/RDisplay.java | 109 +++++++++++------- .../src/de/steamwar/entity/RItemDisplay.java | 14 ++- .../src/de/steamwar/entity/RTextDisplay.java | 28 +++-- 4 files changed, 94 insertions(+), 64 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java index a134dea7..c01fdea2 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java @@ -38,8 +38,9 @@ public class RBlockDisplay extends RDisplay { private static final Class iBlockDataClass = Reflection.getClass("net.minecraft.world.level.block.state.BlockState"); private static final Reflection.Method getState = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.block.data.CraftBlockData"), "getState", iBlockDataClass); private static final Object blockWatcher = BountifulWrapper.impl.getDataWatcherObject(22, iBlockDataClass); - private void getBlock(BiConsumer packetSink) { - if (block.getAsString(true).equals(DEFAULT_BLOCK.getAsString(true))) return; - packetSink.accept(blockWatcher, getState.invoke(block)); + private void getBlock(boolean ignoreDefault, BiConsumer packetSink) { + if (ignoreDefault || !block.getAsString(true).equals(DEFAULT_BLOCK.getAsString(true))) { + packetSink.accept(blockWatcher, getState.invoke(block)); + } } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java index 077be91f..3be30b12 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java @@ -69,16 +69,18 @@ public abstract class RDisplay extends REntity { } @SafeVarargs - protected final void sendPacket(Consumer packetSink, Consumer>... dataSinkSinks) { + protected final void sendPacket(Consumer packetSink, BiConsumer>... dataSinkSinks) { List keyValueData = new ArrayList<>(); - for (Consumer> dataSinkSink : dataSinkSinks) { - dataSinkSink.accept((dataWatcher, value) -> { + boolean ignoreDefault = packetSink == updatePacketSink; + for (BiConsumer> dataSinkSink : dataSinkSinks) { + dataSinkSink.accept(ignoreDefault, (dataWatcher, value) -> { keyValueData.add(dataWatcher); keyValueData.add(value); }); } - if (keyValueData.isEmpty()) return; - packetSink.accept(getDataWatcherPacket(keyValueData.toArray())); + if (!keyValueData.isEmpty()) { + packetSink.accept(getDataWatcherPacket(keyValueData.toArray())); + } } public void setTransform(@NonNull Transformation transform) { @@ -90,12 +92,14 @@ public abstract class RDisplay extends REntity { private static final Object leftRotationWatcher = BountifulWrapper.impl.getDataWatcherObject(12, Quaternionf.class); private static final Object scaleWatcher = BountifulWrapper.impl.getDataWatcherObject(11, Vector3f.class); private static final Object rightRotationWatcher = BountifulWrapper.impl.getDataWatcherObject(13, Quaternionf.class); - private void getTransformData(BiConsumer dataSink) { - if (transform.equals(DEFAULT_TRANSFORM)) return; - dataSink.accept(translationWatcher, transform.getTranslation()); - dataSink.accept(leftRotationWatcher, transform.getLeftRotation()); - dataSink.accept(scaleWatcher, transform.getScale()); - dataSink.accept(rightRotationWatcher, transform.getRightRotation()); + + private void getTransformData(boolean ignoreDefault, BiConsumer dataSink) { + if (ignoreDefault || !transform.equals(DEFAULT_TRANSFORM)) { + dataSink.accept(translationWatcher, transform.getTranslation()); + dataSink.accept(leftRotationWatcher, transform.getLeftRotation()); + dataSink.accept(scaleWatcher, transform.getScale()); + dataSink.accept(rightRotationWatcher, transform.getRightRotation()); + } } public void setInterpolationDuration(int interpolationDuration) { @@ -105,10 +109,12 @@ public abstract class RDisplay extends REntity { private static final Object transformationInterpolationDurationWatcher = BountifulWrapper.impl.getDataWatcherObject(8, Integer.class); private static final Object positionOrRotationInterpolationDurationWatcher = BountifulWrapper.impl.getDataWatcherObject(9, Integer.class); - private void getInterpolationDuration(BiConsumer packetSink) { - if (interpolationDelay == 0) return; - packetSink.accept(transformationInterpolationDurationWatcher, interpolationDuration); - packetSink.accept(positionOrRotationInterpolationDurationWatcher, interpolationDuration); + + private void getInterpolationDuration(boolean ignoreDefault, BiConsumer packetSink) { + if (ignoreDefault || interpolationDelay != 0) { + packetSink.accept(transformationInterpolationDurationWatcher, interpolationDuration); + packetSink.accept(positionOrRotationInterpolationDurationWatcher, interpolationDuration); + } } public void setViewRange(float viewRange) { @@ -117,9 +123,11 @@ public abstract class RDisplay extends REntity { } private static final Object viewRangeWatcher = BountifulWrapper.impl.getDataWatcherObject(16, Float.class); - private void getViewRange(BiConsumer packetSink) { - if (viewRange == 1.0F) return; - packetSink.accept(viewRangeWatcher, viewRange); + + private void getViewRange(boolean ignoreDefault, BiConsumer packetSink) { + if (ignoreDefault || viewRange != 1.0F) { + packetSink.accept(viewRangeWatcher, viewRange); + } } public void setShadowRadius(float shadowRadius) { @@ -128,9 +136,11 @@ public abstract class RDisplay extends REntity { } private static final Object shadowRadiusWatcher = BountifulWrapper.impl.getDataWatcherObject(17, Float.class); - private void getShadowRadius(BiConsumer packetSink) { - if (shadowRadius == 0.0F) return; - packetSink.accept(shadowRadiusWatcher, shadowRadius); + + private void getShadowRadius(boolean ignoreDefault, BiConsumer packetSink) { + if (ignoreDefault || shadowRadius != 0.0F) { + packetSink.accept(shadowRadiusWatcher, shadowRadius); + } } public void setShadowStrength(float shadowStrength) { @@ -139,9 +149,11 @@ public abstract class RDisplay extends REntity { } private static final Object shadowStrengthWatcher = BountifulWrapper.impl.getDataWatcherObject(18, Float.class); - private void getShadowStrength(BiConsumer packetSink) { - if (shadowStrength == 1.0F) return; - packetSink.accept(shadowStrengthWatcher, shadowStrength); + + private void getShadowStrength(boolean ignoreDefault, BiConsumer packetSink) { + if (ignoreDefault || shadowStrength != 1.0F) { + packetSink.accept(shadowStrengthWatcher, shadowStrength); + } } public void setDisplayWidth(float displayWidth) { @@ -150,9 +162,11 @@ public abstract class RDisplay extends REntity { } private static final Object displayWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(19, Float.class); - private void getDisplayWidth(BiConsumer packetSink) { - if (displayWidth == 0.0F) return; - packetSink.accept(displayWidthWatcher, displayWidth); + + private void getDisplayWidth(boolean ignoreDefault, BiConsumer packetSink) { + if (ignoreDefault || displayWidth != 0.0F) { + packetSink.accept(displayWidthWatcher, displayWidth); + } } public void setDisplayHeight(float displayHeight) { @@ -161,9 +175,11 @@ public abstract class RDisplay extends REntity { } private static final Object displayHeightWatcher = BountifulWrapper.impl.getDataWatcherObject(20, Float.class); - private void getDisplayHeight(BiConsumer packetSink) { - if (displayHeight == 0.0F) return; - packetSink.accept(displayHeightWatcher, displayHeight); + + private void getDisplayHeight(boolean ignoreDefault, BiConsumer packetSink) { + if (ignoreDefault || displayHeight != 0.0F) { + packetSink.accept(displayHeightWatcher, displayHeight); + } } public void setInterpolationDelay(int interpolationDelay) { @@ -172,9 +188,11 @@ public abstract class RDisplay extends REntity { } private static final Object interpolationDelayWatcher = BountifulWrapper.impl.getDataWatcherObject(7, Integer.class); - private void getInterpolationDelay(BiConsumer packetSink) { - if (interpolationDelay == 0) return; - packetSink.accept(interpolationDelayWatcher, interpolationDelay); + + private void getInterpolationDelay(boolean ignoreDefault, BiConsumer packetSink) { + if (ignoreDefault || interpolationDelay != 0) { + packetSink.accept(interpolationDelayWatcher, interpolationDelay); + } } public void setBillboard(Display.Billboard billboard) { @@ -183,9 +201,11 @@ public abstract class RDisplay extends REntity { } private static final Object billboardWatcher = BountifulWrapper.impl.getDataWatcherObject(14, Byte.class); - private void getBillboard(BiConsumer packetSink) { - if (billboard == Display.Billboard.FIXED) return; - packetSink.accept(billboardWatcher, (byte) billboard.ordinal()); + + private void getBillboard(boolean ignoreDefault, BiConsumer packetSink) { + if (ignoreDefault || billboard != Display.Billboard.FIXED) { + packetSink.accept(billboardWatcher, (byte) billboard.ordinal()); + } } public void setGlowColorOverride(Color glowColorOverride) { @@ -194,9 +214,11 @@ public abstract class RDisplay extends REntity { } private static final Object glowColorOverrideWatcher = BountifulWrapper.impl.getDataWatcherObject(21, Integer.class); - private void getGlowColorOverride(BiConsumer packetSink) { - if (glowColorOverride == null) return; - packetSink.accept(glowColorOverrideWatcher, glowColorOverride); + + private void getGlowColorOverride(boolean ignoreDefault, BiConsumer packetSink) { + if (ignoreDefault || glowColorOverride != null) { + packetSink.accept(glowColorOverrideWatcher, glowColorOverride == null ? -1 : glowColorOverride.asARGB()); + } } public void setBrightness(Display.Brightness brightness) { @@ -205,9 +227,10 @@ public abstract class RDisplay extends REntity { } private static final Object brightnessWatcher = BountifulWrapper.impl.getDataWatcherObject(15, Integer.class); - private void getBrightness(BiConsumer packetSink) { - if (brightness == null) return; - int brightnessData = brightness.getBlockLight() << 4 | brightness.getSkyLight() << 20; - packetSink.accept(brightnessWatcher, brightnessData); + + private void getBrightness(boolean ignoreDefault, BiConsumer packetSink) { + if (ignoreDefault || brightness != null) { + packetSink.accept(brightnessWatcher, brightness == null ? -1 : brightness.getBlockLight() << 4 | brightness.getSkyLight() << 20); + } } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java index 0b2a8d89..4ed1a4dc 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java @@ -39,9 +39,10 @@ public class RItemDisplay extends RDisplay { } private static final Object itemStackWatcher = BountifulWrapper.impl.getDataWatcherObject(22, ProtocolWrapper.itemStack); - private void getItemStack(BiConsumer packetSink) { - if (itemStack.equals(DEFAULT_ITEM_STACK)) return; - packetSink.accept(itemStackWatcher, asNMSCopy.invoke(null, itemStack)); + private void getItemStack(boolean ignoreDefault, BiConsumer packetSink) { + if (ignoreDefault || !itemStack.equals(DEFAULT_ITEM_STACK)) { + packetSink.accept(itemStackWatcher, asNMSCopy.invoke(null, itemStack)); + } } private static final Object itemDisplayTransformWatcher = BountifulWrapper.impl.getDataWatcherObject(23, Byte.class); @@ -50,8 +51,9 @@ public class RItemDisplay extends RDisplay { sendPacket(updatePacketSink, this::getItemDisplayTransform); } - private void getItemDisplayTransform(BiConsumer packetSink) { - if (itemDisplayTransform == ItemDisplay.ItemDisplayTransform.NONE) return; - packetSink.accept(itemDisplayTransformWatcher, (byte) itemDisplayTransform.ordinal()); + private void getItemDisplayTransform(boolean ignoreDefault, BiConsumer packetSink) { + if (ignoreDefault || itemDisplayTransform != ItemDisplay.ItemDisplayTransform.NONE) { + packetSink.accept(itemDisplayTransformWatcher, (byte) itemDisplayTransform.ordinal()); + } } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java index 1720096d..3abf9f18 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java @@ -53,9 +53,10 @@ public class RTextDisplay extends RDisplay { private static final Class iChatBaseComponent = Reflection.getClass("net.minecraft.network.chat.Component"); private static final Object textWatcher = BountifulWrapper.impl.getDataWatcherObject(22, iChatBaseComponent); - private void getText(BiConsumer packetSink) { - if (text.isEmpty()) return; - packetSink.accept(textWatcher, ChatWrapper.impl.stringToChatComponent(text)); + private void getText(boolean ignoreDefault, BiConsumer packetSink) { + if (ignoreDefault || !text.isEmpty()) { + packetSink.accept(textWatcher, ChatWrapper.impl.stringToChatComponent(text)); + } } public void setLineWidth(int lineWidth) { @@ -64,9 +65,10 @@ public class RTextDisplay extends RDisplay { } private static final Object lineWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(23, Integer.class); - private void getLineWidth(BiConsumer packetSink) { - if (lineWidth == 200) return; - packetSink.accept(lineWidthWatcher, lineWidth); + private void getLineWidth(boolean ignoreDefault, BiConsumer packetSink) { + if (ignoreDefault || lineWidth != 200) { + packetSink.accept(lineWidthWatcher, lineWidth); + } } public void setTextOpacity(byte textOpacity) { @@ -75,9 +77,10 @@ public class RTextDisplay extends RDisplay { } private static final Object textOpacityWatcher = BountifulWrapper.impl.getDataWatcherObject(25, Byte.class); - private void getTextOpacity(BiConsumer packetSink) { - if (textOpacity == (byte) -1) return; - packetSink.accept(textOpacityWatcher, textOpacity); + private void getTextOpacity(boolean ignoreDefault, BiConsumer packetSink) { + if (ignoreDefault || textOpacity != (byte) -1) { + packetSink.accept(textOpacityWatcher, textOpacity); + } } public void setShadowed(boolean shadowed) { @@ -101,7 +104,7 @@ public class RTextDisplay extends RDisplay { } private static final Object textStatusWatcher = BountifulWrapper.impl.getDataWatcherObject(26, Byte.class); - private void getTextStatus(BiConsumer packetSink) { + private void getTextStatus(boolean ignoreDefault, BiConsumer packetSink) { byte status = 0; if (shadowed) { @@ -121,7 +124,8 @@ public class RTextDisplay extends RDisplay { status |= 0x0F; } - if (status == 0) return; - packetSink.accept(textStatusWatcher, status); + if (ignoreDefault || status != 0) { + packetSink.accept(textStatusWatcher, status); + } } } From 522cd850a203e485c153b4c0c73a33fa45aa7ed2 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 12 Mar 2025 08:45:01 +0100 Subject: [PATCH 8/8] Add copyright and usage note! --- .../src/de/steamwar/entity/RBlockDisplay.java | 22 +++++++++++++++++++ .../src/de/steamwar/entity/RDisplay.java | 22 +++++++++++++++++++ .../src/de/steamwar/entity/RItemDisplay.java | 22 +++++++++++++++++++ .../src/de/steamwar/entity/RTextDisplay.java | 22 +++++++++++++++++++ 4 files changed, 88 insertions(+) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java index c01fdea2..5f4c4d50 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java @@ -1,3 +1,22 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package de.steamwar.entity; import de.steamwar.Reflection; @@ -11,6 +30,9 @@ import org.bukkit.entity.EntityType; import java.util.function.BiConsumer; import java.util.function.Consumer; +/** + * !! This class cannot be used in Versions lower than or equal to 1.19.4 !! + */ @Getter public class RBlockDisplay extends RDisplay { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java index 3be30b12..863dc658 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java @@ -1,3 +1,22 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package de.steamwar.entity; import de.steamwar.core.BountifulWrapper; @@ -16,6 +35,9 @@ import java.util.List; import java.util.function.BiConsumer; import java.util.function.Consumer; +/** + * !! This class cannot be used in Versions lower than or equal to 1.19.4 !! + */ @Getter public abstract class RDisplay extends REntity { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java index 4ed1a4dc..52cbfc31 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java @@ -1,3 +1,22 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package de.steamwar.entity; import de.steamwar.core.BountifulWrapper; @@ -12,6 +31,9 @@ import org.bukkit.inventory.ItemStack; import java.util.function.BiConsumer; import java.util.function.Consumer; +/** + * !! This class cannot be used in Versions lower than or equal to 1.19.4 !! + */ @Getter public class RItemDisplay extends RDisplay { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java index 3abf9f18..605b6770 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java @@ -1,3 +1,22 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package de.steamwar.entity; import de.steamwar.Reflection; @@ -11,6 +30,9 @@ import org.bukkit.entity.TextDisplay; import java.util.function.BiConsumer; import java.util.function.Consumer; +/** + * !! This class cannot be used in Versions lower than or equal to 1.19.4 !! + */ @Getter public class RTextDisplay extends RDisplay {