From 68fb2018555e4f6458b0549b60250a7559bf64d5 Mon Sep 17 00:00:00 2001 From: Elikill58 Date: Sun, 16 Jun 2024 14:34:23 +0200 Subject: [PATCH] Changing debug messages --- .../v1/basecomp/hook/ComponentNMSManager.java | 10 +--------- .../v1/listeners/ChatPacketManager.java | 18 +++++++----------- .../chatitem/chatmanager/v2/ChatListener.java | 4 ---- .../chatitem/platform/hook/SpigotPlatform.java | 4 ++-- 4 files changed, 10 insertions(+), 26 deletions(-) diff --git a/src/main/java/me/dadus33/chatitem/chatmanager/v1/basecomp/hook/ComponentNMSManager.java b/src/main/java/me/dadus33/chatitem/chatmanager/v1/basecomp/hook/ComponentNMSManager.java index 27ee215..d3ad4b6 100644 --- a/src/main/java/me/dadus33/chatitem/chatmanager/v1/basecomp/hook/ComponentNMSManager.java +++ b/src/main/java/me/dadus33/chatitem/chatmanager/v1/basecomp/hook/ComponentNMSManager.java @@ -1,7 +1,5 @@ package me.dadus33.chatitem.chatmanager.v1.basecomp.hook; -import java.lang.reflect.Field; - import com.google.gson.JsonParser; import me.dadus33.chatitem.ChatItem; @@ -40,13 +38,7 @@ public void writeJson(ChatItemPacket packet, String json) { ChatItem.debug("(v1 ComponentNMS) Can't send message to discord"); // DiscordSrvSupport.sendChatMessage(p, comp, null); try { - Object obj = PacketEditingChatManager.createSystemChatPacket(json, packet.getPacket()); - ChatItem.debug("Created packet: " + obj.getClass().getPackage().getName() + "." + obj.getClass().getSimpleName()); - for(Field f : obj.getClass().getDeclaredFields()) { - f.setAccessible(true); - ChatItem.debug(" > " + f.getName() + " (" + f.getType().getSimpleName() + "): " + f.get(obj)); - } - packet.setPacket(obj); + packet.setPacket(PacketEditingChatManager.createSystemChatPacket(json, packet.getPacket())); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/me/dadus33/chatitem/chatmanager/v1/listeners/ChatPacketManager.java b/src/main/java/me/dadus33/chatitem/chatmanager/v1/listeners/ChatPacketManager.java index 6dd965d..a76e98a 100644 --- a/src/main/java/me/dadus33/chatitem/chatmanager/v1/listeners/ChatPacketManager.java +++ b/src/main/java/me/dadus33/chatitem/chatmanager/v1/listeners/ChatPacketManager.java @@ -49,7 +49,8 @@ public ChatPacketManager(PacketEditingChatManager manager) { try { Class.forName("net.kyori.adventure.text.Component"); tryRegister(new AdventureComponentManager()); - } catch (Exception e) {} + } catch (Exception e) { + } ChatItem.getInstance().getLogger().info("Loaded " + componentManager.size() + " getter for base components."); ChatItem.debug("ComponentManager: " + String.join(", ", componentManager.stream().map(IComponentManager::getClass).map(Class::getSimpleName).collect(Collectors.toList()))); } @@ -66,7 +67,7 @@ private void tryRegister(IComponentManager getter) { public void onSend(ChatItemPacket e) { if (!e.hasPlayer() || !e.getPacketType().equals(PacketType.Server.CHAT)) return; - if(ChatManager.isTestingEnabled() && !ChatManager.isTesting("packet")) + if (ChatManager.isTestingEnabled() && !ChatManager.isTesting("packet")) return; if (lastSentPacket != null && lastSentPacket == e.getPacket()) return; // prevent infinite loop @@ -76,10 +77,6 @@ public void onSend(ChatItemPacket e) { String json = "{}"; IComponentManager choosedGetter = null; if (version.isNewerOrEquals(Version.V1_19)) { - /*if (packet.getIntegers().readSafely(0, 0) > 1) { // not parsed chat message type - ChatItem.debug("Invalid int: " + packet.getIntegers().read(0)); - return; - }*/ choosedGetter = new StringComponentManager(); json = choosedGetter.getBaseComponentAsJSON(e); // if null, will be re-checked so anyway } else if (version.isNewerOrEquals(Version.V1_12)) { @@ -88,12 +85,13 @@ public void onSend(ChatItemPacket e) { return; // It's an actionbar message, ignoring } else if (version.isNewerOrEquals(Version.V1_8) && packet.getBytes().readSafely(0) == (byte) 2) return; // It's an actionbar message, ignoring - if (json == null || choosedGetter == null) { + if (json == null || choosedGetter == null || !ChatManager.containsSeparator(json)) { for (IComponentManager getters : componentManager) { String tmpJson = getters.getBaseComponentAsJSON(e); if (tmpJson != null) { json = ChatManager.fixSeparator(tmpJson); choosedGetter = getters; + ChatItem.debug("Seems to have one nice manager with " + getters.getClass().getSimpleName() + " (json: " + json + ")"); if (ChatManager.containsSeparator(json)) break; // be sure it's valid one } else @@ -106,10 +104,8 @@ public void onSend(ChatItemPacket e) { PacketUtils.printPacketToDebug(e.getPacket()); return; // can't find something } - if (!ChatManager.containsSeparator(json)) {// if the message doesn't contain the BELL separator - ChatItem.debug("No seperator with " + json); + if (!ChatManager.containsSeparator(json)) // if the message doesn't contain the BELL separator return; - } ChatItem.debug("Found with " + choosedGetter.getClass().getName()); Chat chat = choosedGetter.getChat(json); if (chat == null) { // something went really bad, so we run away and hide (AKA the player left or is @@ -145,7 +141,7 @@ else if (act.equalsIgnoreCase("show_both")) { } else tooltip = new ArrayList<>(); message = JSONManipulator.getInstance().parseEmpty(getter.getBaseComponentAsJSON(e), ChatManager.styleItem(p, copy, getStorage()), tooltip, chat.getPlayer()); - if(message != null) { + if (message != null) { getter.writeJson(e, message); } lastSentPacket = e.getPacket(); diff --git a/src/main/java/me/dadus33/chatitem/chatmanager/v2/ChatListener.java b/src/main/java/me/dadus33/chatitem/chatmanager/v2/ChatListener.java index 632d3d3..16b3f6a 100644 --- a/src/main/java/me/dadus33/chatitem/chatmanager/v2/ChatListener.java +++ b/src/main/java/me/dadus33/chatitem/chatmanager/v2/ChatListener.java @@ -150,7 +150,6 @@ public static void showItem(Player to, Player origin, ChatAction action, String for (char args : msg.toCharArray()) { if (args == '§') { // begin of color if (colorCode.isEmpty() && !text.isEmpty()) { // text before this char - ChatItem.debug("Append '" + text.replace(ChatColor.COLOR_CHAR, '&') + "' (len: " + text.length() + ")"); if(text.length() > 2 && text.startsWith("§") && text.substring(2) == ChatColor.stripColor(text) && color != null && color != ChatColor.WHITE) { text = text.substring(2); // remove some code which should not be here @@ -180,7 +179,6 @@ public static void showItem(Player to, Player origin, ChatAction action, String color = ColorManager.getColor(colorCode); else { color = ColorManager.getColor(colorCode.substring(0, 7)); // only the hex code - ChatItem.debug("Adding color for " + colorCode.substring(7, colorCode.length()) + " (in " + colorCode + ")"); text += ColorManager.getColorString(colorCode.substring(7, colorCode.length())); } } else if (colorCode.length() == 1) // if only one color code @@ -304,14 +302,12 @@ public static BaseComponent[] fixColorComponent(Player to, String message, ChatC color = ColorManager.getColor(colorCode); else { color = ColorManager.getColor(colorCode.substring(0, 7)); // only the hex code - ChatItem.debug("Adding color for " + colorCode.substring(7, colorCode.length()) + " (in " + colorCode + ")"); text += ColorManager.getColorString(colorCode.substring(7, colorCode.length())); } } else if (colorCode.length() == 1) // if only one color code color = ColorManager.getColor(colorCode); else text += ColorManager.getColorString(colorCode); - ChatItem.debug("Color: " + color + ", text: " + text + ", code: " + colorCode); colorCode = ""; } // basic text, not waiting for code after '§' diff --git a/src/main/java/me/dadus33/chatitem/platform/hook/SpigotPlatform.java b/src/main/java/me/dadus33/chatitem/platform/hook/SpigotPlatform.java index 7ef6dde..fc7e860 100644 --- a/src/main/java/me/dadus33/chatitem/platform/hook/SpigotPlatform.java +++ b/src/main/java/me/dadus33/chatitem/platform/hook/SpigotPlatform.java @@ -55,12 +55,12 @@ public String getPluginVersion(Plugin plugin) { @Override public Version getMinecraftVersion() { - return Version.getVersionByName(getNMSVersion()); + return Version.getVersionByName(getNMSVersion().replace("_R4", "_6")); } @Override public String getNMSVersion() { - return Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3].replace("_R4", "_6"); + return Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]; } @Override