From 9507ff966e74c3e646ebce8deb3c09c4161c1308 Mon Sep 17 00:00:00 2001 From: Thomas Meaney Date: Wed, 15 Jan 2025 20:27:29 +0100 Subject: [PATCH 1/2] Add permissions to `/buildsystem`, `/worlds help` and `/worlds item` Each permission is set to `true` by default Fixes #317 --- .../buildsystem/command/BuildSystemCommand.java | 7 ++++++- .../eintosti/buildsystem/command/PagedCommand.java | 8 ++++---- .../eintosti/buildsystem/command/WorldsCommand.java | 2 +- .../buildsystem/command/subcommand/SubCommand.java | 6 ++---- .../command/subcommand/worlds/HelpSubCommand.java | 13 +++++++++++-- .../buildsystem/tabcomplete/WorldsTabComplete.java | 4 ++-- buildsystem-core/src/main/resources/plugin.yml | 8 +++++++- 7 files changed, 33 insertions(+), 15 deletions(-) diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BuildSystemCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BuildSystemCommand.java index e3917aa6..8730fecf 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BuildSystemCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BuildSystemCommand.java @@ -33,7 +33,7 @@ public class BuildSystemCommand extends PagedCommand implements CommandExecutor private final BuildSystem plugin; public BuildSystemCommand(BuildSystem plugin) { - super("buildsystem_permission", "buildsystem_title_with_page"); + super("buildsystem_title_with_page", "buildsystem_permission"); this.plugin = plugin; plugin.getCommand("buildsystem").setExecutor(this); @@ -45,7 +45,12 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N plugin.getLogger().warning(Messages.getString("sender_not_player", null)); return true; } + Player player = (Player) sender; + if (!player.hasPermission("buildsystem.buildsystem")) { + plugin.sendPermissionMessage(player); + return true; + } if (args.length == 0) { sendMessage(player, 1); diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/PagedCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/PagedCommand.java index c8c3f996..f42c964c 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/PagedCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/PagedCommand.java @@ -32,11 +32,11 @@ public abstract class PagedCommand { private static final int MAX_COMMANDS_PER_PAGE = 7; - private final String permission, title; + private final String title, permissionTemplate; - public PagedCommand(String permission, String title) { - this.permission = permission; + public PagedCommand(String title, String permissionTemplate) { this.title = title; + this.permissionTemplate = permissionTemplate; } protected void sendMessage(Player player, int pageNum) { @@ -85,7 +85,7 @@ protected TextComponent createComponent(Player player, String command, String co commandComponent.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, suggest)); commandComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, - new ComponentBuilder(Messages.getString(this.permission, player, new AbstractMap.SimpleEntry<>("%permission%", permission))).create() + new ComponentBuilder(Messages.getString(this.permissionTemplate, player, new AbstractMap.SimpleEntry<>("%permission%", permission))).create() )); commandComponent.addExtra(textComponent); return commandComponent; diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/WorldsCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/WorldsCommand.java index 559f5bbd..1daf1d09 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/WorldsCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/WorldsCommand.java @@ -105,7 +105,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N break; } case HELP: { - subCommand = new HelpSubCommand(); + subCommand = new HelpSubCommand(plugin); break; } case IMPORT_ALL: { diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/SubCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/SubCommand.java index 6f9ae5a1..4b9cc3f8 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/SubCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/SubCommand.java @@ -26,9 +26,7 @@ public interface SubCommand { Argument getArgument(); default boolean hasPermission(Player player) { - if (getArgument().getPermission() == null) { - return true; - } - return player.hasPermission(getArgument().getPermission()); + String permission = getArgument().getPermission(); + return permission == null || player.hasPermission(permission); } } \ No newline at end of file diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/HelpSubCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/HelpSubCommand.java index 3a83d566..f2438c06 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/HelpSubCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/HelpSubCommand.java @@ -18,6 +18,7 @@ package de.eintosti.buildsystem.command.subcommand.worlds; import com.google.common.collect.Lists; +import de.eintosti.buildsystem.BuildSystem; import de.eintosti.buildsystem.Messages; import de.eintosti.buildsystem.command.PagedCommand; import de.eintosti.buildsystem.command.subcommand.Argument; @@ -29,12 +30,20 @@ public class HelpSubCommand extends PagedCommand implements SubCommand { - public HelpSubCommand() { - super("worlds_help_permission", "worlds_help_title_with_page"); + private final BuildSystem plugin; + + public HelpSubCommand(BuildSystem plugin) { + super("worlds_help_title_with_page", "worlds_help_permission"); + this.plugin = plugin; } @Override public void execute(Player player, String[] args) { + if (!hasPermission(player)) { + plugin.sendPermissionMessage(player); + return; + } + if (args.length == 1) { sendMessage(player, 1); } else if (args.length == 2) { diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/WorldsTabComplete.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/WorldsTabComplete.java index 7dacedd9..058db344 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/WorldsTabComplete.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/WorldsTabComplete.java @@ -190,11 +190,11 @@ public enum WorldsArgument implements Argument { BUILDERS("builders", "buildsystem.builders"), DELETE("delete", "buildsystem.delete"), EDIT("edit", "buildsystem.edit"), - HELP("help", null), + HELP("help", "buildsystem.help"), IMPORT("import", "buildsystem.import"), IMPORT_ALL("importAll", "buildsystem.import.all"), INFO("info", "buildsystem.info"), - ITEM("item", null), + ITEM("item", "buildsystem.navigator.item"), REMOVE_BUILDER("removeBuilder", "buildsystem.removebuilder"), RENAME("rename", "buildsystem.rename"), SET_CREATOR("setCreator", "buildsystem.setcreator"), diff --git a/buildsystem-core/src/main/resources/plugin.yml b/buildsystem-core/src/main/resources/plugin.yml index 01bb271e..7719624d 100644 --- a/buildsystem-core/src/main/resources/plugin.yml +++ b/buildsystem-core/src/main/resources/plugin.yml @@ -67,11 +67,17 @@ commands: usage: / permissions: + buildsystem.buildsystem: + description: Display all commands provided by the plugin. + default: true + buildsystem.help: + description: Display all /worlds subcommands. + default: true buildsystem.navigator: description: Open the worlds navigator. default: true buildsystem.navigator.item: - description: Receive and use the naviagtor open. + description: Receive and use the navigator. default: true buildsystem.create: children: From 912997394ff00c96ef1095b8da0b9ea6d3e9cde8 Mon Sep 17 00:00:00 2001 From: Thomas Meaney Date: Wed, 15 Jan 2025 20:37:21 +0100 Subject: [PATCH 2/2] Change permissions for `/buildsystem` and `/worlds help` --- .../eintosti/buildsystem/command/BuildSystemCommand.java | 2 +- .../buildsystem/tabcomplete/WorldsTabComplete.java | 2 +- buildsystem-core/src/main/resources/plugin.yml | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BuildSystemCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BuildSystemCommand.java index 8730fecf..e28b8a82 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BuildSystemCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BuildSystemCommand.java @@ -47,7 +47,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N } Player player = (Player) sender; - if (!player.hasPermission("buildsystem.buildsystem")) { + if (!player.hasPermission("buildsystem.help.buildsystem")) { plugin.sendPermissionMessage(player); return true; } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/WorldsTabComplete.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/WorldsTabComplete.java index 058db344..c6ed74d7 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/WorldsTabComplete.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/WorldsTabComplete.java @@ -190,7 +190,7 @@ public enum WorldsArgument implements Argument { BUILDERS("builders", "buildsystem.builders"), DELETE("delete", "buildsystem.delete"), EDIT("edit", "buildsystem.edit"), - HELP("help", "buildsystem.help"), + HELP("help", "buildsystem.help.worlds"), IMPORT("import", "buildsystem.import"), IMPORT_ALL("importAll", "buildsystem.import.all"), INFO("info", "buildsystem.info"), diff --git a/buildsystem-core/src/main/resources/plugin.yml b/buildsystem-core/src/main/resources/plugin.yml index 7719624d..cd02ce30 100644 --- a/buildsystem-core/src/main/resources/plugin.yml +++ b/buildsystem-core/src/main/resources/plugin.yml @@ -67,12 +67,12 @@ commands: usage: / permissions: - buildsystem.buildsystem: - description: Display all commands provided by the plugin. - default: true buildsystem.help: - description: Display all /worlds subcommands. + children: + - buildsystem.help.buildsystem + - buildsystem.help.worlds default: true + description: Permission for help commands. buildsystem.navigator: description: Open the worlds navigator. default: true