diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 37aef8d..c30b486 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/com/armamc/plugincontrol/commands/subcommands/ActionSubCommand.java b/src/main/java/com/armamc/plugincontrol/commands/subcommands/ActionSubCommand.java index 12ba370..5944c8f 100644 --- a/src/main/java/com/armamc/plugincontrol/commands/subcommands/ActionSubCommand.java +++ b/src/main/java/com/armamc/plugincontrol/commands/subcommands/ActionSubCommand.java @@ -17,7 +17,6 @@ public class ActionSubCommand implements SubCommand { private final MessageManager message; private final PluginsManager manager; private final List actions; - private static final String ACTION_TAG = "action"; @Contract(pure = true) public ActionSubCommand(@NotNull PluginControl plugin) { @@ -30,22 +29,26 @@ public ActionSubCommand(@NotNull PluginControl plugin) { @Override public void execute(CommandSender sender, Command command, String label, String @NotNull [] args) { if (args.length == 0 || args[0].isBlank()) { - message.send(sender, message.getActionType(), Placeholder.parsed(ACTION_TAG, config.getAction().toLowerCase())); + message.send(sender, message.getActionType(), Placeholder.parsed("action", config.getAction().toLowerCase())); return; } try { - var actiontype = ConfigManager.ActionType.from(args[0].toLowerCase()); - config.setAction(actiontype); - message.send(sender, message.getActionSet(), Placeholder.parsed(ACTION_TAG, actiontype.getAction())); + var actionType = ConfigManager.ActionType.from(args[0].toLowerCase()); + config.setAction(actionType); + message.send(sender, message.getActionSet(), Placeholder.parsed("action", actionType.getAction())); + if (actionType != ConfigManager.ActionType.DISALLOW_PLAYER_LOGIN) { + manager.unregisterListener(); + } manager.checkPlugins(); } catch (IllegalArgumentException e) { - message.send(sender, message.getActionTypeList(), Placeholder.parsed(ACTION_TAG, String.join(", ", actions))); + message.send(sender, message.getActionTypeList(), Placeholder.parsed("actions", String.join(", ", actions))); } } @Override public List tabComplete(CommandSender sender, Command command, String label, String[] args) { + if (args.length != 1) return List.of(); return actions.stream().filter(s -> s.startsWith(args[0])).toList(); } diff --git a/src/main/java/com/armamc/plugincontrol/managers/MessageManager.java b/src/main/java/com/armamc/plugincontrol/managers/MessageManager.java index 0d026d2..1457ff8 100644 --- a/src/main/java/com/armamc/plugincontrol/managers/MessageManager.java +++ b/src/main/java/com/armamc/plugincontrol/managers/MessageManager.java @@ -103,7 +103,8 @@ public void send(@NotNull CommandSender sender, @NotNull List message, @ } public @NotNull Component getPluginListComponent(@NotNull Set pluginList) { - var joinConfiguration = JoinConfiguration.separators(MM.deserialize(getPluginListSeparator()), + var joinConfiguration = JoinConfiguration.separators( + MM.deserialize(getPluginListSeparator()), MM.deserialize(getPluginListSeparatorLast())); var componentList = new ArrayList(); @@ -120,6 +121,24 @@ public void send(@NotNull CommandSender sender, @NotNull List message, @ return Component.join(joinConfiguration, componentList); } + public @NotNull Component getGroupListComponent(@NotNull Set groupList) { + var joinConfiguration = JoinConfiguration.separators( + MM.deserialize(getPluginListSeparator()), + MM.deserialize(getPluginListSeparatorLast())); + + var componentList = new ArrayList(); + if (!groupList.isEmpty()) { + var command = "/plugincontrol group delete %s"; + for (var groupName : groupList) { + componentList.add(MM.deserialize(groupName) + .hoverEvent(HoverEvent.showText(MM.deserialize(getGroupClickDelete()))) + .clickEvent(ClickEvent.runCommand(command.formatted(groupName)))); + } + } + + return Component.join(joinConfiguration, componentList); + } + public @NotNull Component getGroupListComponent(@NotNull Map> pluginGroups) { if (pluginGroups.isEmpty()) return MM.deserialize(getGroupListEmpty()); @@ -132,7 +151,8 @@ public void send(@NotNull CommandSender sender, @NotNull List message, @ for (var groupEntry : sortedGroups) { var groupName = groupEntry.getKey(); - componentList.add(Component.newline().append(MM.deserialize(getGroupListName(), Placeholder.parsed("group", groupName)) + componentList.add(Component.newline().append(MM.deserialize(getGroupListName(), + Placeholder.parsed("group", groupName)) .hoverEvent(HoverEvent.showText(MM.deserialize(getGroupClickInfo()))) .clickEvent(ClickEvent.runCommand(groupCommand.formatted(groupName))))); @@ -140,6 +160,7 @@ public void send(@NotNull CommandSender sender, @NotNull List message, @ .sorted(String.CASE_INSENSITIVE_ORDER) .collect(Collectors.toCollection(TreeSet::new)); var pluginComponents = new ArrayList(); + if (!plugins.isEmpty()) { var joinConfiguration = JoinConfiguration.builder() .separator(MM.deserialize(getPluginListSeparator())) @@ -273,8 +294,8 @@ public String getCheckFinished() { return lang.getString("console.finished-checking"); } - public String getLogToConsole() { - return lang.getString("console.log-to-console"); + public String getLogToConsolePlugin() { + return lang.getString("console.log-to-console-plugin"); } public String getLogToConsoleGroup() { @@ -377,6 +398,10 @@ public String getGroupListName() { return lang.getString("command.group-list-name"); } + private String getGroupClickDelete() { + return lang.getString("command.group-click-delete"); + } + public String getGroupClickRemovePlugin() { return lang.getString("command.group-click-remove-plugin"); } diff --git a/src/main/java/com/armamc/plugincontrol/managers/PluginsManager.java b/src/main/java/com/armamc/plugincontrol/managers/PluginsManager.java index 893832b..68331e4 100644 --- a/src/main/java/com/armamc/plugincontrol/managers/PluginsManager.java +++ b/src/main/java/com/armamc/plugincontrol/managers/PluginsManager.java @@ -3,6 +3,7 @@ import com.armamc.plugincontrol.PluginControl; import com.armamc.plugincontrol.listeners.PlayerListener; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import org.bukkit.Bukkit; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.event.player.PlayerLoginEvent; @@ -36,6 +37,7 @@ public void checkPlugins() { } } + var missingGroups = new HashSet(); var pluginGroup = config.getPluginGroups(); for (var groups : pluginGroup.entrySet()) { boolean groupHasEnabledPlugin = false; @@ -48,33 +50,60 @@ public void checkPlugins() { } if (!groupHasEnabledPlugin) { - missingPlugins.add(message.getLogToConsoleGroup().replace("", groups.getKey())); + missingGroups.add(groups.getKey()); } } - if (!missingPlugins.isEmpty()) { - registerAction(missingPlugins); + if (!missingPlugins.isEmpty() || !missingGroups.isEmpty()) { + registerAction(missingPlugins, missingGroups); } else { message.send(console, message.getCheckFinished()); } } - private void registerAction(Set missingPlugins) { - var tag = Placeholder.component("plugins", message.getPluginListComponent(new HashSet<>(missingPlugins))); - if (config.getAction().equalsIgnoreCase(ConfigManager.ActionType.DISALLOW_PLAYER_LOGIN.getAction())) { + private void registerAction(@NotNull Set missingPlugins, @NotNull Set missingGroups) { + TagResolver.Single pluginTag = null; + if (!missingPlugins.isEmpty()) { + pluginTag = Placeholder.component("plugins", message.getPluginListComponent(missingPlugins)); + } + + TagResolver.Single groupTag = null; + if (!missingGroups.isEmpty()) { + groupTag = Placeholder.component("groups", message.getGroupListComponent(missingGroups)); + } + + switch (ConfigManager.ActionType.from(config.getAction().toLowerCase())) { + case DISALLOW_PLAYER_LOGIN -> handleDisallowPlayerLogin(pluginTag, groupTag); + case LOG_TO_CONSOLE -> logToConsole(pluginTag, groupTag); + case SHUTDOWN_SERVER -> shutdownServer(pluginTag, groupTag); + default -> throw new IllegalArgumentException("Unknown action: %s".formatted(config.getAction())); + } + } + + private void handleDisallowPlayerLogin(TagResolver.Single pluginTag, TagResolver.Single groupTag) { + if (playerListener == null) { playerListener = new PlayerListener(plugin); playerListener.init(); - message.send(console, message.getLogToConsole(), tag); - return; } - if (config.getAction().equalsIgnoreCase(ConfigManager.ActionType.LOG_TO_CONSOLE.getAction())) { - message.send(console, message.getLogToConsole(), tag); - return; + + logToConsole(pluginTag, groupTag); + } + + private void shutdownServer(TagResolver.Single pluginTag, TagResolver.Single groupTag) { + logToConsole(pluginTag, groupTag); + message.send(console, message.getDisablingServer()); + plugin.getServer().shutdown(); + } + + private void logToConsole(TagResolver.Single pluginTag, TagResolver.Single groupTag) { + if (pluginTag != null) { + message.send(console, message.getLogToConsolePlugin(), pluginTag); } - if (config.getAction().equalsIgnoreCase(ConfigManager.ActionType.SHUTDOWN_SERVER.getAction())) { - message.send(console, message.getDisablingServer(), tag); - plugin.getServer().shutdown(); + if (groupTag != null) { + message.send(console, message.getLogToConsoleGroup(), groupTag); } + + message.send(console, message.getCheckFinished()); } public void unregisterListener() { diff --git a/src/main/resources/lang.yml b/src/main/resources/lang.yml index 31ef3ff..60455f4 100644 --- a/src/main/resources/lang.yml +++ b/src/main/resources/lang.yml @@ -2,10 +2,10 @@ prefix: '[PluginControl]' kick-message: '[PluginControl] You are not allowed to join the server!' console: checking-plugins: ' Checking plugins...' - disabling-server: ' Disabling server because was not found or enabled!' + disabling-server: ' Disabling server because plugins or groups were not found or enabled!' finished-checking: ' Plugins verified!' - log-to-console: ' Plugin not found or enabled...' - log-to-console-group: 'from the group ' + log-to-console-plugin: ' Required plugins were not found: ' + log-to-console-group: ' Required groups were not found: ' command: action-list: ' Actions available: ' action-set: ' Action set to ' @@ -49,10 +49,11 @@ command: group-has-no-plugins: ' Group has no plugins!' group-plugin-list: ' Plugins in group : ' group-list-name: 'Group :' + group-click-delete: 'Click to delete the group' group-click-remove-plugin: 'Click to remove the plugin from the group' group-click-info: 'Click to see the group info' group-help: - - '==== Plugin Control Group Help ====' + - '=== Plugin Control Group Help ===' - '/ group create - Create a group' - '/ group delete - Remove a group' - '/ group list - List all required groups'