mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2025-01-24 09:11:27 +01:00
Improve getEntityFromID (#1740)
This commit is contained in:
parent
23dac3287b
commit
96155b1065
@ -28,6 +28,7 @@ import com.comphenix.protocol.utility.MinecraftFields;
|
|||||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||||
import com.comphenix.protocol.wrappers.WrappedIntHashMap;
|
import com.comphenix.protocol.wrappers.WrappedIntHashMap;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -56,6 +57,7 @@ class EntityUtilities {
|
|||||||
private FieldAccessor trackedPlayersField;
|
private FieldAccessor trackedPlayersField;
|
||||||
private FieldAccessor trackedEntitiesField;
|
private FieldAccessor trackedEntitiesField;
|
||||||
|
|
||||||
|
private MethodAccessor getEntity;
|
||||||
private MethodAccessor getChunkProvider;
|
private MethodAccessor getChunkProvider;
|
||||||
|
|
||||||
private EntityUtilities() {
|
private EntityUtilities() {
|
||||||
@ -83,6 +85,20 @@ class EntityUtilities {
|
|||||||
.invoke(trackerEntry, nmsPlayers);
|
.invoke(trackerEntry, nmsPlayers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Entity getEntity(World world, int id) {
|
||||||
|
Object level = BukkitUnwrapper.getInstance().unwrapItem(world);
|
||||||
|
if (getEntity == null) {
|
||||||
|
Method entityGetter = FuzzyReflection.fromObject(level).getMethodByParameters(
|
||||||
|
"getEntity",
|
||||||
|
MinecraftReflection.getEntityClass(),
|
||||||
|
new Class[]{int.class});
|
||||||
|
getEntity = Accessors.getMethodAccessor(entityGetter);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object entity = getEntity.invoke(level, id);
|
||||||
|
return (Entity) MinecraftReflection.getBukkitEntity(entity);
|
||||||
|
}
|
||||||
|
|
||||||
private MethodAccessor findScanPlayers(Class<?> trackerClass) {
|
private MethodAccessor findScanPlayers(Class<?> trackerClass) {
|
||||||
MethodAccessor candidate = Accessors.getMethodAcccessorOrNull(trackerClass, "scanPlayers");
|
MethodAccessor candidate = Accessors.getMethodAcccessorOrNull(trackerClass, "scanPlayers");
|
||||||
if (candidate != null) {
|
if (candidate != null) {
|
||||||
|
@ -401,12 +401,7 @@ public class PacketFilterManager implements ListenerInvoker, InternalManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Entity getEntityFromID(World container, int id) {
|
public Entity getEntityFromID(World container, int id) {
|
||||||
for (Entity entity : container.getEntities()) {
|
return EntityUtilities.getInstance().getEntity(container, id);
|
||||||
if (entity.getEntityId() == id) {
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user