Cache destroy packet

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-11-07 17:29:14 +01:00
parent 58b13fd007
commit 5959b37600

View File

@ -27,6 +27,7 @@ import net.minestom.server.instance.InstanceManager;
import net.minestom.server.instance.block.Block;
import net.minestom.server.instance.block.BlockGetter;
import net.minestom.server.instance.block.BlockHandler;
import net.minestom.server.network.packet.CachedPacket;
import net.minestom.server.network.packet.server.ServerPacket;
import net.minestom.server.network.packet.server.play.*;
import net.minestom.server.permission.Permission;
@ -72,6 +73,8 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
private static final Map<UUID, Entity> ENTITY_BY_UUID = new ConcurrentHashMap<>();
private static final AtomicInteger LAST_ENTITY_ID = new AtomicInteger();
private final CachedPacket destroyPacketCache = new CachedPacket(() -> new DestroyEntitiesPacket(getEntityId()));
protected Instance instance;
protected Chunk currentChunk;
protected Pos position;
@ -452,7 +455,7 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
if (passenger != player) passenger.viewEngine.viewableOption.removal.accept(player);
}
}
player.sendPacket(new DestroyEntitiesPacket(getEntityId()));
player.sendPacket(destroyPacketCache.retrieve());
}
@Override