2022-11-11 17:55:50 +01:00
|
|
|
package wtf.beatrice.limbomanager.listeners;
|
|
|
|
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
|
|
|
|
2022-11-11 18:31:46 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2022-11-11 17:55:50 +01:00
|
|
|
public class CommandCanceller implements Listener
|
|
|
|
{
|
|
|
|
|
2022-11-11 18:38:08 +01:00
|
|
|
private final static String allowedCmdsRegex = "\\/(login|register|changepassword|premium|cracked)\\b";
|
2022-11-11 18:31:46 +01:00
|
|
|
/*
|
|
|
|
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)
|
|
|
|
*/
|
|
|
|
|
2022-11-11 17:55:50 +01:00
|
|
|
@EventHandler
|
|
|
|
public void onCommand(PlayerCommandPreprocessEvent event)
|
|
|
|
{
|
2022-11-11 18:31:46 +01:00
|
|
|
if(!event.getMessage().matches(allowedCmdsRegex))
|
|
|
|
// block all commands (except from proxy and allowed ones)
|
|
|
|
event.setCancelled(true);
|
2022-11-11 17:55:50 +01:00
|
|
|
}
|
|
|
|
}
|