Skip to content
This repository was archived by the owner on Feb 24, 2024. It is now read-only.

PlayerChunkUnloadEvent#getInstance null when player quits the server #113

@DasBabyPixel

Description

@DasBabyPixel

When quitting the server the instance is cleared and then the event is called. This causes the instance to be null in the event.

@Override
default @NotNull Instance getInstance() {
    final Instance instance = getEntity().getInstance();
    assert instance != null : "EntityInstanceEvent is only supported on events where the entity's instance is non-null!";
    return instance;
}

Order of method calls:
Entity#remove(boolean)

Instance currentInstance = this.instance;
if (currentInstance != null) {
    removeFromInstance(currentInstance);
    this.instance = null;
}

Then Player#remove(boolean) (second part, after returning from Entity#remove(boolean))

...
// Clear all viewable chunks
ChunkUtils.forChunksInRange(chunkX, chunkZ, MinecraftServer.getChunkViewDistance(), chunkRemover);

Fix might be moving this snippet before the following, though I am unsure of possible side effects:

if (permanent) {
    this.packets.clear();
    EventDispatcher.call(new PlayerDisconnectEvent(this));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions