From 2cd107c31744f37f21b1e4f71b493568e3864de1 Mon Sep 17 00:00:00 2001 From: Video Date: Sun, 26 Mar 2023 17:13:05 -0600 Subject: [PATCH] Even more commands use Adventure now. Includes a bugfix for /creative. --- .../command/Command_admininfo.java | 6 ++- .../command/Command_blockcmd.java | 2 +- .../command/Command_coins.java | 52 ++++++++++++------- .../command/Command_creative.java | 24 ++++----- .../command/Command_explode.java | 5 +- .../command/Command_findip.java | 7 ++- .../command/Command_freeze.java | 6 +-- .../command/Command_fuckoff.java | 3 +- .../totalfreedommod/command/Command_gcmd.java | 13 +++-- .../command/Command_spectator.java | 9 ++-- .../totalfreedommod/command/Command_vote.java | 8 +-- .../command/Command_whohas.java | 31 +++++------ .../command/FreedomCommand.java | 15 +++++- .../totalfreedommod/util/FUtil.java | 6 +++ 14 files changed, 110 insertions(+), 77 deletions(-) diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_admininfo.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_admininfo.java index e114d975..5aae271a 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_admininfo.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_admininfo.java @@ -4,6 +4,8 @@ import java.util.List; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -22,11 +24,11 @@ public class Command_admininfo extends FreedomCommand if (adminInfo.isEmpty()) { - msg("The admin information section of the config.yml file has not been configured.", ChatColor.RED); + msg(Component.text("The admin information section of the config.yml file has not been configured.", NamedTextColor.RED)); } else { - msg(FUtil.colorize(StringUtils.join(adminInfo, "\n"))); + msg(FUtil.colorizeAsComponent(StringUtils.join(adminInfo, "\n"))); } return true; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockcmd.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockcmd.java index 50a57d87..bd1fec04 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockcmd.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockcmd.java @@ -64,7 +64,7 @@ public class Command_blockcmd extends FreedomCommand if (player == null) { - msg(FreedomCommand.PLAYER_NOT_FOUND); + msg(PLAYER_NOT_FOUND); return true; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_coins.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_coins.java index 00d27e45..c1372ba4 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_coins.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_coins.java @@ -4,6 +4,8 @@ import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -21,11 +23,11 @@ public class Command_coins extends FreedomCommand { if (plugin.sh == null || !ConfigEntry.SHOP_ENABLED.getBoolean()) { - msg("The shop is currently disabled!", ChatColor.RED); + msg(Component.text("The shop is currently disabled!", NamedTextColor.RED)); return true; } - final String prefix = FUtil.colorize(ConfigEntry.SHOP_PREFIX.getString() + " "); + final Component prefix = FUtil.colorizeAsComponent(ConfigEntry.SHOP_PREFIX.getString() + " "); switch (args.length) { @@ -35,11 +37,13 @@ public class Command_coins extends FreedomCommand if (senderIsConsole) { msg("When used from the console, you must define a target player."); - } else + } + else { PlayerData playerData = getData(playerSender); - msg(prefix + ChatColor.GREEN + "You have " + ChatColor.RED + playerData.getCoins() + ChatColor.GREEN - + " coins."); + msg(prefix.append(Component.text("You have ", NamedTextColor.GREEN) + .append(Component.text(playerData.getCoins(), NamedTextColor.GOLD)) + .append(Component.text(" coins.", NamedTextColor.GREEN)))); } return true; } @@ -53,10 +57,14 @@ public class Command_coins extends FreedomCommand if (target == null) { msg(PLAYER_NOT_FOUND); - } else + } + else { PlayerData playerData = getData(target); - msg(prefix + ChatColor.GREEN + target.getName() + " has " + ChatColor.RED + playerData.getCoins() + ChatColor.GREEN + " coins."); + msg(prefix.append(Component.text(target.getName(), NamedTextColor.GOLD) + .append(Component.text(" has ", NamedTextColor.GREEN)) + .append(Component.text(playerData.getCoins(), NamedTextColor.GOLD)) + .append(Component.text(" coins.", NamedTextColor.GREEN)))); } return true; } @@ -79,37 +87,43 @@ public class Command_coins extends FreedomCommand { // Prevents players from trying to be cheeky with negative numbers. coinsToTransfer = Math.max(Math.abs(Integer.parseInt(args[2])), 1); - } catch (NumberFormatException ex) + } + catch (NumberFormatException ex) { - msg("Invalid number: " + args[2], ChatColor.RED); + msg(Component.text("Invalid number: " + args[2], NamedTextColor.RED)); return true; } // Prevents players from performing transactions they can't afford to do. if (senderData.getCoins() < coinsToTransfer) { - msg("You don't have enough coins to perform this transaction.", ChatColor.RED); + msg(Component.text("You don't have enough coins to perform this transaction.", NamedTextColor.RED)); return true; } if (target == null) { msg(PLAYER_NOT_FOUND); - } else + } + else { PlayerData playerData = getData(target); playerData.setCoins(playerData.getCoins() + coinsToTransfer); senderData.setCoins(senderData.getCoins() - coinsToTransfer); - msg(target, sender.getName() - + ChatColor.GREEN + " has given you " - + ChatColor.GOLD + coinsToTransfer - + ChatColor.GREEN + " coin" + (coinsToTransfer > 1 ? "s" : "") + "!", ChatColor.GOLD); + boolean plural = coinsToTransfer > 1; - msg("You have given " - + ChatColor.GOLD + coinsToTransfer - + ChatColor.GREEN + " coin" + (coinsToTransfer > 1 ? "s" : "") - + " to " + ChatColor.GOLD + target.getName() + ChatColor.GREEN + ".", ChatColor.GREEN); + msg(target, Component.text(sender.getName(), NamedTextColor.GOLD) + .append(Component.text(" has given you ", NamedTextColor.GREEN)) + .append(Component.text(coinsToTransfer, NamedTextColor.GOLD)) + .append(Component.text(" coin" + (plural ? "s" : "") + "!", NamedTextColor.GREEN))); + + msg(target, Component.text("You have given ", NamedTextColor.GREEN) + .append(Component.text(coinsToTransfer, NamedTextColor.GOLD)) + .append(Component.text(" coin" + (plural ? "s" : ""), NamedTextColor.GOLD)) + .append(Component.text(" to ", NamedTextColor.GREEN)) + .append(Component.text(target.getName(), NamedTextColor.GOLD)) + .append(Component.text(".", NamedTextColor.GREEN))); plugin.pl.save(playerData); plugin.pl.save(senderData); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_creative.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_creative.java index cc7d8d46..99464a24 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_creative.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_creative.java @@ -2,6 +2,7 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; +import net.kyori.adventure.text.Component; import org.bukkit.GameMode; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -11,7 +12,6 @@ import org.bukkit.entity.Player; @CommandParameters(description = "Quickly change your own gamemode to creative, define someone's username to change theirs, or change everyone's gamemode on the server.", usage = "/ <-a | [partialname]>", aliases = "gmc") public class Command_creative extends FreedomCommand { - @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { @@ -19,12 +19,12 @@ public class Command_creative extends FreedomCommand { if (isConsole()) { - msg("When used from the console, you must define a target player."); + msg(Component.text("When used from the console, you must define a target player.")); return true; } playerSender.setGameMode(GameMode.CREATIVE); - msg("Your gamemode has been set to creative."); + msg(Component.text("Your gamemode has been set to creative.")); return true; } @@ -32,13 +32,14 @@ public class Command_creative extends FreedomCommand if (args[0].equals("-a")) { - for (Player targetPlayer : server.getOnlinePlayers()) - { - targetPlayer.setGameMode(GameMode.CREATIVE); - } - FUtil.adminAction(sender.getName(), "Changing everyone's gamemode to creative", false); - msg("Your gamemode has been set to creative."); + + server.getOnlinePlayers().forEach(player -> + { + player.setGameMode(GameMode.CREATIVE); + msg(player, Component.text("Your gamemode has been set to creative.")); + }); + return true; } @@ -50,10 +51,9 @@ public class Command_creative extends FreedomCommand return true; } - msg("Setting " + player.getName() + " to game mode creative"); - msg(player, sender.getName() + " set your game mode to creative"); + msg(Component.text("Setting " + player.getName() + " to gamemode creative")); + msg(player, Component.text(sender.getName() + " set your gamemode to creative.")); player.setGameMode(GameMode.CREATIVE); - return true; } } \ No newline at end of file diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_explode.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_explode.java index 4e6f5200..c58a3ab4 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_explode.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_explode.java @@ -4,6 +4,7 @@ import java.util.Collections; import java.util.List; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; +import net.kyori.adventure.text.Component; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -27,7 +28,7 @@ public class Command_explode extends FreedomCommand if (player == null) { - msg(FreedomCommand.PLAYER_NOT_FOUND); + msg(PLAYER_NOT_FOUND); return true; } @@ -50,7 +51,7 @@ public class Command_explode extends FreedomCommand player.getWorld().createExplosion(player.getLocation(), 4L); } player.setHealth(0.0); - msg("Exploded " + player.getName()); + msg(Component.text("Exploded " + player.getName())); } }.runTaskLater(plugin, 40); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_findip.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_findip.java index 88658116..0b270463 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_findip.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_findip.java @@ -1,6 +1,7 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.rank.Rank; +import net.kyori.adventure.text.Component; import org.apache.commons.lang.StringUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -23,13 +24,11 @@ public class Command_findip extends FreedomCommand if (player == null) { - - msg(FreedomCommand.PLAYER_NOT_FOUND); + msg(PLAYER_NOT_FOUND); return true; } - msg("Player IPs: " + StringUtils.join(plugin.pl.getData(player).getIps(), ", ")); - + msg(Component.text(player.getName() + "'s IPs: " + StringUtils.join(plugin.pl.getData(player).getIps(), ", "))); return true; } } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_freeze.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_freeze.java index 8f4b83f7..ea9b252a 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_freeze.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_freeze.java @@ -68,15 +68,15 @@ public class Command_freeze extends FreedomCommand if (player == null) { - msg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED); + msg(PLAYER_NOT_FOUND); return true; } final FreezeData fd = plugin.pl.getPlayer(player).getFreezeData(); fd.setFrozen(!fd.isFrozen()); - msg(player.getName() + " has been " + (fd.isFrozen() ? "frozen" : "unfrozen") + "."); - msg(player, "You have been " + (fd.isFrozen() ? "frozen" : "unfrozen") + ".", ChatColor.AQUA); + msg(Component.text(player.getName() + " has been " + (fd.isFrozen() ? "frozen" : "unfrozen") + ".")); + msg(player, Component.text("You have been " + (fd.isFrozen() ? "frozen" : "unfrozen") + ".")); return true; } } \ No newline at end of file diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_fuckoff.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_fuckoff.java index 5b3f1204..2091d853 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_fuckoff.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_fuckoff.java @@ -2,6 +2,7 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.rank.Rank; +import net.kyori.adventure.text.Component; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -43,7 +44,7 @@ public class Command_fuckoff extends FreedomCommand player.setFuckoff(radius); } - msg("Fuckoff " + (player.isFuckOff() ? ("enabled. Radius: " + player.getFuckoffRadius() + ".") : "disabled.")); + msg(Component.text("Fuckoff ").append(Component.text(player.isFuckOff() ? "enabled. Radius: " + player.getFuckoffRadius() : "disabled."))); return true; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gcmd.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gcmd.java index 8c1a32a8..0b241801 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gcmd.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gcmd.java @@ -1,6 +1,8 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.rank.Rank; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.apache.commons.lang3.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -36,25 +38,26 @@ public class Command_gcmd extends FreedomCommand if (plugin.al.isAdmin(player)) { - msg(ChatColor.RED + "You can not use gcmd on admins"); + msg(Component.text("You can't use this command on other admins!", NamedTextColor.RED)); return true; } try { - msg("Sending command as " + player.getName() + ": " + outCommand); + msg(Component.text("Sending command as " + player.getName() + ": " + outCommand)); + if (server.dispatchCommand(player, outCommand)) { - msg("Command sent."); + msg(Component.text("Command sent.", NamedTextColor.GREEN)); } else { - msg("Unknown error sending command."); + msg(Component.text("Unknown error sending command.", NamedTextColor.RED)); } } catch (Throwable ex) { - msg("Error sending command: " + ex.getMessage()); + msg(Component.text("Error sending command: " + ex.getMessage(), NamedTextColor.RED)); } return true; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spectator.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spectator.java index 7a64f456..bb0790e2 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spectator.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spectator.java @@ -1,6 +1,7 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.rank.Rank; +import net.kyori.adventure.text.Component; import org.bukkit.GameMode; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -18,12 +19,12 @@ public class Command_spectator extends FreedomCommand { if (isConsole()) { - msg("When used from the console, you must define a target player."); + msg(Component.text("When used from the console, you must define a target player.")); return true; } playerSender.setGameMode(GameMode.SPECTATOR); - msg("Your gamemode has been set to spectator."); + msg(Component.text("Your gamemode has been set to spectator.")); return true; } @@ -35,8 +36,8 @@ public class Command_spectator extends FreedomCommand return true; } - msg("Setting " + player.getName() + " to game mode spectator"); - msg(player, sender.getName() + " set your game mode to spectator"); + msg(Component.text("Setting " + player.getName() + " to gamemode spectator")); + msg(player, Component.text(sender.getName() + " set your gamemode to spectator.")); player.setGameMode(GameMode.SPECTATOR); return true; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vote.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vote.java index 6b838671..239c811a 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vote.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vote.java @@ -4,8 +4,9 @@ import java.util.List; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.apache.commons.lang.StringUtils; -import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -14,7 +15,6 @@ import org.bukkit.entity.Player; @CommandParameters(description = "Information on how to vote", usage = "/") public class Command_vote extends FreedomCommand { - @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { @@ -22,11 +22,11 @@ public class Command_vote extends FreedomCommand if (voteInfo.isEmpty()) { - msg("The voting information section of the config.yml file has not been configured.", ChatColor.RED); + msg(Component.text("The voting information section of the config.yml file has not been configured.", NamedTextColor.RED)); } else { - msg(FUtil.colorize(StringUtils.join(voteInfo, "\n"))); + msg(FUtil.colorizeAsComponent(StringUtils.join(voteInfo, "\n"))); } return true; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_whohas.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_whohas.java index 22dc8f89..63beb305 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_whohas.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_whohas.java @@ -1,15 +1,16 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import me.totalfreedom.totalfreedommod.rank.Rank; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.apache.commons.lang.StringUtils; -import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; +import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; @CommandPermissions(rank = Rank.OP, source = SourceType.BOTH) @@ -31,35 +32,27 @@ public class Command_whohas extends FreedomCommand if (material == null) { - msg("Invalid item: " + materialName, ChatColor.RED); + msg(Component.text("Invalid item: " + materialName, NamedTextColor.RED)); return true; } - final List players = new ArrayList<>(); + List players = server.getOnlinePlayers().stream().filter(player -> player.getInventory().contains(material) && + (!plugin.al.isVanished(player.getUniqueId()) || plugin.al.isAdmin(sender))).toList(); - for (final Player player : server.getOnlinePlayers()) + if (plugin.al.isAdmin(sender) && doClear) { - if (!plugin.al.isAdmin(sender) && plugin.al.isVanished(player.getUniqueId())) - { - continue; - } - if (player.getInventory().contains(material)) - { - players.add(player.getName()); - if (plugin.al.isAdmin(sender) && doClear && !plugin.al.isAdmin(player)) - { - player.getInventory().remove(material); - } - } + players.stream().filter(player -> !plugin.al.isAdmin(player)).forEach(player -> + player.getInventory().remove(material)); } if (players.isEmpty()) { - msg("There are no players with that item"); + msg(Component.text("There are no players with that item.")); } else { - msg("Players with item " + material.name() + ": " + StringUtils.join(players, ", ")); + msg(Component.text("Players with item " + material.name() + ": " + + StringUtils.join(players.stream().map(HumanEntity::getName).toList(), ", "))); } return true; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java index dc2ecfec..eeaa2820 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java @@ -7,6 +7,8 @@ import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -27,7 +29,7 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter public static final String COMMAND_PREFIX = "Command_"; public static final String YOU_ARE_OP = ChatColor.YELLOW + "You are now op!"; public static final String YOU_ARE_NOT_OP = ChatColor.YELLOW + "You are no longer op!"; - public static final String PLAYER_NOT_FOUND = ChatColor.GRAY + "Player not found!"; + public static final Component PLAYER_NOT_FOUND = Component.text("Player not found!", NamedTextColor.GRAY); public static final String ONLY_CONSOLE = ChatColor.RED + "Only console senders may execute this command!"; public static final String ONLY_IN_GAME = ChatColor.RED + "Only in-game players may execute this command!"; public static final String NO_PERMISSION = ChatColor.RED + "You do not have permission to execute this command."; @@ -109,6 +111,17 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter cmd.setExecutor(this); } + protected void msg(CommandSender sender, Component message) + { + sender.sendMessage(message.colorIfAbsent(NamedTextColor.GRAY)); + } + + protected void msg(Component message) + { + msg(sender, message); + } + + protected void msg(CommandSender sender, String message) { sender.sendMessage(ChatColor.GRAY + message); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java index c9f9e3e6..136e0893 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java @@ -3,6 +3,7 @@ package me.totalfreedom.totalfreedommod.util; import com.earth2me.essentials.utils.DateUtil; import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.WordUtils; @@ -454,6 +455,11 @@ public class FUtil return string; } + public static Component colorizeAsComponent(String string) + { + return LEGACY_AMPERSAND.deserialize(string); + } + public static String stripColors(String string) { return string.replaceAll("ยง", "");