mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-11 22:16:57 +00:00
Custom command denied message for the group
This commit is contained in:
@@ -34,7 +34,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.3.0-SNAPSHOT</version>
|
<version>3.2.4</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
|
|||||||
+15
@@ -126,4 +126,19 @@ public class CommandWhitelistBukkit extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
return suggestionList;
|
return suggestionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param command command
|
||||||
|
* @return custom command denied message
|
||||||
|
*/
|
||||||
|
public static String getCommandDeniedMessage(String command) {
|
||||||
|
String commandDeniedMessage = "";
|
||||||
|
HashMap<String, CWGroup> groups = configCache.getGroupList();
|
||||||
|
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
|
||||||
|
if (s.getValue().getCommands().contains(command)) {
|
||||||
|
commandDeniedMessage = s.getValue().getCustomCommandDeniedMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return commandDeniedMessage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-1
@@ -24,7 +24,12 @@ public class PlayerCommandPreProcessListener implements Listener {
|
|||||||
HashSet<String> commands = CommandWhitelistBukkit.getCommands(player);
|
HashSet<String> commands = CommandWhitelistBukkit.getCommands(player);
|
||||||
if (!commands.contains(label)) {
|
if (!commands.contains(label)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
audiences.player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + config.command_denied));
|
String customCommandDeniedMessage = CommandWhitelistBukkit.getCommandDeniedMessage(label);
|
||||||
|
if (!customCommandDeniedMessage.equals("")) {
|
||||||
|
audiences.player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + customCommandDeniedMessage));
|
||||||
|
} else {
|
||||||
|
audiences.player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + config.command_denied));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-1
@@ -12,6 +12,7 @@ import eu.endermite.commandwhitelist.common.CWPermission;
|
|||||||
import eu.endermite.commandwhitelist.common.CommandUtil;
|
import eu.endermite.commandwhitelist.common.CommandUtil;
|
||||||
import eu.endermite.commandwhitelist.common.ConfigCache;
|
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||||
import eu.endermite.commandwhitelist.common.commands.CWCommand;
|
import eu.endermite.commandwhitelist.common.commands.CWCommand;
|
||||||
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
@@ -37,9 +38,15 @@ public class PacketCommandPreProcessListener {
|
|||||||
ConfigCache config = CommandWhitelistBukkit.getConfigCache();
|
ConfigCache config = CommandWhitelistBukkit.getConfigCache();
|
||||||
String label = CommandUtil.getCommandLabel(string.toLowerCase());
|
String label = CommandUtil.getCommandLabel(string.toLowerCase());
|
||||||
HashSet<String> commands = CommandWhitelistBukkit.getCommands(player);
|
HashSet<String> commands = CommandWhitelistBukkit.getCommands(player);
|
||||||
|
BukkitAudiences audiences = CommandWhitelistBukkit.getAudiences();
|
||||||
if (!commands.contains(label)) {
|
if (!commands.contains(label)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
CommandWhitelistBukkit.getAudiences().player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + config.command_denied));
|
String customCommandDeniedMessage = CommandWhitelistBukkit.getCommandDeniedMessage(label);
|
||||||
|
if (!customCommandDeniedMessage.equals("")) {
|
||||||
|
audiences.player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + customCommandDeniedMessage));
|
||||||
|
} else {
|
||||||
|
audiences.player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + config.command_denied));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-5
@@ -4,14 +4,15 @@ import java.util.*;
|
|||||||
|
|
||||||
public class CWGroup {
|
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> commands = new HashSet<>();
|
||||||
private final HashSet<String> subCommands = 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.id = id;
|
||||||
this.permission = "commandwhitelist.group."+id;
|
this.permission = "commandwhitelist.group."+id;
|
||||||
this.commands.addAll(commands);
|
this.commands.addAll(commands);
|
||||||
|
this.custom_command_denied_message = custom_command_denied_message;
|
||||||
this.subCommands.addAll(subCommands);
|
this.subCommands.addAll(subCommands);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,9 +24,9 @@ public class CWGroup {
|
|||||||
return permission;
|
return permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashSet<String> getCommands() {
|
public HashSet<String> getCommands() { return commands; }
|
||||||
return commands;
|
|
||||||
}
|
public String getCustomCommandDeniedMessage() { return custom_command_denied_message; }
|
||||||
|
|
||||||
public void addCommand(String command) {
|
public void addCommand(String command) {
|
||||||
commands.add(command);
|
commands.add(command);
|
||||||
|
|||||||
+7
-2
@@ -51,9 +51,11 @@ public class ConfigCache {
|
|||||||
exampleCommands.add("example");
|
exampleCommands.add("example");
|
||||||
List<String> exampleSubCommands = new ArrayList<>();
|
List<String> exampleSubCommands = new ArrayList<>();
|
||||||
exampleSubCommands.add("example of");
|
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.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.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: []\"");
|
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<>();
|
List<String> defaultSubcommands = new ArrayList<>();
|
||||||
defaultSubcommands.add("help about");
|
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");
|
prefix = config.getString("messages.prefix");
|
||||||
command_denied = config.getString("messages.command_denied");
|
command_denied = config.getString("messages.command_denied");
|
||||||
@@ -130,7 +134,8 @@ public class ConfigCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<String> subCommands = section.getStringList(id + ".subcommands");
|
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) {
|
public void saveCWGroup(String id, CWGroup group) {
|
||||||
|
|||||||
Reference in New Issue
Block a user