Implement command namespace restriction.

This commit is contained in:
JeremyStar™ 2024-10-08 03:15:55 +02:00
parent 15b04de3c4
commit 9263c57326
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
4 changed files with 20 additions and 0 deletions

View file

@ -82,4 +82,7 @@ public enum LanguageString {
// Event for chat messages
CHATMESSAGE_SERVER,
// Event for chat commands
CHATCOMMAND_ERROR_NAMESPACE
}

View file

@ -51,4 +51,17 @@ public final class ChatListener implements Listener {
).append(MiniMessage.miniMessage().deserialize(MiniMessage.miniMessage().serialize(event.originalMessage()).replace("\\<", "<")))
);
}
/**
* Handles chat commands.
*
* @since v1-release0
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void handleChatCommand(@NotNull PlayerCommandPreprocessEvent event) {
if (event.getMessage().split(" ")[0].contains(":")) {
event.setCancelled(true);
event.getPlayer().sendRichMessage(TranslationManager.get(LanguageString.CHATCOMMAND_ERROR_NAMESPACE, event.getPlayer(), true));
}
}
}

View file

@ -30,4 +30,6 @@
"HOME_NORESPAWN": "<error>Du hast keinen gültigen Respawnpunkt.</error>\n<error>Stelle sicher, dass dein Bett oder Respawn Anker nicht abgebaut oder behindert ist.</error>",
"TOGGLEDOWNFALL": "Niederschlag umgestellt",
"CHATCOMMAND_ERROR_NAMESPACE": "<error>Namespaces zu verwenden ist nicht erlaubt, da es verwendet werden kann um Sicherheitsmaßnahmen zu umgehen.</error>"
}

View file

@ -45,4 +45,6 @@
"TOGGLEDOWNFALL": "Toggled downfall",
"CHATMESSAGE_SERVER": "<mention>%sender%</mention> <#d60532>»</#d60532> ",
"CHATCOMMAND_ERROR_NAMESPACE": "<error>Using namespaces is not allowed, as it may be used to circumvent security measures.</error>"
}