Read the commit details for more information

- Removes several old unused commands
- Begins implementing MiniMessage into several commands
This commit is contained in:
Video 2023-03-26 19:49:31 -06:00
parent 2cd107c317
commit 733f668145
22 changed files with 160 additions and 374 deletions

View File

@ -3,11 +3,6 @@ package me.totalfreedom.totalfreedommod.command;
import java.util.List; import java.util.List;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.rank.Rank; 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.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -24,12 +19,13 @@ public class Command_admininfo extends FreedomCommand
if (adminInfo.isEmpty()) if (adminInfo.isEmpty())
{ {
msg(Component.text("The admin information section of the config.yml file has not been configured.", NamedTextColor.RED)); msgNew("<red>The admin information section of the config.yml file has not been configured.");
} }
else else
{ {
msg(FUtil.colorizeAsComponent(StringUtils.join(adminInfo, "\n"))); adminInfo.forEach(this::msgNew);
} }
return true; return true;
} }
} }

View File

@ -4,6 +4,7 @@ import me.totalfreedom.totalfreedommod.banning.Ban;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -32,13 +33,13 @@ public class Command_banip extends FreedomCommand
if (FUtil.isValidIPv4(ip)) if (FUtil.isValidIPv4(ip))
{ {
msg(ip + " is not a valid IP address", ChatColor.RED); msgNew("<red><ip> is not a valid IP address.", Placeholder.unparsed("ip", ip));
return true; return true;
} }
if (plugin.bm.getByIp(ip) != null) if (plugin.bm.getByIp(ip) != null)
{ {
msg("The IP " + ip + " is already banned", ChatColor.RED); msgNew("<red>The IP <ip> is already banned.", Placeholder.unparsed("ip", ip));
return true; return true;
} }
@ -71,12 +72,12 @@ public class Command_banip extends FreedomCommand
if (!silent) if (!silent)
{ {
// Broadcast // Broadcast
FLog.info(ChatColor.RED + sender.getName() + " - Banned the IP " + ip);
String message = sender.getName() + " - Banned " + (plugin.al.isAdmin(player) ? "the IP " + ip : "an IP"); String message = sender.getName() + " - Banned " + (plugin.al.isAdmin(player) ? "the IP " + ip : "an IP");
msg(player, message, ChatColor.RED); msg(player, message, ChatColor.RED);
} }
} }
FLog.info(ChatColor.RED + sender.getName() + " - Banned the IP " + ip);
return true; return true;
} }
} }

View File

@ -2,15 +2,18 @@ package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Collections;
import java.util.List;
@CommandPermissions(rank = Rank.OP, source = SourceType.BOTH) @CommandPermissions(rank = Rank.OP, source = SourceType.BOTH)
@CommandParameters(description = "Shows all banned player names. Admins may optionally use 'purge' to clear the list.", usage = "/<command> [purge]") @CommandParameters(description = "Shows all banned player names. Admins may optionally use 'purge' to clear the list.", usage = "/<command> [purge]")
public class Command_banlist extends FreedomCommand public class Command_banlist extends FreedomCommand
{ {
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
@ -19,18 +22,23 @@ public class Command_banlist extends FreedomCommand
if (args[0].equalsIgnoreCase("purge")) if (args[0].equalsIgnoreCase("purge"))
{ {
checkRank(Rank.SENIOR_ADMIN); checkRank(Rank.SENIOR_ADMIN);
FUtil.adminAction(sender.getName(), "Purging the ban list", true); FUtil.adminAction(sender.getName(), "Purging the ban list", true);
int amount = plugin.bm.purge(); msgNew("<green>Purged <amount> player bans.", Placeholder.unparsed("amount", String.valueOf(plugin.bm.purge())));
msg("Purged " + amount + " player bans.");
return true; return true;
} }
return false; return false;
} }
msg(plugin.bm.getAllBans().size() + " player bans (" msgNew("<total> player bans (<usernames> usernames, <ips> IPs)",
+ plugin.bm.getUsernameBans().size() + " usernames, " Placeholder.unparsed("total", String.valueOf(plugin.bm.getAllBans().size())),
+ plugin.bm.getIpBans().size() + " IPs)"); Placeholder.unparsed("usernames", String.valueOf(plugin.bm.getUsernameBans())),
Placeholder.unparsed("ips", String.valueOf(plugin.bm.getIpBans().size())));
return true; return true;
} }
@Override
protected List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
{
return args.length == 1 && plugin.al.isSeniorAdmin(sender) ? Collections.singletonList("purge") : Collections.emptyList();
}
} }

View File

@ -2,7 +2,6 @@ package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -14,35 +13,16 @@ import org.bukkit.inventory.meta.ItemMeta;
@CommandParameters(description = "For the people that are still alive - gives a cake to everyone on the server.", usage = "/<command>") @CommandParameters(description = "For the people that are still alive - gives a cake to everyone on the server.", usage = "/<command>")
public class Command_cake extends FreedomCommand public class Command_cake extends FreedomCommand
{ {
public static final String CAKE_LYRICS = "But there's no sense crying over every mistake. You just keep on trying till you run out of cake.";
@Override @Override
public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole) public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole)
{ {
final StringBuilder output = new StringBuilder();
for (final String word : CAKE_LYRICS.split(" "))
{
output.append(FUtil.randomChatColor()).append(word).append(" ");
}
final ItemStack heldItem = new ItemStack(Material.CAKE); final ItemStack heldItem = new ItemStack(Material.CAKE);
final ItemMeta heldItemMeta = heldItem.getItemMeta(); final ItemMeta heldItemMeta = heldItem.getItemMeta();
assert heldItemMeta != null; assert heldItemMeta != null;
heldItemMeta.setDisplayName(ChatColor.WHITE + "The " + ChatColor.DARK_GRAY + "Lie"); heldItemMeta.displayName(FUtil.miniMessage("<white>The <dark_gray>Lie"));
heldItem.setItemMeta(heldItemMeta); heldItem.setItemMeta(heldItemMeta);
server.getOnlinePlayers().forEach(player -> player.getInventory().addItem(heldItem));
for (Player player : server.getOnlinePlayers()) server.broadcast(FUtil.miniMessage("<rainbow>But there's no sense crying over every mistake. You just keep on trying till you run out of cake."));
{
final int firstEmpty = player.getInventory().firstEmpty();
if (firstEmpty >= 0)
{
player.getInventory().setItem(firstEmpty, heldItem);
}
}
FUtil.bcastMsg(output.toString());
return true; return true;
} }
} }

View File

@ -1,77 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import java.util.Objects;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Player;
@CommandPermissions(rank = Rank.NON_OP, source = SourceType.BOTH)
@CommandParameters(description = "Sit in nearest minecart. If target is in a minecart already, they will disembark.", usage = "/<command> [partialname]")
public class Command_cartsit extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
Player targetPlayer = playerSender;
if (args.length == 1 && plugin.al.isAdmin(sender))
{
targetPlayer = getPlayer(args[0]);
if (targetPlayer == null)
{
msg(PLAYER_NOT_FOUND);
return true;
}
}
if (senderIsConsole)
{
if (targetPlayer == null)
{
msg("When used from the console, you must define a target player: /cartsit <player>");
return true;
}
}
if (targetPlayer.isInsideVehicle())
{
Objects.requireNonNull(targetPlayer.getVehicle()).eject();
}
else
{
Minecart nearest_cart = null;
for (Minecart cart : targetPlayer.getWorld().getEntitiesByClass(Minecart.class))
{
if (cart.isEmpty())
{
if (nearest_cart == null)
{
nearest_cart = cart;
}
else
{
if (cart.getLocation().distanceSquared(targetPlayer.getLocation()) < nearest_cart.getLocation().distanceSquared(targetPlayer.getLocation()))
{
nearest_cart = cart;
}
}
}
}
if (nearest_cart != null)
{
nearest_cart.addPassenger(targetPlayer);
}
else
{
msg("There are no empty minecarts in the target world.");
}
}
return true;
}
}

View File

@ -13,13 +13,14 @@ public class Command_cleardiscordqueue extends FreedomCommand
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
if (plugin.dc == null) { if (plugin.dc == null)
msg("Discord is not enabled."); {
msgNew("<red>Discord is not enabled.");
return true; return true;
} }
plugin.dc.clearQueue(); plugin.dc.clearQueue();
msg("Cleared the discord message queue."); msg("<green>Cleared the Discord message queue.");
return true; return true;
} }
} }

View File

@ -2,6 +2,7 @@ package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -16,7 +17,7 @@ public class Command_cmdspy extends FreedomCommand
{ {
Admin admin = plugin.al.getAdmin(playerSender); Admin admin = plugin.al.getAdmin(playerSender);
admin.setCommandSpy(!admin.getCommandSpy()); admin.setCommandSpy(!admin.getCommandSpy());
msg("CommandSpy " + (admin.getCommandSpy() ? "enabled." : "disabled.")); msgNew("CommandSpy <status>.", Placeholder.unparsed("status", admin.getCommandSpy() ? "enabled." : "disabled."));
plugin.al.save(admin); plugin.al.save(admin);
plugin.al.updateTables(); plugin.al.updateTables();
return true; return true;

View File

@ -6,6 +6,7 @@ import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -23,12 +24,10 @@ public class Command_coins extends FreedomCommand
{ {
if (plugin.sh == null || !ConfigEntry.SHOP_ENABLED.getBoolean()) if (plugin.sh == null || !ConfigEntry.SHOP_ENABLED.getBoolean())
{ {
msg(Component.text("The shop is currently disabled!", NamedTextColor.RED)); msgNew("<red>The shop is currently disabled!");
return true; return true;
} }
final Component prefix = FUtil.colorizeAsComponent(ConfigEntry.SHOP_PREFIX.getString() + " ");
switch (args.length) switch (args.length)
{ {
// Mode for seeing how many coins the sender has (doesn't work from console) // Mode for seeing how many coins the sender has (doesn't work from console)
@ -36,14 +35,14 @@ public class Command_coins extends FreedomCommand
{ {
if (senderIsConsole) if (senderIsConsole)
{ {
msg("When used from the console, you must define a target player."); msgNew("When used from the console, you must define a target player.");
} }
else else
{ {
PlayerData playerData = getData(playerSender); PlayerData playerData = getData(playerSender);
msg(prefix.append(Component.text("You have ", NamedTextColor.GREEN) msgNew("<green>You have <gold><coins></gold> coin<plural>.",
.append(Component.text(playerData.getCoins(), NamedTextColor.GOLD)) Placeholder.unparsed("coins", String.valueOf(playerData.getCoins())),
.append(Component.text(" coins.", NamedTextColor.GREEN)))); Placeholder.unparsed("plural", playerData.getCoins() > 1 ? "s" : ""));
} }
return true; return true;
} }
@ -61,10 +60,10 @@ public class Command_coins extends FreedomCommand
else else
{ {
PlayerData playerData = getData(target); PlayerData playerData = getData(target);
msg(prefix.append(Component.text(target.getName(), NamedTextColor.GOLD) msgNew("<green><gold><player></gold> has <gold><coins></gold> coin<plural>.",
.append(Component.text(" has ", NamedTextColor.GREEN)) Placeholder.unparsed("player", target.getName()),
.append(Component.text(playerData.getCoins(), NamedTextColor.GOLD)) Placeholder.unparsed("coins", String.valueOf(playerData.getCoins())),
.append(Component.text(" coins.", NamedTextColor.GREEN)))); Placeholder.unparsed("plural", playerData.getCoins() > 1 ? "s" : ""));
} }
return true; return true;
} }
@ -90,14 +89,14 @@ public class Command_coins extends FreedomCommand
} }
catch (NumberFormatException ex) catch (NumberFormatException ex)
{ {
msg(Component.text("Invalid number: " + args[2], NamedTextColor.RED)); msgNew("<red>Invalid number: <num>", Placeholder.unparsed("num", args[2]));
return true; return true;
} }
// Prevents players from performing transactions they can't afford to do. // Prevents players from performing transactions they can't afford to do.
if (senderData.getCoins() < coinsToTransfer) if (senderData.getCoins() < coinsToTransfer)
{ {
msg(Component.text("You don't have enough coins to perform this transaction.", NamedTextColor.RED)); msgNew("<red>You don't have enough coins to perform this transaction.");
return true; return true;
} }
@ -113,17 +112,15 @@ public class Command_coins extends FreedomCommand
boolean plural = coinsToTransfer > 1; boolean plural = coinsToTransfer > 1;
msg(target, Component.text(sender.getName(), NamedTextColor.GOLD) msgNew(target, "<green><gold><sender></gold> has given you <gold><coins></gold> coin<plural>!",
.append(Component.text(" has given you ", NamedTextColor.GREEN)) Placeholder.unparsed("sender", sender.getName()),
.append(Component.text(coinsToTransfer, NamedTextColor.GOLD)) Placeholder.unparsed("coins", String.valueOf(coinsToTransfer)),
.append(Component.text(" coin" + (plural ? "s" : "") + "!", NamedTextColor.GREEN))); Placeholder.unparsed("plural", plural ? "s" : ""));
msg(target, Component.text("You have given ", NamedTextColor.GREEN) msgNew("<green>You have given <gold><coins></gold> coin<plural> to <gold><player></gold>.",
.append(Component.text(coinsToTransfer, NamedTextColor.GOLD)) Placeholder.unparsed("player", target.getName()),
.append(Component.text(" coin" + (plural ? "s" : ""), NamedTextColor.GOLD)) Placeholder.unparsed("coins", String.valueOf(coinsToTransfer)),
.append(Component.text(" to ", NamedTextColor.GREEN)) Placeholder.unparsed("plural", plural ? "s" : ""));
.append(Component.text(target.getName(), NamedTextColor.GOLD))
.append(Component.text(".", NamedTextColor.GREEN)));
plugin.pl.save(playerData); plugin.pl.save(playerData);
plugin.pl.save(senderData); plugin.pl.save(senderData);

View File

@ -1,55 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import java.util.Map;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
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;
@CommandPermissions(rank = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Essentials Interface Command - Set your nickname to a certain color.", usage = "/<command> <color>")
public class Command_colorme extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length != 1)
{
return false;
}
if (args[0].equalsIgnoreCase("list"))
{
msg("Colors: " + StringUtils.join(FUtil.CHAT_COLOR_NAMES.keySet(), ", "));
return true;
}
final String needle = args[0].trim().toLowerCase();
ChatColor color = null;
for (Map.Entry<String, ChatColor> entry : FUtil.CHAT_COLOR_NAMES.entrySet())
{
if (entry.getKey().contains(needle))
{
color = entry.getValue();
break;
}
}
if (color == null)
{
msg("Invalid color: " + needle + " - Use \"/colorme list\" to list colors.");
return true;
}
final String newNick = color + ChatColor.stripColor(playerSender.getDisplayName()).trim() + ChatColor.WHITE;
plugin.esb.setNickname(sender.getName(), newNick);
msg("Your nickname is now: " + newNick);
return true;
}
}

View File

@ -1,50 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@CommandPermissions(rank = Rank.NON_OP, source = SourceType.BOTH)
@CommandParameters(description = "Show all commands for all server plugins.", usage = "/<command>", aliases = "cmdlist")
public class Command_commandlist extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
List<String> commands = new ArrayList<>();
for (Plugin targetPlugin : server.getPluginManager().getPlugins())
{
try
{
PluginDescriptionFile desc = targetPlugin.getDescription();
Map<String, Map<String, Object>> map = desc.getCommands();
for (Entry<String, Map<String, Object>> entry : map.entrySet())
{
String command_name = entry.getKey();
commands.add(command_name);
}
} catch (Throwable ignored)
{
}
}
Collections.sort(commands);
msg(StringUtils.join(commands, ", "));
return true;
}
}

View File

@ -1,8 +1,10 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -22,10 +24,9 @@ public class Command_consolesay extends FreedomCommand
return false; return false;
} }
server.broadcast(Component.text("[CONSOLE] ", NamedTextColor.GRAY) server.broadcast(FUtil.miniMessage("<gray>[CONSOLE] <red><sender> <dark_gray>» <white><message>",
.append(Component.text(sender.getName(), NamedTextColor.RED)) Placeholder.unparsed("sender", sender.getName()),
.append(Component.text("» ", NamedTextColor.DARK_GRAY)) Placeholder.unparsed("message", StringUtils.join(args, " "))));
.append(Component.text(StringUtils.join(args, " "), NamedTextColor.WHITE)));
if (plugin.dc != null) if (plugin.dc != null)
{ {

View File

@ -2,7 +2,7 @@ package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -19,12 +19,12 @@ public class Command_creative extends FreedomCommand
{ {
if (isConsole()) if (isConsole())
{ {
msg(Component.text("When used from the console, you must define a target player.")); msgNew("When used from the console, you must define a target player.");
return true; return true;
} }
playerSender.setGameMode(GameMode.CREATIVE); playerSender.setGameMode(GameMode.CREATIVE);
msg(Component.text("Your gamemode has been set to creative.")); msgNew("Your gamemode has been set to creative.");
return true; return true;
} }
@ -37,7 +37,7 @@ public class Command_creative extends FreedomCommand
server.getOnlinePlayers().forEach(player -> server.getOnlinePlayers().forEach(player ->
{ {
player.setGameMode(GameMode.CREATIVE); player.setGameMode(GameMode.CREATIVE);
msg(player, Component.text("Your gamemode has been set to creative.")); msgNew(player, "Your gamemode has been set to creative.");
}); });
return true; return true;
@ -51,8 +51,8 @@ public class Command_creative extends FreedomCommand
return true; return true;
} }
msg(Component.text("Setting " + player.getName() + " to gamemode creative")); msgNew("Setting <player> to gamemode creative.", Placeholder.unparsed("player", player.getName()));
msg(player, Component.text(sender.getName() + " set your gamemode to creative.")); msgNew(player, "<sender> set your gamemode to creative.", Placeholder.unparsed("sender", sender.getName()));
player.setGameMode(GameMode.CREATIVE); player.setGameMode(GameMode.CREATIVE);
return true; return true;
} }

View File

@ -5,6 +5,7 @@ import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.title.Title; import net.kyori.adventure.title.Title;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -17,7 +18,6 @@ import java.time.Duration;
@CommandParameters(description = "Freeze/Unfreeze a specified player, or all non-admins on the server.", usage = "/<command> [target | purge]", aliases = "fr") @CommandParameters(description = "Freeze/Unfreeze a specified player, or all non-admins on the server.", usage = "/<command> [target | purge]", aliases = "fr")
public class Command_freeze extends FreedomCommand public class Command_freeze extends FreedomCommand
{ {
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
@ -29,38 +29,28 @@ public class Command_freeze extends FreedomCommand
if (!gFreeze) if (!gFreeze)
{ {
FUtil.adminAction(sender.getName(), "Unfreezing all players", false); FUtil.adminAction(sender.getName(), "Unfreezing all players", false);
msg("Players are now free to move."); msgNew("Players are now free to move.");
return true; }
else
{
FUtil.adminAction(sender.getName(), "Freezing all players", false);
server.getOnlinePlayers().stream().filter(player -> !isAdmin(player)).forEach(player ->
{
FUtil.playerTitle(player, "<red>You have been frozen.", "<yellow>Please be patient and you will be unfrozen shortly.");
msgNew(player, "<red>You have been globally frozen due to an OP breaking the rules, please wait and you will be unfrozen soon.");
});
msgNew("Players are now frozen.");
} }
FUtil.adminAction(sender.getName(), "Freezing all players", false);
for (Player player : server.getOnlinePlayers())
{
if (!isAdmin(player))
{
player.showTitle(Title.title(Component.text("You have been frozen.", NamedTextColor.RED),
Component.text("Please be patient and you will be unfrozen shortly.", NamedTextColor.YELLOW),
Title.Times.of(Duration.ofSeconds(1), Duration.ofSeconds(5), Duration.ofSeconds(3))));
msg(player, "You have been globally frozen due to an OP breaking the rules, please wait and you will be unfrozen soon.", ChatColor.RED);
}
}
msg("Players are now frozen.");
return true; return true;
} }
if (args[0].equalsIgnoreCase("purge")) if (args[0].equalsIgnoreCase("purge"))
{ {
FUtil.adminAction(sender.getName(), "Unfreezing all players", false); FUtil.adminAction(sender.getName(), "Unfreezing all players", false);
for (Player player : server.getOnlinePlayers())
{
if (!isAdmin(player))
{
player.showTitle(Title.title(Component.text("You have been unfrozen.", NamedTextColor.GREEN),
Component.text("You may now move again.", NamedTextColor.YELLOW),
Title.Times.of(Duration.ofSeconds(1), Duration.ofSeconds(5), Duration.ofSeconds(3))));
}
}
plugin.fm.purge(); plugin.fm.purge();
server.getOnlinePlayers().stream().filter(player -> !isAdmin(player)).forEach(player -> FUtil.playerTitle(player, "<green>You have been unfrozen.", "<yellow>You may now move again."));
return true; return true;
} }
@ -75,8 +65,9 @@ public class Command_freeze extends FreedomCommand
final FreezeData fd = plugin.pl.getPlayer(player).getFreezeData(); final FreezeData fd = plugin.pl.getPlayer(player).getFreezeData();
fd.setFrozen(!fd.isFrozen()); fd.setFrozen(!fd.isFrozen());
msg(Component.text(player.getName() + " has been " + (fd.isFrozen() ? "frozen" : "unfrozen") + ".")); msgNew("<player> has been <status>.", Placeholder.unparsed("player", player.getName()),
msg(player, Component.text("You have been " + (fd.isFrozen() ? "frozen" : "unfrozen") + ".")); Placeholder.unparsed("status", fd.isFrozen() ? "frozen" : "unfrozen"));
msgNew(player, "You have been <status>.", Placeholder.unparsed("status", fd.isFrozen() ? "frozen" : "unfrozen"));
return true; return true;
} }
} }

View File

@ -2,6 +2,7 @@ package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -11,7 +12,6 @@ import org.bukkit.entity.Player;
@CommandParameters(description = "Quickly change your own gamemode to spectator, or define someone's username to change theirs.", usage = "/<command> <[partialname]>", aliases = "gmsp") @CommandParameters(description = "Quickly change your own gamemode to spectator, or define someone's username to change theirs.", usage = "/<command> <[partialname]>", aliases = "gmsp")
public class Command_spectator extends FreedomCommand public class Command_spectator extends FreedomCommand
{ {
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
@ -19,12 +19,12 @@ public class Command_spectator extends FreedomCommand
{ {
if (isConsole()) if (isConsole())
{ {
msg(Component.text("When used from the console, you must define a target player.")); msgNew("When used from the console, you must define a target player.");
return true; return true;
} }
playerSender.setGameMode(GameMode.SPECTATOR); playerSender.setGameMode(GameMode.SPECTATOR);
msg(Component.text("Your gamemode has been set to spectator.")); msgNew("Your gamemode has been set to spectator.");
return true; return true;
} }
@ -36,9 +36,9 @@ public class Command_spectator extends FreedomCommand
return true; return true;
} }
msg(Component.text("Setting " + player.getName() + " to gamemode spectator")); msgNew("Setting <player> to gamemode spectator", Placeholder.unparsed("player", player.getName()));
msg(player, Component.text(sender.getName() + " set your gamemode to spectator."));
player.setGameMode(GameMode.SPECTATOR); player.setGameMode(GameMode.SPECTATOR);
msgNew(player, "<sender> set your gamemode to spectator.", Placeholder.unparsed("sender", sender.getName()));
return true; return true;
} }
} }

View File

@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -20,13 +21,7 @@ public class Command_stop extends FreedomCommand
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
String reason = args.length != 0 ? "Server is going offline, come back in about 20 seconds." : StringUtils.join(args, " ");
String reason = "Server is going offline, come back in about 20 seconds.";
if (args.length != 0)
{
reason = StringUtils.join(args, " ");
}
if (sender.getName().equals("CONSOLE")) if (sender.getName().equals("CONSOLE"))
{ {
@ -40,7 +35,7 @@ public class Command_stop extends FreedomCommand
} }
msg("Warning: You're about to stop the server. Type /stop again to confirm you want to do this."); msgNew("Warning: You're about to stop the server. Type /stop again to confirm you want to do this.");
STOP_CONFIRM.put(sender, reason); STOP_CONFIRM.put(sender, reason);
new BukkitRunnable() new BukkitRunnable()
@ -51,7 +46,7 @@ public class Command_stop extends FreedomCommand
if (STOP_CONFIRM.containsKey(sender)) if (STOP_CONFIRM.containsKey(sender))
{ {
STOP_CONFIRM.remove(sender); STOP_CONFIRM.remove(sender);
msg("Stop request expired."); msgNew("Stop request expired.");
} }
} }
}.runTaskLater(plugin, 15 * 20); }.runTaskLater(plugin, 15 * 20);
@ -60,15 +55,10 @@ public class Command_stop extends FreedomCommand
public void shutdown(String reason) public void shutdown(String reason)
{ {
FUtil.bcastMsg("Server is going offline!", ChatColor.LIGHT_PURPLE); server.broadcast(FUtil.miniMessage("<light_purple>Server is going offline!"));
server.getOnlinePlayers().forEach(player ->
for (Player player : server.getOnlinePlayers()) player.kick(FUtil.miniMessage("<light_purple><reason>", Placeholder.unparsed("reason", reason))));
{
player.kickPlayer(ChatColor.LIGHT_PURPLE + reason);
}
STOP_CONFIRM.remove(sender); STOP_CONFIRM.remove(sender);
server.shutdown(); server.shutdown();
} }
} }

View File

@ -1,9 +1,11 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -14,38 +16,21 @@ import org.bukkit.entity.Player;
@CommandParameters(description = "Stops all sounds or a specified sound.", usage = "/<command> [sound]") @CommandParameters(description = "Stops all sounds or a specified sound.", usage = "/<command> [sound]")
public class Command_stopsound extends FreedomCommand public class Command_stopsound extends FreedomCommand
{ {
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
if (args.length > 0) if (args.length > 0)
{ {
Sound sound = null; Arrays.stream(Sound.values()).filter(snd -> snd != null && snd.name().equalsIgnoreCase(args[0])).findAny().ifPresentOrElse(sound ->
{
playerSender.stopSound(sound);
msgNew("<green>Stopped all <sound> sounds.", Placeholder.unparsed("sound", sound.name()));
}, () -> msgNew("<red><sound> is not a valid sound.", Placeholder.unparsed("sound", args[0])));
for (Sound loop : Sound.values())
{
if (loop != null && loop.name().equalsIgnoreCase(args[0]))
{
sound = Sound.valueOf(args[0].toUpperCase());
break;
}
}
if (sound == null)
{
msg(args[0] + " is not a valid sound.", ChatColor.RED);
return true; return true;
} }
playerSender.stopSound(sound); playerSender.stopAllSounds();
msg("Stopped all " + sound.name() + " sounds", ChatColor.GREEN);
return true;
}
for (Sound sound : Sound.values())
{
playerSender.stopSound(sound);
}
msg("Stopped all sounds.", ChatColor.GREEN); msg("Stopped all sounds.", ChatColor.GREEN);
return true; return true;
@ -54,20 +39,11 @@ public class Command_stopsound extends FreedomCommand
@Override @Override
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
{ {
if (args.length == 1) if (args.length <= 1)
{ {
return soundList(); return Arrays.stream(Sound.values()).map(Enum::name).toList();
}
return Collections.emptyList();
} }
public List<String> soundList() return Collections.emptyList();
{
List<String> sounds = new ArrayList<>();
for (Sound sound : Sound.values())
{
sounds.add(sound.name());
}
return sounds;
} }
} }

View File

@ -2,6 +2,7 @@ package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -19,12 +20,12 @@ public class Command_survival extends FreedomCommand
{ {
if (isConsole()) if (isConsole())
{ {
msg("When used from the console, you must define a target player."); msgNew("When used from the console, you must define a target player.");
return true; return true;
} }
playerSender.setGameMode(GameMode.SURVIVAL); playerSender.setGameMode(GameMode.SURVIVAL);
msg("Your gamemode has been set to survival."); msgNew("Your gamemode has been set to survival.");
return true; return true;
} }
@ -32,13 +33,14 @@ public class Command_survival extends FreedomCommand
if (args[0].equals("-a")) if (args[0].equals("-a"))
{ {
for (Player targetPlayer : server.getOnlinePlayers())
{
targetPlayer.setGameMode(GameMode.SURVIVAL);
}
FUtil.adminAction(sender.getName(), "Changing everyone's gamemode to survival", false); FUtil.adminAction(sender.getName(), "Changing everyone's gamemode to survival", false);
msg("Your gamemode has been set to survival.");
server.getOnlinePlayers().forEach(player ->
{
player.setGameMode(GameMode.SURVIVAL);
msgNew(player, "Your gamemode has been set to survival.");
});
return true; return true;
} }
@ -50,9 +52,9 @@ public class Command_survival extends FreedomCommand
return true; return true;
} }
msg("Setting " + player.getName() + " to game mode survival."); msgNew("Setting <player> to gamemode survival", Placeholder.unparsed("player", player.getName()));
msg(player, sender.getName() + " set your game mode to survival.");
player.setGameMode(GameMode.SURVIVAL); player.setGameMode(GameMode.SURVIVAL);
msgNew(player, "<sender> set your gamemode to survival.", Placeholder.unparsed("sender", sender.getName()));
return true; return true;
} }
} }

View File

@ -4,6 +4,10 @@ import me.totalfreedom.totalfreedommod.punishments.Punishment;
import me.totalfreedom.totalfreedommod.punishments.PunishmentType; import me.totalfreedom.totalfreedommod.punishments.PunishmentType;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.title.Title;
import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -11,6 +15,8 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.time.Duration;
@CommandPermissions(rank = Rank.ADMIN, source = SourceType.BOTH) @CommandPermissions(rank = Rank.ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Warns the specified player.", usage = "/<command> [-q] <player> <reason>") @CommandParameters(description = "Warns the specified player.", usage = "/<command> [-q] <player> <reason>")
public class Command_warn extends FreedomCommand public class Command_warn extends FreedomCommand
@ -44,25 +50,27 @@ public class Command_warn extends FreedomCommand
if (playerSender == player) if (playerSender == player)
{ {
msg(ChatColor.RED + "Please, don't try to warn yourself."); msgNew("<red>Please, don't try to warn yourself.");
return true; return true;
} }
if (plugin.al.isAdmin(player)) if (plugin.al.isAdmin(player))
{ {
msg(ChatColor.RED + "You can not warn admins"); msgNew("<red>You can't warn other admins!");
return true; return true;
} }
String warnReason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " "); String warnReason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
player.sendTitle(ChatColor.RED + "You've been warned.", ChatColor.YELLOW + "Reason: " + warnReason, 20, 100, 60); player.showTitle(Title.title(Component.text("You have been warned.", NamedTextColor.RED),
msg(player, ChatColor.RED + "[WARNING] You received a warning from " + sender.getName() + ": " + warnReason); Component.text("Reason: " + warnReason, NamedTextColor.YELLOW),
Title.Times.times(Duration.ofSeconds(1), Duration.ofSeconds(5), Duration.ofSeconds(3))));
msgNew("<red>[WARNING] You received a warning from <sender>: <reason>", Placeholder.unparsed("sender", sender.getName()), Placeholder.unparsed("reason", warnReason));
plugin.pl.getPlayer(player).incrementWarnings(quiet); plugin.pl.getPlayer(player).incrementWarnings(quiet);
plugin.pul.logPunishment(new Punishment(player.getName(), FUtil.getIp(player), sender.getName(), PunishmentType.WARN, warnReason)); plugin.pul.logPunishment(new Punishment(player.getName(), FUtil.getIp(player), sender.getName(), PunishmentType.WARN, warnReason));
if (quiet) if (quiet)
{ {
msg("You have successfully warned " + player.getName() + " quietly."); msgNew("You have successfully warned <player> quietly.", Placeholder.unparsed("player", player.getName()));
} }
else else
{ {
@ -76,7 +84,7 @@ public class Command_warn extends FreedomCommand
warnReason; warnReason;
plugin.al.messageAllAdmins(adminNotice); plugin.al.messageAllAdmins(adminNotice);
msg("You have successfully warned " + player.getName() + "."); msgNew("You have successfully warned <player>.", Placeholder.unparsed("player", player.getName()));
} }
return true; return true;
} }

View File

@ -4,6 +4,8 @@ import java.util.*;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -27,11 +29,11 @@ public class Command_whitelist extends FreedomCommand
{ {
if (server.getWhitelistedPlayers().isEmpty()) if (server.getWhitelistedPlayers().isEmpty())
{ {
msg("There are no whitelisted players."); msgNew("There are no whitelisted players.");
return true; return true;
} }
msg("Whitelisted players: " + FUtil.listToString(server.getWhitelistedPlayers().stream().map(player -> msgNew("Whitelisted players: <players>", Placeholder.unparsed("players", FUtil.listToString(server.getWhitelistedPlayers().stream().map(player ->
player.getName() != null ? player.getName() : player.getUniqueId().toString()).toList())); player.getName() != null ? player.getName() : player.getUniqueId().toString()).toList())));
return true; return true;
} }
@ -55,9 +57,9 @@ public class Command_whitelist extends FreedomCommand
totalWPs++; totalWPs++;
} }
msg("Online whitelisted players: " + onlineWPs); msgNew("Online whitelisted players: <online>", Placeholder.unparsed("online", String.valueOf(onlineWPs)));
msg("Offline whitelisted players: " + offlineWPs); msgNew("Offline whitelisted players: <offline>", Placeholder.unparsed("offline", String.valueOf(offlineWPs)));
msg("Total whitelisted players: " + totalWPs); msgNew("Total whitelisted players: <total>", Placeholder.unparsed("total", String.valueOf(totalWPs)));
return true; return true;
} }
@ -126,7 +128,7 @@ public class Command_whitelist extends FreedomCommand
} }
else else
{ {
msg("That player is not whitelisted"); msgNew("That player is not whitelisted");
} }
return true; return true;
} }
@ -145,7 +147,7 @@ public class Command_whitelist extends FreedomCommand
} }
} }
msg("Whitelisted " + counter + " players."); msgNew("Whitelisted <count> players.", Placeholder.unparsed("count", String.valueOf(counter)));
return true; return true;
} }
@ -157,7 +159,7 @@ public class Command_whitelist extends FreedomCommand
if (args[0].equalsIgnoreCase("purge")) if (args[0].equalsIgnoreCase("purge"))
{ {
FUtil.adminAction(sender.getName(), "Removing all players from the whitelist", false); FUtil.adminAction(sender.getName(), "Removing all players from the whitelist", false);
msg("Removed " + purge() + " players from the whitelist."); msgNew("Removed <count> players from the whitelist.", Placeholder.unparsed("count", String.valueOf(purge())));
return true; return true;
} }
return false; return false;

View File

@ -6,6 +6,7 @@ import java.util.List;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -32,7 +33,7 @@ public class Command_whohas extends FreedomCommand
if (material == null) if (material == null)
{ {
msg(Component.text("Invalid item: " + materialName, NamedTextColor.RED)); msgNew("<red>Invalid item: <type>", Placeholder.unparsed("type", materialName));
return true; return true;
} }
@ -47,12 +48,12 @@ public class Command_whohas extends FreedomCommand
if (players.isEmpty()) if (players.isEmpty())
{ {
msg(Component.text("There are no players with that item.")); msgNew("There are no players with that item.");
} }
else else
{ {
msg(Component.text("Players with item " + material.name() + ": " + msgNew("Players with item <type>: <players>", Placeholder.unparsed("type", material.name()),
StringUtils.join(players.stream().map(HumanEntity::getName).toList(), ", "))); Placeholder.unparsed("players", StringUtils.join(players.stream().map(HumanEntity::getName).toList(), ", ")));
} }
return true; return true;

View File

@ -6,6 +6,7 @@ import java.util.List;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -16,7 +17,6 @@ import org.bukkit.entity.Player;
@CommandParameters(description = "Run any command on all users, username placeholder = ?.", usage = "/<command> [fluff] ? [fluff] ?") @CommandParameters(description = "Run any command on all users, username placeholder = ?.", usage = "/<command> [fluff] ? [fluff] ?")
public class Command_wildcard extends FreedomCommand public class Command_wildcard extends FreedomCommand
{ {
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
@ -30,7 +30,7 @@ public class Command_wildcard extends FreedomCommand
boolean alias = plugin.cl.isAlias(args[0]); boolean alias = plugin.cl.isAlias(args[0]);
if (runCmd == null && fCmd == null && !alias) if (runCmd == null && fCmd == null && !alias)
{ {
msg("Unknown command: " + args[0], ChatColor.RED); msgNew("<red>Unknown command: <command>", Placeholder.unparsed("command", args[0]));
return true; return true;
} }
@ -50,7 +50,7 @@ public class Command_wildcard extends FreedomCommand
{ {
if (blockedCommand.equals(args[0].toLowerCase()) || aliases.contains(blockedCommand)) if (blockedCommand.equals(args[0].toLowerCase()) || aliases.contains(blockedCommand))
{ {
msg("Did you really think that was going to work?", ChatColor.RED); msgNew("<red>Did you really think that was going to work?");
return true; return true;
} }
} }
@ -66,7 +66,7 @@ public class Command_wildcard extends FreedomCommand
for (Player player : server.getOnlinePlayers()) for (Player player : server.getOnlinePlayers())
{ {
String runCommand = baseCommand.replaceAll("\\x3f", player.getName()); String runCommand = baseCommand.replaceAll("\\x3f", player.getName());
msg("Running Command: " + runCommand); msgNew("Running command: <command>", Placeholder.unparsed("command", baseCommand));
server.dispatchCommand(sender, runCommand); server.dispatchCommand(sender, runCommand);
} }

View File

@ -9,6 +9,7 @@ import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -142,6 +143,18 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter
msg(sender, message); msg(sender, message);
} }
protected void msgNew(CommandSender sender, String message, TagResolver... placeholders)
{
sender.sendMessage(FUtil.miniMessage("<gray>" + message, placeholders));
}
protected void msgNew(String message, TagResolver... placeholders)
{
msgNew(sender, message, placeholders);
}
protected void msg(String message, ChatColor color) protected void msg(String message, ChatColor color)
{ {
msg(color + message); msg(color + message);