package com.alttd.chat.handler; import com.alttd.chat.ChatPlugin; import com.alttd.chat.config.Config; import com.alttd.chat.managers.ChatUserManager; import com.alttd.chat.objects.ChatUser; import com.alttd.chat.util.Utility; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.Template; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; public class ChatHandler { private final ChatPlugin plugin; private final MiniMessage miniMessage; private final Component GCNOTENABLED; public ChatHandler() { plugin = ChatPlugin.getInstance(); miniMessage = MiniMessage.get(); GCNOTENABLED = miniMessage.parse(Config.GCNOTENABLED); } public void globalChat(Player player, String message) { ChatUser user = ChatUserManager.getChatUser(player.getUniqueId()); if(user == null) return; if(!user.isGcOn()) { player.sendMessage(GCNOTENABLED);// GC IS OFF INFORM THEM ABOUT THIS and cancel return; } long timeLeft = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - user.getGcCooldown()); if(timeLeft <= Config.GCCOOLDOWN) { // player is on cooldown and should wait x seconds player.sendMessage(miniMessage.parse(Config.GCONCOOLDOWN, Template.of("cooldown", timeLeft+""))); return; } String senderName, prefix = ""; senderName = player.getDisplayName(); // TODO this can be a component // can also be cached in the chatuser object? prefix = user.getPrefix(); message = Utility.parseColors(message); if(!player.hasPermission("chat.format")) message = miniMessage.stripTokens(message); if(message.contains("[i]")) message = message.replace("[i]", "<[i]>"); List