From d22a8152e021ed32a0eebb8d9e48bea0828be4c2 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Mon, 26 Jun 2023 17:41:02 +0200 Subject: [PATCH] add papi support to holograms --- .../lol/pyr/znpcsplus/packets/V1_8PacketFactory.java | 3 ++- .../src/main/java/lol/pyr/znpcsplus/util/PapiUtil.java | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java index e50f950..4aaa6eb 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java @@ -17,6 +17,7 @@ import lol.pyr.znpcsplus.metadata.MetadataFactory; import lol.pyr.znpcsplus.scheduling.TaskScheduler; import lol.pyr.znpcsplus.skin.BaseSkinDescriptor; import lol.pyr.znpcsplus.util.NpcLocation; +import lol.pyr.znpcsplus.util.PapiUtil; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Color; @@ -144,7 +145,7 @@ public class V1_8PacketFactory implements PacketFactory { add(data, metadataFactory.usingItem(properties.getProperty(propertyRegistry.getByName("using_item", Boolean.class)), false, false)); add(data, metadataFactory.potionColor(properties.getProperty(propertyRegistry.getByName("potion_color", Color.class)).asRGB())); add(data, metadataFactory.potionAmbient(properties.getProperty(propertyRegistry.getByName("potion_ambient", Boolean.class)))); - if (properties.hasProperty(propertyRegistry.getByName("name"))) addAll(data, metadataFactory.name(properties.getProperty(propertyRegistry.getByName("name", Component.class)))); + if (properties.hasProperty(propertyRegistry.getByName("name"))) addAll(data, metadataFactory.name(PapiUtil.set(player, properties.getProperty(propertyRegistry.getByName("name", Component.class))))); return data; } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/util/PapiUtil.java b/plugin/src/main/java/lol/pyr/znpcsplus/util/PapiUtil.java index 7deec76..a979939 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/util/PapiUtil.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/util/PapiUtil.java @@ -1,6 +1,8 @@ package lol.pyr.znpcsplus.util; import me.clip.placeholderapi.PlaceholderAPI; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -16,4 +18,11 @@ public class PapiUtil { public static String set(Player player, String str) { return isSupported() ? PlaceholderAPI.setPlaceholders(player, str) : str; } + + // Ugly workaround would be cool if a better solution existed + public static Component set(Player player, Component component) { + if (isSupported()) return component; + LegacyComponentSerializer serializer = LegacyComponentSerializer.legacySection(); + return serializer.deserialize(set(player, serializer.serialize(component))); + } }