From 8fcaed1e1a19c084e40bacb13afb675de6b85565 Mon Sep 17 00:00:00 2001 From: Hellxd Date: Thu, 7 Jul 2022 20:16:29 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"feat:=20=E4=BD=BF=E7=94=A8MethodHandl?= =?UTF-8?q?e=E6=9B=BF=E6=8D=A2plib=E5=9B=9E=E8=B0=83=E7=9A=84=E5=8F=8D?= =?UTF-8?q?=E5=B0=84"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 32f087c258f0bfc77250e0b70775360c9d2884c2. --- .../ProtocolLibCallbackHandler.java | 28 ++++++------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/main/java/io/github/dionatestserver/pluginhooker/hook/impl/protocollib/ProtocolLibCallbackHandler.java b/src/main/java/io/github/dionatestserver/pluginhooker/hook/impl/protocollib/ProtocolLibCallbackHandler.java index d411b18..02bd1bc 100644 --- a/src/main/java/io/github/dionatestserver/pluginhooker/hook/impl/protocollib/ProtocolLibCallbackHandler.java +++ b/src/main/java/io/github/dionatestserver/pluginhooker/hook/impl/protocollib/ProtocolLibCallbackHandler.java @@ -1,6 +1,5 @@ package io.github.dionatestserver.pluginhooker.hook.impl.protocollib; -import com.comphenix.protocol.concurrency.AbstractConcurrentListenerMultimap; import com.comphenix.protocol.concurrency.SortedCopyOnWriteArray; import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketListener; @@ -12,17 +11,13 @@ import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; import java.lang.reflect.Field; import java.util.Collection; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; public class ProtocolLibCallbackHandler { - private MethodHandle listenersGetter; - private MethodHandle listenersSetter; + private Field mapListeners; public SortedPacketListenerList handleProtocolLibPacket(SortedPacketListenerList listenerList, PacketEvent event, boolean outbound) { DionaPlayer dionaPlayer = DionaPluginHooker.getPlayerManager().getDionaPlayer(event.getPlayer()); @@ -62,28 +57,21 @@ private SortedPacketListenerList deepCopyListenerList(SortedPacketListenerList s SortedPacketListenerList result = new SortedPacketListenerList(); try { - if (this.listenersGetter == null) { - Field mapListeners = SortedPacketListenerList.class.getSuperclass().getDeclaredField("mapListeners"); - mapListeners.setAccessible(true); - - MethodHandles.Lookup lookup = MethodHandles.lookup(); - this.listenersGetter = lookup.unreflectGetter(mapListeners); - this.listenersSetter = lookup.unreflectSetter(mapListeners); + if (this.mapListeners == null) { + this.mapListeners = SortedPacketListenerList.class.getSuperclass().getDeclaredField("mapListeners"); + this.mapListeners.setAccessible(true); } -// ConcurrentHashMap listeners = (ConcurrentHashMap) mapListeners.get(sortedPacketListenerList); - ConcurrentMap listeners = - (ConcurrentMap) listenersGetter.invokeExact(((AbstractConcurrentListenerMultimap) sortedPacketListenerList)); - ConcurrentMap resultMap = listeners.keySet().stream().collect( + ConcurrentHashMap listeners = (ConcurrentHashMap) mapListeners.get(sortedPacketListenerList); + ConcurrentHashMap resultMap = listeners.keySet().stream().collect( ConcurrentHashMap::new, (map, packetType) -> map.put(packetType, new SortedCopyOnWriteArray((Collection) listeners.get(packetType))), ConcurrentHashMap::putAll ); -// mapListeners.set(result, resultMap); - listenersSetter.invokeExact((AbstractConcurrentListenerMultimap) result, resultMap); + mapListeners.set(result, resultMap); return result; - } catch (Throwable e) { + } catch (Exception e) { e.printStackTrace(); } return null;