Skip to content

player.sendMessage() throws exception after calling player.disconnect() #847

@Packsolite

Description

@Packsolite

Problem

The following exception was thrown when calling the ProxiedPlayer#sendMessage() method:
https://pastebin.com/m7FeSwAM

Reason

It seems like after disconnecting a player using the ProxiedPlayer#disconnect() method, an invalid or broken reference to the player can still be obtained via the api using ProxyServer#getPlayers(). Using the sendMessage() function on such a reference results in an error.

How to reproduce

So as a basic example you want a custom kick command implemented as a plugin:
After disconnecting the player, you may want to send a message to other staff members.

The code could look something like this:

player.disconnect(text);
for (ProxiedPlayer staff: server.getPlayers()) {
    staff.sendMessage(player.getName() + " was kicked by " + sender.getName());
}

In this specific example sure i can move the disconnect after the staff broadcast, however in other situations that might not be as easy and the api should be safe in that regard.

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