From 1f933ce80494600d6e362346006388ac81167bbe Mon Sep 17 00:00:00 2001 From: nickreesdev Date: Sat, 20 Feb 2021 11:57:14 -0600 Subject: [PATCH] Added a 3 second chat cooldown for non-donators. --- .../zone/themcgamer/core/chat/ChatManager.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/src/main/java/zone/themcgamer/core/chat/ChatManager.java b/core/src/main/java/zone/themcgamer/core/chat/ChatManager.java index a094a34..51a626e 100644 --- a/core/src/main/java/zone/themcgamer/core/chat/ChatManager.java +++ b/core/src/main/java/zone/themcgamer/core/chat/ChatManager.java @@ -9,6 +9,8 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.plugin.java.JavaPlugin; +import zone.themcgamer.core.account.Account; +import zone.themcgamer.core.account.AccountManager; import zone.themcgamer.core.badSportSystem.BadSportClient; import zone.themcgamer.core.badSportSystem.BadSportSystem; import zone.themcgamer.core.badSportSystem.Punishment; @@ -16,10 +18,13 @@ import zone.themcgamer.core.badSportSystem.PunishmentCategory; import zone.themcgamer.core.chat.command.ClearChatCommand; import zone.themcgamer.core.chat.component.IChatComponent; import zone.themcgamer.core.common.Style; +import zone.themcgamer.core.cooldown.CooldownHandler; import zone.themcgamer.core.module.Module; import zone.themcgamer.core.module.ModuleInfo; +import zone.themcgamer.data.Rank; import java.util.*; +import java.util.concurrent.TimeUnit; /** * @author Braydon @@ -59,6 +64,9 @@ public class ChatManager extends Module { event.setCancelled(true); + Optional optionalAccount = AccountManager.fromCache(player.getUniqueId()); + if (optionalAccount.isEmpty()) + return; Optional optionalBadSportClient = badSportSystem.lookup(player.getUniqueId()); if (optionalBadSportClient.isEmpty()) { player.sendMessage(Style.error("Chat", "§cCannot find bad sport profile")); @@ -78,6 +86,12 @@ public class ChatManager extends Module { player.sendMessage(Style.error("Chat", "§cCannot format chat message")); return; } + if (!CooldownHandler.canUse(player, "Chat", TimeUnit.SECONDS.toMillis(3L), false) + && !optionalAccount.get().hasRank(Rank.GAMER)) { + player.sendMessage(Style.error("Chat", "You are chatting too quickly! To bypass this cooldown," + + " please consider purchasing a donator rank over at §bstore.mcgamerzone.net§7.")); + return; + } for (Map.Entry emote : emotes.entrySet()) message = message.replace(":" + emote.getKey() + ":", emote.getValue()); List components = new ArrayList<>();