@@ -37,7 +37,7 @@ public class CustomChat {
3737 private final @ Nullable String command ;
3838 private final @ Nullable Integer cooldown ;
3939 @ Getter
40- private final HashMap <CommandSender , Long > lastChatTimes = new HashMap <>();
40+ private final HashMap <Player , Long > lastChatTimes = new HashMap <>();
4141
4242 public CustomChat (String key , String name , @ Nullable String permission , @ Nullable String command , @ Nullable Integer cooldown ) {
4343 this .key = key ;
@@ -80,11 +80,11 @@ public CustomChat(String key, String name, @Nullable String permission, @Nullabl
8080 if (permission !=null ) cmd .withPermission (permission );
8181 cmd .register ("potatoessentialschannel" );
8282 }
83- public void sendMessage (CommandSender sender , String message ) {
84- if (this .getCooldown ()!=null ) {
85- boolean canBypassCooldown = sender .hasPermission (PotatoEssentials .NAMESPACE +".chat.bypass-cooldown" );
86- if (this .getLastChatTimes ().containsKey (sender ) && !canBypassCooldown ) {
87- long lastTime = this .getLastChatTimes ().get (sender );
83+ public void sendMessage (CommandSender sender , String message , boolean async ) {
84+ if (sender instanceof Player p && this .getCooldown ()!=null ) {
85+ boolean canBypassCooldown = p .hasPermission (PotatoEssentials .NAMESPACE +".chat.bypass-cooldown" );
86+ if (this .getLastChatTimes ().containsKey (p ) && !canBypassCooldown ) {
87+ long lastTime = this .getLastChatTimes ().get (p );
8888 long currentTime = System .currentTimeMillis ();
8989 long cooldownMillis = this .getCooldown () * 1000L ;
9090 long timeElapsed = currentTime - lastTime ;
@@ -95,13 +95,13 @@ public void sendMessage(CommandSender sender, String message) {
9595 double cooldownRemainder = cooldownRemainderMillis / 1000D ;
9696 var msg = Config .replaceFormat (Config .getString ("chat.cooldownMessage" ),
9797 new Replacer ("cooldown" , df .format (cooldownRemainder )));
98- var event = new ChatCooldownEvent (( Player ) sender , msg , cooldownRemainder , this .getKey ());
98+ var event = new ChatCooldownEvent (p , msg , cooldownRemainder , this .getKey (), async );
9999 Bukkit .getPluginManager ().callEvent (event );
100- sender .sendMessage (msg );
100+ if ( event . shouldSendMessage ()) p .sendMessage (msg );
101101 return ;
102102 }
103103 }
104- this .getLastChatTimes ().put (sender , System .currentTimeMillis ());
104+ this .getLastChatTimes ().put (p , System .currentTimeMillis ());
105105 }
106106 boolean miniMsg = sender .hasPermission (PotatoEssentials .NAMESPACE +".chat.minimessage" );
107107 if (!miniMsg ) message = Utils .escapeTags (message );
@@ -122,6 +122,9 @@ public void sendMessage(CommandSender sender, String message) {
122122 recipients .forEach (p -> p .sendMessage (msg ));
123123 Bukkit .getConsoleSender ().sendMessage (msg );
124124 }
125+ public void sendMessage (CommandSender sender , String message ) {
126+ sendMessage (sender , message , false );
127+ }
125128 public boolean checkPerm (CommandSender sender ) {
126129 return this .getPermission () == null || sender .hasPermission (this .getPermission ());
127130 }
0 commit comments