Skip to content

Commit

Permalink
Changing debug messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Elikill58 committed Jun 16, 2024
1 parent baa4eab commit 68fb201
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())));
}
Expand All @@ -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
Expand All @@ -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)) {
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 '§'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 68fb201

Please sign in to comment.