i'm trying to make a plugin, it must block a specified commands setted by config. i've maked this but it doesn't block any command.
Code:
@EventHandler(priority = EventPriority.HIGHEST)
public void onPreprocess(PlayerCommandPreprocessEvent event)
{
Player player = event.getPlayer();
String command = event.getMessage();
List<String> bCmds = this.plugin.cfg.getStringList("blocked-commands");
for (String bCmd : bCmds)
{
if(command.equalsIgnoreCase(bCmd))
{
event.setCancelled(true);
}
}
}
Config:
blocked-commands:
- /pl
- /op
- /sp
- /gravityblock
PS: I've tried to use:
String command = event.getMessage().subString(1);
Thanks for Help... :)
答案 0 :(得分:0)
注册活动?实施了清单?
此外,您的代码将无法使用命令中的其他参数。 如果它包含空格,则用“”拆分它并获取第一个元素以获取命令
if(cmd.contains(“”))cmd = cmd.split(“”)[0];
答案 1 :(得分:0)
如Bukkit's wiiki所述,优先级按以下顺序调用:
也许您可以尝试使用最低优先级,因此在处理命令之前会取消事件。
我也相信命令可能有参数,所以它可能不等于提供的字符串,你也应该尝试
String command = event.getMessage();
if (command.toLowerCase().startsWith("/command") ) {
//cancel
}