From 44ba3cd7ab4cb06186c2e84e3a5e4c50fca89673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beatrice=20Dellac=C3=A0?= Date: Fri, 11 Nov 2022 18:31:46 +0100 Subject: [PATCH] Allow exceptions to commands --- .../limbomanager/listeners/CommandCanceller.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/wtf/beatrice/limbomanager/listeners/CommandCanceller.java b/src/main/java/wtf/beatrice/limbomanager/listeners/CommandCanceller.java index 9e3fd8a..c617fe6 100644 --- a/src/main/java/wtf/beatrice/limbomanager/listeners/CommandCanceller.java +++ b/src/main/java/wtf/beatrice/limbomanager/listeners/CommandCanceller.java @@ -4,13 +4,24 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import java.util.ArrayList; +import java.util.List; + 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 public void onCommand(PlayerCommandPreprocessEvent event) { - // block literally all commands (except from proxy ones) - event.setCancelled(true); + if(!event.getMessage().matches(allowedCmdsRegex)) + // block all commands (except from proxy and allowed ones) + event.setCancelled(true); } }