1
1
package com .comphenix .protocol .wrappers ;
2
2
3
+ import com .comphenix .protocol .reflect .ExactReflection ;
4
+ import com .comphenix .protocol .reflect .FuzzyReflection ;
3
5
import com .comphenix .protocol .reflect .StructureModifier ;
4
6
import com .comphenix .protocol .reflect .accessors .Accessors ;
5
7
import com .comphenix .protocol .reflect .accessors .ConstructorAccessor ;
8
+ import com .comphenix .protocol .reflect .accessors .FieldAccessor ;
9
+ import com .comphenix .protocol .reflect .accessors .MethodAccessor ;
6
10
import com .comphenix .protocol .utility .MinecraftReflection ;
11
+ import org .bukkit .entity .Player ;
7
12
13
+ import javax .annotation .Nullable ;
8
14
import java .util .UUID ;
9
15
10
16
/**
@@ -16,6 +22,9 @@ public class WrappedRemoteChatSessionData extends AbstractWrapper {
16
22
private final static Class <?> HANDLE_TYPE = MinecraftReflection .getRemoteChatSessionDataClass ();
17
23
private static ConstructorAccessor CONSTRUCTOR ;
18
24
private StructureModifier <Object > modifier ;
25
+ private static MethodAccessor PLAYER_GET_HANDLE ;
26
+ private static FieldAccessor REMOTE_CHAT_SESSION_FIELD ;
27
+ private static MethodAccessor AS_DATA_METHOD ;
19
28
20
29
/**
21
30
* Constructs a new profile public key wrapper directly from a nms RemoteChatSession.Data/RemoteChatSession.a object.
@@ -93,4 +102,29 @@ public String toString() {
93
102
public int hashCode () {
94
103
return handle .hashCode ();
95
104
}
105
+
106
+ /**
107
+ * Retrieves the current session data of the player
108
+ * @since 1.19.4
109
+ * @return Wrapper for session data or null if not present
110
+ */
111
+ @ Nullable
112
+ public static WrappedRemoteChatSessionData fromPlayer (Player player ) {
113
+ if (PLAYER_GET_HANDLE == null ) {
114
+ PLAYER_GET_HANDLE = Accessors .getMethodAccessor (MinecraftReflection .getCraftPlayerClass (), "getHandle" );
115
+ }
116
+ if (REMOTE_CHAT_SESSION_FIELD == null ) {
117
+ REMOTE_CHAT_SESSION_FIELD = Accessors .getFieldAccessor (MinecraftReflection .getEntityPlayerClass (), MinecraftReflection .getRemoteChatSessionClass (), true );
118
+ }
119
+ if (AS_DATA_METHOD == null ) {
120
+ AS_DATA_METHOD = Accessors .getMethodAccessor (FuzzyReflection .fromClass (MinecraftReflection .getRemoteChatSessionClass (), true ).getMethodListByParameters (HANDLE_TYPE ).get (0 ));
121
+ }
122
+ Object handle = PLAYER_GET_HANDLE .invoke (player );
123
+ Object remoteChatSession = REMOTE_CHAT_SESSION_FIELD .get (handle );
124
+ if (remoteChatSession == null ) {
125
+ return null ;
126
+ }
127
+ Object remoteChatSessionData = AS_DATA_METHOD .invoke (remoteChatSession );
128
+ return remoteChatSessionData == null ? null : new WrappedRemoteChatSessionData (remoteChatSessionData );
129
+ }
96
130
}
0 commit comments