- Баллы
- 76
Нужно сделать вайтлист команд. Они хранятся в конфиге.
Сделал это, но не работает):
Сделал это, но не работает):
Код:
public class ConfigManager implements Listener {
private List<String> allowedCmds = new ArrayList<String>();
private Configuration config;
private boolean isRestrictCommands = false;
@SuppressWarnings("unused")
private boolean enabled;
@EventHandler(priority=EventPriority.LOW)
public void onCommandPreProcess(PlayerCommandPreprocessEvent event) {
if (event.getPlayer().hasPermission("prison.admin")) {
return;
}
for (String ac : getAllowedCmds()) {
if (!event.getMessage().startsWith("/" + ac)) continue;
return;
}
event.getPlayer().sendMessage((Object)Commands.prefix + "§cНеивестная команда.");
event.setCancelled(true);
}
public List<String> getAllowedCmds() {
return this.allowedCmds;
}
public ConfigManager(Configuration config) {
this.config = config;
this.config = config;
this.enabled = config.getBoolean("enabled");
if (this.getBoolenOrDefault("features.restrict_commands.enabled", true)) {
this.allowedCmds = this.getConfig().getStringList("features.restrict_commands.allowed_cmds");
this.isRestrictCommands = true;
}
}
public void shade(Configuration config) {
if (config.contains("features.restrict_commands.enabled")) {
this.isRestrictCommands = config.getBoolean("features.restrict_commands.enabled");
if (isRestrictCommands()) {
this.allowedCmds = config.getStringList("features.restrict_commands.allowed_cmds");
}
}
}
private boolean getBoolenOrDefault(String path, boolean def) {
config = Prison.instance.getConfig();
return config.contains(path) ? config.getBoolean(path) : def;
}
public Configuration getConfig() {
return this.config;
}
public boolean isRestrictCommands() {
return this.isRestrictCommands;
}
}