From fca9a947f5219b686593bb2016dc3773f1a7ca8c Mon Sep 17 00:00:00 2001 From: Tofpu Date: Wed, 14 Aug 2024 13:50:23 +0300 Subject: [PATCH] Add PAPI support for all messages --- .../model/common/util/BridgeUtil.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/spigot/src/main/java/io/tofpu/speedbridge2/model/common/util/BridgeUtil.java b/spigot/src/main/java/io/tofpu/speedbridge2/model/common/util/BridgeUtil.java index 91e3035e..1bdef7e1 100644 --- a/spigot/src/main/java/io/tofpu/speedbridge2/model/common/util/BridgeUtil.java +++ b/spigot/src/main/java/io/tofpu/speedbridge2/model/common/util/BridgeUtil.java @@ -6,9 +6,11 @@ import io.tofpu.speedbridge2.model.common.database.wrapper.DatabaseQuery; import io.tofpu.speedbridge2.model.common.database.wrapper.DatabaseSet; import io.tofpu.speedbridge2.model.leaderboard.object.BoardPlayer; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; import io.tofpu.speedbridge2.model.player.object.CommonBridgePlayer; import io.tofpu.speedbridge2.model.player.object.score.Score; import io.tofpu.speedbridge2.plugin.SpeedBridgePlugin; +import me.clip.placeholderapi.PlaceholderAPI; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.platform.bukkit.BukkitComponentSerializer; import net.kyori.adventure.text.Component; @@ -16,6 +18,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import java.util.UUID; @@ -119,11 +122,15 @@ public static Component sendMessage(final CommonBridgePlayer sender, * @param content The content of the message. * @return Nothing. */ - public static Component sendMessage(final CommandSender sender, - final String content) { + public static Component sendMessage(final CommandSender sender, String content) { if (content.isEmpty()) { return null; } + + if (sender instanceof Player) { + content = replaceWithPAPI((Player) sender, content); + } + final Component component = translateMiniMessage(content); sendMessage(sender, component); return component; @@ -154,6 +161,16 @@ public static String translate(final String replace) { return ChatColor.translateAlternateColorCodes('&', replace); } + public static String replaceWithPAPI(Player player, String text) { + if (player == null) { + return text; + } + if (!Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) { + return text; + } + return PlaceholderAPI.setBracketPlaceholders(player.getPlayer(), text); + } + /** * Given a row or column, and a database set, return a BoardPlayer *