From 9d6305607d53d4746b661da13a0dca76f5d58297 Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 25 Jul 2025 19:01:58 +0200 Subject: [PATCH] fancyholograms v3: Remove implementation modules for 1.194 - 1.20.4 --- plugins/fancyholograms/build.gradle.kts | 5 - .../implementation_1_19_4/build.gradle.kts | 33 --- .../hologram/version/Hologram1_19_4.java | 253 ------------------ .../hologram/version/MappingKeys1_19_4.java | 20 -- .../implementation_1_20_1/build.gradle.kts | 33 --- .../hologram/version/Hologram1_20_1.java | 253 ------------------ .../hologram/version/MappingKeys1_20_1.java | 20 -- .../implementation_1_20_2/build.gradle.kts | 33 --- .../hologram/version/Hologram1_20_2.java | 253 ------------------ .../hologram/version/MappingKeys1_20_2.java | 20 -- .../implementation_1_20_4/build.gradle.kts | 33 --- .../hologram/version/Hologram1_20_4.java | 253 ------------------ .../hologram/version/MappingKeys1_20_4.java | 20 -- .../main/FancyHologramsPlugin.java | 21 +- settings.gradle.kts | 4 - 15 files changed, 4 insertions(+), 1250 deletions(-) delete mode 100644 plugins/fancyholograms/implementation_1_19_4/build.gradle.kts delete mode 100644 plugins/fancyholograms/implementation_1_19_4/src/main/java/de/oliver/fancyholograms/hologram/version/Hologram1_19_4.java delete mode 100644 plugins/fancyholograms/implementation_1_19_4/src/main/java/de/oliver/fancyholograms/hologram/version/MappingKeys1_19_4.java delete mode 100644 plugins/fancyholograms/implementation_1_20_1/build.gradle.kts delete mode 100644 plugins/fancyholograms/implementation_1_20_1/src/main/java/de/oliver/fancyholograms/hologram/version/Hologram1_20_1.java delete mode 100644 plugins/fancyholograms/implementation_1_20_1/src/main/java/de/oliver/fancyholograms/hologram/version/MappingKeys1_20_1.java delete mode 100644 plugins/fancyholograms/implementation_1_20_2/build.gradle.kts delete mode 100644 plugins/fancyholograms/implementation_1_20_2/src/main/java/de/oliver/fancyholograms/hologram/version/Hologram1_20_2.java delete mode 100644 plugins/fancyholograms/implementation_1_20_2/src/main/java/de/oliver/fancyholograms/hologram/version/MappingKeys1_20_2.java delete mode 100644 plugins/fancyholograms/implementation_1_20_4/build.gradle.kts delete mode 100644 plugins/fancyholograms/implementation_1_20_4/src/main/java/de/oliver/fancyholograms/hologram/version/Hologram1_20_4.java delete mode 100644 plugins/fancyholograms/implementation_1_20_4/src/main/java/de/oliver/fancyholograms/hologram/version/MappingKeys1_20_4.java diff --git a/plugins/fancyholograms/build.gradle.kts b/plugins/fancyholograms/build.gradle.kts index becedd74..c93211db 100644 --- a/plugins/fancyholograms/build.gradle.kts +++ b/plugins/fancyholograms/build.gradle.kts @@ -53,11 +53,6 @@ dependencies { compileOnly("io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT") implementation(project(":plugins:fancyholograms:fh-api")) - implementation(project(":plugins:fancyholograms:implementation_1_20_4", configuration = "reobf")) - implementation(project(":plugins:fancyholograms:implementation_1_20_2", configuration = "reobf")) - implementation(project(":plugins:fancyholograms:implementation_1_20_1", configuration = "reobf")) - implementation(project(":plugins:fancyholograms:implementation_1_19_4", configuration = "reobf")) - rootProject.subprojects .filter { it.path.startsWith(":libraries:packets:implementations") } diff --git a/plugins/fancyholograms/implementation_1_19_4/build.gradle.kts b/plugins/fancyholograms/implementation_1_19_4/build.gradle.kts deleted file mode 100644 index e2bebb19..00000000 --- a/plugins/fancyholograms/implementation_1_19_4/build.gradle.kts +++ /dev/null @@ -1,33 +0,0 @@ -plugins { - id("java-library") - id("io.papermc.paperweight.userdev") -} - - -val minecraftVersion = "1.19.4" - - -dependencies { - paperweight.paperDevBundle("$minecraftVersion-R0.1-SNAPSHOT") - - implementation(project(":plugins:fancyholograms:fh-api")) - implementation(project(":libraries:common")) - compileOnly("com.viaversion:viaversion-api:5.2.1") -} - - -tasks { - named("assemble") { - dependsOn(named("reobfJar")) - } - - javadoc { - options.encoding = Charsets.UTF_8.name() - } - - compileJava { - options.encoding = Charsets.UTF_8.name() - - options.release.set(17) - } -} \ No newline at end of file diff --git a/plugins/fancyholograms/implementation_1_19_4/src/main/java/de/oliver/fancyholograms/hologram/version/Hologram1_19_4.java b/plugins/fancyholograms/implementation_1_19_4/src/main/java/de/oliver/fancyholograms/hologram/version/Hologram1_19_4.java deleted file mode 100644 index 1f7d1089..00000000 --- a/plugins/fancyholograms/implementation_1_19_4/src/main/java/de/oliver/fancyholograms/hologram/version/Hologram1_19_4.java +++ /dev/null @@ -1,253 +0,0 @@ -package de.oliver.fancyholograms.hologram.version; - -import com.mojang.math.Transformation; -import de.oliver.fancyholograms.api.data.*; -import de.oliver.fancyholograms.api.events.HologramDespawnEvent; -import de.oliver.fancyholograms.api.events.HologramSpawnEvent; -import de.oliver.fancyholograms.api.hologram.Hologram; -import de.oliver.fancylib.ReflectionUtils; -import io.papermc.paper.adventure.PaperAdventure; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; -import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket; -import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; -import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; -import net.minecraft.network.syncher.EntityDataAccessor; -import net.minecraft.network.syncher.SynchedEntityData.DataItem; -import net.minecraft.network.syncher.SynchedEntityData.DataValue; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.util.Brightness; -import net.minecraft.world.entity.Display; -import net.minecraft.world.entity.Display.TextDisplay; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.Block; -import org.bukkit.craftbukkit.v1_19_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.joml.Quaternionf; - -import java.util.ArrayList; - -import static de.oliver.fancylib.ReflectionUtils.getValue; - -public final class Hologram1_19_4 extends Hologram { - - @Nullable - private Display display; - - public Hologram1_19_4(@NotNull final HologramData data) { - super(data); - - create(); - } - - public void create() { - final var location = data.getLocation(); - if (location.getWorld() == null) { - return; // no location data, cannot be created - } - - ServerLevel world = ((CraftWorld) location.getWorld()).getHandle(); - - switch (data.getType()) { - case TEXT -> this.display = new Display.TextDisplay(EntityType.TEXT_DISPLAY, world); - case BLOCK -> this.display = new Display.BlockDisplay(EntityType.BLOCK_DISPLAY, world); - case ITEM -> this.display = new Display.ItemDisplay(EntityType.ITEM_DISPLAY, world); - } - } - - public void syncWithData() { - final var display = this.display; - if (display == null) { - return; // doesn't exist, nothing to update - } - - // location data - final var location = data.getLocation(); - if (!location.isWorldLoaded()) { - return; - } else { - display.setPosRaw(location.x(), location.y(), location.z()); - display.setYRot(location.getYaw()); - display.setXRot(location.getPitch()); - } - - if (display instanceof TextDisplay textDisplay && data instanceof TextHologramData textData) { - // line width - final var DATA_LINE_WIDTH_ID = ReflectionUtils.getStaticValue(TextDisplay.class, MappingKeys1_19_4.DATA_LINE_WIDTH_ID.getMapping()); - display.getEntityData().set((EntityDataAccessor) DATA_LINE_WIDTH_ID, Hologram.LINE_WIDTH); - - // background - final var DATA_BACKGROUND_COLOR_ID = ReflectionUtils.getStaticValue(TextDisplay.class, MappingKeys1_19_4.DATA_BACKGROUND_COLOR_ID.getMapping()); - - final var background = textData.getBackground(); - if (background == null) { - display.getEntityData().set((EntityDataAccessor) DATA_BACKGROUND_COLOR_ID, TextDisplay.INITIAL_BACKGROUND); - } else if (background == Hologram.TRANSPARENT) { - display.getEntityData().set((EntityDataAccessor) DATA_BACKGROUND_COLOR_ID, 0); - } else { - display.getEntityData().set((EntityDataAccessor) DATA_BACKGROUND_COLOR_ID, background.asARGB()); - } - - // text shadow - if (textData.hasTextShadow()) { - textDisplay.setFlags((byte) (textDisplay.getFlags() | TextDisplay.FLAG_SHADOW)); - } else { - textDisplay.setFlags((byte) (textDisplay.getFlags() & ~TextDisplay.FLAG_SHADOW)); - } - - // text alignment - if (textData.getTextAlignment() == org.bukkit.entity.TextDisplay.TextAlignment.LEFT) { - textDisplay.setFlags((byte) (textDisplay.getFlags() | TextDisplay.FLAG_ALIGN_LEFT)); - } else { - textDisplay.setFlags((byte) (textDisplay.getFlags() & ~TextDisplay.FLAG_ALIGN_LEFT)); - } - - // see through - if (textData.isSeeThrough()) { - textDisplay.setFlags((byte) (textDisplay.getFlags() | TextDisplay.FLAG_SEE_THROUGH)); - } else { - textDisplay.setFlags((byte) (textDisplay.getFlags() & ~TextDisplay.FLAG_SEE_THROUGH)); - } - - if (textData.getTextAlignment() == org.bukkit.entity.TextDisplay.TextAlignment.RIGHT) { - textDisplay.setFlags((byte) (textDisplay.getFlags() | TextDisplay.FLAG_ALIGN_RIGHT)); - } else { - textDisplay.setFlags((byte) (textDisplay.getFlags() & ~TextDisplay.FLAG_ALIGN_RIGHT)); - } - - } else if (display instanceof Display.ItemDisplay itemDisplay && data instanceof ItemHologramData itemData) { - // item - itemDisplay.setItemStack(ItemStack.fromBukkitCopy(itemData.getItemStack())); - - } else if (display instanceof Display.BlockDisplay blockDisplay && data instanceof BlockHologramData blockData) { - Block block = BuiltInRegistries.BLOCK.get(ResourceLocation.of("minecraft:" + blockData.getBlock().name().toLowerCase(), ':')); - blockDisplay.setBlockState(block.defaultBlockState()); - } - - if (data instanceof DisplayHologramData displayData) { - // interpolation - final var DATA_INTERPOLATION_DURATION_ID = ReflectionUtils.getStaticValue(Display.class, MappingKeys1_19_4.DATA_INTERPOLATION_DURATION_ID.getMapping()); - display.getEntityData().set((EntityDataAccessor) DATA_INTERPOLATION_DURATION_ID, displayData.getInterpolationDuration()); - - final var DATA_INTERPOLATION_START_DELTA_TICKS_ID = ReflectionUtils.getStaticValue(Display.class, MappingKeys1_19_4.DATA_INTERPOLATION_START_DELTA_TICKS_ID.getMapping()); - display.getEntityData().set((EntityDataAccessor) DATA_INTERPOLATION_START_DELTA_TICKS_ID, 0); - - // billboard data - display.setBillboardConstraints(switch (displayData.getBillboard()) { - case FIXED -> Display.BillboardConstraints.FIXED; - case VERTICAL -> Display.BillboardConstraints.VERTICAL; - case HORIZONTAL -> Display.BillboardConstraints.HORIZONTAL; - case CENTER -> Display.BillboardConstraints.CENTER; - }); - - // brightness - if (displayData.getBrightness() != null) { - display.setBrightnessOverride(new Brightness(displayData.getBrightness().getBlockLight(), displayData.getBrightness().getSkyLight())); - } - - // entity scale AND MORE! - display.setTransformation(new Transformation( - displayData.getTranslation(), - new Quaternionf(), - displayData.getScale(), - new Quaternionf()) - ); - - // entity shadow - display.setShadowRadius(displayData.getShadowRadius()); - display.setShadowStrength(displayData.getShadowStrength()); - - // view range - display.setViewRange(displayData.getVisibilityDistance()); - } - } - - - @Override - public void spawnTo(@NotNull final Player player) { - if (!new HologramSpawnEvent(this, player).callEvent()) { - return; - } - - if (this.display == null) { - create(); // try to create it if it doesn't exist every time - } - - final var display = this.display; - if (display == null) { - return; // could not be created, nothing to show - } - - if (!data.getWorldName().equals(player.getLocation().getWorld().getName())) { - return; - } - - ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle(); - - // TODO: cache player protocol version - // TODO: fix this -// final var protocolVersion = FancyHologramsPlugin.get().isUsingViaVersion() ? Via.getAPI().getPlayerVersion(player) : MINIMUM_PROTOCOL_VERSION; -// if (protocolVersion < MINIMUM_PROTOCOL_VERSION) { -// return false; -// } - - serverPlayer.connection.send(new ClientboundAddEntityPacket(display)); - this.viewers.add(player.getUniqueId()); - updateFor(player); - - } - - @Override - public void despawnFrom(@NotNull final Player player) { - if (!new HologramDespawnEvent(this, player).callEvent()) { - return; - } - - final var display = this.display; - if (display == null) { - return; // doesn't exist, nothing to hide - } - - ((CraftPlayer) player).getHandle().connection.send(new ClientboundRemoveEntitiesPacket(display.getId())); - - this.viewers.remove(player.getUniqueId()); - } - - - @Override - public void updateFor(@NotNull final Player player) { - final var display = this.display; - if (display == null) { - return; // doesn't exist, nothing to refresh - } - - if (!isViewer(player)) { - return; - } - - syncWithData(); - - ((CraftPlayer) player).getHandle().connection.send(new ClientboundTeleportEntityPacket(display)); - - if (display instanceof TextDisplay textDisplay) { - textDisplay.setText(PaperAdventure.asVanilla(getShownText(player))); - } - - final var values = new ArrayList>(); - - //noinspection unchecked - for (final var item : ((Int2ObjectMap>) getValue(display.getEntityData(), "e")).values()) { - values.add(item.value()); - } - - ((CraftPlayer) player).getHandle().connection.send(new ClientboundSetEntityDataPacket(display.getId(), values)); - } - -} diff --git a/plugins/fancyholograms/implementation_1_19_4/src/main/java/de/oliver/fancyholograms/hologram/version/MappingKeys1_19_4.java b/plugins/fancyholograms/implementation_1_19_4/src/main/java/de/oliver/fancyholograms/hologram/version/MappingKeys1_19_4.java deleted file mode 100644 index 75115d4a..00000000 --- a/plugins/fancyholograms/implementation_1_19_4/src/main/java/de/oliver/fancyholograms/hologram/version/MappingKeys1_19_4.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.oliver.fancyholograms.hologram.version; - -public enum MappingKeys1_19_4 { - - DATA_INTERPOLATION_DURATION_ID("r"), - DATA_INTERPOLATION_START_DELTA_TICKS_ID("q"), - DATA_LINE_WIDTH_ID("aL"), - DATA_BACKGROUND_COLOR_ID("aM"), - ; - - private final String mapping; - - MappingKeys1_19_4(String mapping) { - this.mapping = mapping; - } - - public String getMapping() { - return mapping; - } -} diff --git a/plugins/fancyholograms/implementation_1_20_1/build.gradle.kts b/plugins/fancyholograms/implementation_1_20_1/build.gradle.kts deleted file mode 100644 index f327ac2d..00000000 --- a/plugins/fancyholograms/implementation_1_20_1/build.gradle.kts +++ /dev/null @@ -1,33 +0,0 @@ -plugins { - id("java-library") - id("io.papermc.paperweight.userdev") -} - - -val minecraftVersion = "1.20.1" - - -dependencies { - paperweight.paperDevBundle("$minecraftVersion-R0.1-SNAPSHOT") - - implementation(project(":plugins:fancyholograms:fh-api")) - implementation(project(":libraries:common")) - compileOnly("com.viaversion:viaversion-api:5.2.1") -} - - -tasks { - named("assemble") { - dependsOn(named("reobfJar")) - } - - javadoc { - options.encoding = Charsets.UTF_8.name() - } - - compileJava { - options.encoding = Charsets.UTF_8.name() - - options.release.set(17) - } -} \ No newline at end of file diff --git a/plugins/fancyholograms/implementation_1_20_1/src/main/java/de/oliver/fancyholograms/hologram/version/Hologram1_20_1.java b/plugins/fancyholograms/implementation_1_20_1/src/main/java/de/oliver/fancyholograms/hologram/version/Hologram1_20_1.java deleted file mode 100644 index 7f86efe1..00000000 --- a/plugins/fancyholograms/implementation_1_20_1/src/main/java/de/oliver/fancyholograms/hologram/version/Hologram1_20_1.java +++ /dev/null @@ -1,253 +0,0 @@ -package de.oliver.fancyholograms.hologram.version; - -import com.mojang.math.Transformation; -import de.oliver.fancyholograms.api.data.*; -import de.oliver.fancyholograms.api.events.HologramDespawnEvent; -import de.oliver.fancyholograms.api.events.HologramSpawnEvent; -import de.oliver.fancyholograms.api.hologram.Hologram; -import de.oliver.fancylib.ReflectionUtils; -import io.papermc.paper.adventure.PaperAdventure; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; -import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket; -import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; -import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; -import net.minecraft.network.syncher.EntityDataAccessor; -import net.minecraft.network.syncher.SynchedEntityData.DataItem; -import net.minecraft.network.syncher.SynchedEntityData.DataValue; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.util.Brightness; -import net.minecraft.world.entity.Display; -import net.minecraft.world.entity.Display.TextDisplay; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.Block; -import org.bukkit.craftbukkit.v1_20_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.joml.Quaternionf; - -import java.util.ArrayList; - -import static de.oliver.fancylib.ReflectionUtils.getValue; - -public final class Hologram1_20_1 extends Hologram { - - @Nullable - private Display display; - - public Hologram1_20_1(@NotNull final HologramData data) { - super(data); - - create(); - } - - public void create() { - final var location = data.getLocation(); - if (location.getWorld() == null) { - return; // no location data, cannot be created - } - - ServerLevel world = ((CraftWorld) location.getWorld()).getHandle(); - - switch (data.getType()) { - case TEXT -> this.display = new Display.TextDisplay(EntityType.TEXT_DISPLAY, world); - case BLOCK -> this.display = new Display.BlockDisplay(EntityType.BLOCK_DISPLAY, world); - case ITEM -> this.display = new Display.ItemDisplay(EntityType.ITEM_DISPLAY, world); - } - } - - public void syncWithData() { - final var display = this.display; - if (display == null) { - return; // doesn't exist, nothing to update - } - - // location data - final var location = data.getLocation(); - if (!location.isWorldLoaded()) { - return; - } else { - display.setPosRaw(location.x(), location.y(), location.z()); - display.setYRot(location.getYaw()); - display.setXRot(location.getPitch()); - } - - if (display instanceof TextDisplay textDisplay && data instanceof TextHologramData textData) { - // line width - final var DATA_LINE_WIDTH_ID = ReflectionUtils.getStaticValue(TextDisplay.class, MappingKeys1_20_1.DATA_LINE_WIDTH_ID.getMapping()); - display.getEntityData().set((EntityDataAccessor) DATA_LINE_WIDTH_ID, Hologram.LINE_WIDTH); - - // background - final var DATA_BACKGROUND_COLOR_ID = ReflectionUtils.getStaticValue(TextDisplay.class, MappingKeys1_20_1.DATA_BACKGROUND_COLOR_ID.getMapping()); //DATA_BACKGROUND_COLOR_ID - - final var background = textData.getBackground(); - if (background == null) { - display.getEntityData().set((EntityDataAccessor) DATA_BACKGROUND_COLOR_ID, TextDisplay.INITIAL_BACKGROUND); - } else if (background == Hologram.TRANSPARENT) { - display.getEntityData().set((EntityDataAccessor) DATA_BACKGROUND_COLOR_ID, 0); - } else { - display.getEntityData().set((EntityDataAccessor) DATA_BACKGROUND_COLOR_ID, background.asARGB()); - } - - // text shadow - if (textData.hasTextShadow()) { - textDisplay.setFlags((byte) (textDisplay.getFlags() | TextDisplay.FLAG_SHADOW)); - } else { - textDisplay.setFlags((byte) (textDisplay.getFlags() & ~TextDisplay.FLAG_SHADOW)); - } - - // text alignment - if (textData.getTextAlignment() == org.bukkit.entity.TextDisplay.TextAlignment.LEFT) { - textDisplay.setFlags((byte) (textDisplay.getFlags() | TextDisplay.FLAG_ALIGN_LEFT)); - } else { - textDisplay.setFlags((byte) (textDisplay.getFlags() & ~TextDisplay.FLAG_ALIGN_LEFT)); - } - - // see through - if (textData.isSeeThrough()) { - textDisplay.setFlags((byte) (textDisplay.getFlags() | TextDisplay.FLAG_SEE_THROUGH)); - } else { - textDisplay.setFlags((byte) (textDisplay.getFlags() & ~TextDisplay.FLAG_SEE_THROUGH)); - } - - if (textData.getTextAlignment() == org.bukkit.entity.TextDisplay.TextAlignment.RIGHT) { - textDisplay.setFlags((byte) (textDisplay.getFlags() | TextDisplay.FLAG_ALIGN_RIGHT)); - } else { - textDisplay.setFlags((byte) (textDisplay.getFlags() & ~TextDisplay.FLAG_ALIGN_RIGHT)); - } - - } else if (display instanceof Display.ItemDisplay itemDisplay && data instanceof ItemHologramData itemData) { - // item - itemDisplay.setItemStack(ItemStack.fromBukkitCopy(itemData.getItemStack())); - - } else if (display instanceof Display.BlockDisplay blockDisplay && data instanceof BlockHologramData blockData) { - Block block = BuiltInRegistries.BLOCK.get(ResourceLocation.of("minecraft:" + blockData.getBlock().name().toLowerCase(), ':')); - blockDisplay.setBlockState(block.defaultBlockState()); - } - - if (data instanceof DisplayHologramData displayData) { - // interpolation - final var DATA_INTERPOLATION_DURATION_ID = ReflectionUtils.getStaticValue(Display.class, MappingKeys1_20_1.DATA_INTERPOLATION_DURATION_ID.getMapping()); - display.getEntityData().set((EntityDataAccessor) DATA_INTERPOLATION_DURATION_ID, displayData.getInterpolationDuration()); - - final var DATA_INTERPOLATION_START_DELTA_TICKS_ID = ReflectionUtils.getStaticValue(Display.class, MappingKeys1_20_1.DATA_INTERPOLATION_START_DELTA_TICKS_ID.getMapping()); - display.getEntityData().set((EntityDataAccessor) DATA_INTERPOLATION_START_DELTA_TICKS_ID, 0); - - // billboard data - display.setBillboardConstraints(switch (displayData.getBillboard()) { - case FIXED -> Display.BillboardConstraints.FIXED; - case VERTICAL -> Display.BillboardConstraints.VERTICAL; - case HORIZONTAL -> Display.BillboardConstraints.HORIZONTAL; - case CENTER -> Display.BillboardConstraints.CENTER; - }); - - // brightness - if (displayData.getBrightness() != null) { - display.setBrightnessOverride(new Brightness(displayData.getBrightness().getBlockLight(), displayData.getBrightness().getSkyLight())); - } - - // entity scale AND MORE! - display.setTransformation(new Transformation( - displayData.getTranslation(), - new Quaternionf(), - displayData.getScale(), - new Quaternionf()) - ); - - // entity shadow - display.setShadowRadius(displayData.getShadowRadius()); - display.setShadowStrength(displayData.getShadowStrength()); - - // view range - display.setViewRange(displayData.getVisibilityDistance()); - } - } - - - @Override - public void spawnTo(@NotNull final Player player) { - if (!new HologramSpawnEvent(this, player).callEvent()) { - return; - } - - if (this.display == null) { - create(); // try to create it if it doesn't exist every time - } - - final var display = this.display; - if (display == null) { - return; // could not be created, nothing to show - } - - if (!data.getWorldName().equals(player.getLocation().getWorld().getName())) { - return; - } - - ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle(); - - // TODO: cache player protocol version - // TODO: fix this -// final var protocolVersion = FancyHologramsPlugin.get().isUsingViaVersion() ? Via.getAPI().getPlayerVersion(player) : MINIMUM_PROTOCOL_VERSION; -// if (protocolVersion < MINIMUM_PROTOCOL_VERSION) { -// return false; -// } - - serverPlayer.connection.send(new ClientboundAddEntityPacket(display)); - this.viewers.add(player.getUniqueId()); - updateFor(player); - - } - - @Override - public void despawnFrom(@NotNull final Player player) { - if (!new HologramDespawnEvent(this, player).callEvent()) { - return; - } - - final var display = this.display; - if (display == null) { - return; // doesn't exist, nothing to hide - } - - ((CraftPlayer) player).getHandle().connection.send(new ClientboundRemoveEntitiesPacket(display.getId())); - - this.viewers.remove(player.getUniqueId()); - } - - - @Override - public void updateFor(@NotNull final Player player) { - final var display = this.display; - if (display == null) { - return; // doesn't exist, nothing to refresh - } - - if (!isViewer(player)) { - return; - } - - syncWithData(); - - ((CraftPlayer) player).getHandle().connection.send(new ClientboundTeleportEntityPacket(display)); - - if (display instanceof TextDisplay textDisplay) { - textDisplay.setText(PaperAdventure.asVanilla(getShownText(player))); - } - - final var values = new ArrayList>(); - - //noinspection unchecked - for (final var item : ((Int2ObjectMap>) getValue(display.getEntityData(), "e")).values()) { - values.add(item.value()); - } - - ((CraftPlayer) player).getHandle().connection.send(new ClientboundSetEntityDataPacket(display.getId(), values)); - } - -} diff --git a/plugins/fancyholograms/implementation_1_20_1/src/main/java/de/oliver/fancyholograms/hologram/version/MappingKeys1_20_1.java b/plugins/fancyholograms/implementation_1_20_1/src/main/java/de/oliver/fancyholograms/hologram/version/MappingKeys1_20_1.java deleted file mode 100644 index 9fffe629..00000000 --- a/plugins/fancyholograms/implementation_1_20_1/src/main/java/de/oliver/fancyholograms/hologram/version/MappingKeys1_20_1.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.oliver.fancyholograms.hologram.version; - -public enum MappingKeys1_20_1 { - - DATA_INTERPOLATION_DURATION_ID("q"), - DATA_INTERPOLATION_START_DELTA_TICKS_ID("p"), - DATA_LINE_WIDTH_ID("aM"), - DATA_BACKGROUND_COLOR_ID("aN"), - ; - - private final String mapping; - - MappingKeys1_20_1(String mapping) { - this.mapping = mapping; - } - - public String getMapping() { - return mapping; - } -} diff --git a/plugins/fancyholograms/implementation_1_20_2/build.gradle.kts b/plugins/fancyholograms/implementation_1_20_2/build.gradle.kts deleted file mode 100644 index 85bc7751..00000000 --- a/plugins/fancyholograms/implementation_1_20_2/build.gradle.kts +++ /dev/null @@ -1,33 +0,0 @@ -plugins { - id("java-library") - id("io.papermc.paperweight.userdev") -} - - -val minecraftVersion = "1.20.2" - - -dependencies { - paperweight.paperDevBundle("$minecraftVersion-R0.1-SNAPSHOT") - - implementation(project(":plugins:fancyholograms:fh-api")) - implementation(project(":libraries:common")) - compileOnly("com.viaversion:viaversion-api:5.2.1") -} - - -tasks { - named("assemble") { - dependsOn(named("reobfJar")) - } - - javadoc { - options.encoding = Charsets.UTF_8.name() - } - - compileJava { - options.encoding = Charsets.UTF_8.name() - - options.release.set(17) - } -} \ No newline at end of file diff --git a/plugins/fancyholograms/implementation_1_20_2/src/main/java/de/oliver/fancyholograms/hologram/version/Hologram1_20_2.java b/plugins/fancyholograms/implementation_1_20_2/src/main/java/de/oliver/fancyholograms/hologram/version/Hologram1_20_2.java deleted file mode 100644 index 6f0765b4..00000000 --- a/plugins/fancyholograms/implementation_1_20_2/src/main/java/de/oliver/fancyholograms/hologram/version/Hologram1_20_2.java +++ /dev/null @@ -1,253 +0,0 @@ -package de.oliver.fancyholograms.hologram.version; - -import com.mojang.math.Transformation; -import de.oliver.fancyholograms.api.data.*; -import de.oliver.fancyholograms.api.events.HologramDespawnEvent; -import de.oliver.fancyholograms.api.events.HologramSpawnEvent; -import de.oliver.fancyholograms.api.hologram.Hologram; -import de.oliver.fancylib.ReflectionUtils; -import io.papermc.paper.adventure.PaperAdventure; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; -import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket; -import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; -import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; -import net.minecraft.network.syncher.EntityDataAccessor; -import net.minecraft.network.syncher.SynchedEntityData.DataItem; -import net.minecraft.network.syncher.SynchedEntityData.DataValue; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.util.Brightness; -import net.minecraft.world.entity.Display; -import net.minecraft.world.entity.Display.TextDisplay; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.Block; -import org.bukkit.craftbukkit.v1_20_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.joml.Quaternionf; - -import java.util.ArrayList; - -import static de.oliver.fancylib.ReflectionUtils.getValue; - -public final class Hologram1_20_2 extends Hologram { - - @Nullable - private Display display; - - public Hologram1_20_2(@NotNull final HologramData data) { - super(data); - - create(); - } - - public void create() { - final var location = data.getLocation(); - if (location.getWorld() == null) { - return; // no location data, cannot be created - } - - ServerLevel world = ((CraftWorld) location.getWorld()).getHandle(); - - switch (data.getType()) { - case TEXT -> this.display = new Display.TextDisplay(EntityType.TEXT_DISPLAY, world); - case BLOCK -> this.display = new Display.BlockDisplay(EntityType.BLOCK_DISPLAY, world); - case ITEM -> this.display = new Display.ItemDisplay(EntityType.ITEM_DISPLAY, world); - } - } - - public void syncWithData() { - final var display = this.display; - if (display == null) { - return; // doesn't exist, nothing to update - } - - // location data - final var location = data.getLocation(); - if (!location.isWorldLoaded()) { - return; - } else { - display.setPosRaw(location.x(), location.y(), location.z()); - display.setYRot(location.getYaw()); - display.setXRot(location.getPitch()); - } - - if (display instanceof TextDisplay textDisplay && data instanceof TextHologramData textData) { - // line width - final var DATA_LINE_WIDTH_ID = ReflectionUtils.getStaticValue(TextDisplay.class, MappingKeys1_20_2.DATA_LINE_WIDTH_ID.getMapping()); - display.getEntityData().set((EntityDataAccessor) DATA_LINE_WIDTH_ID, Hologram.LINE_WIDTH); - - // background - final var DATA_BACKGROUND_COLOR_ID = ReflectionUtils.getStaticValue(TextDisplay.class, MappingKeys1_20_2.DATA_BACKGROUND_COLOR_ID.getMapping()); //DATA_BACKGROUND_COLOR_ID - - final var background = textData.getBackground(); - if (background == null) { - display.getEntityData().set((EntityDataAccessor) DATA_BACKGROUND_COLOR_ID, TextDisplay.INITIAL_BACKGROUND); - } else if (background == Hologram.TRANSPARENT) { - display.getEntityData().set((EntityDataAccessor) DATA_BACKGROUND_COLOR_ID, 0); - } else { - display.getEntityData().set((EntityDataAccessor) DATA_BACKGROUND_COLOR_ID, background.asARGB()); - } - - // text shadow - if (textData.hasTextShadow()) { - textDisplay.setFlags((byte) (textDisplay.getFlags() | TextDisplay.FLAG_SHADOW)); - } else { - textDisplay.setFlags((byte) (textDisplay.getFlags() & ~TextDisplay.FLAG_SHADOW)); - } - - // text alignment - if (textData.getTextAlignment() == org.bukkit.entity.TextDisplay.TextAlignment.LEFT) { - textDisplay.setFlags((byte) (textDisplay.getFlags() | TextDisplay.FLAG_ALIGN_LEFT)); - } else { - textDisplay.setFlags((byte) (textDisplay.getFlags() & ~TextDisplay.FLAG_ALIGN_LEFT)); - } - - // see through - if (textData.isSeeThrough()) { - textDisplay.setFlags((byte) (textDisplay.getFlags() | TextDisplay.FLAG_SEE_THROUGH)); - } else { - textDisplay.setFlags((byte) (textDisplay.getFlags() & ~TextDisplay.FLAG_SEE_THROUGH)); - } - - if (textData.getTextAlignment() == org.bukkit.entity.TextDisplay.TextAlignment.RIGHT) { - textDisplay.setFlags((byte) (textDisplay.getFlags() | TextDisplay.FLAG_ALIGN_RIGHT)); - } else { - textDisplay.setFlags((byte) (textDisplay.getFlags() & ~TextDisplay.FLAG_ALIGN_RIGHT)); - } - - } else if (display instanceof Display.ItemDisplay itemDisplay && data instanceof ItemHologramData itemData) { - // item - itemDisplay.setItemStack(ItemStack.fromBukkitCopy(itemData.getItemStack())); - - } else if (display instanceof Display.BlockDisplay blockDisplay && data instanceof BlockHologramData blockData) { - Block block = BuiltInRegistries.BLOCK.get(ResourceLocation.of("minecraft:" + blockData.getBlock().name().toLowerCase(), ':')); - blockDisplay.setBlockState(block.defaultBlockState()); - } - - if (data instanceof DisplayHologramData displayData) { - // interpolation - final var DATA_INTERPOLATION_DURATION_ID = ReflectionUtils.getStaticValue(Display.class, MappingKeys1_20_2.DATA_INTERPOLATION_DURATION_ID.getMapping()); - display.getEntityData().set((EntityDataAccessor) DATA_INTERPOLATION_DURATION_ID, displayData.getInterpolationDuration()); - - final var DATA_INTERPOLATION_START_DELTA_TICKS_ID = ReflectionUtils.getStaticValue(Display.class, MappingKeys1_20_2.DATA_INTERPOLATION_START_DELTA_TICKS_ID.getMapping()); - display.getEntityData().set((EntityDataAccessor) DATA_INTERPOLATION_START_DELTA_TICKS_ID, 0); - - // billboard data - display.setBillboardConstraints(switch (displayData.getBillboard()) { - case FIXED -> Display.BillboardConstraints.FIXED; - case VERTICAL -> Display.BillboardConstraints.VERTICAL; - case HORIZONTAL -> Display.BillboardConstraints.HORIZONTAL; - case CENTER -> Display.BillboardConstraints.CENTER; - }); - - // brightness - if (displayData.getBrightness() != null) { - display.setBrightnessOverride(new Brightness(displayData.getBrightness().getBlockLight(), displayData.getBrightness().getSkyLight())); - } - - // entity scale AND MORE! - display.setTransformation(new Transformation( - displayData.getTranslation(), - new Quaternionf(), - displayData.getScale(), - new Quaternionf()) - ); - - // entity shadow - display.setShadowRadius(displayData.getShadowRadius()); - display.setShadowStrength(displayData.getShadowStrength()); - - // view range - display.setViewRange(displayData.getVisibilityDistance()); - } - } - - - @Override - public void spawnTo(@NotNull final Player player) { - if (!new HologramSpawnEvent(this, player).callEvent()) { - return; - } - - if (this.display == null) { - create(); // try to create it if it doesn't exist every time - } - - final var display = this.display; - if (display == null) { - return; // could not be created, nothing to show - } - - if (!data.getWorldName().equals(player.getLocation().getWorld().getName())) { - return; - } - - ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle(); - - // TODO: cache player protocol version - // TODO: fix this -// final var protocolVersion = FancyHologramsPlugin.get().isUsingViaVersion() ? Via.getAPI().getPlayerVersion(player) : MINIMUM_PROTOCOL_VERSION; -// if (protocolVersion < MINIMUM_PROTOCOL_VERSION) { -// return false; -// } - - serverPlayer.connection.send(new ClientboundAddEntityPacket(display)); - this.viewers.add(player.getUniqueId()); - updateFor(player); - - } - - @Override - public void despawnFrom(@NotNull final Player player) { - if (!new HologramDespawnEvent(this, player).callEvent()) { - return; - } - - final var display = this.display; - if (display == null) { - return; // doesn't exist, nothing to hide - } - - ((CraftPlayer) player).getHandle().connection.send(new ClientboundRemoveEntitiesPacket(display.getId())); - - this.viewers.remove(player.getUniqueId()); - } - - - @Override - public void updateFor(@NotNull final Player player) { - final var display = this.display; - if (display == null) { - return; // doesn't exist, nothing to refresh - } - - if (!isViewer(player)) { - return; - } - - syncWithData(); - - ((CraftPlayer) player).getHandle().connection.send(new ClientboundTeleportEntityPacket(display)); - - if (display instanceof TextDisplay textDisplay) { - textDisplay.setText(PaperAdventure.asVanilla(getShownText(player))); - } - - final var values = new ArrayList>(); - - //noinspection unchecked - for (final var item : ((Int2ObjectMap>) getValue(display.getEntityData(), "e")).values()) { - values.add(item.value()); - } - - ((CraftPlayer) player).getHandle().connection.send(new ClientboundSetEntityDataPacket(display.getId(), values)); - } - -} diff --git a/plugins/fancyholograms/implementation_1_20_2/src/main/java/de/oliver/fancyholograms/hologram/version/MappingKeys1_20_2.java b/plugins/fancyholograms/implementation_1_20_2/src/main/java/de/oliver/fancyholograms/hologram/version/MappingKeys1_20_2.java deleted file mode 100644 index 59ee90ee..00000000 --- a/plugins/fancyholograms/implementation_1_20_2/src/main/java/de/oliver/fancyholograms/hologram/version/MappingKeys1_20_2.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.oliver.fancyholograms.hologram.version; - -public enum MappingKeys1_20_2 { - - DATA_INTERPOLATION_DURATION_ID("r"), - DATA_INTERPOLATION_START_DELTA_TICKS_ID("q"), - DATA_LINE_WIDTH_ID("aN"), - DATA_BACKGROUND_COLOR_ID("aO"), - ; - - private final String mapping; - - MappingKeys1_20_2(String mapping) { - this.mapping = mapping; - } - - public String getMapping() { - return mapping; - } -} diff --git a/plugins/fancyholograms/implementation_1_20_4/build.gradle.kts b/plugins/fancyholograms/implementation_1_20_4/build.gradle.kts deleted file mode 100644 index 54ccd59d..00000000 --- a/plugins/fancyholograms/implementation_1_20_4/build.gradle.kts +++ /dev/null @@ -1,33 +0,0 @@ -plugins { - id("java-library") - id("io.papermc.paperweight.userdev") -} - - -val minecraftVersion = "1.20.4" - - -dependencies { - paperweight.paperDevBundle("$minecraftVersion-R0.1-SNAPSHOT") - - implementation(project(":plugins:fancyholograms:fh-api")) - implementation(project(":libraries:common")) - compileOnly("com.viaversion:viaversion-api:5.2.1") -} - - -tasks { - named("assemble") { - dependsOn(named("reobfJar")) - } - - javadoc { - options.encoding = Charsets.UTF_8.name() - } - - compileJava { - options.encoding = Charsets.UTF_8.name() - - options.release.set(17) - } -} \ No newline at end of file diff --git a/plugins/fancyholograms/implementation_1_20_4/src/main/java/de/oliver/fancyholograms/hologram/version/Hologram1_20_4.java b/plugins/fancyholograms/implementation_1_20_4/src/main/java/de/oliver/fancyholograms/hologram/version/Hologram1_20_4.java deleted file mode 100644 index 1912e232..00000000 --- a/plugins/fancyholograms/implementation_1_20_4/src/main/java/de/oliver/fancyholograms/hologram/version/Hologram1_20_4.java +++ /dev/null @@ -1,253 +0,0 @@ -package de.oliver.fancyholograms.hologram.version; - -import com.mojang.math.Transformation; -import de.oliver.fancyholograms.api.data.*; -import de.oliver.fancyholograms.api.events.HologramDespawnEvent; -import de.oliver.fancyholograms.api.events.HologramSpawnEvent; -import de.oliver.fancyholograms.api.hologram.Hologram; -import de.oliver.fancylib.ReflectionUtils; -import io.papermc.paper.adventure.PaperAdventure; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; -import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket; -import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; -import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; -import net.minecraft.network.syncher.EntityDataAccessor; -import net.minecraft.network.syncher.SynchedEntityData.DataItem; -import net.minecraft.network.syncher.SynchedEntityData.DataValue; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.util.Brightness; -import net.minecraft.world.entity.Display; -import net.minecraft.world.entity.Display.TextDisplay; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.Block; -import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.joml.Quaternionf; - -import java.util.ArrayList; - -import static de.oliver.fancylib.ReflectionUtils.getValue; - -public final class Hologram1_20_4 extends Hologram { - - @Nullable - private Display display; - - public Hologram1_20_4(@NotNull final HologramData data) { - super(data); - - create(); - } - - public void create() { - final var location = data.getLocation(); - if (location.getWorld() == null) { - return; // no location data, cannot be created - } - - ServerLevel world = ((CraftWorld) location.getWorld()).getHandle(); - - switch (data.getType()) { - case TEXT -> this.display = new Display.TextDisplay(EntityType.TEXT_DISPLAY, world); - case BLOCK -> this.display = new Display.BlockDisplay(EntityType.BLOCK_DISPLAY, world); - case ITEM -> this.display = new Display.ItemDisplay(EntityType.ITEM_DISPLAY, world); - } - } - - public void syncWithData() { - final var display = this.display; - if (display == null) { - return; // doesn't exist, nothing to update - } - - // location data - final var location = data.getLocation(); - if (!location.isWorldLoaded()) { - return; - } else { - display.setPosRaw(location.x(), location.y(), location.z()); - display.setYRot(location.getYaw()); - display.setXRot(location.getPitch()); - } - - if (display instanceof TextDisplay textDisplay && data instanceof TextHologramData textData) { - // line width - final var DATA_LINE_WIDTH_ID = ReflectionUtils.getStaticValue(TextDisplay.class, MappingKeys1_20_4.TEXT_DISPLAY__DATA_LINE_WIDTH_ID.getMapping()); - display.getEntityData().set((EntityDataAccessor) DATA_LINE_WIDTH_ID, Hologram.LINE_WIDTH); - - // background - final var DATA_BACKGROUND_COLOR_ID = ReflectionUtils.getStaticValue(TextDisplay.class, MappingKeys1_20_4.TEXT_DISPLAY__DATA_BACKGROUND_COLOR_ID.getMapping()); //DATA_BACKGROUND_COLOR_ID - - final var background = textData.getBackground(); - if (background == null) { - display.getEntityData().set((EntityDataAccessor) DATA_BACKGROUND_COLOR_ID, TextDisplay.INITIAL_BACKGROUND); - } else if (background == Hologram.TRANSPARENT) { - display.getEntityData().set((EntityDataAccessor) DATA_BACKGROUND_COLOR_ID, 0); - } else { - display.getEntityData().set((EntityDataAccessor) DATA_BACKGROUND_COLOR_ID, background.asARGB()); - } - - // text shadow - if (textData.hasTextShadow()) { - textDisplay.setFlags((byte) (textDisplay.getFlags() | TextDisplay.FLAG_SHADOW)); - } else { - textDisplay.setFlags((byte) (textDisplay.getFlags() & ~TextDisplay.FLAG_SHADOW)); - } - - // text alignment - if (textData.getTextAlignment() == org.bukkit.entity.TextDisplay.TextAlignment.LEFT) { - textDisplay.setFlags((byte) (textDisplay.getFlags() | TextDisplay.FLAG_ALIGN_LEFT)); - } else { - textDisplay.setFlags((byte) (textDisplay.getFlags() & ~TextDisplay.FLAG_ALIGN_LEFT)); - } - - // see through - if (textData.isSeeThrough()) { - textDisplay.setFlags((byte) (textDisplay.getFlags() | TextDisplay.FLAG_SEE_THROUGH)); - } else { - textDisplay.setFlags((byte) (textDisplay.getFlags() & ~TextDisplay.FLAG_SEE_THROUGH)); - } - - if (textData.getTextAlignment() == org.bukkit.entity.TextDisplay.TextAlignment.RIGHT) { - textDisplay.setFlags((byte) (textDisplay.getFlags() | TextDisplay.FLAG_ALIGN_RIGHT)); - } else { - textDisplay.setFlags((byte) (textDisplay.getFlags() & ~TextDisplay.FLAG_ALIGN_RIGHT)); - } - - } else if (display instanceof Display.ItemDisplay itemDisplay && data instanceof ItemHologramData itemData) { - // item - itemDisplay.setItemStack(ItemStack.fromBukkitCopy(itemData.getItemStack())); - - } else if (display instanceof Display.BlockDisplay blockDisplay && data instanceof BlockHologramData blockData) { - Block block = BuiltInRegistries.BLOCK.get(ResourceLocation.of("minecraft:" + blockData.getBlock().name().toLowerCase(), ':')); - blockDisplay.setBlockState(block.defaultBlockState()); - } - - if (data instanceof DisplayHologramData displayData) { - // interpolation - final var DATA_INTERPOLATION_DURATION_ID = ReflectionUtils.getStaticValue(Display.class, MappingKeys1_20_4.DISPLAY__DATA_TRANSFORMATION_INTERPOLATION_DURATION_ID.getMapping()); - display.getEntityData().set((EntityDataAccessor) DATA_INTERPOLATION_DURATION_ID, displayData.getInterpolationDuration()); - - final var DATA_INTERPOLATION_START_DELTA_TICKS_ID = ReflectionUtils.getStaticValue(Display.class, MappingKeys1_20_4.DISPLAY__DATA_TRANSFORMATION_INTERPOLATION_START_DELTA_TICKS_ID.getMapping()); - display.getEntityData().set((EntityDataAccessor) DATA_INTERPOLATION_START_DELTA_TICKS_ID, 0); - - // billboard data - display.setBillboardConstraints(switch (displayData.getBillboard()) { - case FIXED -> Display.BillboardConstraints.FIXED; - case VERTICAL -> Display.BillboardConstraints.VERTICAL; - case HORIZONTAL -> Display.BillboardConstraints.HORIZONTAL; - case CENTER -> Display.BillboardConstraints.CENTER; - }); - - // brightness - if (displayData.getBrightness() != null) { - display.setBrightnessOverride(new Brightness(displayData.getBrightness().getBlockLight(), displayData.getBrightness().getSkyLight())); - } - - // entity scale AND MORE! - display.setTransformation(new Transformation( - displayData.getTranslation(), - new Quaternionf(), - displayData.getScale(), - new Quaternionf()) - ); - - // entity shadow - display.setShadowRadius(displayData.getShadowRadius()); - display.setShadowStrength(displayData.getShadowStrength()); - - // view range - display.setViewRange(displayData.getVisibilityDistance()); - } - } - - - @Override - public void spawnTo(@NotNull final Player player) { - if (!new HologramSpawnEvent(this, player).callEvent()) { - return; - } - - if (this.display == null) { - create(); // try to create it if it doesn't exist every time - } - - final var display = this.display; - if (display == null) { - return; // could not be created, nothing to show - } - - if (!data.getWorldName().equals(player.getLocation().getWorld().getName())) { - return; - } - - ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle(); - - // TODO: cache player protocol version - // TODO: fix this -// final var protocolVersion = FancyHologramsPlugin.get().isUsingViaVersion() ? Via.getAPI().getPlayerVersion(player) : MINIMUM_PROTOCOL_VERSION; -// if (protocolVersion < MINIMUM_PROTOCOL_VERSION) { -// return false; -// } - - serverPlayer.connection.send(new ClientboundAddEntityPacket(display)); - this.viewers.add(player.getUniqueId()); - updateFor(player); - - } - - @Override - public void despawnFrom(@NotNull final Player player) { - if (!new HologramDespawnEvent(this, player).callEvent()) { - return; - } - - final var display = this.display; - if (display == null) { - return; // doesn't exist, nothing to hide - } - - ((CraftPlayer) player).getHandle().connection.send(new ClientboundRemoveEntitiesPacket(display.getId())); - - this.viewers.remove(player.getUniqueId()); - } - - - @Override - public void updateFor(@NotNull final Player player) { - final var display = this.display; - if (display == null) { - return; // doesn't exist, nothing to refresh - } - - if (!isViewer(player)) { - return; - } - - syncWithData(); - - ((CraftPlayer) player).getHandle().connection.send(new ClientboundTeleportEntityPacket(display)); - - if (display instanceof TextDisplay textDisplay) { - textDisplay.setText(PaperAdventure.asVanilla(getShownText(player))); - } - - final var values = new ArrayList>(); - - //noinspection unchecked - for (final var item : ((Int2ObjectMap>) getValue(display.getEntityData(), "e")).values()) { - values.add(item.value()); - } - - ((CraftPlayer) player).getHandle().connection.send(new ClientboundSetEntityDataPacket(display.getId(), values)); - } - -} diff --git a/plugins/fancyholograms/implementation_1_20_4/src/main/java/de/oliver/fancyholograms/hologram/version/MappingKeys1_20_4.java b/plugins/fancyholograms/implementation_1_20_4/src/main/java/de/oliver/fancyholograms/hologram/version/MappingKeys1_20_4.java deleted file mode 100644 index f9736289..00000000 --- a/plugins/fancyholograms/implementation_1_20_4/src/main/java/de/oliver/fancyholograms/hologram/version/MappingKeys1_20_4.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.oliver.fancyholograms.hologram.version; - -public enum MappingKeys1_20_4 { - - DISPLAY__DATA_TRANSFORMATION_INTERPOLATION_DURATION_ID("r"), - DISPLAY__DATA_TRANSFORMATION_INTERPOLATION_START_DELTA_TICKS_ID("q"), - TEXT_DISPLAY__DATA_LINE_WIDTH_ID("aN"), - TEXT_DISPLAY__DATA_BACKGROUND_COLOR_ID("aO"), - ; - - private final String mapping; - - MappingKeys1_20_4(String mapping) { - this.mapping = mapping; - } - - public String getMapping() { - return mapping; - } -} diff --git a/plugins/fancyholograms/src/main/java/de/oliver/fancyholograms/main/FancyHologramsPlugin.java b/plugins/fancyholograms/src/main/java/de/oliver/fancyholograms/main/FancyHologramsPlugin.java index fdddf8c8..3c6866c7 100644 --- a/plugins/fancyholograms/src/main/java/de/oliver/fancyholograms/main/FancyHologramsPlugin.java +++ b/plugins/fancyholograms/src/main/java/de/oliver/fancyholograms/main/FancyHologramsPlugin.java @@ -163,18 +163,16 @@ public final class FancyHologramsPlugin extends JavaPlugin implements FancyHolog """); } - hologramFactory = resolveHologramFactory(); - if (hologramFactory == null) { - List supportedVersions = new ArrayList<>(List.of("1.19.4", "1.20", "1.20.1", "1.20.2", "1.20.3", "1.20.4")); - supportedVersions.addAll(ServerVersion.getSupportedVersions()); - + if (ServerVersion.isVersionSupported(Bukkit.getMinecraftVersion())) { + hologramFactory = HologramImpl::new; + } else { fancyLogger.warn(""" -------------------------------------------------- Unsupported minecraft server version. Please update the server to one of (%s). Disabling the FancyHolograms plugin. -------------------------------------------------- - """.formatted(String.join(" / ", supportedVersions))); + """.formatted(String.join(" / ", ServerVersion.getSupportedVersions()))); Bukkit.getPluginManager().disablePlugin(this); return; } @@ -248,17 +246,6 @@ public final class FancyHologramsPlugin extends JavaPlugin implements FancyHolog INSTANCE = null; } - private @Nullable Function resolveHologramFactory() { - final var version = Bukkit.getMinecraftVersion(); - - // check if the server version is supported by FancySitula - if (ServerVersion.isVersionSupported(version)) { - return HologramImpl::new; - } - - return null; - } - private void registerCommands() { Collection commands = Arrays.asList(new HologramCMD(this), new FancyHologramsCMD(this)); diff --git a/settings.gradle.kts b/settings.gradle.kts index 68ea3983..0e51e680 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -23,10 +23,6 @@ include(":plugins:fancyholograms-v2:implementation_1_19_4") include(":plugins:fancyholograms") include(":plugins:fancyholograms:fh-api") -include(":plugins:fancyholograms:implementation_1_20_4") -include(":plugins:fancyholograms:implementation_1_20_2") -include(":plugins:fancyholograms:implementation_1_20_1") -include(":plugins:fancyholograms:implementation_1_19_4") include(":plugins:fancyvisuals")