ZNPCsPlus/plugin/src/main/java/lol/pyr/znpcsplus/util/PapiUtil.java

29 lines
1002 B
Java
Raw Normal View History

package lol.pyr.znpcsplus.util;
import me.clip.placeholderapi.PlaceholderAPI;
2023-06-26 15:41:02 +00:00
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class PapiUtil {
private static boolean isSupported() {
return Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI");
}
public static String set(String str) {
return set(null, str);
}
public static String set(Player player, String str) {
return isSupported() ? PlaceholderAPI.setPlaceholders(player, str) : str;
}
2023-06-26 15:41:02 +00:00
// Ugly workaround would be cool if a better solution existed
public static Component set(Player player, Component component) {
2023-06-26 15:55:16 +00:00
if (!isSupported()) return component;
2023-06-26 15:41:02 +00:00
LegacyComponentSerializer serializer = LegacyComponentSerializer.legacySection();
return serializer.deserialize(set(player, serializer.serialize(component)));
}
}