Custom command denied message for the group

This commit is contained in:
kforbro
2021-10-26 12:48:59 +03:00
parent 48fbd59a50
commit d43bde0750
6 changed files with 43 additions and 10 deletions
@@ -4,14 +4,15 @@ import java.util.*;
public class CWGroup {
private final String id, permission;
private final String id, permission, custom_command_denied_message;
private final HashSet<String> commands = new HashSet<>();
private final HashSet<String> subCommands = new HashSet<>();
public CWGroup(String id, Collection<String> commands, Collection<String> subCommands) {
public CWGroup(String id, Collection<String> commands, Collection<String> subCommands, String custom_command_denied_message) {
this.id = id;
this.permission = "commandwhitelist.group."+id;
this.commands.addAll(commands);
this.custom_command_denied_message = custom_command_denied_message;
this.subCommands.addAll(subCommands);
}
@@ -23,9 +24,9 @@ public class CWGroup {
return permission;
}
public HashSet<String> getCommands() {
return commands;
}
public HashSet<String> getCommands() { return commands; }
public String getCustomCommandDeniedMessage() { return custom_command_denied_message; }
public void addCommand(String command) {
commands.add(command);
@@ -51,9 +51,11 @@ public class ConfigCache {
exampleCommands.add("example");
List<String> exampleSubCommands = new ArrayList<>();
exampleSubCommands.add("example of");
String exampleCustomCommandDeniedMessage = "You don't have commandwhitelist.group.example permission.";
config.addExample("groups.example.commands", exampleCommands, "This is the WHITELIST of commands that players will be able to see/use in the group \"example\"");
config.addExample("groups.example.subcommands", exampleSubCommands, "This is the BLACKLIST of subcommands that players will NOT be able to see/use in the group \"example\"");
config.addExample("groups.example.custom_command_denied_message", exampleCustomCommandDeniedMessage, "This is a custom message that players will see if they do not have commandwhitelist.group.<group_name> permission.\ncommandwhitelist.group.example in this case\nIf you don't want to use a custom message, set custom_command_denid_message: \"\"");
config.addComment("groups.example", "All groups except from default require commandwhitelist.group.<group_name> permission\ncommandwhitelist.group.example in this case\n If you wish to leave the list empty, put \"commands: []\" or \"subcommands: []\"");
}
@@ -75,7 +77,9 @@ public class ConfigCache {
List<String> defaultSubcommands = new ArrayList<>();
defaultSubcommands.add("help about");
config.addDefault("groups.default", new CWGroup("default", defaultCommands, defaultSubcommands).serialize());
String defaultCustomCommandDeniedMessage = "";
config.addDefault("groups.default", new CWGroup("default", defaultCommands, defaultSubcommands, defaultCustomCommandDeniedMessage).serialize());
prefix = config.getString("messages.prefix");
command_denied = config.getString("messages.command_denied");
@@ -130,7 +134,8 @@ public class ConfigCache {
}
List<String> subCommands = section.getStringList(id + ".subcommands");
return new CWGroup(id, commands, subCommands);
String customCommandDeniedMessage = section.getString(id + ".custom_command_denied_message");
return new CWGroup(id, commands, subCommands, customCommandDeniedMessage);
}
public void saveCWGroup(String id, CWGroup group) {