diff --git a/src/main/java/loganintech/regionforcefield/command/ForcefieldCommand.java b/src/main/java/loganintech/regionforcefield/command/ForcefieldCommand.java index 20aeff9..ec321bc 100644 --- a/src/main/java/loganintech/regionforcefield/command/ForcefieldCommand.java +++ b/src/main/java/loganintech/regionforcefield/command/ForcefieldCommand.java @@ -35,8 +35,7 @@ public class ForcefieldCommand implements CommandExecutor, TabCompleter { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { if (args.length == 0) { - sendHelp(sender); - return true; + return handleHelp(sender); } switch (args[0].toLowerCase()) { @@ -53,8 +52,7 @@ public class ForcefieldCommand implements CommandExecutor, TabCompleter { case "material": return handleMaterial(sender, args); case "help": - sendHelp(sender); - return true; + return handleHelp(sender); default: sender.sendMessage(ChatColor.RED + "Unknown subcommand. Use /forcefield help"); return true; @@ -234,7 +232,7 @@ public class ForcefieldCommand implements CommandExecutor, TabCompleter { } private boolean handleMaterial(@NotNull CommandSender sender, @NotNull String[] args) { - if (!sender.hasPermission("regionforcefield.reload")) { + if (!sender.hasPermission("regionforcefield.material")) { sender.sendMessage(ChatColor.RED + "You don't have permission to use this command."); return true; } @@ -274,6 +272,16 @@ public class ForcefieldCommand implements CommandExecutor, TabCompleter { return true; } + private boolean handleHelp(@NotNull CommandSender sender) { + if (!sender.hasPermission("regionforcefield.help")) { + sender.sendMessage(ChatColor.RED + "You don't have permission to use this command."); + return true; + } + + sendHelp(sender); + return true; + } + private void sendHelp(@NotNull CommandSender sender) { sender.sendMessage(ChatColor.GOLD + "=== RegionForcefield Commands ==="); sender.sendMessage(ChatColor.YELLOW + "/forcefield debug " + ChatColor.GRAY + "- Toggle debug mode"); @@ -336,15 +344,36 @@ public class ForcefieldCommand implements CommandExecutor, TabCompleter { List completions = new ArrayList<>(); if (args.length == 1) { - List subcommands = Arrays.asList("debug", "reload", "status", "info", "test", "material", "help"); String input = args[0].toLowerCase(); - for (String subcommand : subcommands) { - if (subcommand.startsWith(input)) { - completions.add(subcommand); - } + // Only show subcommands the sender has permission to use + if (sender.hasPermission("regionforcefield.debug") && "debug".startsWith(input)) { + completions.add("debug"); + } + if (sender.hasPermission("regionforcefield.reload") && "reload".startsWith(input)) { + completions.add("reload"); + } + if (sender.hasPermission("regionforcefield.status") && "status".startsWith(input)) { + completions.add("status"); + } + if (sender.hasPermission("regionforcefield.info") && "info".startsWith(input)) { + completions.add("info"); + } + if (sender.hasPermission("regionforcefield.debug") && "test".startsWith(input)) { + completions.add("test"); + } + if (sender.hasPermission("regionforcefield.material") && "material".startsWith(input)) { + completions.add("material"); + } + if (sender.hasPermission("regionforcefield.help") && "help".startsWith(input)) { + completions.add("help"); } } else if (args.length == 2 && args[0].equalsIgnoreCase("material")) { + // Only show material suggestions if the sender has permission + if (!sender.hasPermission("regionforcefield.material")) { + return completions; + } + // Suggest common block materials List commonMaterials = Arrays.asList( "BARRIER", "GLASS", "GLASS_PANE", diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index af39f1c..61b5f50 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -24,11 +24,13 @@ permissions: regionforcefield.reload: true regionforcefield.status: true regionforcefield.info: true + regionforcefield.material: true + regionforcefield.help: true regionforcefield.command: description: Allows access to the base /forcefield command default: true regionforcefield.debug: - description: Allows toggling debug mode + description: Allows toggling debug mode and using test command default: op regionforcefield.reload: description: Allows reloading the plugin configuration @@ -39,3 +41,9 @@ permissions: regionforcefield.info: description: Allows viewing region information default: true + regionforcefield.material: + description: Allows changing the forcefield block material + default: op + regionforcefield.help: + description: Allows viewing command help + default: true