2023-05-16 13:46:11 +00:00
|
|
|
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;
|
2023-05-16 13:46:11 +00:00
|
|
|
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) {
|
|
|
|
if (isSupported()) return component;
|
|
|
|
LegacyComponentSerializer serializer = LegacyComponentSerializer.legacySection();
|
|
|
|
return serializer.deserialize(set(player, serializer.serialize(component)));
|
|
|
|
}
|
2023-05-16 13:46:11 +00:00
|
|
|
}
|