Support multiple EntityTrackerEntryImpls, fixes #732 (#733)

This commit is contained in:
MiniDigger 2019-12-16 18:32:26 +01:00 committed by Dan Mulloy
parent 3ff2ccf1b3
commit 524fb1ba68

View File

@ -19,6 +19,7 @@ package com.comphenix.protocol.injector;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -59,7 +60,7 @@ class EntityUtilities {
private FieldAccessor trackedPlayersField;
private FieldAccessor trackerField;
private MethodAccessor scanPlayersMethod;
private Map<Class<?>, MethodAccessor> scanPlayersMethods = new HashMap<>();
public void updateEntity(Entity entity, List<Player> observers) {
if (entity == null || !entity.isValid()) {
@ -73,11 +74,8 @@ class EntityUtilities {
Object trackerEntry = getEntityTrackerEntry(entity.getWorld(), entity.getEntityId());
if (scanPlayersMethod == null) {
scanPlayersMethod = findScanPlayers(trackerEntry.getClass());
}
scanPlayersMethod.invoke(trackerEntry, nmsPlayers);
// there can be multiple different entity tracker entry impls, see GH-732....
scanPlayersMethods.computeIfAbsent(trackerEntry.getClass(), this::findScanPlayers).invoke(trackerEntry, nmsPlayers);
}
private MethodAccessor findScanPlayers(Class<?> trackerClass) {