Skip to content

Commit

Permalink
fix: threat chat commands as messages instead of commands (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
rexlManu authored Feb 6, 2024
1 parent 5757561 commit 22b6744
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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));
}

}
12 changes: 12 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 22b6744

Please sign in to comment.