Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@
/**
* Extended version of {@link ServerListPingEvent} that allows full control
* of the response sent to the client.
* <p>
* This event will sometimes fire synchronously, depending on how it was
* triggered.
* <p>
* If a request is done from outside the server, via the Minecraft client
* server menu or external tools, this event will be asynchronous.
* If a player joins the server, this event will be synchronous.
* <p>
* Care should be taken to check {@link #isAsynchronous()} and treat the event
* appropriately.
*/
public class PaperServerListPingEvent extends ServerListPingEvent implements Cancellable {

Expand All @@ -56,9 +66,9 @@ public class PaperServerListPingEvent extends ServerListPingEvent implements Can
private Object[] players;

@ApiStatus.Internal
public PaperServerListPingEvent(@NotNull StatusClient client, @NotNull net.kyori.adventure.text.Component motd, int numPlayers, int maxPlayers,
@NotNull String version, int protocolVersion, @Nullable CachedServerIcon favicon) {
super("", client.getAddress().getAddress(), motd, numPlayers, maxPlayers);
public PaperServerListPingEvent(final boolean async, @NotNull StatusClient client, @NotNull net.kyori.adventure.text.Component motd, int numPlayers,
int maxPlayers, @NotNull String version, int protocolVersion, @Nullable CachedServerIcon favicon) {
super(async, "", client.getAddress().getAddress(), motd, numPlayers, maxPlayers);
this.client = client;
this.numPlayers = numPlayers;
this.version = version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class ServerListPingEvent extends ServerEvent implements Iterable<Player>

@ApiStatus.Internal
@Deprecated(forRemoval = true)
public ServerListPingEvent(@NotNull final String hostname, @NotNull final InetAddress address, @NotNull final String motd, final int numPlayers, final int maxPlayers) {
super(true);
public ServerListPingEvent(final boolean async, @NotNull final String hostname, @NotNull final InetAddress address, @NotNull final String motd, final int numPlayers, final int maxPlayers) {
super(async);
Preconditions.checkArgument(numPlayers >= 0, "Cannot have negative number of players online", numPlayers);
this.hostname = hostname;
this.address = address;
Expand All @@ -47,8 +47,8 @@ public ServerListPingEvent(@NotNull final String hostname, @NotNull final InetAd

@ApiStatus.Internal
@Deprecated(forRemoval = true)
protected ServerListPingEvent(@NotNull final String hostname, @NotNull final InetAddress address, @NotNull final String motd, final int maxPlayers) {
super(true);
protected ServerListPingEvent(final boolean async, @NotNull final String hostname, @NotNull final InetAddress address, @NotNull final String motd, final int maxPlayers) {
super(async);
this.numPlayers = MAGIC_PLAYER_COUNT;
this.hostname = hostname;
this.address = address;
Expand All @@ -58,13 +58,13 @@ protected ServerListPingEvent(@NotNull final String hostname, @NotNull final Ine

@ApiStatus.Internal
@Deprecated(forRemoval = true)
public ServerListPingEvent(@NotNull final InetAddress address, @NotNull final Component motd, final int numPlayers, final int maxPlayers) {
this("", address, motd, numPlayers, maxPlayers);
public ServerListPingEvent(final boolean async, @NotNull final InetAddress address, @NotNull final Component motd, final int numPlayers, final int maxPlayers) {
this(async, "", address, motd, numPlayers, maxPlayers);
}

@ApiStatus.Internal
public ServerListPingEvent(@NotNull final String hostname, @NotNull final InetAddress address, @NotNull final Component motd, final int numPlayers, final int maxPlayers) {
super(true);
public ServerListPingEvent(final boolean async, @NotNull final String hostname, @NotNull final InetAddress address, @NotNull final Component motd, final int numPlayers, final int maxPlayers) {
super(async);
this.hostname = hostname;
this.address = address;
this.motd = motd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
serverGamePacketListenerImpl.send(new ClientboundChangeDifficultyPacket(levelData.getDifficulty(), levelData.isDifficultyLocked()));
serverGamePacketListenerImpl.send(new ClientboundPlayerAbilitiesPacket(player.getAbilities()));
serverGamePacketListenerImpl.send(new ClientboundSetHeldSlotPacket(player.getInventory().getSelectedSlot()));
@@ -203,24 +_,129 @@
@@ -203,24 +_,135 @@
mutableComponent = Component.translatable("multiplayer.player.joined.renamed", player.getDisplayName(), string);
}

Expand All @@ -97,7 +97,14 @@
serverGamePacketListenerImpl.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot());
ServerStatus status = this.server.getStatus();
if (status != null && !cookie.transferred()) {
player.sendServerStatus(status);
- player.sendServerStatus(status);
+ // Paper start - Fire PaperServerListPingEvent when the player joins
+ // player.sendServerStatus(status);
+ status = com.destroystokyo.paper.network.StandardPaperServerListPingEventImpl.getEventResponse(this.server, player.connection.connection, false);
+ if (status != null) {
+ player.sendServerStatus(status);
+ }
+ // Paper end - Fire PaperServerListPingEvent when the player joins
}

- player.connection.send(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(this.players));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static PaperServerListPingEvent processRequest(MinecraftServer server,
InetSocketAddress address, int protocolVersion, @Nullable InetSocketAddress virtualHost) {

PaperServerListPingEvent event = new PaperServerListPingEventImpl(server,
new PaperLegacyStatusClient(address, protocolVersion, virtualHost), Byte.MAX_VALUE, null);
new PaperLegacyStatusClient(address, protocolVersion, virtualHost), Byte.MAX_VALUE, null, true);
server.server.getPluginManager().callEvent(event);

if (event.isCancelled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class PaperServerListPingEventImpl extends PaperServerListPingEvent {

private final MinecraftServer server;

PaperServerListPingEventImpl(MinecraftServer server, StatusClient client, int protocolVersion, @Nullable CachedServerIcon icon) {
super(client, server.motd(), server.getPlayerCount(), server.getMaxPlayers(),
PaperServerListPingEventImpl(MinecraftServer server, StatusClient client, int protocolVersion, @Nullable CachedServerIcon icon, boolean async) {
super(async, client, server.motd(), server.getPlayerCount(), server.getMaxPlayers(),
server.getServerModName() + ' ' + server.getServerVersion(), protocolVersion, icon);
this.server = server;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public final class StandardPaperServerListPingEventImpl extends PaperServerListP

private List<NameAndId> originalSample;

private StandardPaperServerListPingEventImpl(MinecraftServer server, Connection networkManager, ServerStatus ping) {
super(server, new PaperStatusClient(networkManager), ping.version().map(ServerStatus.Version::protocol).orElse(-1), server.server.getServerIcon());
private StandardPaperServerListPingEventImpl(MinecraftServer server, Connection networkManager, ServerStatus ping, boolean async) {
super(server, new PaperStatusClient(networkManager), ping.version().map(ServerStatus.Version::protocol).orElse(-1), server.server.getServerIcon(), async);
this.originalSample = ping.players().map(ServerStatus.Players::sample).orElse(null); // GH-1473 - pre-tick race condition NPE
}

Expand Down Expand Up @@ -64,13 +64,24 @@ private List<NameAndId> getPlayerSampleHandle() {
}

public static void processRequest(MinecraftServer server, Connection networkManager) {
StandardPaperServerListPingEventImpl event = new StandardPaperServerListPingEventImpl(server, networkManager, server.getStatus());
ServerStatus ping = getEventResponse(server, networkManager, true);

if (ping == null) {
networkManager.disconnect((Component) null);
return;
}

// Send response
networkManager.send(new ClientboundStatusResponsePacket(ping));
}

public static ServerStatus getEventResponse(MinecraftServer server, Connection networkManager, boolean async) {
StandardPaperServerListPingEventImpl event = new StandardPaperServerListPingEventImpl(server, networkManager, server.getStatus(), async);
server.server.getPluginManager().callEvent(event);

// Close connection immediately if event is cancelled
if (event.isCancelled()) {
networkManager.disconnect((Component) null);
return;
return null;
}

// Setup response
Expand All @@ -96,10 +107,9 @@ public static void processRequest(MinecraftServer server, Connection networkMana
} else {
favicon = Optional.empty();
}
final ServerStatus ping = new ServerStatus(description, players, Optional.of(version), favicon, server.enforceSecureProfile());

// Send response
networkManager.send(new ClientboundStatusResponsePacket(ping));
// Return response
return new ServerStatus(description, players, Optional.of(version), favicon, server.enforceSecureProfile());
}

}