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..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 @@ -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.help.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..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,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.worlds"), 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..cd02ce30 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.help: + children: + - buildsystem.help.buildsystem + - buildsystem.help.worlds + default: true + description: Permission for help commands. 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: