diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_creative.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_creative.java index 5e4ac1fe..7862b06b 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_creative.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_creative.java @@ -1,6 +1,5 @@ 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.GameMode; @@ -8,7 +7,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(rank = Rank.OP, source = SourceType.BOTH) +@CommandPermissions(permission = "creative", source = SourceType.BOTH) @CommandParameters(description = "Quickly change your own gamemode to creative, define someone's username to change theirs, or change everyone's gamemode on the server.", usage = "/ <-a | [partialname]>", aliases = "gmc") public class Command_creative extends FreedomCommand { @@ -28,7 +27,7 @@ public class Command_creative extends FreedomCommand return true; } - checkPermission(Rank.ADMIN); + checkPermission("tfm.creative.other"); if (args[0].equals("-a")) { 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 d9ddd12d..a5001a2a 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 @@ -1,13 +1,12 @@ package me.totalfreedom.totalfreedommod.command; -import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.api.ShopItem; 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) +@CommandPermissions(permission = "lightningrod", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Obtain a lightning rod", usage = "/") public class Command_lightningrod extends FreedomCommand { @@ -15,7 +14,8 @@ public class Command_lightningrod extends FreedomCommand @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (plugin.sh == null) { + if (plugin.sh == null) + { msg("The shop is currently disabled.", ChatColor.RED); return true; } @@ -24,8 +24,7 @@ public class Command_lightningrod extends FreedomCommand { playerSender.getInventory().addItem(plugin.sh.getLightningRod()); msg("You have been given a Lightning Rod", ChatColor.GREEN); - } - else + } else { msg("You do not own a Lightning Rod! Purchase one from the shop.", ChatColor.RED); } 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 240fef65..989201aa 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 @@ -1,13 +1,12 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.player.PlayerData; -import me.totalfreedom.totalfreedommod.rank.Rank; 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) +@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_links.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_links.java index acbdccd7..54bbf74a 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_links.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_links.java @@ -1,9 +1,5 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import me.totalfreedom.totalfreedommod.rank.Rank; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -11,7 +7,11 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; -@CommandPermissions(rank = Rank.OP, source = SourceType.BOTH) +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@CommandPermissions(permission = "links", source = SourceType.BOTH) @CommandParameters(description = "See TotalFreedom's social media links.", usage = "/", aliases = "link") public class Command_links extends FreedomCommand { @@ -30,16 +30,15 @@ public class Command_links extends FreedomCommand .stream() .filter(key -> values.get(key) instanceof String) .forEach(key -> - { - String link = (String) values.get(key); - lines.add(ChatColor.GOLD + "- " + key + ": " + ChatColor.AQUA + link); - }); + { + String link = (String) values.get(key); + lines.add(ChatColor.GOLD + "- " + key + ": " + ChatColor.AQUA + link); + }); msg("Social Media Links:", ChatColor.AQUA); sender.sendMessage(lines.toArray(new String[0])); return true; - } - else + } else { msg("There are no links added in the configuration file.", ChatColor.RED); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java index 3b9bc701..504e0078 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java @@ -1,7 +1,6 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.admin.Admin; -import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; import net.md_5.bungee.api.ChatColor; import org.apache.commons.lang.StringUtils; @@ -11,7 +10,7 @@ import org.bukkit.entity.Player; import java.util.List; -@CommandPermissions(rank = Rank.NON_OP, source = SourceType.BOTH) +@CommandPermissions(permission = "list", source = SourceType.BOTH) @CommandParameters(description = "Lists the real names of all online players.", usage = "/ [-a | -v]", aliases = "who,lsit") public class Command_list extends FreedomCommand { @@ -31,12 +30,12 @@ public class Command_list extends FreedomCommand case "-s", "-a" -> listFilter = ListFilter.ADMINS; case "-v" -> { - checkPermission(Rank.ADMIN); + checkPermission("tfm.list.vanished"); listFilter = ListFilter.VANISHED_ADMINS; } case "-t" -> { - checkPermission(Rank.ADMIN); + checkPermission("tfm.list.telnet"); listFilter = ListFilter.TELNET_SESSIONS; } default -> @@ -44,8 +43,7 @@ public class Command_list extends FreedomCommand return false; } } - } - else + } else { listFilter = ListFilter.PLAYERS; } @@ -58,16 +56,15 @@ public class Command_list extends FreedomCommand players = plugin.btb.getConnectedAdmins().stream().map(Admin::getName).toList(); onlineStats = ChatColor.BLUE + "There are " + ChatColor.RED + players.size() + ChatColor.BLUE + " admins connected to telnet."; - } - else + } else { onlineStats = ChatColor.BLUE + "There are " + ChatColor.RED + FUtil.getFakePlayerCount() + ChatColor.BLUE + " out of a maximum " + ChatColor.RED + server.getMaxPlayers() + ChatColor.BLUE + " players online."; players = server.getOnlinePlayers().stream().filter(pl -> (listFilter == ListFilter.ADMINS && plugin.al.isAdmin(pl) && !plugin.al.isVanished(pl.getUniqueId())) - || (listFilter == ListFilter.VANISHED_ADMINS && plugin.al.isVanished(pl.getUniqueId())) - || (listFilter == ListFilter.PLAYERS && !plugin.al.isVanished(pl.getUniqueId()))).map(player -> + || (listFilter == ListFilter.VANISHED_ADMINS && plugin.al.isVanished(pl.getUniqueId())) + || (listFilter == ListFilter.PLAYERS && !plugin.al.isVanished(pl.getUniqueId()))).map(player -> plugin.rm.getDisplay(player).getColoredTag() + player.getName()).toList(); } @@ -78,8 +75,7 @@ public class Command_list extends FreedomCommand { msg(ChatColor.stripColor(onlineStats)); msg(ChatColor.stripColor(onlineUsers)); - } - else + } else { msg(onlineStats); msg(onlineUsers); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_localspawn.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_localspawn.java index cd36de17..3bfae9c9 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_localspawn.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_localspawn.java @@ -1,12 +1,11 @@ package me.totalfreedom.totalfreedommod.command; import io.papermc.lib.PaperLib; -import me.totalfreedom.totalfreedommod.rank.Rank; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(rank = Rank.NON_OP, source = SourceType.ONLY_IN_GAME) +@CommandPermissions(permission = "localspawn", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Teleport to the spawn point for the current world, instead of the Essentials spawn point.", usage = "/", aliases = "worldspawn,gotospawn") public class Command_localspawn extends FreedomCommand { diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_lockup.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_lockup.java index 8721f8a8..266a6dea 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_lockup.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_lockup.java @@ -1,16 +1,17 @@ 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.Component; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; -@CommandPermissions(rank = Rank.SENIOR_ADMIN, source = SourceType.BOTH, blockHostConsole = true) +@CommandPermissions(permission = "lockup", source = SourceType.BOTH, blockHostConsole = true) @CommandParameters(description = "This is evil, and I never should have wrote it - blocks specified player's input.", usage = "/ on | off> [-q]>") public class Command_lockup extends FreedomCommand { @@ -30,8 +31,7 @@ public class Command_lockup extends FreedomCommand startLockup(player); } msgNew("Locked up all players."); - } - else if (args[0].equalsIgnoreCase("purge")) + } else if (args[0].equalsIgnoreCase("purge")) { FUtil.adminAction(sender.getName(), "Unlocking all players", true); for (Player player : server.getOnlinePlayers()) @@ -40,13 +40,11 @@ public class Command_lockup extends FreedomCommand } msgNew("Unlocked all players."); - } - else + } else { return false; } - } - else if (args.length == 2) + } else if (args.length == 2) { if (args[1].equalsIgnoreCase("on")) { @@ -64,8 +62,7 @@ public class Command_lockup extends FreedomCommand } startLockup(player); msgNew("Locked up .", Placeholder.unparsed("player", player.getName())); - } - else if ("off".equals(args[1])) + } else if ("off".equals(args[1])) { final Player player = getPlayer(args[0]); @@ -81,13 +78,11 @@ public class Command_lockup extends FreedomCommand } cancelLockup(player); msgNew("Unlocked .", Placeholder.unparsed("player", player.getName())); - } - else + } else { return false; } - } - else + } else { return false; } @@ -124,9 +119,8 @@ public class Command_lockup extends FreedomCommand { if (player.isOnline()) { - player.openInventory(player.getInventory()); - } - else + player.openInventory(Bukkit.createInventory(null, 9, Component.text("You are locked up!"))); // TODO: Use MiniMessage instead of using Component. + } else { cancelLockup(playerdata); } 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 75c1ab4e..324066d4 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 @@ -1,15 +1,14 @@ package me.totalfreedom.totalfreedommod.command; -import me.totalfreedom.totalfreedommod.player.PlayerData; -import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.api.ShopItem; +import me.totalfreedom.totalfreedommod.player.PlayerData; 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) +@CommandPermissions(permission = "loginmessage", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Change your login message", usage = "/ [message]") public class Command_loginmessage extends FreedomCommand { @@ -28,7 +27,7 @@ public class Command_loginmessage extends FreedomCommand return true; } - checkPermission(Rank.ADMIN); + checkPermission("tfm.loginmessage.custom"); String message = StringUtils.join(args, " "); if (!message.contains("%rank%") && !message.contains("%coloredrank%")) 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 9780d2c0..0b9f58b0 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 @@ -1,20 +1,24 @@ package me.totalfreedom.totalfreedommod.command; -import me.totalfreedom.totalfreedommod.player.PlayerData; -import me.totalfreedom.totalfreedommod.rank.Rank; 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; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(rank = Rank.ADMIN, source = SourceType.BOTH) +@CommandPermissions(permission = "manageshop", source = SourceType.BOTH) @CommandParameters(description = "Manage the shop", usage = "/ | items: ", aliases = "ms") public class Command_manageshop extends FreedomCommand { + + // These are here because SonarLint said "use a constant instead of duplicating this literal". + public static final String AMOUNT = "amount"; + public static final String PLAYER = "player"; + public static final String BALANCE = "balance"; + @Override public boolean run(final CommandSender sender, final Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { @@ -41,7 +45,7 @@ public class Command_manageshop extends FreedomCommand } switch (args[1]) { - case "add": + case "add" -> { try { @@ -57,19 +61,18 @@ public class Command_manageshop extends FreedomCommand playerData.setCoins(playerData.getCoins() + amount); plugin.pl.save(playerData); msgNew("Successfully gave coins to . Their new balance is .", - Placeholder.unparsed("amount", String.valueOf(amount)), - Placeholder.unparsed("player", playerData.getName()), - Placeholder.unparsed("balance", String.valueOf(playerData.getCoins()))); + Placeholder.unparsed(AMOUNT, String.valueOf(amount)), + Placeholder.unparsed(PLAYER, playerData.getName()), + Placeholder.unparsed(BALANCE, String.valueOf(playerData.getCoins()))); Player player = getPlayer(args[3]); if (player != null) { msgNew(player, " gave you coins. Your new balance is .", - Placeholder.unparsed("player", sender.getName()), - Placeholder.unparsed("amount", String.valueOf(amount)), - Placeholder.unparsed("balance", String.valueOf(playerData.getCoins()))); + Placeholder.unparsed(PLAYER, sender.getName()), + Placeholder.unparsed(AMOUNT, String.valueOf(amount)), + Placeholder.unparsed(BALANCE, String.valueOf(playerData.getCoins()))); } - } - else + } else { for (Player player : server.getOnlinePlayers()) { @@ -78,23 +81,22 @@ public class Command_manageshop extends FreedomCommand plugin.pl.save(playerData); msgNew(player, " gave you coins. Your new balance is .", - Placeholder.unparsed("player", sender.getName()), - Placeholder.unparsed("amount", String.valueOf(amount)), - Placeholder.unparsed("balance", String.valueOf(playerData.getCoins()))); + Placeholder.unparsed(PLAYER, sender.getName()), + Placeholder.unparsed(AMOUNT, String.valueOf(amount)), + Placeholder.unparsed(BALANCE, String.valueOf(playerData.getCoins()))); } msgNew("Successfully gave coins to all online players.", - Placeholder.unparsed("amount", String.valueOf(amount))); + Placeholder.unparsed(AMOUNT, String.valueOf(amount))); } return true; - } - catch (NumberFormatException ex) + } catch (NumberFormatException ex) { - msgNew("Invalid number: ", Placeholder.unparsed("amount", args[2])); + msgNew("Invalid number: ", Placeholder.unparsed(AMOUNT, args[2])); return true; } } - case "remove": + case "remove" -> { try { @@ -114,20 +116,19 @@ public class Command_manageshop extends FreedomCommand } plugin.pl.save(playerData); msgNew("Successfully took coins from . Their new balance is .", - Placeholder.unparsed("amount", String.valueOf(amount)), - Placeholder.unparsed("player", playerData.getName()), - Placeholder.unparsed("balance", String.valueOf(playerData.getCoins()))); + Placeholder.unparsed(AMOUNT, String.valueOf(amount)), + Placeholder.unparsed(PLAYER, playerData.getName()), + Placeholder.unparsed(BALANCE, String.valueOf(playerData.getCoins()))); Player player = getPlayer(args[3]); if (player != null) { msgNew(player, " took coins from you. Your new balance is .", - Placeholder.unparsed("player", sender.getName()), - Placeholder.unparsed("amount", String.valueOf(amount)), - Placeholder.unparsed("balance", String.valueOf(playerData.getCoins()))); + Placeholder.unparsed(PLAYER, sender.getName()), + Placeholder.unparsed(AMOUNT, String.valueOf(amount)), + Placeholder.unparsed(BALANCE, String.valueOf(playerData.getCoins()))); } - } - else + } else { for (Player player : server.getOnlinePlayers()) { @@ -140,23 +141,22 @@ public class Command_manageshop extends FreedomCommand plugin.pl.save(playerData); msgNew(player, " took coins from you. Your new balance is .", - Placeholder.unparsed("player", sender.getName()), - Placeholder.unparsed("amount", String.valueOf(amount)), - Placeholder.unparsed("balance", String.valueOf(playerData.getCoins()))); + Placeholder.unparsed(PLAYER, sender.getName()), + Placeholder.unparsed(AMOUNT, String.valueOf(amount)), + Placeholder.unparsed(BALANCE, String.valueOf(playerData.getCoins()))); } msgNew("Successfully took coins from all online players.", - Placeholder.unparsed("amount", String.valueOf(amount))); + Placeholder.unparsed(AMOUNT, String.valueOf(amount))); } return true; - } - catch (NumberFormatException ex) + } catch (NumberFormatException ex) { - msgNew("Invalid number: ", Placeholder.unparsed("amount", args[2])); + msgNew("Invalid number: ", Placeholder.unparsed(AMOUNT, args[2])); return true; } } - case "set": + case "set" -> { try { @@ -171,31 +171,29 @@ public class Command_manageshop extends FreedomCommand plugin.pl.save(playerData); msgNew("Successfully set 's coin balance to .", - Placeholder.unparsed("player", playerData.getName()), - Placeholder.unparsed("amount", String.valueOf(amount))); + Placeholder.unparsed(PLAYER, playerData.getName()), + Placeholder.unparsed(AMOUNT, String.valueOf(amount))); Player player = getPlayer(args[3]); if (player != null) { msgNew(player, " set your coin balance to .", - Placeholder.unparsed("player", sender.getName()), - Placeholder.unparsed("amount", String.valueOf(amount))); + Placeholder.unparsed(PLAYER, sender.getName()), + Placeholder.unparsed(AMOUNT, String.valueOf(amount))); } return true; - } - catch (NumberFormatException ex) + } catch (NumberFormatException ex) { - msgNew("Invalid number: ", Placeholder.unparsed("amount", args[2])); + msgNew("Invalid number: ", Placeholder.unparsed(AMOUNT, args[2])); return true; } } - default: + default -> { return false; } } - } - else if (args[0].equals("items")) + } else if (args[0].equals("items")) { if (args[1].equals("list")) { @@ -227,18 +225,17 @@ public class Command_manageshop extends FreedomCommand plugin.pl.save(playerData); msgNew("Successfully gave the to .", Placeholder.unparsed("item", item.getName()), - Placeholder.unparsed("player", playerData.getName())); + Placeholder.unparsed(PLAYER, playerData.getName())); Player player = getPlayer(args[3]); if (player != null) { msgNew(player, " gave the to you.", Placeholder.unparsed("item", item.getName()), - Placeholder.unparsed("player", sender.getName())); + Placeholder.unparsed(PLAYER, sender.getName())); } return true; - } - else if (args[1].equals("take")) + } else if (args[1].equals("take")) { ShopItem item = ShopItem.findItem(args[2].toUpperCase()); if (item == null) @@ -258,14 +255,14 @@ public class Command_manageshop extends FreedomCommand msgNew("Successfully took the from .", Placeholder.unparsed("item", item.getName()), - Placeholder.unparsed("player", playerData.getName())); + Placeholder.unparsed(PLAYER, playerData.getName())); Player player = getPlayer(args[3]); if (player != null) { msgNew(player, " took the from you.", Placeholder.unparsed("item", item.getName()), - Placeholder.unparsed("player", sender.getName())); + Placeholder.unparsed(PLAYER, sender.getName())); } return true; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_masterbuilderinfo.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_masterbuilderinfo.java index 7d1311b2..23cb2bf8 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_masterbuilderinfo.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_masterbuilderinfo.java @@ -1,8 +1,6 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.List; 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; @@ -10,7 +8,9 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(rank = Rank.OP, source = SourceType.BOTH) +import java.util.List; + +@CommandPermissions(permission = "masterbuilderinfo", source = SourceType.BOTH) @CommandParameters(description = "Information on how to apply for Master Builder.", usage = "/", aliases = "mbi") public class Command_masterbuilderinfo extends FreedomCommand { @@ -23,8 +23,7 @@ public class Command_masterbuilderinfo extends FreedomCommand if (masterBuilderInfo.isEmpty()) { msg("The master builder information section of the config.yml file has not been configured.", ChatColor.RED); - } - else + } else { msg(FUtil.colorize(StringUtils.join(masterBuilderInfo, "\n"))); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_masterbuilderworld.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_masterbuilderworld.java index 193c2640..c54972bb 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_masterbuilderworld.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_masterbuilderworld.java @@ -1,10 +1,6 @@ package me.totalfreedom.totalfreedommod.command; import io.papermc.lib.PaperLib; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.world.WorldTime; import me.totalfreedom.totalfreedommod.world.WorldWeather; import org.bukkit.World; @@ -12,7 +8,11 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(rank = Rank.OP, source = SourceType.BOTH) +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +@CommandPermissions(permission = "masterbuilderworld", source = SourceType.BOTH) @CommandParameters(description = "Allows for master builders to configure the time, the weather of the MasterBuilder, and allows for players to go to the MasterBuilderWorld.", usage = "/ [time | weather ]", aliases = "mbw,mbworld") @@ -27,14 +27,12 @@ public class Command_masterbuilderworld extends FreedomCommand if (args.length == 0) { commandMode = CommandMode.TELEPORT; - } - else if (args.length >= 2) + } else if (args.length >= 2) { if ("time".equalsIgnoreCase(args[0])) { commandMode = CommandMode.TIME; - } - else if ("weather".equalsIgnoreCase(args[0])) + } else if ("weather".equalsIgnoreCase(args[0])) { commandMode = CommandMode.WEATHER; } @@ -60,8 +58,7 @@ public class Command_masterbuilderworld extends FreedomCommand try { masterBuilderWorld = plugin.wm.masterBuilderWorld.getWorld(); - } - catch (Exception ignored) + } catch (Exception ignored) { } @@ -69,8 +66,7 @@ public class Command_masterbuilderworld extends FreedomCommand { msg("Going to the main world."); PaperLib.teleportAsync(playerSender, server.getWorlds().get(0).getSpawnLocation()); - } - else + } else { msg("Going to the Master Builder world"); plugin.wm.masterBuilderWorld.sendToWorld(playerSender); @@ -89,13 +85,11 @@ public class Command_masterbuilderworld extends FreedomCommand { plugin.wm.masterBuilderWorld.setTimeOfDay(timeOfDay); msg("MasterBuilder world time set to: " + timeOfDay.name()); - } - else + } else { msg("Invalid time of day. Can be: sunrise, noon, sunset, midnight"); } - } - else + } else { return false; } @@ -113,13 +107,11 @@ public class Command_masterbuilderworld extends FreedomCommand { plugin.wm.masterBuilderWorld.setWeatherMode(weatherMode); msg("MasterBuilder world weather set to: " + weatherMode.name()); - } - else + } else { msg("Invalid weather mode. Can be: off, rain, storm"); } - } - else + } else { return false; } @@ -131,8 +123,7 @@ public class Command_masterbuilderworld extends FreedomCommand return false; } } - } - catch (PermissionDeniedException ex) + } catch (PermissionDeniedException ex) { if (ex.getMessage().isEmpty()) { @@ -155,14 +146,12 @@ public class Command_masterbuilderworld extends FreedomCommand if (args.length == 1) { return Arrays.asList("time", "weather"); - } - else if (args.length == 2) + } else if (args.length == 2) { if (args[0].equals("time")) { return Arrays.asList("morning", "noon", "evening", "night"); - } - else if (args[0].equals("weather")) + } else if (args[0].equals("weather")) { return Arrays.asList("off", "rain", "storm"); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mbconfig.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mbconfig.java index c51ea87c..455c339f 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mbconfig.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mbconfig.java @@ -1,10 +1,6 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; import me.totalfreedom.totalfreedommod.player.PlayerData; -import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; @@ -12,7 +8,11 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(rank = Rank.OP, source = SourceType.BOTH) +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +@CommandPermissions(permission = "mbconfig", source = SourceType.BOTH) @CommandParameters(description = "List, add, or remove master builders. Master builders can also clear their own IPs.", usage = "/ | clearips | < >>") public class Command_mbconfig extends FreedomCommand { @@ -125,8 +125,7 @@ public class Command_mbconfig extends FreedomCommand { plugin.rm.updateDisplay(player); } - } - else + } else { msg("That player is already on the Master Builder list."); } @@ -175,18 +174,15 @@ public class Command_mbconfig extends FreedomCommand if (args.length == 1) { return Arrays.asList("add", "remove", "list", "clearips", "clearip"); - } - else if (args.length == 2) + } else if (args.length == 2) { if (args[0].equalsIgnoreCase("add")) { return FUtil.getPlayerList(); - } - else if (args[0].equalsIgnoreCase("remove")) + } else if (args[0].equalsIgnoreCase("remove")) { return plugin.pl.getMasterBuilderNames(); - } - else if (args[0].equalsIgnoreCase("clearip")) + } else if (args[0].equalsIgnoreCase("clearip")) { PlayerData data = plugin.pl.getData(sender.getName()); if (data.isMasterBuilder()) diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_moblimiter.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_moblimiter.java index f7ae07b4..980d0e31 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_moblimiter.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_moblimiter.java @@ -2,13 +2,12 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.GameRuleHandler; import me.totalfreedom.totalfreedommod.config.ConfigEntry; -import me.totalfreedom.totalfreedommod.rank.Rank; 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) +@CommandPermissions(permission = "moblimiter", source = SourceType.BOTH) @CommandParameters(description = "Control mob limiting parameters.", usage = "/ | dragon | giant | ghast | slime>") public class Command_moblimiter extends FreedomCommand { @@ -24,10 +23,14 @@ public class Command_moblimiter extends FreedomCommand { case "on" -> ConfigEntry.MOB_LIMITER_ENABLED.setBoolean(true); case "off" -> ConfigEntry.MOB_LIMITER_ENABLED.setBoolean(false); - case "dragon" -> ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean()); - case "giant" -> ConfigEntry.MOB_LIMITER_DISABLE_GIANT.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean()); - case "slime" -> ConfigEntry.MOB_LIMITER_DISABLE_SLIME.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean()); - case "ghast" -> ConfigEntry.MOB_LIMITER_DISABLE_GHAST.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean()); + case "dragon" -> + ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean()); + case "giant" -> + ConfigEntry.MOB_LIMITER_DISABLE_GIANT.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean()); + case "slime" -> + ConfigEntry.MOB_LIMITER_DISABLE_SLIME.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean()); + case "ghast" -> + ConfigEntry.MOB_LIMITER_DISABLE_GHAST.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean()); case "setmax" -> { if (args.length < 2) @@ -38,8 +41,7 @@ public class Command_moblimiter extends FreedomCommand try { ConfigEntry.MOB_LIMITER_MAX.setInteger(Math.max(0, Math.min(2000, Integer.parseInt(args[1])))); - } - catch (Exception ex) + } catch (Exception ex) { msg("Invalid number: " + args[1], ChatColor.RED); return true; @@ -59,8 +61,7 @@ public class Command_moblimiter extends FreedomCommand msg("Giant: " + (ConfigEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean() ? "disabled" : "enabled") + "."); msg("Slime: " + (ConfigEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean() ? "disabled" : "enabled") + "."); msg("Ghast: " + (ConfigEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean() ? "disabled" : "enabled") + "."); - } - else + } else { msg("Moblimiter is disabled. No mob restrictions are in effect."); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mobpurge.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mobpurge.java index b8ab1b39..0f64ecc2 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mobpurge.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mobpurge.java @@ -1,8 +1,5 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.Collections; -import java.util.List; -import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.Groups; import org.bukkit.ChatColor; @@ -11,7 +8,11 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; -@CommandPermissions(rank = Rank.ADMIN, source = SourceType.BOTH) +import java.util.Collections; +import java.util.List; + + +@CommandPermissions(permission = "mobpurge", source = SourceType.BOTH) @CommandParameters(description = "Purge all mobs in all worlds.", usage = "/ [name]", aliases = "mp") public class Command_mobpurge extends FreedomCommand { @@ -25,8 +26,7 @@ public class Command_mobpurge extends FreedomCommand try { type = EntityType.valueOf(args[0].toUpperCase()); - } - catch (Exception e) + } catch (Exception e) { msg(args[0] + " is not a valid mob type.", ChatColor.RED); return true; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mp44.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mp44.java index 85864b8e..42510b37 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mp44.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mp44.java @@ -1,9 +1,7 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.Objects; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.FPlayer; -import me.totalfreedom.totalfreedommod.rank.Rank; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.command.Command; @@ -11,7 +9,9 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -@CommandPermissions(rank = Rank.OP, source = SourceType.ONLY_IN_GAME) +import java.util.Objects; + +@CommandPermissions(permission = "mp44", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Modern weaponry, FTW. Use 'draw' to start firing, 'sling' to stop firing.", usage = "/ ") public class Command_mp44 extends FreedomCommand { @@ -40,8 +40,7 @@ public class Command_mp44 extends FreedomCommand msg("Type /mp44 sling to disable. -by Madgeek1450", ChatColor.GREEN); Objects.requireNonNull(playerSender.getEquipment()).setItemInMainHand(new ItemStack(Material.GUNPOWDER, 1)); - } - else + } else { playerdata.disarmMP44(); 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 5936555a..bfea71e2 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 @@ -1,19 +1,18 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.*; 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 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.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(rank = Rank.ADMIN, source = SourceType.BOTH) +import java.util.*; + +@CommandPermissions(permission = "tfm.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 { @@ -34,8 +33,7 @@ public class Command_mute extends FreedomCommand if (muted.isEmpty()) { msgNew("Nobody is currently muted."); - } - else + } else { msgNew("Muted players: ", Placeholder.unparsed("players", FUtil.listToString(muted))); } @@ -93,8 +91,7 @@ public class Command_mute extends FreedomCommand { msgNew(" is an admin, and as such can't be muted.", Placeholder.unparsed("player", player.getName())); return; - } - else if (plugin.pl.getPlayer(player).isMuted()) + } else if (plugin.pl.getPlayer(player).isMuted()) { msgNew(" is already muted.", Placeholder.unparsed("player", player.getName())); return; @@ -122,8 +119,7 @@ public class Command_mute extends FreedomCommand if (quiet) { msgNew("Muted .", Placeholder.unparsed("player", player.getName())); - } - else + } else { msgNew("Quietly muted .", Placeholder.unparsed("player", player.getName())); } 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 7fede5df..b4a858c2 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 @@ -13,7 +13,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(rank = Rank.ADMIN, source = SourceType.BOTH) +@CommandPermissions(permission = "notes", source = SourceType.BOTH) @CommandParameters(description = "Manage notes for a player", usage = "/ | remove | clear>") public class Command_notes extends FreedomCommand { diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_opme.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_opme.java index 6e840bd2..b3062ac5 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_opme.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_opme.java @@ -1,12 +1,14 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.rank.GroupProvider; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; +import net.luckperms.api.model.user.User; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(rank = Rank.NON_OP, source = SourceType.ONLY_IN_GAME) +@CommandPermissions(permission = "opme", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "OPs the command sender.", usage = "/") public class Command_opme extends FreedomCommand { @@ -15,7 +17,8 @@ public class Command_opme extends FreedomCommand public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { FUtil.adminAction(sender.getName(), "Opping " + sender.getName(), false); - sender.setOp(true); + User user = GroupProvider.getUser(playerSender); + user.setPrimaryGroup(GroupProvider.OP.getGroup().getLuckPermsGroup().getName()); msg(YOU_ARE_OP); plugin.rm.updateDisplay(playerSender); return true; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/Displayable.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/Displayable.java index 2b2f2e49..b0870c02 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/Displayable.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/Displayable.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.rank; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.JoinConfiguration; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.md_5.bungee.api.ChatColor; public interface Displayable @@ -21,7 +25,7 @@ public interface Displayable String getColoredName(); - String getColoredTag(); + Component getColoredTag(); String getColoredLoginMessage(); @@ -29,4 +33,15 @@ public interface Displayable boolean hasDefaultLoginMessage(); + default Component generateColoredTag(String colorAndTag) + { + Component open = Component.text("[").color(NamedTextColor.DARK_GRAY); + Component close = Component.text("]").color(NamedTextColor.DARK_GRAY); + Component tagComponent = LegacyComponentSerializer.legacyAmpersand().deserialize(colorAndTag); + return Component.join(JoinConfiguration + .builder() + .separator(Component.text(" ")) + .build(), open, tagComponent, close); + } + } \ No newline at end of file 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 3a92163d..dccb2693 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/DisplayableGroup.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/DisplayableGroup.java @@ -1,12 +1,17 @@ package me.totalfreedom.totalfreedommod.rank; import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import net.kyori.adventure.text.Component; +import net.luckperms.api.model.data.DataType; import net.luckperms.api.model.group.Group; +import net.luckperms.api.node.types.PrefixNode; +import net.luckperms.api.node.types.WeightNode; import net.md_5.bungee.api.ChatColor; import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; import java.util.Locale; +import java.util.concurrent.CompletableFuture; public class DisplayableGroup implements Displayable { @@ -17,10 +22,11 @@ public class DisplayableGroup implements Displayable private final String abbr; private final String plural; private final String article; + private final int weight; private final String tag; - private final String coloredTag; + private final Component coloredTag; private final ChatColor color; @@ -33,6 +39,7 @@ public class DisplayableGroup implements Displayable public DisplayableGroup(String group, String plural, String tag, + int weight, ChatColor color, org.bukkit.ChatColor teamColor, boolean hasTeam, @@ -41,7 +48,22 @@ public class DisplayableGroup implements Displayable Group matched = TotalFreedomMod.getPlugin().lpb.getAPI().getGroupManager().getGroup(group); if (matched == null) { - throw new IllegalArgumentException("Group " + group + " does not exist!"); + CompletableFuture cfg = TotalFreedomMod.getPlugin() + .lpb + .getAPI() + .getGroupManager() + .createAndLoadGroup(group); + + cfg.thenAcceptAsync(g -> { + WeightNode weightNode = WeightNode.builder(weight).build(); + PrefixNode prefixNode = PrefixNode.builder().prefix(ChatColor.DARK_GRAY + "[" + color + tag + ChatColor.DARK_GRAY + "]" + getColor()).build(); + g.getData(DataType.NORMAL).add(prefixNode); + g.getData(DataType.NORMAL).add(weightNode); + }).join(); // Block until the group is created and loaded. + + matched = TotalFreedomMod.getPlugin().lpb.getAPI().getGroupManager().getGroup(group); + + if (matched == null) throw new IllegalArgumentException("Group " + group + " does not exist and could not be created."); } this.group = matched; @@ -49,11 +71,12 @@ public class DisplayableGroup implements Displayable this.plural = plural; this.article = StringUtils.startsWithAny(this.name.toLowerCase(Locale.ROOT), new String[]{"a", "e", "i", "o", "u"}) ? "an" : "a"; this.abbr = tag; + this.weight = weight; this.tag = "[" + tag + "]"; this.color = color; this.teamColor = teamColor; this.hasTeam = hasTeam; - this.coloredTag = ChatColor.DARK_GRAY + "[" + getColor() + getTag() + ChatColor.DARK_GRAY + "]" + getColor(); + this.coloredTag = generateColoredTag(color + tag); this.hasDefaultLoginMessage = hasDefaultLoginMessage; } @@ -116,7 +139,7 @@ public class DisplayableGroup implements Displayable } @Override - public String getColoredTag() + public Component getColoredTag() { return coloredTag; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/GroupProvider.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/GroupProvider.java index 44b4bcc6..8544cec5 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/GroupProvider.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/GroupProvider.java @@ -3,18 +3,18 @@ package me.totalfreedom.totalfreedommod.rank; import me.totalfreedom.totalfreedommod.TotalFreedomMod; import net.luckperms.api.model.user.User; import net.md_5.bungee.api.ChatColor; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import java.util.UUID; +import java.util.Set; @FunctionalInterface public interface GroupProvider { - GroupProvider NON_OP = () -> new DisplayableGroup("non_op", "Non-Ops", "", ChatColor.WHITE, null, false, false); - GroupProvider OP = () -> new DisplayableGroup("op", "Operators", "Op", ChatColor.GREEN, null, false, false); - GroupProvider ADMIN = () -> new DisplayableGroup("admin", "Administrators", "Admin", ChatColor.DARK_GREEN, org.bukkit.ChatColor.DARK_GREEN, true, true); - GroupProvider SENIOR_ADMIN = () -> new DisplayableGroup("senior", "Senior Administrators", "SrA", ChatColor.GOLD, org.bukkit.ChatColor.GOLD, true, true); + GroupProvider NON_OP = () -> new DisplayableGroup("non_op", "Non-Ops", "", 0, ChatColor.WHITE, null, false, false); + GroupProvider OP = () -> new DisplayableGroup("op", "Operators", "Op", 1, ChatColor.GREEN, null, false, false); + GroupProvider MASTER_BUILDER = () -> new DisplayableGroup("builder", "Master Builders", "MB", 2, ChatColor.DARK_AQUA, org.bukkit.ChatColor.DARK_AQUA, true, true); + GroupProvider ADMIN = () -> new DisplayableGroup("admin", "Administrators", "Admin", 3, ChatColor.DARK_GREEN, org.bukkit.ChatColor.DARK_GREEN, true, true); + GroupProvider SENIOR_ADMIN = () -> new DisplayableGroup("senior", "Senior Administrators", "SrA", 4, ChatColor.GOLD, org.bukkit.ChatColor.GOLD, true, true); static User getUser(Player player) { @@ -24,15 +24,21 @@ public interface GroupProvider .getUser(player); } - T getGroup(); - - static GroupProvider fromArgument(String arg) { + static GroupProvider fromArgument(String arg) + { return switch (arg.toLowerCase()) { case "op" -> OP; + case "builder" -> MASTER_BUILDER; case "admin" -> ADMIN; case "senior" -> SENIOR_ADMIN; default -> NON_OP; }; } + + static Set> providerSet() { + return Set.of(NON_OP, OP, MASTER_BUILDER, ADMIN, SENIOR_ADMIN); + } + + T getGroup(); } \ No newline at end of file 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 84d8703c..0a728d68 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java @@ -6,7 +6,10 @@ import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.util.FUtil; +import net.luckperms.api.model.data.DataType; import net.luckperms.api.model.group.Group; +import net.luckperms.api.node.types.PrefixNode; +import net.luckperms.api.node.types.WeightNode; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -18,18 +21,23 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Team; -import java.util.Objects; +import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class RankManager extends FreedomService { @Override public void onStart() { + // We don't need to do anything here. } @Override public void onStop() { + // We don't need to do anything here. } public Displayable getDisplay(CommandSender sender) diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/Title.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/Title.java index 8cdd0118..c5dabc61 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/Title.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/Title.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.rank; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.JoinConfiguration; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.md_5.bungee.api.ChatColor; public enum Title implements Displayable @@ -21,7 +25,7 @@ public enum Title implements Displayable private final String tag; - private final String coloredTag; + private final Component coloredTag; private final ChatColor color; @@ -35,7 +39,7 @@ public enum Title implements Displayable this.article = article; this.name = name; this.plural = plural; - this.coloredTag = ChatColor.DARK_GRAY + "[" + color + tag + ChatColor.DARK_GRAY + "]" + color; + this.coloredTag = generateColoredTag(color + tag); this.abbr = tag; this.tag = "[" + tag + "]"; this.color = color; @@ -99,7 +103,7 @@ public enum Title implements Displayable } @Override - public String getColoredTag() + public Component getColoredTag() { return coloredTag; } diff --git a/discord/src/main/java/me/totalfreedom/discord/util/TFM_Bridge.java b/discord/src/main/java/me/totalfreedom/discord/util/TFM_Bridge.java index 72651855..67a94c2e 100644 --- a/discord/src/main/java/me/totalfreedom/discord/util/TFM_Bridge.java +++ b/discord/src/main/java/me/totalfreedom/discord/util/TFM_Bridge.java @@ -9,6 +9,7 @@ import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.PlayerData; +import me.totalfreedom.totalfreedommod.rank.GroupProvider; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Title; import me.totalfreedom.totalfreedommod.util.FLog; @@ -52,15 +53,15 @@ public class TFM_Bridge } else if (role.getId().equals(SnowflakeEntry.SENIOR_ADMIN_ROLE_ID.getSnowflake())) { - return Rank.SENIOR_ADMIN.getColoredTag(); + return GroupProvider.SENIOR_ADMIN.getGroup().getColoredTag().toString(); } else if (role.getId().equals(SnowflakeEntry.ADMIN_ROLE_ID.getSnowflake())) { - return Rank.ADMIN.getColoredTag(); + return GroupProvider.ADMIN.getGroup().getColoredTag().toString(); } else if (role.getId().equals(SnowflakeEntry.MASTERBUILDER_ROLE_ID.getSnowflake())) { - return Title.MASTER_BUILDER.getColoredTag(); + return GroupProvider.MASTER_BUILDER.getGroup().getColoredTag().toString()); } else {