From 177733950d54cd7068451734d956ed420738aa59 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sun, 11 Feb 2024 11:44:57 +0100 Subject: [PATCH] New reflected static method in CraftPlayer --- .../lib/paper/reflect/wrapper/craftbukkit/CraftPlayer.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/craftbukkit/CraftPlayer.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/craftbukkit/CraftPlayer.java index 232bd5e..e6818b2 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/craftbukkit/CraftPlayer.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/craftbukkit/CraftPlayer.java @@ -10,6 +10,7 @@ import fr.pandacube.lib.reflect.ReflectMethod; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; +import javax.annotation.Nullable; import java.lang.ref.WeakReference; import java.util.Map; import java.util.Set; @@ -21,6 +22,7 @@ import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx; public class CraftPlayer extends ReflectWrapperTyped { public static final ReflectClass REFLECT = wrapEx(() -> OBCReflect.ofClass("entity.CraftPlayer")); private static final ReflectMethod getHandle = wrapEx(() -> REFLECT.method("getHandle")); + private static final ReflectMethod getPluginWeakReference = wrapEx(() -> REFLECT.method("getPluginWeakReference")); private static final ReflectField invertedVisibilityEntities = wrapEx(() -> REFLECT.field("invertedVisibilityEntities")); public ServerPlayer getHandle() { @@ -33,6 +35,11 @@ public class CraftPlayer extends ReflectWrapperTyped { return (Map>>) wrapReflectEx(() -> invertedVisibilityEntities.getValue(__getRuntimeInstance())); } + @SuppressWarnings("unchecked") + public static WeakReference getPluginWeakReference(@Nullable Plugin plugin) { + return (WeakReference) wrapReflectEx(() -> getPluginWeakReference.invokeStatic(plugin)); + } + protected CraftPlayer(Object obj) { super(obj); }