27
27
import com .comphenix .protocol .utility .MinecraftFields ;
28
28
import com .comphenix .protocol .utility .MinecraftReflection ;
29
29
import com .comphenix .protocol .utility .MinecraftVersion ;
30
+ import com .comphenix .protocol .utility .Util ;
30
31
import com .comphenix .protocol .wrappers .WrappedIntHashMap ;
31
32
32
33
import java .lang .reflect .Field ;
33
34
import java .lang .reflect .Method ;
34
35
import java .lang .reflect .Modifier ;
35
36
import java .util .ArrayList ;
36
37
import java .util .Collection ;
37
- import java .util .HashMap ;
38
38
import java .util .List ;
39
39
import java .util .Map ;
40
40
import java .util .concurrent .ConcurrentHashMap ;
@@ -61,6 +61,7 @@ class EntityUtilities {
61
61
private FieldAccessor entityTrackerField ;
62
62
private FieldAccessor trackedPlayersField ;
63
63
private FieldAccessor trackedEntitiesField ;
64
+ private FieldAccessor foliaTrackerField ;
64
65
65
66
private MethodAccessor getEntity ;
66
67
private MethodAccessor getChunkProvider ;
@@ -203,6 +204,25 @@ private Collection<?> getTrackedPlayers(Entity entity) {
203
204
204
205
@ SuppressWarnings ("unchecked" )
205
206
private Object getNewEntityTracker (Object worldServer , int entityId ) {
207
+ if (Util .isUsingFolia ()) {
208
+ if (this .getEntity == null ) {
209
+ Method entityGetter = FuzzyReflection .fromObject (worldServer ).getMethodByReturnTypeAndParameters (
210
+ "getEntity" ,
211
+ MinecraftReflection .getEntityClass (),
212
+ int .class );
213
+ this .getEntity = Accessors .getMethodAccessor (entityGetter );
214
+ }
215
+
216
+ Object entity = this .getEntity .invoke (worldServer , entityId );
217
+
218
+ if (this .foliaTrackerField == null ) {
219
+ this .foliaTrackerField = Accessors .getFieldAccessor (FuzzyReflection .fromClass (entity .getClass (), false )
220
+ .getField (FuzzyFieldContract .newBuilder ().typeExact (MinecraftReflection .getEntityTrackerClass ()).build ()));
221
+ }
222
+
223
+ return this .foliaTrackerField .get (entity );
224
+ }
225
+
206
226
if (this .getChunkProvider == null ) {
207
227
Class <?> chunkProviderClass = MinecraftReflection .getChunkProviderServer ();
208
228
this .getChunkProvider = Accessors .getMethodAccessor (FuzzyReflection .fromClass (worldServer .getClass (), false )
0 commit comments