From ef8883626f9077be65a0b2b8d4584ec06b7d9dcb Mon Sep 17 00:00:00 2001 From: 502647092 Date: Mon, 24 Jul 2017 22:15:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=80=9A=E8=BF=87=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E5=BC=82=E6=AD=A5=E6=A3=80=E6=B5=8B=E6=B6=88=E9=99=A4Paper?= =?UTF-8?q?=E7=9A=84=E5=BC=82=E6=AD=A5=E5=91=BD=E4=BB=A4=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- .../java/pw/yumc/YumCore/bukkit/compatible/C.java | 13 +++++-------- src/main/java/pw/yumc/YumCore/tellraw/Tellraw.java | 1 + 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/pw/yumc/YumCore/bukkit/compatible/C.java b/src/main/java/pw/yumc/YumCore/bukkit/compatible/C.java index 88f9822..9fd7278 100644 --- a/src/main/java/pw/yumc/YumCore/bukkit/compatible/C.java +++ b/src/main/java/pw/yumc/YumCore/bukkit/compatible/C.java @@ -32,6 +32,8 @@ public class C { private static Class nmsIChatBaseComponent; private static Class packetType; + private static Constructor packetTypeConstructor; + private static Method chatSerializer; private static Method getHandle; @@ -50,6 +52,7 @@ public class C { chatSerializer = nmsChatSerializer.getMethod("a", String.class); nmsIChatBaseComponent = Class.forName(a("IChatBaseComponent")); packetType = Class.forName(a("PacketPlayOutChat")); + packetTypeConstructor = packetType.getConstructor(nmsIChatBaseComponent, newversion ? int.class : byte.class); Class typeCraftPlayer = Class.forName(b("entity.CraftPlayer")); Class typeNMSPlayer = Class.forName(a("EntityPlayer")); Class typePlayerConnection = Class.forName(a("PlayerConnection")); @@ -96,17 +99,11 @@ public class C { * 2. ActionBar */ public static void sendJson(org.bukkit.entity.Player receivingPacket, String json, int type) { - Object packet; try { - Object serialized = nmsChatSerializer.getMethod("a", String.class).invoke(null, json); - if (!version.contains("1_7")) { - packet = packetType.getConstructor(nmsIChatBaseComponent, byte.class).newInstance(serialized, (byte) type); - } else { - packet = packetType.getConstructor(nmsIChatBaseComponent, int.class).newInstance(serialized, type); - } + Object serialized = chatSerializer.invoke(null, json); Object player = getHandle.invoke(receivingPacket); Object connection = playerConnection.get(player); - sendPacket.invoke(connection, packet); + sendPacket.invoke(connection, packetTypeConstructor.newInstance(serialized, newversion ? type : (byte) type)); } catch (Exception ex) { Log.d("Json发包错误 " + version, ex); } diff --git a/src/main/java/pw/yumc/YumCore/tellraw/Tellraw.java b/src/main/java/pw/yumc/YumCore/tellraw/Tellraw.java index e2b85fd..0a6372d 100644 --- a/src/main/java/pw/yumc/YumCore/tellraw/Tellraw.java +++ b/src/main/java/pw/yumc/YumCore/tellraw/Tellraw.java @@ -27,6 +27,7 @@ public class Tellraw implements Cloneable { static { if (Bukkit.getVersion().contains("Paper") || Bukkit.getVersion().contains("Torch")) { try { + // Paper 根据 org.spigotmc.AsyncCatcher.enabled 判断是否拦截异步命令 Class AsyncCatcherClass = Class.forName("org.spigotmc.AsyncCatcher"); Field enabledField = AsyncCatcherClass.getDeclaredField("enabled"); enabledField.setAccessible(true);