From 22b6744c22346f64ecfc6d9a7a4fe230608c9914 Mon Sep 17 00:00:00 2001 From: Emmanuel Lampe Date: Tue, 6 Feb 2024 22:47:11 +0100 Subject: [PATCH] fix: threat chat commands as messages instead of commands (#44) --- .../simplychat/listener/PlayerListener.java | 14 ++++++++++++++ src/main/resources/config.yml | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/main/java/net/simplyvanilla/simplychat/listener/PlayerListener.java b/src/main/java/net/simplyvanilla/simplychat/listener/PlayerListener.java index 2217502..79e089f 100644 --- a/src/main/java/net/simplyvanilla/simplychat/listener/PlayerListener.java +++ b/src/main/java/net/simplyvanilla/simplychat/listener/PlayerListener.java @@ -93,6 +93,11 @@ public void handlePlayerCommand(PlayerCommandPreprocessEvent event) { PlayerState playerState = SimplyChatPlugin.getInstance().getPlayerStateManager() .getPlayerState(player.getUniqueId()); + if (this.isChattingCommand(message)) { + // remove first character + message = message.substring(1); + } + float remainingTime = handler.getRemainingTime( playerState, @@ -110,5 +115,14 @@ public void handlePlayerCommand(PlayerCommandPreprocessEvent event) { playerState.addLastMessage(message, System.currentTimeMillis()); } + private boolean isChattingCommand(String message) { + String[] split = message.split(" "); + if (split.length == 0) { + return false; + } + String mainCommand = split[0]; + return this.plugin.getConfig().getStringList("cooldown.commands").stream() + .anyMatch(command -> command.equalsIgnoreCase(mainCommand)); + } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index a960e72..7484679 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -50,6 +50,18 @@ cooldown: normal-time: 5 command-time: 5 + # Commands that will be treated as normal messages + commands: + # msg + - /msg + - /whisper + - /w + - /tell + - /pm + # reply + - /reply + - /r + database: url: jdbc:mysql://127.0.0.1:3306/simplyrank?autoReconnect=true&allowPublicKeyRetrieval=true&useSSL=false username: user