mirror of
https://e.coding.net/circlecloud/YumCore.git
synced 2024-11-22 01:48:50 +00:00
feat: 通过关闭异步检测消除Paper的异步命令提示
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
20783b1e61
commit
ef8883626f
@ -32,6 +32,8 @@ public class C {
|
|||||||
private static Class<?> nmsIChatBaseComponent;
|
private static Class<?> nmsIChatBaseComponent;
|
||||||
private static Class<?> packetType;
|
private static Class<?> packetType;
|
||||||
|
|
||||||
|
private static Constructor<?> packetTypeConstructor;
|
||||||
|
|
||||||
private static Method chatSerializer;
|
private static Method chatSerializer;
|
||||||
private static Method getHandle;
|
private static Method getHandle;
|
||||||
|
|
||||||
@ -50,6 +52,7 @@ public class C {
|
|||||||
chatSerializer = nmsChatSerializer.getMethod("a", String.class);
|
chatSerializer = nmsChatSerializer.getMethod("a", String.class);
|
||||||
nmsIChatBaseComponent = Class.forName(a("IChatBaseComponent"));
|
nmsIChatBaseComponent = Class.forName(a("IChatBaseComponent"));
|
||||||
packetType = Class.forName(a("PacketPlayOutChat"));
|
packetType = Class.forName(a("PacketPlayOutChat"));
|
||||||
|
packetTypeConstructor = packetType.getConstructor(nmsIChatBaseComponent, newversion ? int.class : byte.class);
|
||||||
Class<?> typeCraftPlayer = Class.forName(b("entity.CraftPlayer"));
|
Class<?> typeCraftPlayer = Class.forName(b("entity.CraftPlayer"));
|
||||||
Class<?> typeNMSPlayer = Class.forName(a("EntityPlayer"));
|
Class<?> typeNMSPlayer = Class.forName(a("EntityPlayer"));
|
||||||
Class<?> typePlayerConnection = Class.forName(a("PlayerConnection"));
|
Class<?> typePlayerConnection = Class.forName(a("PlayerConnection"));
|
||||||
@ -96,17 +99,11 @@ public class C {
|
|||||||
* 2. ActionBar
|
* 2. ActionBar
|
||||||
*/
|
*/
|
||||||
public static void sendJson(org.bukkit.entity.Player receivingPacket, String json, int type) {
|
public static void sendJson(org.bukkit.entity.Player receivingPacket, String json, int type) {
|
||||||
Object packet;
|
|
||||||
try {
|
try {
|
||||||
Object serialized = nmsChatSerializer.getMethod("a", String.class).invoke(null, json);
|
Object serialized = chatSerializer.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 player = getHandle.invoke(receivingPacket);
|
Object player = getHandle.invoke(receivingPacket);
|
||||||
Object connection = playerConnection.get(player);
|
Object connection = playerConnection.get(player);
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packetTypeConstructor.newInstance(serialized, newversion ? type : (byte) type));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Log.d("Json发包错误 " + version, ex);
|
Log.d("Json发包错误 " + version, ex);
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ public class Tellraw implements Cloneable {
|
|||||||
static {
|
static {
|
||||||
if (Bukkit.getVersion().contains("Paper") || Bukkit.getVersion().contains("Torch")) {
|
if (Bukkit.getVersion().contains("Paper") || Bukkit.getVersion().contains("Torch")) {
|
||||||
try {
|
try {
|
||||||
|
// Paper 根据 org.spigotmc.AsyncCatcher.enabled 判断是否拦截异步命令
|
||||||
Class AsyncCatcherClass = Class.forName("org.spigotmc.AsyncCatcher");
|
Class AsyncCatcherClass = Class.forName("org.spigotmc.AsyncCatcher");
|
||||||
Field enabledField = AsyncCatcherClass.getDeclaredField("enabled");
|
Field enabledField = AsyncCatcherClass.getDeclaredField("enabled");
|
||||||
enabledField.setAccessible(true);
|
enabledField.setAccessible(true);
|
||||||
|
Loading…
Reference in New Issue
Block a user