mirror of
https://github.com/loganintech/render-region-forcefield.git
synced 2026-05-30 22:31:15 +00:00
More permissions and a material command
This commit is contained in:
@@ -35,8 +35,7 @@ public class ForcefieldCommand implements CommandExecutor, TabCompleter {
|
|||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
|
||||||
@NotNull String label, @NotNull String[] args) {
|
@NotNull String label, @NotNull String[] args) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
sendHelp(sender);
|
return handleHelp(sender);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (args[0].toLowerCase()) {
|
switch (args[0].toLowerCase()) {
|
||||||
@@ -53,8 +52,7 @@ public class ForcefieldCommand implements CommandExecutor, TabCompleter {
|
|||||||
case "material":
|
case "material":
|
||||||
return handleMaterial(sender, args);
|
return handleMaterial(sender, args);
|
||||||
case "help":
|
case "help":
|
||||||
sendHelp(sender);
|
return handleHelp(sender);
|
||||||
return true;
|
|
||||||
default:
|
default:
|
||||||
sender.sendMessage(ChatColor.RED + "Unknown subcommand. Use /forcefield help");
|
sender.sendMessage(ChatColor.RED + "Unknown subcommand. Use /forcefield help");
|
||||||
return true;
|
return true;
|
||||||
@@ -234,7 +232,7 @@ public class ForcefieldCommand implements CommandExecutor, TabCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean handleMaterial(@NotNull CommandSender sender, @NotNull String[] args) {
|
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.");
|
sender.sendMessage(ChatColor.RED + "You don't have permission to use this command.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -274,6 +272,16 @@ public class ForcefieldCommand implements CommandExecutor, TabCompleter {
|
|||||||
return true;
|
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) {
|
private void sendHelp(@NotNull CommandSender sender) {
|
||||||
sender.sendMessage(ChatColor.GOLD + "=== RegionForcefield Commands ===");
|
sender.sendMessage(ChatColor.GOLD + "=== RegionForcefield Commands ===");
|
||||||
sender.sendMessage(ChatColor.YELLOW + "/forcefield debug " + ChatColor.GRAY + "- Toggle debug mode");
|
sender.sendMessage(ChatColor.YELLOW + "/forcefield debug " + ChatColor.GRAY + "- Toggle debug mode");
|
||||||
@@ -336,15 +344,36 @@ public class ForcefieldCommand implements CommandExecutor, TabCompleter {
|
|||||||
List<String> completions = new ArrayList<>();
|
List<String> completions = new ArrayList<>();
|
||||||
|
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
List<String> subcommands = Arrays.asList("debug", "reload", "status", "info", "test", "material", "help");
|
|
||||||
String input = args[0].toLowerCase();
|
String input = args[0].toLowerCase();
|
||||||
|
|
||||||
for (String subcommand : subcommands) {
|
// Only show subcommands the sender has permission to use
|
||||||
if (subcommand.startsWith(input)) {
|
if (sender.hasPermission("regionforcefield.debug") && "debug".startsWith(input)) {
|
||||||
completions.add(subcommand);
|
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")) {
|
} 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
|
// Suggest common block materials
|
||||||
List<String> commonMaterials = Arrays.asList(
|
List<String> commonMaterials = Arrays.asList(
|
||||||
"BARRIER", "GLASS", "GLASS_PANE",
|
"BARRIER", "GLASS", "GLASS_PANE",
|
||||||
|
|||||||
@@ -24,11 +24,13 @@ permissions:
|
|||||||
regionforcefield.reload: true
|
regionforcefield.reload: true
|
||||||
regionforcefield.status: true
|
regionforcefield.status: true
|
||||||
regionforcefield.info: true
|
regionforcefield.info: true
|
||||||
|
regionforcefield.material: true
|
||||||
|
regionforcefield.help: true
|
||||||
regionforcefield.command:
|
regionforcefield.command:
|
||||||
description: Allows access to the base /forcefield command
|
description: Allows access to the base /forcefield command
|
||||||
default: true
|
default: true
|
||||||
regionforcefield.debug:
|
regionforcefield.debug:
|
||||||
description: Allows toggling debug mode
|
description: Allows toggling debug mode and using test command
|
||||||
default: op
|
default: op
|
||||||
regionforcefield.reload:
|
regionforcefield.reload:
|
||||||
description: Allows reloading the plugin configuration
|
description: Allows reloading the plugin configuration
|
||||||
@@ -39,3 +41,9 @@ permissions:
|
|||||||
regionforcefield.info:
|
regionforcefield.info:
|
||||||
description: Allows viewing region information
|
description: Allows viewing region information
|
||||||
default: true
|
default: true
|
||||||
|
regionforcefield.material:
|
||||||
|
description: Allows changing the forcefield block material
|
||||||
|
default: op
|
||||||
|
regionforcefield.help:
|
||||||
|
description: Allows viewing command help
|
||||||
|
default: true
|
||||||
|
|||||||
Reference in New Issue
Block a user