From 979bb5c358ab7be56ef8164a72d9c1f68455b728 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Wed, 3 May 2023 07:23:03 +0700 Subject: [PATCH] ah i see why its just the new anti skid update thing,.,. --- .../plugins/ChatCommandHandlerPlugin.java | 4 +- .../chomens_bot/plugins/ChatPlugin.java | 157 ++++++++---------- 2 files changed, 75 insertions(+), 86 deletions(-) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatCommandHandlerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatCommandHandlerPlugin.java index 4ce97da..4e3ec21 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatCommandHandlerPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatCommandHandlerPlugin.java @@ -32,7 +32,9 @@ public class ChatCommandHandlerPlugin extends ChatPlugin.ChatListener { public void commandSpyMessageReceived (PlayerMessage message) { listener(message, true); } private void listener (PlayerMessage message, boolean cspy) { - if (message.sender().profile().getName().equals(bot.username())) return; + try { + if (message.sender().profile().getName().equals(bot.username())) return; + } catch (Exception ignored) {} // kinda sus ngl final Component displayNameComponent = message.displayName(); final Component messageComponent = message.contents(); 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 b700e9c..e5b7b5b 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 @@ -60,127 +60,114 @@ public class ChatPlugin extends Bot.Listener { } public void packetReceived (ClientboundSystemChatPacket packet) { + final Component component = packet.getContent(); + try { - final Component component = packet.getContent(); + final String key = ((TranslatableComponent) component).key(); - try { - final String key = ((TranslatableComponent) component).key(); + if ( + key.equals("advMode.setCommand.success") || + key.equals("advMode.notAllowed") + ) return; + } catch (ClassCastException ignored) {} - if ( - key.equals("advMode.setCommand.success") || - key.equals("advMode.notAllowed") - ) return; - } catch (ClassCastException ignored) { - } + PlayerMessage playerMessage = null; - PlayerMessage playerMessage = null; + for (ChatParser parser : chatParsers) { + playerMessage = parser.parse(component); + if (playerMessage != null) break; + } - for (ChatParser parser : chatParsers) { - playerMessage = parser.parse(component); - if (playerMessage != null) break; - } + PlayerMessage commandSpyMessage; + commandSpyMessage = commandSpyParser.parse(component); - PlayerMessage commandSpyMessage; - commandSpyMessage = commandSpyParser.parse(component); - - for (ChatListener listener : listeners) { - listener.systemMessageReceived(component); - if (playerMessage != null) listener.playerMessageReceived(playerMessage); - if (commandSpyMessage != null) listener.commandSpyMessageReceived(commandSpyMessage); - } - } catch (Exception e) { - e.printStackTrace(); + for (ChatListener listener : listeners) { + listener.systemMessageReceived(component); + if (playerMessage != null) listener.playerMessageReceived(playerMessage); + if (commandSpyMessage != null) listener.commandSpyMessageReceived(commandSpyMessage); } } public void packetReceived (ClientboundPlayerChatPacket packet) { - try { - final UUID senderUUID = packet.getSender(); + final UUID senderUUID = packet.getSender(); - final MutablePlayerListEntry entry = bot.players().getEntry(senderUUID); + final MutablePlayerListEntry entry = bot.players().getEntry(senderUUID); - if (entry == null) return; + if (entry == null) return; - final PlayerMessage playerMessage = new PlayerMessage( - entry, - packet.getName(), - Component.text(packet.getContent()) - ); + final PlayerMessage playerMessage = new PlayerMessage( + entry, + packet.getName(), + Component.text(packet.getContent()) + ); - for (ChatListener listener : listeners) { - listener.playerMessageReceived(playerMessage); + for (ChatListener listener : listeners) { + listener.playerMessageReceived(playerMessage); - if (packet.getChatType() == 4) { // type 4 is /say - final Component component = Component.translatable( - "chat.type.announcement", - playerMessage.displayName(), - playerMessage.contents() - ); + if (packet.getChatType() == 4) { // type 4 is /say + final Component component = Component.translatable( + "chat.type.announcement", + playerMessage.displayName(), + playerMessage.contents() + ); - listener.systemMessageReceived(component); - } else { - final Component unsignedContent = packet.getUnsignedContent(); + listener.systemMessageReceived(component); + } else { + final Component unsignedContent = packet.getUnsignedContent(); - if (unsignedContent == null) return; + if (unsignedContent == null) return; - listener.systemMessageReceived(unsignedContent); - } + listener.systemMessageReceived(unsignedContent); } - } catch (Exception e) { - e.printStackTrace(); } } public void packetReceived (ClientboundDisguisedChatPacket packet) { // totallynotskidded™ from chipmunkbot and modified i guess - try { - final int type = packet.getChatType(); + final int type = packet.getChatType(); - // i think im missing other types - if (type == 1 || type == 4) { // type 1 is /me, type 4 is /say - final Component name = packet.getName(); - final Component content = packet.getMessage(); + // i think im missing other types + if (type == 1 || type == 4) { // type 1 is /me, type 4 is /say + final Component name = packet.getName(); + final Component content = packet.getMessage(); - for (ChatParser parser : chatParsers) { - final Component component = Component.translatable( - type == 1 ? "chat.type.emote" : "chat.type.announcement", - name, - content - ); + for (ChatParser parser : chatParsers) { + final Component component = Component.translatable( + type == 1 ? "chat.type.emote" : "chat.type.announcement", + name, + content + ); - final PlayerMessage parsed = parser.parse(component); + final PlayerMessage parsed = parser.parse(component); - if (parsed == null) continue; + if (parsed == null) continue; - final PlayerMessage playerMessage = new PlayerMessage(parsed.sender(), packet.getName(), parsed.contents()); - - for (ChatListener listener : listeners) { - listener.playerMessageReceived(playerMessage); - listener.systemMessageReceived(component); - } - } - } else { - final Component component = packet.getMessage(); - - PlayerMessage parsedFromMessage = null; - - for (ChatParser parser : chatParsers) { - parsedFromMessage = parser.parse(component); - if (parsedFromMessage != null) break; - } - - if (parsedFromMessage == null) return; - - final PlayerMessage playerMessage = new PlayerMessage(parsedFromMessage.sender(), packet.getName(), parsedFromMessage.contents()); + final PlayerMessage playerMessage = new PlayerMessage(parsed.sender(), packet.getName(), parsed.contents()); for (ChatListener listener : listeners) { listener.playerMessageReceived(playerMessage); listener.systemMessageReceived(component); } } - } catch (Exception e) { - e.printStackTrace(); + } else { + final Component component = packet.getMessage(); + + PlayerMessage parsedFromMessage = null; + + for (ChatParser parser : chatParsers) { + parsedFromMessage = parser.parse(component); + if (parsedFromMessage != null) break; + } + + if (parsedFromMessage == null) return; + + final PlayerMessage playerMessage = new PlayerMessage(parsedFromMessage.sender(), packet.getName(), parsedFromMessage.contents()); + + for (ChatListener listener : listeners) { + listener.playerMessageReceived(playerMessage); + listener.systemMessageReceived(component); + } } }