diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java index 5dcf18ab..5f1a3abe 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java @@ -1,20 +1,24 @@ package me.totalfreedom.totalfreedommod; import com.google.common.base.Strings; +import io.papermc.paper.event.player.AsyncChatEvent; import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.FPlayer; +import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.rank.Displayable; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FSync; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.StyleBuilderApplicable; import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.minimessage.tag.Tag; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import net.md_5.bungee.api.ChatColor; import org.bukkit.Sound; import org.bukkit.SoundCategory; @@ -23,6 +27,9 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.player.AsyncPlayerChatEvent; + +import java.util.Arrays; + import static me.totalfreedom.totalfreedommod.util.FUtil.playerMsg; public class ChatManager extends FreedomService @@ -38,107 +45,103 @@ public class ChatManager extends FreedomService } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void onPlayerChatFormat(AsyncPlayerChatEvent event) + public void onPlayerChat(AsyncChatEvent event) { - try - { - handleChatEvent(event); - } - catch (Exception ex) - { - FLog.severe(ex); - } - } - - private void handleChatEvent(AsyncPlayerChatEvent event) - { - final Player player = event.getPlayer(); - String message = event.getMessage().trim(); - - // Format colors and strip &k - message = FUtil.colorize(message); - message = message.replaceAll(ChatColor.MAGIC.toString(), "&k"); + // Important information for later down the line + String steamrolled = FUtil.steamroll(event.originalMessage()); + Player player = event.getPlayer(); + FPlayer fPlayer = plugin.pl.getPlayer(player); + PlayerData playerData = plugin.pl.getData(player); + // Chat is disabled if (!ConfigEntry.TOGGLE_CHAT.getBoolean() && !plugin.al.isAdmin(player)) { - event.setCancelled(true); - playerMsg(player, "Chat is currently disabled.", org.bukkit.ChatColor.RED); - return; - } - - // Truncate messages that are too long - 256 characters is vanilla client max - if (message.length() > 256) - { - message = message.substring(0, 256); - FSync.playerMsg(player, "Message was shortened because it was too long to send."); - } - - final FPlayer fPlayer = plugin.pl.getPlayerSync(player); - if (fPlayer.isLockedUp()) - { - FSync.playerMsg(player, "You're locked up and cannot talk."); + event.getPlayer().sendMessage(FUtil.miniMessage("The chat is currently disabled.")); event.setCancelled(true); return; } - - // Check for adminchat - if (fPlayer.inAdminChat()) + // Locked up + else if (fPlayer.isLockedUp()) { - FSync.adminChatMessage(player, message); + event.getPlayer().sendMessage(FUtil.miniMessage("You are locked up and thus can't talk.")); event.setCancelled(true); return; } - - // Check for 4chan trigger - if (ConfigEntry.FOURCHAN_ENABLED.getBoolean()) + // Admin chat is enabled + else if (fPlayer.inAdminChat()) { - boolean green = ChatColor.stripColor(message).toLowerCase().startsWith(">"); - boolean orange = ChatColor.stripColor(message).toLowerCase().endsWith("<"); + adminChat(player, steamrolled); + event.setCancelled(true); + return; + } + // The event was already cancelled elsewhere or the player was muted + else if (event.isCancelled() || fPlayer.isMuted()) + { + return; + } - if (green) + // Tag + Component tag = Strings.isNullOrEmpty(fPlayer.getTag()) ? Component.empty() : FUtil.miniMessage(fPlayer.getTag()) + .append(Component.space()); + + // Nickname + Component nickname = player.displayName(); + + // Splitter + Component splitter = Component.text("»", NamedTextColor.DARK_GRAY); + + // Message + TextComponent.Builder message = Component.text(); + + // Truncate the message if it's too long + if (steamrolled.length() > 256) + { + steamrolled = steamrolled.substring(0, 256); + } + + // Pinging + Arrays.stream(steamrolled.split(" ")).filter(string -> string.startsWith("@")).forEach(possiblePlayer -> + { + Player potential = server.getPlayer(possiblePlayer.replaceAll("@", "")); + + // Ping only that particular player + if (potential != null) { - message = ChatColor.GREEN + message; + ping(player); } - else if (orange) + // Ping everyone (if the person pinging is an admin) + else if (possiblePlayer.equalsIgnoreCase("@everyone") && plugin.al.isAdmin(player)) { - message = ChatColor.GOLD + message; + server.getOnlinePlayers().forEach(this::ping); } - } + }); - // Finally, set message - event.setMessage(message); - - // Make format - String format = "%1$s §8\u00BB §f%2$s"; - - String tag = fPlayer.getTag(); - if (tag != null && !tag.isEmpty()) + // Chat colorization + // -- 4chan mode -- + if (steamrolled.startsWith("> ") && ConfigEntry.FOURCHAN_ENABLED.getBoolean()) { - format = tag.replace("%", "%%") + " " + format; + message.append(Component.text(steamrolled, NamedTextColor.GREEN)); } - - // Check for mentions - String stripped = ChatColor.stripColor(message).toLowerCase(); - - /* There is an issue would have allowed muted players to ping players. The issue is caused by the order in which - * these event handlers are registered when the plugin starts up. Muter is registered after the ChatManager, - * which results in latter being called first (before the former can cancel it). EventPriority does not seem to - * make a difference. As a short-term solution I've added this mute check alongside the usual isCancelled check - * so that the issue is mitigated, but a long-term solution should be to change the order in which things like - * ChatManager and Muter are registered. */ - if (!event.isCancelled() && !plugin.pl.getPlayer(player).isMuted()) + // -- Legacy chat colors -- + else if (FUtil.containsChatColor(steamrolled)) { - server.getOnlinePlayers().forEach(pl -> - { - if (stripped.contains("@" + pl.getName()) || (plugin.al.isAdmin(player) && stripped.contains("@everyone"))) - { - pl.playSound(pl.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, SoundCategory.MASTER, 1337F, 0.9F); - } - }); + message.append(FUtil.colorizeAsComponent(steamrolled.replaceAll("&k", ""))); + } + // -- MiniMessage -- + else + { + message.append(FUtil.miniMessage(steamrolled)); } - // Set format - event.setFormat(format); + // This simply filters out shit like &k in a simple but stupid way. + Component filtered = FUtil.miniMessage(FUtil.miniMessage(message.build())); + + event.setCancelled(true); + server.broadcast(FUtil.miniMessage(" ", + Placeholder.component("tag", tag), + Placeholder.component("nickname", nickname), + Placeholder.component("splitter", splitter), + Placeholder.component("message", filtered))); } public ChatColor getColor(Displayable display) @@ -193,9 +196,21 @@ public class ChatManager extends FreedomService public void messageAllAdmins(String message, TagResolver... placeholders) { - Component parsed = FUtil.MINI_MESSAGE.deserialize(message, placeholders); + Component parsed = FUtil.miniMessage(message, placeholders); plugin.getComponentLogger().info(parsed); server.getOnlinePlayers().stream().filter(player -> plugin.al.isAdmin(player)).forEach(player -> player.sendMessage(parsed)); } + + public void broadcastSplit(String forAdmins, String forOperators, TagResolver... placeholders) + { + messageAllAdmins(forAdmins, placeholders); + server.getOnlinePlayers().stream().filter(player -> !plugin.al.isAdmin(player)).forEach(player -> + player.sendMessage(FUtil.miniMessage(forOperators, placeholders))); + } + + public void ping(Player player) + { + player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, SoundCategory.MASTER, 1337F, 0.9F); + } } \ No newline at end of file diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java index 47d64f93..473fc5f2 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java @@ -36,7 +36,6 @@ public class LoginProcess extends FreedomService private static boolean lockdownEnabled = false; public List TELEPORT_ON_JOIN = new ArrayList<>(); public List CLEAR_ON_JOIN = new ArrayList<>(); - public List CLOWNFISH_TOGGLE = new ArrayList<>(); public static boolean isLockdownEnabled() { diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminchat.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminchat.java index af004961..5c2e6403 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminchat.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminchat.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.minimessage.tag.resolver.Placeholder; import org.apache.commons.lang.StringUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -19,13 +20,13 @@ public class Command_adminchat extends FreedomCommand { if (senderIsConsole) { - msg("You must be in-game to toggle admin chat, it cannot be toggled via CONSOLE or Telnet."); + msgNew("You must be in-game to toggle admin chat, it cannot be toggled via CONSOLE or Telnet."); return true; } FPlayer userinfo = plugin.pl.getPlayer(playerSender); userinfo.setAdminChat(!userinfo.inAdminChat()); - msg("Admin chat turned " + (userinfo.inAdminChat() ? "on" : "off") + "."); + msgNew("Admin chat turned .", Placeholder.unparsed("status", userinfo.inAdminChat() ? "on" : "off")); } else { diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_attributelist.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_attributelist.java index 68286faa..a3d8deab 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_attributelist.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_attributelist.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.minimessage.tag.resolver.Placeholder; import org.bukkit.attribute.Attribute; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -15,7 +16,7 @@ public class Command_attributelist extends FreedomCommand @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - msg("All possible attributes: " + FUtil.listToString(Arrays.stream(Attribute.values()).map(Enum::name).toList())); + msgNew("All possible attributes: ", Placeholder.unparsed("attributes", FUtil.listToString(Arrays.stream(Attribute.values()).map(Enum::name).toList()))); return true; } } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_autoclear.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_autoclear.java index ae937afe..b8952a0a 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_autoclear.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_autoclear.java @@ -1,6 +1,7 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.rank.Rank; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -29,7 +30,8 @@ public class Command_autoclear extends FreedomCommand plugin.lp.CLEAR_ON_JOIN.add(args[0]); } - msg(args[0] + " will " + (enabled ? "no longer" : "now") + " have their inventory cleared when they join."); + msgNew(" will have their inventory cleared when they join.", + Placeholder.unparsed("player", args[0]), Placeholder.unparsed("status", enabled ? "no longer" : "now")); return true; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_autotp.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_autotp.java index 6b4518b2..084dab56 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_autotp.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_autotp.java @@ -1,6 +1,7 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.rank.Rank; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -29,8 +30,8 @@ public class Command_autotp extends FreedomCommand plugin.lp.TELEPORT_ON_JOIN.add(args[0]); } - msg(args[0] + " will " + (enabled ? "no longer" : "now") + " be automatically teleported when they join."); - + msgNew(" will be automatically teleported when they join.", + Placeholder.unparsed("player", args[0]), Placeholder.unparsed("status", enabled ? "no longer" : "now")); return true; } } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_banip.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_banip.java index f295ec00..b84c3779 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_banip.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_banip.java @@ -62,22 +62,15 @@ public class Command_banip extends FreedomCommand plugin.bm.addBan(ban); // Kick player and handle others on IP - for (Player player : server.getOnlinePlayers()) - { - if (FUtil.getIp(player).equals(ip)) - { - player.kickPlayer(ban.bakeKickMessage()); - } + server.getOnlinePlayers().stream().filter(player -> FUtil.getIp(player).equalsIgnoreCase(ip)).forEach(player -> + player.kickPlayer(ban.bakeKickMessage())); - if (!silent) - { - // Broadcast - String message = sender.getName() + " - Banned " + (plugin.al.isAdmin(player) ? "the IP " + ip : "an IP"); - msg(player, message, ChatColor.RED); - } + // Broadcasts the message + if (!silent) + { + plugin.cm.broadcastSplit(" - Banned the IP ", " - Banned an IP", Placeholder.unparsed("ip", ip)); } - FLog.info(ChatColor.RED + sender.getName() + " - Banned the IP " + ip); return true; } } \ No newline at end of file diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_bird.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_bird.java index 06b52272..07f4d76a 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_bird.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_bird.java @@ -20,7 +20,7 @@ public class Command_bird extends FreedomCommand { Location location = playerSender.getTargetBlock(null, 15).getLocation().add(0, 1, 0); playerSender.getWorld().spawnEntity(location, getRandomFish()); - msg(":goodbird:"); + msgNew(":goodbird:"); 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 bd1fec04..5fff5459 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 @@ -5,7 +5,7 @@ import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.PunishmentType; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; -import org.bukkit.ChatColor; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -36,7 +36,8 @@ public class Command_blockcmd extends FreedomCommand playerdata.setCommandsBlocked(false); } } - msg("Unblocked commands for " + counter + " players."); + + msgNew("Unblocked commands for players.", Placeholder.unparsed("count", String.valueOf(counter))); return true; } @@ -53,10 +54,10 @@ public class Command_blockcmd extends FreedomCommand counter += 1; plugin.pl.getPlayer(player).setCommandsBlocked(true); - msg(player, "Your commands have been blocked by an admin.", ChatColor.RED); + msgNew(player, "Your commands have been blocked by an admin."); } - msg("Blocked commands for " + counter + " players."); + msgNew("Blocked commands for players.", Placeholder.unparsed("count", String.valueOf(counter))); return true; } @@ -70,7 +71,7 @@ public class Command_blockcmd extends FreedomCommand if (isAdmin(player)) { - msg(player.getName() + " is an admin, and cannot have their commands blocked."); + msgNew(" is an admin, and cannot have their commands blocked.", Placeholder.unparsed("player", player.getName())); return true; } @@ -79,13 +80,13 @@ public class Command_blockcmd extends FreedomCommand { FUtil.adminAction(sender.getName(), "Blocking all commands for " + player.getName(), true); playerdata.setCommandsBlocked(true); - msg("Blocked commands for " + player.getName() + "."); + msgNew("Blocked commands for .", Placeholder.unparsed("player", player.getName())); plugin.pul.logPunishment(new Punishment(player.getName(), FUtil.getIp(player), sender.getName(), PunishmentType.BLOCKCMD, null)); } else { - msg("That players commands are already blocked.", ChatColor.RED); + msgNew("That player's commands are already blocked."); } return true; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_clownfish.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_clownfish.java index 95d9c572..cc29e261 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_clownfish.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_clownfish.java @@ -3,6 +3,7 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.api.ShopItem; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -16,20 +17,27 @@ public class Command_clownfish extends FreedomCommand @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (plugin.sh == null) { - sender.sendMessage(Component.text("The shop is currently disabled.")); + if (plugin.sh == null) + { + msgNew("Shop is currently disabled."); return true; } - if (plugin.pl.getData(playerSender).hasItem(ShopItem.CLOWN_FISH) && (!plugin.lp.CLOWNFISH_TOGGLE.contains(playerSender.getName()))) + if (plugin.pl.getData(playerSender).hasItem(ShopItem.CLOWN_FISH)) { playerSender.getInventory().addItem(plugin.sh.getClownFish()); - msg("You have been given a Clown Fish", ChatColor.GREEN); + msgNew("You have been given a .", Placeholder.unparsed("name", ShopItem.CLOWN_FISH.getName())); + } + else if (plugin.pl.getPlayer(playerSender).isClownfishDisabled()) + { + msgNew("An admin has disabled your ability to use the . Guess you were the clown after all.", + Placeholder.unparsed("name", ShopItem.CLOWN_FISH.getName())); } else { - msg("You do not own a Clown Fish or an admin has toggled your ability to use it. Purchase one from the shop.", ChatColor.RED); + msgNew("You don't own a ! Purchase one from the shop.", Placeholder.unparsed("name", ShopItem.CLOWN_FISH.getName())); } + return true; } } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_notes.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_notes.java index 5b6a2fb0..7a00be2c 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_notes.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_notes.java @@ -6,9 +6,9 @@ import java.util.List; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.rank.Rank; 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.StringUtils; -import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -17,7 +17,6 @@ import org.bukkit.entity.Player; @CommandParameters(description = "Manage notes for a player", usage = "/ | remove | clear>") public class Command_notes extends FreedomCommand { - @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { @@ -35,7 +34,7 @@ public class Command_notes extends FreedomCommand if (entry == null) { - msg("Can't find that user. If target is not logged in, make sure that you spelled the name exactly."); + msg(PLAYER_NOT_FOUND); return true; } @@ -50,16 +49,15 @@ public class Command_notes extends FreedomCommand { case "list": { - final StringBuilder noteList = new StringBuilder(); - noteList.append(ChatColor.GREEN).append("Player notes for ").append(playerData.getName()).append(":"); + msgNew("Player notes for :", Placeholder.unparsed("player", playerData.getName())); int id = 1; for (String note : playerData.getNotes()) { - String noteLine = id + ". " + note; - noteList.append("\n").append(ChatColor.GOLD).append(noteLine); + msgNew(". ", + Placeholder.unparsed("num", String.valueOf(id)), + Placeholder.unparsed("note", note)); id++; } - msg(noteList.toString()); return true; } @@ -72,7 +70,7 @@ public class Command_notes extends FreedomCommand String note = sender.getName() + ": " + StringUtils.join(ArrayUtils.subarray(args, 2, args.length), " "); playerData.addNote(note); plugin.pl.save(playerData); - msg("Note added.", ChatColor.GREEN); + msgNew("Note added."); return true; } @@ -90,7 +88,7 @@ public class Command_notes extends FreedomCommand } catch (NumberFormatException e) { - msg("Invalid number: " + args[2], ChatColor.RED); + msgNew("Invalid number: ", Placeholder.unparsed("num", args[2])); return true; } @@ -99,12 +97,13 @@ public class Command_notes extends FreedomCommand if (playerData.removeNote(id)) { plugin.pl.save(playerData); - msg("Note removed."); + msgNew("Note removed."); } else { - msg("No note with the ID of " + args[2] + " exists.", ChatColor.RED); + msgNew("No note with the ID of exists.", Placeholder.unparsed("id", args[2])); } + return true; } @@ -113,7 +112,7 @@ public class Command_notes extends FreedomCommand int count = playerData.getNotes().size(); playerData.clearNotes(); plugin.pl.save(playerData); - msg("Cleared " + count + " notes.", ChatColor.GREEN); + msgNew("Cleared notes.", Placeholder.unparsed("count", String.valueOf(count))); return true; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_op.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_op.java index cee92841..9bb0d5f6 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_op.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_op.java @@ -53,7 +53,7 @@ public class Command_op extends FreedomCommand } else { - msg("Either the player is already opped, or the player could not be found."); + msgNew("Either the player is already opped, or the player could not be found."); } return true; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_plugincontrol.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_plugincontrol.java index e92a29b0..08775f97 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_plugincontrol.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_plugincontrol.java @@ -2,6 +2,10 @@ package me.totalfreedom.totalfreedommod.command; import java.util.*; import me.totalfreedom.totalfreedommod.rank.Rank; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.minimessage.tag.Tag; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -33,9 +37,11 @@ public class Command_plugincontrol extends FreedomCommand Arrays.stream(pm.getPlugins()).forEach(pl -> { final String version = pl.getDescription().getVersion(); - msg(ChatColor.GRAY + "- " + (pl.isEnabled() ? ChatColor.GREEN : ChatColor.RED) + pl.getName() - + ChatColor.GOLD + (!version.isEmpty() ? " v" + version : "") + " by " - + StringUtils.join(pl.getDescription().getAuthors(), ", ")); + msgNew("- by ", + TagResolver.resolver("statuscolor", Tag.styling(pl.isEnabled() ? NamedTextColor.GREEN : NamedTextColor.RED)), + Placeholder.unparsed("name", pl.getName()), + Placeholder.unparsed("version", version.isEmpty() ? " v" + version : ""), + Placeholder.unparsed("authors", StringUtils.join(pl.getDescription().getAuthors(), ", "))); }); return true; @@ -53,7 +59,7 @@ public class Command_plugincontrol extends FreedomCommand { if (pl.isEnabled()) { - msg(pl.getName() + " is already enabled."); + msgNew(" is already enabled.", Placeholder.unparsed("plugin", pl.getName())); return true; } @@ -61,11 +67,11 @@ public class Command_plugincontrol extends FreedomCommand if (pl.isEnabled()) { - msg(pl.getName() + " is now enabled."); + msgNew(" is now enabled.", Placeholder.unparsed("plugin", pl.getName())); } else { - msg("An error occurred whilst attempting to enable " + pl.getName() + "."); + msgNew("An error occurred whilst attempting to enable ", Placeholder.unparsed("plugin", pl.getName())); } return true; } @@ -73,32 +79,32 @@ public class Command_plugincontrol extends FreedomCommand { if (!pl.isEnabled()) { - msg(pl.getName() + " is already disabled."); + msgNew(" is already disabled.", Placeholder.unparsed("plugin", pl.getName())); return true; } else if (UNTOUCHABLE_PLUGINS.contains(pl.getName())) { - msg(pl.getName() + " can't be disabled."); + msgNew(" can't be disabled.", Placeholder.unparsed("plugin", pl.getName())); return true; } pm.disablePlugin(pl); - msg(pl.getName() + " is now disabled."); + msgNew(" is now disabled.", Placeholder.unparsed("plugin", pl.getName())); return true; } case "reload" -> { if (UNTOUCHABLE_PLUGINS.contains(pl.getName())) { - msg(pl.getName() + " can't be reloaded."); + msgNew(" can't be reloaded.", Placeholder.unparsed("plugin", pl.getName())); return true; } pm.disablePlugin(pl); pm.enablePlugin(pl); - msg(pl.getName() + " has been reloaded."); + msgNew(" has been reloaded.", Placeholder.unparsed("plugin", pl.getName()));; return true; } default -> @@ -109,7 +115,7 @@ public class Command_plugincontrol extends FreedomCommand } else { - msg("Plugin not found!"); + msgNew("Plugin not found!"); return true; } } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stop.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stop.java index 68414aab..1e2565d8 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stop.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stop.java @@ -21,7 +21,7 @@ public class Command_stop extends FreedomCommand @Override 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 = args.length == 0 ? "Server is going offline, come back in about 20 seconds." : StringUtils.join(args, " "); if (sender.getName().equals("CONSOLE")) { diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java index 461f6a16..f52db123 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java @@ -1,39 +1,37 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.List; - import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.FPlayer; 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.event.ClickEvent; +import net.kyori.adventure.text.event.HoverEvent; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; -import org.bukkit.ChatColor; -import org.bukkit.Color; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @CommandPermissions(rank = Rank.OP, source = SourceType.BOTH) -@CommandParameters(description = "Allows you to set your own prefix.", usage = "/ [-s[ave]] | list | gradient | off | clear | clearall>") +@CommandParameters(description = "Allows you to set your own prefix.", usage = "/ [-ns] | list | off | clear | clearall>") public class Command_tag extends FreedomCommand { - @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - - boolean save = false; + boolean save = true; if (args.length < 1) { return false; } - if (args[0].equals("-s") || args[0].equals("-save")) + if (args[0].equalsIgnoreCase("-ns")) { - save = true; + save = false; args = ArrayUtils.remove(args, 0); } @@ -146,142 +144,50 @@ public class Command_tag extends FreedomCommand { if (senderIsConsole) { - msg("\"/tag set\" can't be used from the console."); + msgNew("\"/tag set\" can't be used from the console."); return true; } final String inputTag = StringUtils.join(args, " ", 1, args.length); - final String strippedTag = StringUtils.replaceEachRepeatedly(StringUtils.strip(inputTag), - new String[] - { - "" + ChatColor.COLOR_CHAR, "&k" - }, - new String[] - { - "", "" - }); + Component tag; - final String outputTag = FUtil.colorize(strippedTag); + if (FUtil.containsChatColor(inputTag)) + { + tag = FUtil.colorizeAsComponent(inputTag.replace("&k", "")); + } + else + { + tag = FUtil.miniMessage(inputTag); + } + + String steamrolled = FUtil.steamroll(tag); int tagLimit = (plugin.al.isAdmin(sender) ? 30 : 20); - final String rawTag = ChatColor.stripColor(outputTag).toLowerCase(); - - if (rawTag.length() > tagLimit) + if (steamrolled.length() > tagLimit) { - msg("That tag is too long (Max is " + tagLimit + " characters)."); + msgNew("That tag is too long (Max is characters).", Placeholder.unparsed("max", String.valueOf(tagLimit))); return true; } - - if (!plugin.al.isAdmin(sender)) + else if (!plugin.al.isAdmin(sender) && ConfigEntry.FORBIDDEN_WORDS.getStringList().stream().anyMatch(word -> steamrolled.toLowerCase().contains(word))) { - for (String word : ConfigEntry.FORBIDDEN_WORDS.getStringList()) - { - if (rawTag.contains(word)) - { - msg("That tag contains a forbidden word."); - return true; - } - } - } - - plugin.pl.getPlayer(playerSender).setTag(outputTag); - - if (save) - { - save(playerSender, strippedTag); - } - - msg("Tag set to '" + outputTag + ChatColor.GRAY + "'." + (save ? " (Saved)" : "")); - return true; - } - - case "gradient": - { - if (senderIsConsole) - { - msg("\"/tag gradient\" can't be used from the console."); + msgNew("That tag contains a forbidden word."); return true; } - - if (args.length < 4) + else { - return false; - } + String flattened = FUtil.miniMessage(tag); - String from = "", to = ""; - java.awt.Color awt1, awt2; + plugin.pl.getPlayer(playerSender).setTag(flattened); - try - { - if (args[1].equalsIgnoreCase("random") || args[1].equalsIgnoreCase("r")) + if (save) { - awt1 = FUtil.getRandomAWTColor(); - from = " (From: " + FUtil.getHexStringOfAWTColor(awt1) + ")"; - } - else - { - awt1 = java.awt.Color.decode(args[1]); + save(playerSender, flattened); } - if (args[2].equalsIgnoreCase("random") || args[2].equalsIgnoreCase("r")) - { - awt2 = FUtil.getRandomAWTColor(); - to = " (To: " + FUtil.getHexStringOfAWTColor(awt2) + ")"; - } - else - { - awt2 = java.awt.Color.decode(args[2]); - } + msgNew("Tag set to '' ", + Placeholder.component("tag", tag.hoverEvent(HoverEvent.showText(Component.translatable("chat.copy"))) + .clickEvent(ClickEvent.copyToClipboard(flattened))), + Placeholder.unparsed("saved", save ? "(Saved)" : "")); } - catch (NumberFormatException ex) - { - msg("Invalid hex values."); - return true; - } - - Color c1 = FUtil.fromAWT(awt1); - Color c2 = FUtil.fromAWT(awt2); - String tag = StringUtils.join(args, " ", 3, args.length); - List gradient = FUtil.createColorGradient(c1, c2, tag.length()); - String[] splitTag = tag.split(""); - - for (int i = 0; i < splitTag.length; i++) - { - splitTag[i] = net.md_5.bungee.api.ChatColor.of(FUtil.toAWT(gradient.get(i))) + splitTag[i]; - } - - tag = StringUtils.join(splitTag, ""); - final String outputTag = FUtil.colorize(tag); - - int tagLimit = (plugin.al.isAdmin(sender) ? 30 : 20); - - final String rawTag = ChatColor.stripColor(outputTag).toLowerCase(); - - if (rawTag.length() > tagLimit) - { - msg("That tag is too long (Max is " + tagLimit + " characters)."); - return true; - } - - if (!plugin.al.isAdmin(sender)) - { - for (String word : ConfigEntry.FORBIDDEN_WORDS.getStringList()) - { - if (rawTag.contains(word)) - { - msg("That tag contains a forbidden word."); - return true; - } - } - } - - plugin.pl.getPlayer(playerSender).setTag(outputTag); - - if (save) - { - save(playerSender, tag); - } - - msg("Tag set to '" + outputTag + ChatColor.GRAY + "'." + (save ? " (Saved)" : "") + from + to); return true; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tagrainbow.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tagrainbow.java deleted file mode 100644 index 98b86bc6..00000000 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tagrainbow.java +++ /dev/null @@ -1,51 +0,0 @@ -package me.totalfreedom.totalfreedommod.command; - -import me.totalfreedom.totalfreedommod.config.ConfigEntry; -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 = "Give yourself a prefix with rainbow colors.", usage = "/ ") -public class Command_tagrainbow extends FreedomCommand -{ - - @Override - public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - if (args.length < 1) - { - return false; - } - - final String tag = ChatColor.stripColor(FUtil.colorize(StringUtils.join(args, " "))); - - if (!plugin.al.isAdmin(sender)) - { - final String rawTag = ChatColor.stripColor(tag).toLowerCase(); - - if (rawTag.length() > 20) - { - msg("That tag is too long (Max is 20 characters)."); - return true; - } - - for (String word : ConfigEntry.FORBIDDEN_WORDS.getStringList()) - { - if (rawTag.contains(word)) - { - msg("That tag contains a forbidden word."); - return true; - } - } - } - - plugin.pl.getPlayer(playerSender).setTag(FUtil.rainbowify(tag)); - msg("Set tag to " + tag); - return true; - } -} \ No newline at end of file diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java index 7b8ea040..debcdc4e 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java @@ -29,11 +29,8 @@ public class Command_toggle extends FreedomCommand { if (args.length == 0) { - msg("Available toggles: "); - for (String toggle : toggles) - { - msg("- " + toggle); - } + msgNew("Available toggles: "); + toggles.forEach(toggle -> msgNew("- ", Placeholder.unparsed("toggle", toggle))); return false; } @@ -70,7 +67,7 @@ public class Command_toggle extends FreedomCommand } catch (NumberFormatException ex) { - msg("The input provided is not a valid integer."); + msgNew("The input provided is not a valid integer."); return true; } } @@ -106,7 +103,7 @@ public class Command_toggle extends FreedomCommand } catch (NumberFormatException ex) { - msg("The input provided is not a valid integer."); + msgNew("The input provided is not a valid integer."); return true; } } @@ -139,11 +136,8 @@ public class Command_toggle extends FreedomCommand case "chat" -> toggle("Chat is", ConfigEntry.TOGGLE_CHAT); default -> { - msg("Available toggles: "); - for (String toggle : toggles) - { - msg("- " + toggle); - } + msgNew("Available toggles: "); + toggles.forEach(toggle -> msgNew("- ", Placeholder.unparsed("toggle", toggle))); return false; } } @@ -152,7 +146,8 @@ public class Command_toggle extends FreedomCommand private void toggle(final String name, final ConfigEntry entry) { - msg(name + " now " + (entry.setBoolean(!entry.getBoolean()) ? "enabled." : "disabled.")); + msgNew(" now .", Placeholder.unparsed("name", name), Placeholder.unparsed("status", + entry.setBoolean(!entry.getBoolean()) ? "enabled" : "disabled")); } @Override diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggleclownfish.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggleclownfish.java index 74f5a278..d1ed7d27 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggleclownfish.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggleclownfish.java @@ -1,6 +1,8 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.rank.Rank; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -9,7 +11,6 @@ import org.bukkit.entity.Player; @CommandParameters(description = "Toggle whether or not a player has the ability to use clownfish", usage = "/ ", aliases = "togglecf") public class Command_toggleclownfish extends FreedomCommand { - @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { @@ -18,19 +19,19 @@ public class Command_toggleclownfish extends FreedomCommand return false; } - boolean enabled = plugin.lp.CLOWNFISH_TOGGLE.contains(args[0]); - - if (enabled) + Player player = server.getPlayer(args[0]); + if (player == null) { - plugin.lp.CLOWNFISH_TOGGLE.remove(args[0]); - } - else - { - plugin.lp.CLOWNFISH_TOGGLE.add(args[0]); + msg(PLAYER_NOT_FOUND); + return true; } - msg(args[0] + " will " + (enabled ? "now" : "no longer") + " have the ability to use clownfish."); + FPlayer fplayer = plugin.pl.getPlayer(player); + fplayer.setClownfishDisabled(!fplayer.isClownfishDisabled()); + msgNew(" will have the ability to use the Clownfish.", + Placeholder.unparsed("player", args[0]), + Placeholder.unparsed("status", fplayer.isClownfishDisabled() ? "no longer" : "now")); return true; } } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tossmob.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tossmob.java index a4dd5eb9..5d19f8d9 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tossmob.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tossmob.java @@ -6,7 +6,7 @@ import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.Groups; -import org.bukkit.ChatColor; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -24,7 +24,7 @@ public class Command_tossmob extends FreedomCommand { if (!ConfigEntry.TOSSMOB_ENABLED.getBoolean()) { - msg("Tossmob is currently disabled."); + msgNew("Tossmob is currently disabled."); return true; } @@ -39,13 +39,13 @@ public class Command_tossmob extends FreedomCommand if (args[0].equalsIgnoreCase("off")) { playerData.disableMobThrower(); - msg("Turned off.", ChatColor.GREEN); + msgNew("Tossmob has been turned off."); return true; } if (args[0].equalsIgnoreCase("list")) { - msg("Supported mobs: " + Groups.MOB_TYPES.stream().map(Enum::name).toList(), ChatColor.GREEN); + msgNew("Supported mobs: ", Placeholder.unparsed("mobs", String.join(", ", Groups.MOB_TYPES.stream().map(Enum::name).toList()))); return true; } @@ -60,13 +60,13 @@ public class Command_tossmob extends FreedomCommand if (type == null) { - msg("Unknown entity type: " + args[0], ChatColor.RED); + msgNew("Unknown entity type: ", Placeholder.unparsed("type", args[0])); return true; } if (!Groups.MOB_TYPES.contains(type)) { - msg(FUtil.formatName(type.name()) + " is an entity, however it is not a mob.", ChatColor.RED); + msgNew(" is an entity, however it is not a mob.", Placeholder.unparsed("entity", FUtil.formatName(type.name()))); return true; } @@ -79,7 +79,7 @@ public class Command_tossmob extends FreedomCommand } catch (NumberFormatException ex) { - msg("The input provided is not a valid integer."); + msgNew("The input provided is not a valid integer."); return true; } } @@ -94,9 +94,11 @@ public class Command_tossmob extends FreedomCommand } playerData.enableMobThrower(type, speed); - msg("MobThrower is enabled. Mob: " + type + " - Speed: " + speed + ".", ChatColor.GREEN); - msg("Right click while holding a " + Material.BONE.toString() + " to throw mobs!", ChatColor.GREEN); - msg("Type '/tossmob off' to disable. -By Madgeek1450", ChatColor.GREEN); + msgNew("Tossmob is enabled. Mob: - Speed: .", + Placeholder.unparsed("type", String.valueOf(type)), + Placeholder.unparsed("speed", String.valueOf(speed))); + msgNew("Right click while holding a Bone to throw mobs!"); + msgNew("Type '/tossmob off' to disable. - By Madgeek1450"); Objects.requireNonNull(playerSender.getEquipment()).setItemInMainHand(new ItemStack(Material.BONE, 1)); return true; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unban.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unban.java index 1b77cbbe..6edbef12 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unban.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unban.java @@ -4,6 +4,7 @@ import com.earth2me.essentials.User; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -45,14 +46,15 @@ public class Command_unban extends FreedomCommand FUtil.adminAction(sender.getName(), "Unbanning " + username, true); plugin.bm.removeBan(plugin.bm.getByUsername(username)); plugin.bm.removeBan(plugin.bm.getByIp(ip)); - msg(username + " has been unbanned along with the IP: " + ip); + msgNew(" has been unbanned along with the IP: ", + Placeholder.unparsed("player", username), Placeholder.unparsed("ip", ip)); - if (args.length >= 2) + if (args.length >= 2 && plugin.cpb.isEnabled()) { if (args[1].equalsIgnoreCase("-r")) { plugin.cpb.restore(username); - msg("Restored edits for: " + username); + msgNew("Restored 's edits as well.", Placeholder.unparsed("player", username)); } } return true; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unbanip.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unbanip.java index 1824a10f..ca2741a6 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unbanip.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unbanip.java @@ -3,13 +3,14 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.banning.Ban; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @CommandPermissions(rank = Rank.ADMIN, source = SourceType.BOTH) -@CommandParameters(description = "Unbans the specified ip.", usage = "/ [-q]") +@CommandParameters(description = "Unbans the specified IP.", usage = "/ [-q]") public class Command_unbanip extends FreedomCommand { @@ -27,7 +28,7 @@ public class Command_unbanip extends FreedomCommand if (FUtil.isValidIPv4(ip)) { - msg(ip + " is not a valid IP address", ChatColor.RED); + msgNew(" is not a valid IP address.", Placeholder.unparsed("ip", ip)); return true; } @@ -35,13 +36,13 @@ public class Command_unbanip extends FreedomCommand if (ban == null) { - msg("The ip " + ip + " is not banned", ChatColor.RED); + msgNew(" is not a banned IP address.", Placeholder.unparsed("ip", ip)); return true; } if (ban.hasUsername()) { - msg("This ban is not an ip-only ban."); + msgNew("This ban is not an IP-only ban."); return true; } @@ -54,7 +55,9 @@ public class Command_unbanip extends FreedomCommand if (!silent) { - FUtil.adminAction(sender.getName(), "Unbanned the ip " + ip, true); + plugin.cm.broadcastSplit(" - Unbanned the IP ", " - Unbanned an IP", + Placeholder.unparsed("sender", sender.getName()), + Placeholder.unparsed("ip", ip)); } return true; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unbanname.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unbanname.java index 83a23470..e0439f6d 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unbanname.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unbanname.java @@ -3,6 +3,7 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.banning.Ban; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -29,13 +30,12 @@ public class Command_unbanname extends FreedomCommand if (ban == null) { - msg("The name " + name + " is not banned", ChatColor.RED); + msgNew("The name is not banned.", Placeholder.unparsed("name", name)); return true; } - - if (ban.hasIps()) + else if (ban.hasIps()) { - msg("This ban is not a name-only ban."); + msgNew("This ban is not a name-only ban."); return true; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unblockcmd.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unblockcmd.java index 2d8c5076..a23ad8a7 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unblockcmd.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unblockcmd.java @@ -33,11 +33,11 @@ public class Command_unblockcmd extends FreedomCommand { fPlayer.setCommandsBlocked(false); FUtil.adminAction(sender.getName(), "Unblocking all commands for " + player.getName(), true); - msg("Unblocked commands for " + player.getName() + "."); + msgNew("Unblocked commands for ."); } else { - msg("That players commands aren't blocked.", ChatColor.RED); + msgNew("That player's commands aren't blocked."); } return true; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_uncage.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_uncage.java index f0241de9..b6d3c400 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_uncage.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_uncage.java @@ -37,7 +37,7 @@ public class Command_uncage extends FreedomCommand } else { - msg("That player is not caged!", ChatColor.RED); + msgNew("That player is not caged!"); } return true; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_undisguiseall.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_undisguiseall.java index 83410f3a..0a90045f 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_undisguiseall.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_undisguiseall.java @@ -15,7 +15,7 @@ public class Command_undisguiseall extends FreedomCommand { if (!plugin.ldb.isEnabled()) { - msg("LibsDisguises is not enabled."); + msgNew("LibsDisguises is not enabled."); return true; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unlinkdiscord.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unlinkdiscord.java index d858e50f..445c1d28 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unlinkdiscord.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unlinkdiscord.java @@ -2,6 +2,7 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.rank.Rank; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -17,7 +18,7 @@ public class Command_unlinkdiscord extends FreedomCommand { if (plugin.dc == null || !plugin.dc.isEnabled()) { - msg("The Discord integration system is currently disabled.", ChatColor.RED); + msgNew("The Discord integration system is currently disabled."); return true; } @@ -31,19 +32,19 @@ public class Command_unlinkdiscord extends FreedomCommand } playerData.setDiscordID(null); - msg("Unlinked " + args[0] + "'s Discord account.", ChatColor.GREEN); + msgNew("Unlinked 's Discord account.", Placeholder.unparsed("player", playerData.getName())); return true; } PlayerData data = plugin.pl.getData(playerSender); if (data.getDiscordID() == null) { - msg("Your Minecraft account is not linked to a Discord account.", ChatColor.RED); + msgNew("Your Minecraft account is not linked to a Discord account."); return true; } data.setDiscordID(null); plugin.pl.save(data); - msg("Your Minecraft account has been successfully unlinked from the Discord account.", ChatColor.GREEN); + msgNew("Your Minecraft account has been successfully unlinked from the Discord account."); return true; } } \ No newline at end of file diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unmute.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unmute.java index a2c0b505..9152e337 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unmute.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unmute.java @@ -3,6 +3,7 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.apache.commons.lang3.ArrayUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -13,7 +14,6 @@ import org.bukkit.entity.Player; @CommandParameters(description = "Unmutes a player", usage = "/ [-q] ") public class Command_unmute extends FreedomCommand { - @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { @@ -45,22 +45,25 @@ public class Command_unmute extends FreedomCommand if (playerdata.isMuted()) { playerdata.setMuted(false); - player.sendTitle(ChatColor.RED + "You've been unmuted.", ChatColor.YELLOW + "Be sure to follow the rules!", 20, 100, 60); + FUtil.playerTitle(sender, "You have been unmuted.", "Be sure to follow the rules!"); + msgNew("You have been unmuted."); if (quiet) { - msg("Unmuted " + player.getName() + " quietly"); + msgNew("Quietly unmuted .", Placeholder.unparsed("player", player.getName())); return true; } - - FUtil.adminAction(sender.getName(), "Unmuting " + player.getName(), true); - msg("Unmuted " + player.getName()); - msg(player, "You have been unmuted.", ChatColor.RED); + else + { + FUtil.adminAction(sender.getName(), "Unmuting " + player.getName(), true); + msgNew("Unmuted .", Placeholder.unparsed("player", player.getName())); + } } else { - msg(ChatColor.RED + "That player is not muted."); + msgNew("That player is not muted."); } + return true; } } \ No newline at end of file diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vanish.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vanish.java index 79c9f1d9..ca5d6ae8 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vanish.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vanish.java @@ -8,6 +8,7 @@ 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 net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -38,11 +39,11 @@ public class Command_vanish extends FreedomCommand { if (silent) { - msg(ChatColor.GOLD + "Silently unvanished."); + msgNew("Silently unvanished."); } else { - msg("You have unvanished.", ChatColor.GOLD); + msgNew("You have unvanished."); FUtil.bcastMsg(plugin.rm.craftLoginMessage(playerSender, null)); server.broadcast(Component.translatable("multiplayer.player.joined", Component.text(playerSender.getName())) .color(NamedTextColor.YELLOW)); @@ -59,16 +60,11 @@ public class Command_vanish extends FreedomCommand } plugin.pl.getData(playerSender).setTag(tag); - FLog.info(playerSender.getName() + " is no longer vanished."); - plugin.al.messageAllAdmins(ChatColor.YELLOW + sender.getName() + " has unvanished and is now visible to everyone."); + plugin.cm.messageAllAdmins(" has unvanished and is now visible to everyone.", Placeholder.unparsed("player", sender.getName())); + + server.getOnlinePlayers().stream().filter(player -> !plugin.al.isAdmin(player)).forEach(player -> + player.showPlayer(plugin, playerSender)); - for (Player player : server.getOnlinePlayers()) - { - if (!plugin.al.isAdmin(player)) - { - player.showPlayer(plugin, playerSender); - } - } plugin.esb.setVanished(playerSender.getName(), false); playerSender.setPlayerListName(StringUtils.substring(displayName, 0, 16)); AdminList.vanished.remove(playerSender.getUniqueId()); @@ -93,11 +89,11 @@ public class Command_vanish extends FreedomCommand if (silent) { - msg("Silently vanished.", ChatColor.GOLD); + msgNew("Silently vanished."); } else { - msg("You have vanished.", ChatColor.GOLD); + msgNew("You have vanished."); server.broadcast(Component.translatable("multiplayer.player.left", Component.text(playerSender.getName())) .color(NamedTextColor.YELLOW)); if (plugin.dc != null) { @@ -105,8 +101,7 @@ public class Command_vanish extends FreedomCommand } } - FLog.info(playerSender.getName() + " is now vanished."); - plugin.al.messageAllAdmins(ChatColor.YELLOW + sender.getName() + " has vanished and is now only visible to admins."); + plugin.cm.messageAllAdmins(" has vanished and is now only visible to admins.", Placeholder.unparsed("player", sender.getName())); server.getOnlinePlayers().stream().filter(player -> !plugin.al.isAdmin(player)).forEach(player -> player.hidePlayer(plugin,playerSender)); 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 239c811a..465ae56d 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 @@ -22,7 +22,7 @@ public class Command_vote extends FreedomCommand if (voteInfo.isEmpty()) { - msg(Component.text("The voting information section of the config.yml file has not been configured.", NamedTextColor.RED)); + msgNew("The voting information section of the config.yml file has not been configured."); } else { diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_warn.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_warn.java index 90f7fa46..35726917 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_warn.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_warn.java @@ -61,9 +61,7 @@ public class Command_warn extends FreedomCommand } String warnReason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " "); - player.showTitle(Title.title(Component.text("You have been warned.", NamedTextColor.RED), - Component.text("Reason: " + warnReason, NamedTextColor.YELLOW), - Title.Times.times(Duration.ofSeconds(1), Duration.ofSeconds(5), Duration.ofSeconds(3)))); + FUtil.playerTitle(player, "You have been warned.", "Reason: ", Placeholder.unparsed("reason", warnReason)); msgNew("[WARNING] You received a warning from : ", Placeholder.unparsed("sender", sender.getName()), Placeholder.unparsed("reason", warnReason)); plugin.pl.getPlayer(player).incrementWarnings(quiet); plugin.pul.logPunishment(new Punishment(player.getName(), FUtil.getIp(player), sender.getName(), PunishmentType.WARN, warnReason)); @@ -74,15 +72,10 @@ public class Command_warn extends FreedomCommand } else { - String adminNotice = ChatColor.RED + - sender.getName() + - " - " + - "Warning: " + - player.getName() + - " - Reason: " + - ChatColor.YELLOW + - warnReason; - plugin.al.messageAllAdmins(adminNotice); + plugin.cm.messageAllAdmins(" - Warning: - Reason: ", + Placeholder.unparsed("sender", sender.getName()), + Placeholder.unparsed("player", player.getName()), + Placeholder.unparsed("reason", warnReason)); msgNew("You have successfully warned .", Placeholder.unparsed("player", player.getName())); } 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 83bbffcc..b01560c4 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java @@ -133,11 +133,13 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter player.sendMessage(ChatColor.GRAY + message); } + @Deprecated protected void msg(Player player, String message, ChatColor color) { player.sendMessage(color + message); } + @Deprecated protected void msg(String message) { msg(sender, message); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java index 10877034..e9c5ae45 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java @@ -228,7 +228,7 @@ public class ItemFun extends FreedomService final int RADIUS_HIT = 5; final int STRENGTH = 4; - if (plugin.lp.CLOWNFISH_TOGGLE.contains(player.getName())) + if (plugin.pl.getPlayer(player).isClownfishDisabled()) { player.sendMessage(ChatColor.GRAY + "An admin has disabled your ability to use clownfish."); break; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/player/FPlayer.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/player/FPlayer.java index d1f74e10..238b145d 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/player/FPlayer.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/player/FPlayer.java @@ -63,6 +63,8 @@ public class FPlayer private boolean invSee = false; + private boolean clownfishDisabled = false; + public FPlayer(TotalFreedomMod plugin, Player player) { this(plugin, player.getUniqueId(), player.getName(), FUtil.getIp(player)); @@ -350,14 +352,7 @@ public class FPlayer public void setTag(String tag) { - if (tag == null) - { - this.tag = null; - } - else - { - this.tag = FUtil.colorize(tag) + ChatColor.WHITE; - } + this.tag = tag; } public void incrementWarnings(boolean quiet) @@ -442,6 +437,16 @@ public class FPlayer this.invSee = invSee; } + public boolean isClownfishDisabled() + { + return clownfishDisabled; + } + + public void setClownfishDisabled(boolean bool) + { + this.clownfishDisabled = bool; + } + private static class ArrowShooter extends BukkitRunnable { diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java index df39351c..0680fa52 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java @@ -167,7 +167,8 @@ public class RankManager extends FreedomService fPlayer.setTag(null); player.setPlayerListName(null); } - fPlayer.setTag(getTag(player, display.getColoredTag())); + // FIXME: Adjust Rank to use MiniMessage instead of the legacy stuff + fPlayer.setTag(getTag(player, FUtil.miniMessage(FUtil.colorizeAsComponent(display.getColoredTag())))); updatePlayerTeam(player); plugin.pem.setPermissions(player); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FConverter.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FConverter.java index 1d4affba..6a52fae8 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FConverter.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FConverter.java @@ -1,12 +1,10 @@ package me.totalfreedom.totalfreedommod.util; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; - import java.util.regex.Pattern; public class FConverter { - private static final Pattern godFuckingDamnit = Pattern.compile(".*(?i)(&((#[a-f0-9]{3,6})|([0-9a-fklmnopr]))|%[a-z]+%).*"); + private static final Pattern godFuckingDamnit = Pattern.compile(".*(?i)(&((#[a-f0-9]{3,6})|([0-9a-fklmnor]))|%[a-z]+%).*"); public static boolean needsConversion(String messageOrFormat) { @@ -15,18 +13,11 @@ public class FConverter public static String convertAdminChatFormat(String format) { - // %name% - // %rank% - // %rankcolor% - // %msg% - return FUtil.MINI_MESSAGE.serialize(FUtil.LEGACY_AMPERSAND.deserialize( format.replaceAll("%name%", "") .replaceAll("%rank%", "") .replaceAll("%rankcolor%", "") .replaceAll("%msg%", ""))) .replaceAll("\\\\<", "<"); // GOD FUCKING DAMMIT - - //zTagResolver.resolver("rankcolor", Tag.styling(lol -> lol.color())) } } 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 cb59cdbd..214a8859 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java @@ -9,6 +9,7 @@ import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import net.kyori.adventure.text.minimessage.tag.standard.StandardTags; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import net.kyori.adventure.title.Title; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.WordUtils; @@ -19,7 +20,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; -import org.jetbrains.annotations.Contract; import java.io.*; import java.lang.management.ManagementFactory; @@ -80,6 +80,8 @@ public class FUtil "Taahh", "G6_", "ayunami2000"); + + private static final PlainTextComponentSerializer STEAMROLLER = PlainTextComponentSerializer.plainText(); public static final LegacyComponentSerializer LEGACY_AMPERSAND = LegacyComponentSerializer.legacyAmpersand(); public static final MiniMessage MINI_MESSAGE = MiniMessage.builder().tags(TagResolver.resolver( StandardTags.color(), @@ -89,7 +91,6 @@ public class FUtil StandardTags.decorations(TextDecoration.BOLD), StandardTags.decorations(TextDecoration.STRIKETHROUGH), StandardTags.decorations(TextDecoration.UNDERLINED))).build(); - public static final Map CHAT_COLOR_NAMES = new HashMap<>(); public static final List CHAT_COLOR_POOL = Arrays.asList( ChatColor.DARK_RED, ChatColor.RED, @@ -103,15 +104,11 @@ public class FUtil ChatColor.DARK_BLUE, ChatColor.DARK_PURPLE, ChatColor.LIGHT_PURPLE); + private static final Pattern CHATCOLOR_PATTERN = Pattern.compile(".*(?i)(&((#[a-f0-9]{3,6})|([0-9a-fklmnor]))).*"); private static final SplittableRandom RANDOM = new SplittableRandom(); public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z"; private static final List regxList = Arrays.asList("y", "mo", "w", "d", "h", "m", "s"); - static - { - CHAT_COLOR_POOL.forEach(color -> CHAT_COLOR_NAMES.put(color.name().toLowerCase().replace("_", ""), color)); - } - public static void cancel(BukkitTask task) { if (task == null) @@ -498,6 +495,21 @@ public class FUtil return MINI_MESSAGE.deserialize(string, placeholders); } + public static String miniMessage(Component component) + { + return MINI_MESSAGE.serialize(component); + } + + public static String steamroll(Component text) + { + return STEAMROLLER.serialize(text); + } + + public static boolean containsChatColor(String input) + { + return CHATCOLOR_PATTERN.matcher(input).find(); + } + public static String stripColors(String string) { return string.replaceAll("§", "");