Skip to content

Commit

Permalink
Add PAPI support for all messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofpu committed Aug 15, 2024
1 parent c3b84d8 commit fca9a94
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
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;
import net.kyori.adventure.text.minimessage.MiniMessage;
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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit fca9a94

Please sign in to comment.