mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-12 06:26:57 +00:00
config shenanigans
This commit is contained in:
+8
-11
@@ -55,15 +55,10 @@ public final class CommandWhitelistWaterfall extends Plugin {
|
||||
}
|
||||
|
||||
public void loadConfig() {
|
||||
try {
|
||||
if (!getDataFolder().exists()) {
|
||||
getDataFolder().mkdir();
|
||||
}
|
||||
|
||||
configCache = new ConfigCache(new File(getDataFolder(), "config.yml"), false);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (configCache == null)
|
||||
configCache = new ConfigCache(new File(getDataFolder(), "config.yml"), false, getLogger());
|
||||
else
|
||||
configCache.reloadConfig();
|
||||
}
|
||||
|
||||
public void loadConfigAsync(CommandSender sender) {
|
||||
@@ -77,8 +72,9 @@ public final class CommandWhitelistWaterfall extends Plugin {
|
||||
* @param player Bungee Player
|
||||
* @return commands available to the player
|
||||
*/
|
||||
public static HashSet<String> getCommands(ProxiedPlayer player, HashMap<String, CWGroup> groups) {
|
||||
public static HashSet<String> getCommands(ProxiedPlayer player) {
|
||||
HashSet<String> commandList = new HashSet<>();
|
||||
HashMap<String, CWGroup> groups = configCache.getGroupList();
|
||||
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
|
||||
if (s.getKey().equalsIgnoreCase("default"))
|
||||
commandList.addAll(s.getValue().getCommands());
|
||||
@@ -92,7 +88,8 @@ public final class CommandWhitelistWaterfall extends Plugin {
|
||||
* @param player Bungee Player
|
||||
* @return subcommands unavailable for the player
|
||||
*/
|
||||
public static HashSet<String> getSuggestions(ProxiedPlayer player, HashMap<String, CWGroup> groups) {
|
||||
public static HashSet<String> getSuggestions(ProxiedPlayer player) {
|
||||
HashMap<String, CWGroup> groups = configCache.getGroupList();
|
||||
HashSet<String> suggestionList = new HashSet<>();
|
||||
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
|
||||
if (s.getKey().equalsIgnoreCase("default"))
|
||||
|
||||
+2
-2
@@ -29,14 +29,14 @@ public class BungeeChatEventListener implements Listener {
|
||||
BungeeAudiences audiences = CommandWhitelistWaterfall.getAudiences();
|
||||
|
||||
String label = CommandUtil.getCommandLabel(command);
|
||||
HashSet<String> commands = CommandWhitelistWaterfall.getCommands(player, configCache.getGroupList());
|
||||
HashSet<String> commands = CommandWhitelistWaterfall.getCommands(player);
|
||||
if (!commands.contains(label)) {
|
||||
event.setCancelled(true);
|
||||
CommandWhitelistWaterfall.getAudiences().player(player).sendMessage(MiniMessage.markdown().parse(configCache.prefix + configCache.command_denied));
|
||||
return;
|
||||
}
|
||||
|
||||
HashSet<String> bannedSubCommands = CommandWhitelistWaterfall.getSuggestions(player, configCache.getGroupList());
|
||||
HashSet<String> bannedSubCommands = CommandWhitelistWaterfall.getSuggestions(player);
|
||||
for (String bannedSubCommand : bannedSubCommands) {
|
||||
if (command.toLowerCase().substring(1).startsWith(bannedSubCommand)) {
|
||||
event.setCancelled(true);
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ public class WaterfallDefineCommandsListener implements Listener {
|
||||
if (player.hasPermission("commandwhitelist.bypass"))
|
||||
return;
|
||||
HashMap<String, Command> commandHashMap = new HashMap<>();
|
||||
CommandWhitelistWaterfall.getCommands(player, CommandWhitelistWaterfall.getConfigCache().getGroupList()).forEach(cmdName ->
|
||||
CommandWhitelistWaterfall.getCommands(player).forEach(cmdName ->
|
||||
CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().getCommands()
|
||||
.stream()
|
||||
.filter(commandEntry -> cmdName.equalsIgnoreCase(commandEntry.getValue().getName()))
|
||||
|
||||
Reference in New Issue
Block a user