PaperMC / PaperMC/Waterfall

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

Open
#847 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Shell
Stars
752
Forks
307
Avg merge
15h 48m
Merged PRs (30d)
7

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing ProxiedPlayer#disconnect(), ProxyServer#getPlayers(), and ProxiedPlayer#sendMessage() to understand how player references behave after disconnecting. Reproduce the custom kick-and-broadcast example, then verify that obtaining players and sending a staff message no longer throws an exception after the disconnected player is removed or invalidated.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.