Allow exceptions to commands
This commit is contained in:
parent
a33204b7b8
commit
44ba3cd7ab
@ -4,13 +4,24 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class CommandCanceller implements Listener
|
public class CommandCanceller implements Listener
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private final static String allowedCmdsRegex = "\\/(login|register|changepassword)\\b";
|
||||||
|
/*
|
||||||
|
first "/" is the command prefix
|
||||||
|
(login|register|...) means either one or the other
|
||||||
|
\b means end of word (end of string, whitespace, ...) so NO other characters (like /loginabc)
|
||||||
|
*/
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onCommand(PlayerCommandPreprocessEvent event)
|
public void onCommand(PlayerCommandPreprocessEvent event)
|
||||||
{
|
{
|
||||||
// block literally all commands (except from proxy ones)
|
if(!event.getMessage().matches(allowedCmdsRegex))
|
||||||
event.setCancelled(true);
|
// block all commands (except from proxy and allowed ones)
|
||||||
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user