diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/BukkitNetworkManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/BukkitNetworkManager.java index d9cafa4fa..841a0e18e 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/BukkitNetworkManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/BukkitNetworkManager.java @@ -899,7 +899,12 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes } private void onNMSPacketReceive(NetWorkUser user, NMSPacketEvent event, Object packet) { - Debugger.PACKET.debug(() -> "[C->S]" + packet.getClass()); + Debugger.PACKET.debug(() -> { + if (Config.isPacketIgnored(packet.getClass())) { + return null; + } + return "[C->S]" + packet.getClass(); + }); handleReceiveNMSPacket(user, event, packet); } @@ -910,7 +915,12 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes onNMSPacketSend(player, event, p); } } else { - Debugger.PACKET.debug(() -> "[S->C]" + packet.getClass()); + Debugger.PACKET.debug(() -> { + if (Config.isPacketIgnored(packet.getClass())) { + return null; + } + return "[S->C]" + packet.getClass(); + }); handleSendNMSPacket(player, event, packet); } } diff --git a/common-files/src/main/resources/config.yml b/common-files/src/main/resources/config.yml index 14f683dca..f9341093b 100644 --- a/common-files/src/main/resources/config.yml +++ b/common-files/src/main/resources/config.yml @@ -579,9 +579,10 @@ client-optimization: # Enables or disables debug mode debug: common: false - packet: false furniture: false item: false resource-pack: false block: false - entity-culling: false \ No newline at end of file + entity-culling: false + packet: false + ignored-packets: [] \ No newline at end of file diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ResolutionMergePackMcMeta.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ResolutionMergePackMcMeta.java index 8adaaa1eb..f09831c88 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ResolutionMergePackMcMeta.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ResolutionMergePackMcMeta.java @@ -52,8 +52,8 @@ public class ResolutionMergePackMcMeta implements Resolution { } if (mcmeta1Pack.has("min_format") || mcmeta2Pack.has("min_format")) { - int[] minFormat1 = new int[]{Integer.MAX_VALUE, 0}; - int[] minFormat2 = new int[]{Integer.MAX_VALUE, 0}; + int[] minFormat1 = new int[]{1000, 15}; + int[] minFormat2 = new int[]{1000, 15}; if (mcmeta1Pack.has("min_format")) { JsonElement minFormat = mcmeta1Pack.get("min_format"); @@ -62,9 +62,13 @@ public class ResolutionMergePackMcMeta implements Resolution { } if (minFormat.isJsonArray()) { JsonArray minFormatArray = minFormat.getAsJsonArray(); - minFormat1[0] = minFormatArray.get(0).getAsInt(); - if (minFormatArray.size() > 1) { - minFormat1[1] = minFormatArray.get(1).getAsInt(); + if (!minFormatArray.isEmpty()) { + if (minFormatArray.get(0) instanceof JsonPrimitive jp0) { + minFormat1[0] = jp0.getAsInt(); + } + if (minFormatArray.size() > 1 && minFormatArray.get(1) instanceof JsonPrimitive jp1) { + minFormat1[1] = jp1.getAsInt(); + } } } } @@ -74,11 +78,15 @@ public class ResolutionMergePackMcMeta implements Resolution { if (minFormat.isJsonPrimitive()) { minFormat2[0] = minFormat.getAsInt(); } - if (mcmeta2Pack.isJsonArray()) { + if (minFormat.isJsonArray()) { JsonArray minFormatArray = minFormat.getAsJsonArray(); - minFormat2[0] = minFormatArray.get(0).getAsInt(); - if (minFormatArray.size() > 1) { - minFormat2[1] = minFormatArray.get(1).getAsInt(); + if (!minFormatArray.isEmpty()) { + if (minFormatArray.get(0) instanceof JsonPrimitive jp0) { + minFormat2[0] = jp0.getAsInt(); + } + if (minFormatArray.size() > 1 && minFormatArray.get(1) instanceof JsonPrimitive jp1) { + minFormat2[1] = jp1.getAsInt(); + } } } } @@ -100,9 +108,13 @@ public class ResolutionMergePackMcMeta implements Resolution { } if (maxFormat.isJsonArray()) { JsonArray maxFormatArray = maxFormat.getAsJsonArray(); - maxFormat1[0] = maxFormatArray.get(0).getAsInt(); - if (maxFormatArray.size() > 1) { - maxFormat1[1] = maxFormatArray.get(1).getAsInt(); + if (!maxFormatArray.isEmpty()) { + if (maxFormatArray.get(0) instanceof JsonPrimitive jp0) { + maxFormat1[0] = jp0.getAsInt(); + } + if (maxFormatArray.size() > 1 && maxFormatArray.get(1) instanceof JsonPrimitive jp1) { + maxFormat1[1] = jp1.getAsInt(); + } } } } @@ -114,9 +126,13 @@ public class ResolutionMergePackMcMeta implements Resolution { } if (maxFormat.isJsonArray()) { JsonArray maxFormatArray = maxFormat.getAsJsonArray(); - maxFormat2[0] = maxFormatArray.get(0).getAsInt(); - if (maxFormatArray.size() > 1) { - maxFormat2[1] = maxFormatArray.get(1).getAsInt(); + if (!maxFormatArray.isEmpty()) { + if (maxFormatArray.get(0) instanceof JsonPrimitive jp0) { + maxFormat2[0] = jp0.getAsInt(); + } + if (maxFormatArray.size() > 1 && maxFormatArray.get(1) instanceof JsonPrimitive jp1) { + maxFormat2[1] = jp1.getAsInt(); + } } } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/Config.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/Config.java index 13b130d1b..ab118e62a 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/Config.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/Config.java @@ -56,6 +56,7 @@ public class Config { protected boolean debug$resource_pack; protected boolean debug$block; protected boolean debug$entity_culling; + protected Set debug$ignored_packets; protected boolean resource_pack$remove_tinted_leaves_particle; protected boolean resource_pack$generate_mod_assets; @@ -323,6 +324,7 @@ public class Config { debug$resource_pack = config.getBoolean("debug.resource-pack", false); debug$block = config.getBoolean("debug.block", false); debug$entity_culling = config.getBoolean("debug.entity-culling", false); + debug$ignored_packets = new HashSet<>(config.getStringList("debug.ignored-packets")); // resource pack resource_pack$path = resolvePath(config.getString("resource-pack.path", "./generated/resource_pack.zip")); @@ -1228,6 +1230,10 @@ public class Config { return instance.client_optimization$entity_culling$ray_tracing; } + public static boolean isPacketIgnored(Class clazz) { + return instance.debug$ignored_packets.contains(clazz.toString()); + } + public static boolean enableBedrockEditionSupport() { return instance.bedrock_edition_support$enable; } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/logger/Debugger.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/logger/Debugger.java index 3dd1cf3f2..424c7675b 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/logger/Debugger.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/logger/Debugger.java @@ -22,16 +22,24 @@ public enum Debugger { public void debug(Supplier message) { if (this.condition.get()) { - CraftEngine.instance().logger().info("[DEBUG] " + message.get()); + String s = message.get(); + if (s != null) { + CraftEngine.instance().logger().info("[DEBUG] " + s); + } } } public void warn(Supplier message, Throwable e) { if (this.condition.get()) { + String s = message.get(); if (e != null) { - CraftEngine.instance().logger().warn("[DEBUG] " + message.get(), e); + if (s != null) { + CraftEngine.instance().logger().warn("[DEBUG] " + s, e); + } } else { - CraftEngine.instance().logger().warn("[DEBUG] " + message.get()); + if (s != null) { + CraftEngine.instance().logger().warn("[DEBUG] " + s); + } } } }