diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatPlugin.java index 030e99db..dde15754 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatPlugin.java @@ -34,6 +34,7 @@ public class ChatPlugin extends Bot.Listener { private final CommandSpyParser commandSpyParser; @Getter private final List queue = new ArrayList<>(); + private final List _queue = new ArrayList<>(); private final List listeners = new ArrayList<>(); @@ -49,6 +50,7 @@ public class ChatPlugin extends Bot.Listener { chatParsers.add(new KaboomChatParser(bot)); chatParsers.add(new ChomeNSCustomChatParser(bot)); + bot.executor().scheduleAtFixedRate(this::_sendChatTick, 0, 1, TimeUnit.MILLISECONDS); bot.executor().scheduleAtFixedRate(this::sendChatTick, 0, bot.config().chatQueueDelay(), TimeUnit.MILLISECONDS); } @@ -182,7 +184,8 @@ public class ChatPlugin extends Bot.Listener { } } - private void sendChatTick () { + // TODO: Probably improve this code + private void _sendChatTick () { try { if (queue.size() == 0) return; @@ -190,28 +193,10 @@ public class ChatPlugin extends Bot.Listener { final String[] splitted = message.split("(?<=\\G.{255})|\\n"); - for (String splitMessage : splitted) { - if (splitMessage.trim().equals("")) continue; + for (String subMessage : splitted) { + if (subMessage.trim().equals("")) continue; - if (splitMessage.startsWith("/")) { - bot.session().send(new ServerboundChatCommandPacket( - splitMessage.substring(1), - Instant.now().toEpochMilli(), - 0L, - Collections.emptyList(), - 0, - new BitSet() - )); - } else { - bot.session().send(new ServerboundChatPacket( - splitMessage, - Instant.now().toEpochMilli(), - 0L, - null, - 0, - new BitSet() - )); - } + _queue.add(subMessage); } queue.remove(0); @@ -220,6 +205,34 @@ public class ChatPlugin extends Bot.Listener { } } + private void sendChatTick () { + if (_queue.size() == 0) return; + + final String message = _queue.get(0); + + if (message.startsWith("/")) { + bot.session().send(new ServerboundChatCommandPacket( + message.substring(1), + Instant.now().toEpochMilli(), + 0L, + Collections.emptyList(), + 0, + new BitSet() + )); + } else { + bot.session().send(new ServerboundChatPacket( + message, + Instant.now().toEpochMilli(), + 0L, + null, + 0, + new BitSet() + )); + } + + _queue.remove(0); + } + public void send (String message) { queue.add(message); }