diff --git a/README.md b/README.md index dbfb1d7..8e23616 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ ![Static Badge](https://img.shields.io/badge/MC-1.18-green) ![Static Badge](https://img.shields.io/badge/MC-1.19-green) ![Static Badge](https://img.shields.io/badge/MC-1.20-green) +![Static Badge](https://img.shields.io/badge/MC-1.21-green) ![Modrinth Downloads](https://img.shields.io/modrinth/dt/km0yAITg?logo=Modrinth&style=flat-square) @@ -41,10 +42,14 @@ This is a Minecraft plugin for Spigot/Paper servers that allows players to set t - The Plugin got Placeholders: - `%tubsstatusplugin_status_playername%` (playname should be changed out for the real Playername, Duuuh.) - `%tubsstatusplugin_status%` +- Groupmode + - turn on Group Mode in the Config and preconfigure set Groups for Players + - A Player will not be able to set a fully custom status but he can use one of the preconfigured Groups. ## Permissions - `StatusPlugin.setStatus`: Allows a player to set their own status and remove it. (default: `true`) +- `StatusPlugin.group.set`: Allows players to set their status as a group status. (default: `true`) - `StatusPlugin.admin.setStatus`: Allows a player to set and remove other players' statuses. (default: `false`) - `StatusPlugin.admin.reload`: Allows a player to reload all statuses.(default: `false`) - `StatusPlugin.admin.setMaxlength:` Allows a player to set the maximum length of statuses. (default: `false`) diff --git a/pom.xml b/pom.xml index 25ae916..0f56e25 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ de.tubyoub StatusPlugin - 1.3.5 + 1.4 jar Tub's Status Plugin diff --git a/src/main/java/de/tubyoub/statusplugin/Listener/ChatListener.java b/src/main/java/de/tubyoub/statusplugin/Listener/ChatListener.java index 20ec6aa..00d717f 100644 --- a/src/main/java/de/tubyoub/statusplugin/Listener/ChatListener.java +++ b/src/main/java/de/tubyoub/statusplugin/Listener/ChatListener.java @@ -2,6 +2,7 @@ import de.tubyoub.statusplugin.Managers.ConfigManager; import de.tubyoub.statusplugin.Managers.StatusManager; +import de.tubyoub.statusplugin.StatusPlugin; import de.tubyoub.utils.ColourUtils; import me.clip.placeholderapi.PlaceholderAPI; import org.bukkit.Bukkit; @@ -18,15 +19,15 @@ public class ChatListener implements Listener { private final StatusManager statusManager; private final ConfigManager configManager; + private final StatusPlugin plugin; /** * Constructor for the ChatListener class. - * @param statusManager The StatusManager instance used to manage player statuses. - * @param configManager The ConfigManager instance used to manage the plugin configuration. */ - public ChatListener(StatusManager statusManager, ConfigManager configManager) { - this.statusManager = statusManager; - this.configManager = configManager; + public ChatListener(StatusPlugin plugin) { + this.plugin = plugin; + this.statusManager = plugin.getStatusManager(); + this.configManager = plugin.getConfigManager(); } /** @@ -45,7 +46,9 @@ public void onPlayerChat(PlayerChatEvent event) { // Translate the player's status and add placeholders String status = statusManager.translateColorsAndFormatting(statusManager.getStatus(player),player); - status = PlaceholderAPI.setPlaceholders(player, status); + if (plugin.isPlaceholderAPIPresent()) { + status = PlaceholderAPI.setPlaceholders(player, status); + } // Format the broadcast message String broadcastMessage; diff --git a/src/main/java/de/tubyoub/statusplugin/Managers/ConfigManager.java b/src/main/java/de/tubyoub/statusplugin/Managers/ConfigManager.java index 5200cc8..4009529 100644 --- a/src/main/java/de/tubyoub/statusplugin/Managers/ConfigManager.java +++ b/src/main/java/de/tubyoub/statusplugin/Managers/ConfigManager.java @@ -10,6 +10,8 @@ import java.io.File; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import java.util.Objects; public class ConfigManager { @@ -17,6 +19,8 @@ public class ConfigManager { private int maxStatusLength; private boolean chatFormatter; private boolean tablistFormatter; + private boolean groupMode; + private Map statusGroups; private final StatusPlugin plugin; public ConfigManager(StatusPlugin plugin) { @@ -30,18 +34,30 @@ public void loadConfig() { GeneralSettings.DEFAULT, LoaderSettings.builder().setAutoUpdate(true).build(), DumperSettings.DEFAULT, - UpdaterSettings.builder().setVersioning(new BasicVersioning("fileversion")) .setOptionSorting(UpdaterSettings.OptionSorting.SORT_BY_DEFAULTS).build()); maxStatusLength = config.getInt("maxStatusLength", 15); chatFormatter = config.getBoolean("chatFormatter", true); tablistFormatter = config.getBoolean("changeTablistNames", true); + groupMode = config.getBoolean("groupMode", false); + loadStatusGroups(); } catch (IOException e) { plugin.getLogger().severe("Could not load configuration: " + e.getMessage()); } } + private void loadStatusGroups() { + statusGroups = new HashMap<>(); + if (config.contains("statusGroups")) { + for (Object key : config.getSection("statusGroups").getKeys()) { + String groupName = key.toString(); + String status = config.getString("statusGroups." + groupName + ".status"); + statusGroups.put(groupName, status); + } + } + } + public void saveConfig() { try { config.save(); @@ -49,28 +65,29 @@ public void saveConfig() { plugin.getLogger().severe("Could not save configuration: " + e.getMessage()); } } - public boolean isTablistFormatter(){ + + public boolean isTablistFormatter() { return tablistFormatter; } - public void setTablistFormatter(boolean tablistFormatter){ - if (this.tablistFormatter == tablistFormatter){ - return; - }else { + + public void setTablistFormatter(boolean tablistFormatter) { + if (this.tablistFormatter != tablistFormatter) { this.tablistFormatter = tablistFormatter; config.set("changeTablistNames", tablistFormatter); } } - public boolean isChatFormatter(){ + + public boolean isChatFormatter() { return chatFormatter; } - public void setChatFormatter(boolean chatFormatter){ - if (this.chatFormatter == chatFormatter){ - return; - }else { + + public void setChatFormatter(boolean chatFormatter) { + if (this.chatFormatter != chatFormatter) { this.chatFormatter = chatFormatter; config.set("chatFormatter", chatFormatter); } } + public int getMaxStatusLength() { return maxStatusLength; } @@ -87,6 +104,20 @@ public void resetMaxStatusLength() { saveConfig(); } + public boolean isGroupMode() { + return groupMode; + } + + public void setGroupMode(boolean groupMode) { + this.groupMode = groupMode; + config.set("groupMode", groupMode); + saveConfig(); + } + + public Map getStatusGroups() { + return statusGroups; + } + public void reloadConfig() { loadConfig(); } diff --git a/src/main/java/de/tubyoub/statusplugin/Managers/StatusManager.java b/src/main/java/de/tubyoub/statusplugin/Managers/StatusManager.java index 663d29a..a9d07e2 100644 --- a/src/main/java/de/tubyoub/statusplugin/Managers/StatusManager.java +++ b/src/main/java/de/tubyoub/statusplugin/Managers/StatusManager.java @@ -39,7 +39,7 @@ public class StatusManager { */ public StatusManager(StatusPlugin plugin) { this.plugin = plugin; - this.placeholderAPIPresent = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null; + this.placeholderAPIPresent = plugin.isPlaceholderAPIPresent(); this.configManager = plugin.getConfigManager(); maxStatusLength = configManager.getMaxStatusLength(); this.statusFile = new File(plugin.getDataFolder(), "statuses.yml"); @@ -54,7 +54,12 @@ public StatusManager(StatusPlugin plugin) { * @return A boolean indicating whether the status was set successfully. */ public boolean setStatus(Player player, String status, CommandSender sender) { - if (status.contains("&_")){ + if (configManager.isGroupMode() && !sender.hasPermission("StatusPlugin.admin.setStatus")) { + sender.sendMessage(ChatColor.RED + "Group mode is enabled. Use /status group to set your status."); + return false; + } + + if (status.contains("&_")) { status = status.replace("&_", " "); } String translatedStatus = translateColorsAndFormatting(status, sender); @@ -63,7 +68,27 @@ public boolean setStatus(Player player, String status, CommandSender sender) { return false; } - // Store the original status, not the translated one + statusMap.put(player.getUniqueId(), status); + if (configManager.isTablistFormatter()) { + updateDisplayName(player); + } + saveStatuses(); + return true; + } + + public boolean setGroupStatus(Player player, String groupName) { + Map statusGroups = configManager.getStatusGroups(); + if (!statusGroups.containsKey(groupName)) { + player.sendMessage(ChatColor.RED + "Invalid group name."); + return false; + } + + if (!player.hasPermission("StatusPlugin.group.set" + groupName)) { + player.sendMessage(plugin.getPluginPrefix() + ChatColor.RED + "You don't have permission to use this status group."); + return false; + } + + String status = statusGroups.get(groupName); statusMap.put(player.getUniqueId(), status); if (configManager.isTablistFormatter()) { updateDisplayName(player); @@ -223,6 +248,14 @@ public int calculateEffectiveLength(String text) { return withoutColorCodesAndPlaceholders.length(); } + public boolean isGroupMode() { + return configManager.isGroupMode(); + } + + public Map getStatusGroups() { + return configManager.getStatusGroups(); + } + /** * Reloads the statuses from the status file into the status map. */ diff --git a/src/main/java/de/tubyoub/statusplugin/StatusPlugin.java b/src/main/java/de/tubyoub/statusplugin/StatusPlugin.java index ac3c6c4..068f7dd 100644 --- a/src/main/java/de/tubyoub/statusplugin/StatusPlugin.java +++ b/src/main/java/de/tubyoub/statusplugin/StatusPlugin.java @@ -4,7 +4,10 @@ import de.tubyoub.statusplugin.Listener.PlayerJoinListener; import de.tubyoub.statusplugin.Managers.ConfigManager; import de.tubyoub.statusplugin.Managers.StatusManager; +import de.tubyoub.statusplugin.commands.GroupCommand; import de.tubyoub.statusplugin.commands.StatusCommand; +import de.tubyoub.statusplugin.commands.tabCompleter.GroupTabCompleter; +import de.tubyoub.statusplugin.commands.tabCompleter.StatusTabCompleter; import de.tubyoub.utils.VersionChecker; import de.tubyoub.statusplugin.metrics.Metrics; import org.bukkit.Bukkit; @@ -13,15 +16,17 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; +import java.util.ArrayList; + /** * Main class for the StatusPlugin. * This class extends JavaPlugin and represents the main entry point for the plugin. */ public class StatusPlugin extends JavaPlugin { - private final String version = "1.3.5"; + private final String version = "1.4"; private StatusManager statusManager; private VersionChecker versionChecker; - //private boolean placeholderAPIPresent; + private boolean placeholderAPIPresent = false; private ConfigManager configManager; private StatusPlaceholderExpansion placeholderExpansion; private boolean newVersion; @@ -51,12 +56,16 @@ public void onEnable() { // Register the PlayerJoinListener and ChatListener getServer().getPluginManager().registerEvents(new PlayerJoinListener(this ,this.statusManager), this); - getServer().getPluginManager().registerEvents(new ChatListener(this.statusManager, configManager), this); + getServer().getPluginManager().registerEvents(new ChatListener(this), this); // Set the executor and tab completer for the "status" command StatusCommand statusCommand = new StatusCommand(statusManager,newVersion,version); getCommand("status").setExecutor(statusCommand); - getCommand("status").setTabCompleter(new StatusTabCompleter()); + getCommand("status").setTabCompleter(new StatusTabCompleter(this)); + + GroupCommand groupCommand = new GroupCommand(this); + getCommand("group").setExecutor(groupCommand); + getCommand("group").setTabCompleter(new GroupTabCompleter(this)); // Initialize the Metrics Metrics metrics = new Metrics(this, pluginId); @@ -65,6 +74,7 @@ public void onEnable() { if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { placeholderExpansion = new StatusPlaceholderExpansion(this); placeholderExpansion.register(); + placeholderAPIPresent = true; getLogger().info("Tub's StatusPlugin will now use PlaceholderAPI"); } else { getLogger().warning("Could not find PlaceholderAPI! Tub's StatusPlugin will run without it.."); @@ -97,7 +107,6 @@ public void sendPluginMessages(CommandSender sender, String type) { + ChatColor.GOLD + "-"); } } - /** * Method to get the plugin prefix. * @return The plugin prefix. @@ -122,6 +131,9 @@ public StatusManager getStatusManager(){ return statusManager; } + public boolean isPlaceholderAPIPresent() { + return placeholderAPIPresent; + } /** * This method is called when the plugin is disabled. * It saves the statuses. diff --git a/src/main/java/de/tubyoub/statusplugin/commands/GroupCommand.java b/src/main/java/de/tubyoub/statusplugin/commands/GroupCommand.java new file mode 100644 index 0000000..9131ee6 --- /dev/null +++ b/src/main/java/de/tubyoub/statusplugin/commands/GroupCommand.java @@ -0,0 +1,46 @@ +package de.tubyoub.statusplugin.commands; + +import de.tubyoub.statusplugin.Managers.StatusManager; +import de.tubyoub.statusplugin.StatusPlugin; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class GroupCommand implements CommandExecutor { + private final StatusManager statusManager; + private final StatusPlugin plugin; + + public GroupCommand(StatusPlugin plugin) { + this.statusManager = plugin.getStatusManager(); + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(plugin.getPluginPrefix() + " This command can only be run by a player."); + return true; + } + + Player player = (Player) sender; + + if (!statusManager.isGroupMode()) { + player.sendMessage(plugin.getPluginPrefix() + ChatColor.RED + " Group mode is not enabled."); + return true; + } + + if (args.length != 1) { + player.sendMessage(plugin.getPluginPrefix() + ChatColor.RED + " Usage: /" + command.getName() + " "); + return true; + } + + String groupName = args[0]; + if (statusManager.setGroupStatus(player, groupName)) { + player.sendMessage(plugin.getPluginPrefix() + ChatColor.GREEN + " Your status has been set to the " + groupName + " group."); + } + + return true; + } +} \ No newline at end of file diff --git a/src/main/java/de/tubyoub/statusplugin/commands/StatusCommand.java b/src/main/java/de/tubyoub/statusplugin/commands/StatusCommand.java index a44afe3..48f2bd2 100644 --- a/src/main/java/de/tubyoub/statusplugin/commands/StatusCommand.java +++ b/src/main/java/de/tubyoub/statusplugin/commands/StatusCommand.java @@ -97,6 +97,13 @@ public boolean onCommand(CommandSender sender, Command command, String label, St player.sendMessage(plugin.getPluginPrefix() + ChatColor.RED + " Usage: /status remove [player]"); } return true; + case "group": + if (args.length == 2) { + handleGroupCommand(player, args[1]); + } else { + player.sendMessage(plugin.getPluginPrefix() + ChatColor.RED + " Usage: /status group "); + } + return true; default: handleDefaultCommand(player, args); return true; @@ -129,13 +136,29 @@ private void handleDefaultCommand(Player player, String[] args) { player.sendMessage("Invalid player name: " + args[0]); return; } - if (!player.hasPermission("StatusPlugin.setStatus")) { - player.sendMessage(plugin.getPluginPrefix() + ChatColor.RED + " You don't have permission to set your own status."); + if (!plugin.getConfigManager().isGroupMode()) { + if (!player.hasPermission("StatusPlugin.setStatus")) { + player.sendMessage(plugin.getPluginPrefix() + ChatColor.RED + " You don't have permission to set your own status."); + return; + } + String status = String.join(" ", args); + + if (statusManager.setStatus(player, status, player)) { + player.sendMessage(plugin.getPluginPrefix() + " Your status has been set to: " + "[" + ColourUtils.format(statusManager.getStatus(player)) + ChatColor.RESET + "]"); + } + }else { + player.sendMessage(plugin.getPluginPrefix() + ChatColor.RED + " Group mode is enabled."); + } + } + + private void handleGroupCommand(Player player, String groupName) { + if (!statusManager.isGroupMode()) { + player.sendMessage(plugin.getPluginPrefix() + ChatColor.RED + " Group mode is not enabled."); return; } - String status = String.join(" ", args); - if (statusManager.setStatus(player, status, player)) { - player.sendMessage(plugin.getPluginPrefix() + " Your status has been set to: " + "[" + ColourUtils.format(statusManager.getStatus(player)) + ChatColor.RESET + "]"); + + if (statusManager.setGroupStatus(player, groupName)) { + player.sendMessage(plugin.getPluginPrefix() + ChatColor.GREEN + " Your status has been set to the " + groupName + " group."); } } @@ -177,6 +200,10 @@ private void helpCommand(Player sender, StatusPlugin plugin, String[] args) { sender.sendMessage("/status - Set your own status."); sender.sendMessage("/status remove - Remove your Status."); sender.sendMessage("/status help colorcodes - Get all colorcodes to use in your status."); + if (statusManager.isGroupMode()) { + sender.sendMessage("/status group - Set your status to a predefined group."); + sender.sendMessage("/group - Set your status to a predefined group."); + } if (sender.hasPermission("StatusPlugin.admin.setStatus")) { sender.sendMessage("/status remove - Remove a player's status. (Admin)"); sender.sendMessage("/status - Set a player's status. (Admin)"); diff --git a/src/main/java/de/tubyoub/statusplugin/commands/tabCompleter/GroupTabCompleter.java b/src/main/java/de/tubyoub/statusplugin/commands/tabCompleter/GroupTabCompleter.java new file mode 100644 index 0000000..1bc1f4b --- /dev/null +++ b/src/main/java/de/tubyoub/statusplugin/commands/tabCompleter/GroupTabCompleter.java @@ -0,0 +1,38 @@ +package de.tubyoub.statusplugin.commands.tabCompleter; + +import de.tubyoub.statusplugin.StatusPlugin; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import java.util.ArrayList; +import java.util.List; + +/** + * Class implementing the TabCompleter interface to provide tab completion functionality for the group command. + */ +public class GroupTabCompleter implements TabCompleter { + private final StatusPlugin plugin; + + public GroupTabCompleter(StatusPlugin plugin) { + this.plugin = plugin; + } + + /** + * Method to handle tab completion for the group command. + * @param sender The sender of the command. + * @param command The command to be completed. + * @param alias The alias of the command. + * @param args The arguments of the command. + * @return A list of suggestions for tab completion. + */ + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + List suggestions = new ArrayList<>(); + + if (args.length == 1) { + // Suggest available groups for the first argument + suggestions.addAll(plugin.getConfigManager().getStatusGroups().keySet()); + } + return suggestions; + } +} \ No newline at end of file diff --git a/src/main/java/de/tubyoub/statusplugin/StatusTabCompleter.java b/src/main/java/de/tubyoub/statusplugin/commands/tabCompleter/StatusTabCompleter.java similarity index 81% rename from src/main/java/de/tubyoub/statusplugin/StatusTabCompleter.java rename to src/main/java/de/tubyoub/statusplugin/commands/tabCompleter/StatusTabCompleter.java index 77c983f..ba78526 100644 --- a/src/main/java/de/tubyoub/statusplugin/StatusTabCompleter.java +++ b/src/main/java/de/tubyoub/statusplugin/commands/tabCompleter/StatusTabCompleter.java @@ -1,5 +1,6 @@ -package de.tubyoub.statusplugin; +package de.tubyoub.statusplugin.commands.tabCompleter; +import de.tubyoub.statusplugin.StatusPlugin; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; @@ -13,6 +14,11 @@ * Class implementing the TabCompleter interface to provide tab completion functionality for the status plugin. */ public class StatusTabCompleter implements TabCompleter { + private final StatusPlugin plugin; + + public StatusTabCompleter(StatusPlugin plugin) { + this.plugin = plugin; + } /** * Method to handle tab completion for the status plugin commands. @@ -34,6 +40,7 @@ public List onTabComplete(CommandSender sender, Command command, String suggestions.add("resetmaxlength"); suggestions.add("info"); suggestions.add("reload"); + suggestions.add("grave"); } else if (args.length == 2) { // Add suggestions for the second argument of the command based on the first argument if (args[0].equalsIgnoreCase("remove")) { @@ -47,6 +54,9 @@ public List onTabComplete(CommandSender sender, Command command, String } else if (args[0].equalsIgnoreCase("help")) { // If the first argument is "help", suggest "colorcodes" suggestions.add("colorcodes"); + } else if (args[0].equalsIgnoreCase("grave")) { + // If the first argument is the group command, suggest available groups + suggestions.addAll(plugin.getConfigManager().getStatusGroups().keySet()); } } return suggestions; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index cb062bb..bfa6732 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -3,7 +3,7 @@ # by TubYoub # ################################ # Don't change this value, it's changed by the plugin if needed -fileversion: 2 +fileversion: 3 # maximum Character length a Status should be allowed to have. # default: 15 @@ -13,4 +13,17 @@ maxStatusLength: 15 chatFormatter: true # If the Tablist name should be changed by the plugin or not. (restart your server so the changes will work correctly) # default: true -changeTablistNames: true \ No newline at end of file +changeTablistNames: true +# Enable group mode for statuses +# When enabled, players can only choose from predefined status groups +# default: false +groupMode: false +# Define status groups +# Each group has a name and a status +statusGroups: + t1: + status: 'Team1' + t2: + status: 'Team2' + t3: + status: 'Team3' \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index d90a93a..0389394 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -7,10 +7,15 @@ softdepend: [PlaceholderAPI] commands: status: description: Set a player's status, get info, get help, reload the plugin, set/reset max length + group: + description: Set a player's status group permissions: StatusPlugin.setStatus: description: Allows setting own status. (default player) default: true + StatusPlugin.group.set: + description: Allows setting own status group. (default player) + default: true StatusPlugin.admin.setStatus: description: Allows setting other players' statuses. (default op) default: op