diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java index f244a341..b27e3e43 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java @@ -173,7 +173,8 @@ public class ChatManager extends FreedomService Placeholder.unparsed("rank", flatAbv), TagResolver.resolver("rankcolor", Tag.styling(getColor(display))), Placeholder.unparsed("message", message))); - } else + } + else { Component defaultFormat = FUtil.miniMessage("[ADMIN] ]: ", Placeholder.unparsed("", sender.getName()), diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandDependencies.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandDependencies.java new file mode 100644 index 00000000..349759e6 --- /dev/null +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandDependencies.java @@ -0,0 +1,10 @@ +package me.totalfreedom.totalfreedommod.command; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface CommandDependencies +{ + String[] value(); +} diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandLoader.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandLoader.java index ed3acd5f..d7cb4b94 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandLoader.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandLoader.java @@ -63,10 +63,25 @@ public class CommandLoader extends FreedomService Set> commandClasses = commandDir.getSubTypesOf(FreedomCommand.class); + commandLoading: for (Class commandClass : commandClasses) { try { + if (commandClass.isAnnotationPresent(CommandDependencies.class)) + { + String[] dependencies = commandClass.getAnnotation(CommandDependencies.class).value(); + + for (String plugin : dependencies) + { + if (!server.getPluginManager().isPluginEnabled(plugin)) + { + FLog.warning("Not loading command due to missing dependency (" + plugin + "): /" + commandClass.getSimpleName().replace("Command_", "")); + continue commandLoading; + } + } + } + add(commandClass.newInstance()); } catch (InstantiationException | IllegalAccessException | ExceptionInInitializerError ex) diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cleardiscordqueue.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cleardiscordqueue.java index 465ec89f..bd08aece 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cleardiscordqueue.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cleardiscordqueue.java @@ -4,8 +4,9 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@CommandDependencies({"TFD4J"}) @CommandPermissions(permission = "cleardiscordqueue", source = SourceType.ONLY_CONSOLE) -@CommandParameters(description = "Clear the discord message queue.", usage = "/") +@CommandParameters(description = "Clear the Discord message queue.", usage = "/") public class Command_cleardiscordqueue extends FreedomCommand { 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 9397c9a8..2dcf3f20 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 @@ -6,6 +6,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@CommandDependencies({"TF-Shoppe"}) @CommandPermissions(permission = "clownfish", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Obtain a clown fish", usage = "/") public class Command_clownfish extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_coins.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_coins.java index 9c94e11d..c9abb49f 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_coins.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_coins.java @@ -11,6 +11,7 @@ import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.List; +@CommandDependencies({"TF-Shoppe"}) @CommandPermissions(permission = "coins", source = SourceType.BOTH) @CommandParameters(description = "Shows the amount of coins you or another player has. Also allows you to give coins to other players.", usage = "/ [player] | pay ") public class Command_coins extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_fireball.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_fireball.java index afb0b859..bca7675b 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_fireball.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_fireball.java @@ -6,6 +6,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@CommandDependencies({"TF-Shoppe"}) @CommandPermissions(permission = "fireball", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Obtain a fire ball", usage = "/") public class Command_fireball extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_grapplinghook.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_grapplinghook.java index a1e12440..bd3b0ea5 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_grapplinghook.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_grapplinghook.java @@ -6,6 +6,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@CommandDependencies({"TF-Shoppe"}) @CommandPermissions(permission = "grapplinghook", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Obtain a grappling hook", usage = "/") public class Command_grapplinghook extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_lightningrod.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_lightningrod.java index a5001a2a..65d3f686 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_lightningrod.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_lightningrod.java @@ -6,6 +6,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@CommandDependencies({"TF-Shoppe"}) @CommandPermissions(permission = "lightningrod", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Obtain a lightning rod", usage = "/") public class Command_lightningrod extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_linkdiscord.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_linkdiscord.java index 989201aa..7c37f8d8 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_linkdiscord.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_linkdiscord.java @@ -6,6 +6,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@CommandDependencies({"TFD4J"}) @CommandPermissions(permission = "linkdiscord", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Link your Discord account to your Minecraft account", usage = "/ [ ]") public class Command_linkdiscord extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_loginmessage.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_loginmessage.java index 25a20019..3f35590e 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_loginmessage.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_loginmessage.java @@ -2,6 +2,8 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.api.ShopItem; import me.totalfreedom.totalfreedommod.player.PlayerData; +import me.totalfreedom.totalfreedommod.util.FUtil; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -30,21 +32,25 @@ public class Command_loginmessage extends FreedomCommand checkPermission("tfm.loginmessage.custom"); String message = StringUtils.join(args, " "); - if (!message.contains("%rank%") && !message.contains("%coloredrank%")) + if (!message.contains("") && !message.contains("")) { - msg("Your login message must contain your rank. Use either %rank% or %coloredrank% to specify where you want the rank", ChatColor.RED); + msgNew("Your login message must contain your rank. Use either \\\\ or \\\\ to specify where you want the rank."); return true; } - int length = message.replace("%name%", "").replace("%rank%", "").replace("%coloredrank%", "").replace("%art%", "").length(); + int length = FUtil.steamroll(FUtil.miniMessage(message, Placeholder.unparsed("name", ""), + Placeholder.unparsed("rank", ""), + Placeholder.unparsed("coloredrank", ""), + Placeholder.unparsed("art", ""))).length(); if (length > 100) { - msg("Your login message cannot be more than 100 characters (excluding your rank and your name)", ChatColor.RED); + msgNew("Your login message cannot be more than 100 characters (excluding your rank and your name)"); return true; } PlayerData data = getData(playerSender); data.setLoginMessage(message); plugin.pl.save(data); - msg("Your login message is now the following:\n" + plugin.rm.craftLoginMessage(playerSender, message), ChatColor.GREEN); + msgNew("Your login message is now the following:"); + msg(plugin.rm.craftLoginMessage(playerSender, message)); return true; } } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_manageshop.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_manageshop.java index 0b9f58b0..5e5e4ef8 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_manageshop.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_manageshop.java @@ -9,6 +9,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@CommandDependencies({"TF-Shoppe"}) @CommandPermissions(permission = "manageshop", source = SourceType.BOTH) @CommandParameters(description = "Manage the shop", usage = "/ | items: ", aliases = "ms") public class Command_manageshop extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mute.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mute.java index bfea71e2..0bbffaae 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mute.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mute.java @@ -12,7 +12,7 @@ import org.bukkit.entity.Player; import java.util.*; -@CommandPermissions(permission = "tfm.mute", source = SourceType.BOTH) +@CommandPermissions(permission = "mute", source = SourceType.BOTH) @CommandParameters(description = "Mutes a player with brute force.", usage = "/ <[-q] [reason] | list | purge | all>", aliases = "stfu") public class Command_mute extends FreedomCommand { diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_myadmin.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_myadmin.java index e10a70d0..449af1a1 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_myadmin.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_myadmin.java @@ -51,7 +51,7 @@ public class Command_myadmin extends FreedomCommand target = getAdmin(targetPlayer); if (target == null) { - msgNew("That player is not an admin"); + msgNew("That player is not an admin."); return true; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_plotworld.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_plotworld.java index 246930f4..2bfe28f3 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_plotworld.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_plotworld.java @@ -6,6 +6,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@CommandDependencies({"PlotSquared"}) @CommandPermissions(permission = "plotworld", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Go to the PlotWorld.", usage = "/", aliases = "pw") public class Command_plotworld extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rideablepearl.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rideablepearl.java index f974959a..6d82e39e 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rideablepearl.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rideablepearl.java @@ -6,6 +6,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@CommandDependencies({"TF-Shoppe"}) @CommandPermissions(permission = "rideablepearl", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Obtain a rideable ender pearl", usage = "/") public class Command_rideablepearl extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setlimit.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setlimit.java index 58f9f9f8..39f3bb41 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setlimit.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setlimit.java @@ -6,6 +6,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@CommandDependencies({"WorldEdit"}) @CommandPermissions(permission = "worldedit.limit", source = SourceType.BOTH) @CommandParameters(description = "Sets everyone's WorldEdit block modification limit to the default limit or to a custom limit.", usage = "/ [limit]", aliases = "setl,swl") public class Command_setlimit extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setplayerlimit.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setplayerlimit.java index 89f63db7..49e74903 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setplayerlimit.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setplayerlimit.java @@ -7,6 +7,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@CommandDependencies({"WorldEdit"}) @CommandPermissions(permission = "worldedit.limit.other", source = SourceType.BOTH) @CommandParameters(description = "Sets a specific player's WorldEdit block modification limit to the default limit or to a custom limit.", usage = "/ [limit]", aliases = "setpl,spl") public class Command_setplayerlimit extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_shop.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_shop.java index 7188eefa..93621dc5 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_shop.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_shop.java @@ -5,6 +5,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@CommandDependencies({"TF-Shoppe"}) @CommandPermissions(permission = "shop", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Open the shop GUI", usage = "/", aliases = "sh") public class Command_shop extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stackingpotato.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stackingpotato.java index 72eecaaf..9e539afe 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stackingpotato.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stackingpotato.java @@ -6,6 +6,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@CommandDependencies({"TF-Shoppe"}) @CommandPermissions(permission = "stackingpotato", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Obtain a stacking potato", usage = "/") public class Command_stackingpotato extends FreedomCommand 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 9c639fa3..be406793 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 @@ -40,27 +40,17 @@ public class Command_tag extends FreedomCommand { case "list": { - msg("Tags for all online players:"); - - for (final Player player : server.getOnlinePlayers()) - { - if (plugin.al.isVanished(player.getUniqueId()) && !plugin.al.isAdmin(sender)) - { - continue; - } - - final FPlayer playerdata = plugin.pl.getPlayer(player); - if (playerdata.getTag() != null) - { - msg(player.getName() + ": " + playerdata.getTag()); - } - } + msgNew("Tags for all online players:"); + server.getOnlinePlayers().stream().filter(player -> !(plugin.al.isVanished(player.getUniqueId()) && !isAdmin(sender)) && plugin.pl.getPlayer(player).getTag() != null).forEach(player -> { + msgNew(": ", Placeholder.unparsed("player", player.getName()), + Placeholder.component("tag", plugin.pl.getPlayer(player).getTag())); + }); return true; } case "clearall": { - if (!plugin.al.isAdmin(sender)) + if (!sender.hasPermission("tfm.tag.clear.all")) { noPerms(); return true; @@ -79,7 +69,7 @@ public class Command_tag extends FreedomCommand } } - msg(count + " tag(s) removed."); + msgNew(" tag(s) removed.", Placeholder.unparsed("count", String.valueOf(count))); return true; } @@ -87,8 +77,9 @@ public class Command_tag extends FreedomCommand { if (senderIsConsole) { - msg("\"/tag off\" can't be used from the console. Use \"/tag clear \" or \"/tag clearall\" instead."); - } else + msgNew("\"/tag off\" can't be used from the console."); + } + else { plugin.pl.getPlayer(playerSender).setTag(null); @@ -97,7 +88,8 @@ public class Command_tag extends FreedomCommand save(playerSender, null); } - msg("Your tag has been removed." + (save ? " (Saved)" : "")); + msgNew("Your tag has been removed. ", + Placeholder.unparsed("saved", save ? "(Saved)" : "")); } return true; } @@ -107,13 +99,14 @@ public class Command_tag extends FreedomCommand return false; } } - } else if (args.length >= 2) + } + else if (args.length >= 2) { switch (args[0].toLowerCase()) { case "clear": { - if (!plugin.al.isAdmin(sender)) + if (!sender.hasPermission("tfm.tag.clear.others")) { noPerms(); return true; @@ -133,7 +126,9 @@ public class Command_tag extends FreedomCommand save(player, null); } - msg("Removed " + player.getName() + "'s tag." + (save ? " (Saved)" : "")); + msgNew("Removed 's tag. ", + Placeholder.unparsed("player", player.getName()), + Placeholder.unparsed("saved", save ? "(Saved)" : "")); return true; } @@ -162,11 +157,13 @@ public class Command_tag extends FreedomCommand { msgNew("That tag is too long (Max is characters).", Placeholder.unparsed("max", String.valueOf(tagLimit))); return true; - } else if (!plugin.al.isAdmin(sender) && ConfigEntry.FORBIDDEN_WORDS.getStringList().stream().anyMatch(word -> steamrolled.toLowerCase().contains(word))) + } + else if (!plugin.al.isAdmin(sender) && ConfigEntry.FORBIDDEN_WORDS.getStringList().stream().anyMatch(word -> steamrolled.toLowerCase().contains(word))) { msgNew("That tag contains a forbidden word."); return true; - } else + } + else { plugin.pl.getPlayer(playerSender).setTag(tag); 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 1cdbaa6a..bd3387e6 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 @@ -6,6 +6,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@CommandDependencies({"TF-Shoppe"}) @CommandPermissions(permission = "clownfish.toggle", source = SourceType.BOTH) @CommandParameters(description = "Toggle whether or not a player has the ability to use clownfish", usage = "/ ", aliases = "togglecf") public class Command_toggleclownfish extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_togglediscord.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_togglediscord.java index b7dfae02..b07452cd 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_togglediscord.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_togglediscord.java @@ -6,6 +6,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@CommandDependencies({"TFD4J"}) @CommandPermissions(permission = "discord.toggle", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Toggle the display of Discord messages in-game.", usage = "/", aliases = "tdiscord,tdisc") public class Command_togglediscord extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_trail.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_trail.java index 0c3ad310..41ab266f 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_trail.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_trail.java @@ -6,8 +6,9 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@CommandDependencies({"TF-Shoppe"}) @CommandPermissions(permission = "trail", source = SourceType.ONLY_IN_GAME) -@CommandParameters(description = "Trails rainbow wool behind you as you walk/fly.", usage = "/") +@CommandParameters(description = "Trails rainbow particles behind you as you walk/fly.", usage = "/") public class Command_trail extends FreedomCommand { 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 0dae38f5..87739ee3 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 @@ -5,6 +5,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@CommandDependencies({"LibsDisguises"}) @CommandPermissions(permission = "undisguiseall", source = SourceType.BOTH) @CommandParameters(description = "Undisguise all online players on the server", usage = "/ [-a]", aliases = "uall") public class Command_undisguiseall extends FreedomCommand 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 5f68d8b4..4549f614 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 @@ -6,6 +6,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@CommandDependencies({"TFD4J"}) @CommandPermissions(permission = "unlinkdiscord", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Unlink your Discord account from your Minecraft account", usage = "/ [player]") public class Command_unlinkdiscord extends FreedomCommand 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 5643f724..742f4246 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 @@ -34,7 +34,7 @@ public class Command_vanish extends FreedomCommand else { msgNew("You have unvanished."); - FUtil.bcastMsg(plugin.rm.craftLoginMessage(playerSender, null)); + server.broadcast(plugin.rm.craftLoginMessage(playerSender, null)); server.broadcast(Component.translatable("multiplayer.player.joined", Component.text(playerSender.getName())) .color(NamedTextColor.YELLOW)); 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 d3309580..ba21ec2e 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java @@ -391,7 +391,7 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter public boolean permissionCheck() { - if (!sender.hasPermission(permission) || !(sender instanceof ConsoleCommandSender)) + if (!sender.hasPermission(permission) || !source.permissionCheck(sender)) { msg(ChatColor.RED + "You do not have permission to use this command."); return true; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/SourceType.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/SourceType.java index 20dc8211..7a678bd3 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/SourceType.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/SourceType.java @@ -1,6 +1,15 @@ package me.totalfreedom.totalfreedommod.command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; + public enum SourceType { - ONLY_IN_GAME, ONLY_CONSOLE, BOTH + ONLY_IN_GAME, ONLY_CONSOLE, BOTH; + + public boolean permissionCheck(CommandSender sender) + { + return (sender instanceof Player && this == ONLY_IN_GAME) || (sender instanceof ConsoleCommandSender && this == ONLY_CONSOLE) || this == BOTH; + } } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerData.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerData.java index f595357c..2872a2f8 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerData.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerData.java @@ -1,10 +1,13 @@ package me.totalfreedom.totalfreedommod.player; +import com.google.common.base.Strings; import com.google.common.collect.Lists; import me.totalfreedom.totalfreedommod.api.ShopItem; +import me.totalfreedom.totalfreedommod.util.FConverter; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; @@ -50,7 +53,7 @@ public class PlayerData ips.addAll(FUtil.stringToList(resultSet.getString("ips"))); notes.clear(); notes.addAll(FUtil.stringToList(resultSet.getString("notes"))); - tag = LegacyComponentSerializer.legacyAmpersand().deserialize(resultSet.getString("tag")); + tag = FUtil.miniMessage(resultSet.getString("tag")); discordID = resultSet.getString("discord_id"); masterBuilder = resultSet.getBoolean("master_builder"); rideMode = RideMode.valueOf(resultSet.getString("ride_mode").toUpperCase()); @@ -59,11 +62,19 @@ public class PlayerData items.addAll(FUtil.stringToList(resultSet.getString("items"))); totalVotes = resultSet.getInt("total_votes"); displayDiscord = resultSet.getBoolean("display_discord"); - loginMessage = resultSet.getString("login_message"); + //-- + String tempLoginMessage = resultSet.getString("login_message"); + if (!Strings.isNullOrEmpty(tempLoginMessage) && FConverter.needsConversion(tempLoginMessage)) + { + tempLoginMessage = FConverter.convertLoginMessage(tempLoginMessage); + } + loginMessage = tempLoginMessage; + //-- inspect = resultSet.getBoolean("inspect"); } catch (SQLException e) { FLog.severe("Failed to load player: " + e.getMessage()); + e.printStackTrace(); } } @@ -190,7 +201,7 @@ public class PlayerData objectMap.put("uuid", uuid.toString()); objectMap.put("ips", FUtil.listToString(ips)); objectMap.put("notes", FUtil.listToString(notes)); - objectMap.put("tag", tag.toString()); + objectMap.put("tag", FUtil.miniMessage(tag)); objectMap.put("discord_id", discordID); objectMap.put("master_builder", masterBuilder); objectMap.put("ride_mode", rideMode.name()); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/DisplayableGroup.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/DisplayableGroup.java index cfdedaa3..73c56960 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/DisplayableGroup.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/DisplayableGroup.java @@ -59,7 +59,7 @@ public class DisplayableGroup implements Displayable cfg.thenAcceptAsync(g -> { WeightNode weightNode = WeightNode.builder(weight).build(); - PrefixNode prefixNode = PrefixNode.builder().prefix(FUtil.miniMessage(GroupProvider.OPEN.append(tag.color(color)).append(GroupProvider.CLOSE))).build(); + PrefixNode prefixNode = PrefixNode.builder().prefix(FUtil.miniMessage(GroupProvider.OPEN.append(tag.color(color)).append(GroupProvider.CLOSE))).priority(1).build(); g.getData(DataType.NORMAL).add(prefixNode); g.getData(DataType.NORMAL).add(weightNode); }).join(); // Block until the group is created and loaded. 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 6dc97357..6cdc1155 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java @@ -7,6 +7,8 @@ import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.Component; +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.CommandSender; @@ -165,11 +167,12 @@ public class RankManager extends FreedomService FPlayer fPlayer = plugin.pl.getPlayer(player); PlayerData data = plugin.pl.getData(player); Displayable display = getDisplay(player); + if (plugin.al.isAdmin(player) || data.isMasterBuilder() || FUtil.isDeveloper(player)) { - String displayName = display.getColor() + player.getName(); - player.setPlayerListName(displayName); - } else + player.playerListName(Component.text(player.getName()).color(display.getColor())); + } + else { fPlayer.setTag(null); player.setPlayerListName(null); @@ -203,7 +206,7 @@ public class RankManager extends FreedomService if ((isAdmin || FUtil.isDeveloper(player) || plugin.pl.getData(player).isMasterBuilder() || plugin.pl.getData(player).hasLoginMessage()) && !plugin.al.isVanished(player.getUniqueId())) { - FUtil.bcastMsg(craftLoginMessage(player, null)); + server.broadcast(craftLoginMessage(player, null)); } // Set display @@ -215,7 +218,7 @@ public class RankManager extends FreedomService } } - public String craftLoginMessage(Player player, String message) + public Component craftLoginMessage(Player player, String message) { Displayable display = plugin.rm.getDisplay(player); PlayerData playerData = plugin.pl.getData(player); @@ -224,21 +227,22 @@ public class RankManager extends FreedomService if (playerData.hasLoginMessage()) { message = playerData.getLoginMessage(); - } else + } + else { if (display.hasDefaultLoginMessage()) { - message = "%name% is %art% %coloredrank%"; + message = " is "; } } } if (message != null) { - return FUtil.colorize(ChatColor.AQUA + (message.contains("%name%") ? "" : player.getName() + " is ") - + FUtil.colorize(message).replace("%name%", player.getName()) - .replace("%rank%", FUtil.miniMessage(display.getName())) - .replace("%coloredrank%", FUtil.miniMessage(display.getColoredName())) - .replace("%art%", FUtil.miniMessage(display.getArticle()))); + return FUtil.miniMessage(message, + Placeholder.unparsed("name", player.getName()), + Placeholder.component("rank", display.getName()), + Placeholder.component("coloredrank", display.getColoredName()), + Placeholder.component("art", display.getArticle())); } return null; 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 6a52fae8..5d036827 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FConverter.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FConverter.java @@ -20,4 +20,14 @@ public class FConverter .replaceAll("%msg%", ""))) .replaceAll("\\\\<", "<"); // GOD FUCKING DAMMIT } + + public static String convertLoginMessage(String message) + { + return FUtil.MINI_MESSAGE.serialize(FUtil.LEGACY_AMPERSAND.deserialize( + message.replaceAll("%name%", "") + .replaceAll("%rank%", "") + .replaceAll("%coloredrank%", "") + .replaceAll("%art%", ""))) + .replaceAll("\\\\<", "<"); // GOD FUCKING DAMMIT + } } diff --git a/shop/src/main/java/me/totalfreedom/shop/Shop.java b/shop/src/main/java/me/totalfreedom/shop/Shop.java index 210cfa03..a853eb64 100644 --- a/shop/src/main/java/me/totalfreedom/shop/Shop.java +++ b/shop/src/main/java/me/totalfreedom/shop/Shop.java @@ -200,7 +200,7 @@ public class Shop extends FreedomService implements ShoppeCommons ItemStack icon = new ItemStack(Material.NAME_TAG); ItemMeta meta = icon.getItemMeta(); assert meta != null; - meta.setDisplayName(FUtil.colorize(plugin.rm.craftLoginMessage(player, loginMessage))); + meta.displayName(plugin.rm.craftLoginMessage(player, loginMessage)); icon.setItemMeta(meta); gui.setItem(slot, icon); slot++; @@ -423,7 +423,8 @@ public class Shop extends FreedomService implements ShoppeCommons String message = ConfigEntry.SHOP_LOGIN_MESSAGES.getStringList().get(slot); data.setLoginMessage(message); plugin.pl.save(data); - player.sendMessage(ChatColor.GREEN + "Your login message is now the following:\n" + plugin.rm.craftLoginMessage(player, message)); + player.sendMessage(ChatColor.GREEN + "Your login message is now the following:"); + player.sendMessage(plugin.rm.craftLoginMessage(player, message)); } player.closeInventory();