mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-01 00:10:32 +01:00
31699ae9a8
* Updated Upstream (Bukkit/CraftBukkit) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: a6a9d2a4 Remove some old ApiStatus.Experimental annotations be72314c SPIGOT-7300, PR-829: Add new DamageSource API providing enhanced information about entity damage b252cf05 SPIGOT-7576, PR-970: Add methods in MushroomCow to change stew effects b1c689bd PR-902: Add Server#isLoggingIPs to get log-ips configuration 08f86d1c PR-971: Add Player methods for client-side potion effects 2e3024a9 PR-963: Add API for in-world structures a23292a7 SPIGOT-7530, PR-948: Improve Resource Pack API with new 1.20.3 functionality 1851857b SPIGOT-3071, PR-969: Add entity spawn method with spawn reason cde4c52a SPIGOT-5553, PR-964: Add EntityKnockbackEvent CraftBukkit Changes: 38fd4bd50 Fix accidentally renamed internal damage method 80f0ce4be SPIGOT-7300, PR-1180: Add new DamageSource API providing enhanced information about entity damage 7e43f3b16 SPIGOT-7581: Fix typo in BlockMushroom ea14b7d90 SPIGOT-7576, PR-1347: Add methods in MushroomCow to change stew effects 4c687f243 PR-1259: Add Server#isLoggingIPs to get log-ips configuration 22a541a29 Improve support for per-world game rules cb7dccce2 PR-1348: Add Player methods for client-side potion effects b8d6109f0 PR-1335: Add API for in-world structures 4398a1b5b SPIGOT-7577: Make CraftWindCharge#explode discard the entity e74107678 Fix Crafter maximum stack size 0bb0f4f6a SPIGOT-7530, PR-1314: Improve Resource Pack API with new 1.20.3 functionality 4949f556d SPIGOT-3071, PR-1345: Add entity spawn method with spawn reason 20ac73ca2 PR-1353: Fix Structure#place not working as documented with 0 palette 3c1b77871 SPIGOT-6911, PR-1349: Change max book length in CraftMetaBook 333701839 SPIGOT-7572: Bee nests generated without bees f48f4174c SPIGOT-5553, PR-1336: Add EntityKnockbackEvent
242 lines
11 KiB
Diff
242 lines
11 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Minecrell <minecrell@minecrell.net>
|
|
Date: Wed, 11 Oct 2017 15:56:26 +0200
|
|
Subject: [PATCH] Implement extended PaperServerListPingEvent
|
|
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/network/PaperServerListPingEventImpl.java b/src/main/java/com/destroystokyo/paper/network/PaperServerListPingEventImpl.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..6ed2114f577ce12d2d493985e798609c7d83f15e
|
|
--- /dev/null
|
|
+++ b/src/main/java/com/destroystokyo/paper/network/PaperServerListPingEventImpl.java
|
|
@@ -0,0 +1,31 @@
|
|
+package com.destroystokyo.paper.network;
|
|
+
|
|
+import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
|
|
+import net.minecraft.server.MinecraftServer;
|
|
+import net.minecraft.server.level.ServerPlayer;
|
|
+import org.bukkit.entity.Player;
|
|
+import org.bukkit.util.CachedServerIcon;
|
|
+
|
|
+import javax.annotation.Nullable;
|
|
+
|
|
+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(),
|
|
+ server.getServerModName() + ' ' + server.getServerVersion(), protocolVersion, icon);
|
|
+ this.server = server;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ protected final Object[] getOnlinePlayers() {
|
|
+ return this.server.getPlayerList().players.toArray();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ protected final Player getBukkitPlayer(Object player) {
|
|
+ return ((ServerPlayer) player).getBukkitEntity();
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/com/destroystokyo/paper/network/PaperStatusClient.java b/src/main/java/com/destroystokyo/paper/network/PaperStatusClient.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..d926ad804355ee2fdc5910b2505e8671602acdab
|
|
--- /dev/null
|
|
+++ b/src/main/java/com/destroystokyo/paper/network/PaperStatusClient.java
|
|
@@ -0,0 +1,11 @@
|
|
+package com.destroystokyo.paper.network;
|
|
+
|
|
+import net.minecraft.network.Connection;
|
|
+
|
|
+class PaperStatusClient extends PaperNetworkClient implements StatusClient {
|
|
+
|
|
+ PaperStatusClient(Connection networkManager) {
|
|
+ super(networkManager);
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/com/destroystokyo/paper/network/StandardPaperServerListPingEventImpl.java b/src/main/java/com/destroystokyo/paper/network/StandardPaperServerListPingEventImpl.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..6b0bdc266109cdfb874f08bf74323603921d2260
|
|
--- /dev/null
|
|
+++ b/src/main/java/com/destroystokyo/paper/network/StandardPaperServerListPingEventImpl.java
|
|
@@ -0,0 +1,116 @@
|
|
+package com.destroystokyo.paper.network;
|
|
+
|
|
+import com.destroystokyo.paper.profile.CraftPlayerProfile;
|
|
+import com.destroystokyo.paper.profile.PlayerProfile;
|
|
+import com.google.common.base.MoreObjects;
|
|
+import com.google.common.base.Strings;
|
|
+import com.mojang.authlib.GameProfile;
|
|
+import io.papermc.paper.adventure.AdventureComponent;
|
|
+import java.util.ArrayList;
|
|
+import java.util.Collections;
|
|
+import java.util.List;
|
|
+import java.util.Optional;
|
|
+import java.util.UUID;
|
|
+import javax.annotation.Nonnull;
|
|
+import net.minecraft.network.Connection;
|
|
+import net.minecraft.network.chat.Component;
|
|
+import net.minecraft.network.protocol.status.ClientboundStatusResponsePacket;
|
|
+import net.minecraft.network.protocol.status.ServerStatus;
|
|
+import net.minecraft.server.MinecraftServer;
|
|
+import org.bukkit.craftbukkit.util.CraftIconCache;
|
|
+
|
|
+public final class StandardPaperServerListPingEventImpl extends PaperServerListPingEventImpl {
|
|
+
|
|
+ // private static final GameProfile[] EMPTY_PROFILES = new GameProfile[0];
|
|
+ private static final UUID FAKE_UUID = new UUID(0, 0);
|
|
+
|
|
+ private List<GameProfile> 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());
|
|
+ this.originalSample = ping.players().map(ServerStatus.Players::sample).orElse(null); // GH-1473 - pre-tick race condition NPE
|
|
+ }
|
|
+
|
|
+ @Nonnull
|
|
+ @Override
|
|
+ public List<PlayerProfile> getPlayerSample() {
|
|
+ List<PlayerProfile> sample = super.getPlayerSample();
|
|
+
|
|
+ if (this.originalSample != null) {
|
|
+ for (GameProfile profile : this.originalSample) {
|
|
+ sample.add(CraftPlayerProfile.asBukkitCopy(profile));
|
|
+ }
|
|
+ this.originalSample = null;
|
|
+ }
|
|
+
|
|
+ return sample;
|
|
+ }
|
|
+
|
|
+ private List<GameProfile> getPlayerSampleHandle() {
|
|
+ if (this.originalSample != null) {
|
|
+ return this.originalSample;
|
|
+ }
|
|
+
|
|
+ List<PlayerProfile> entries = super.getPlayerSample();
|
|
+ if (entries.isEmpty()) {
|
|
+ return Collections.emptyList();
|
|
+ }
|
|
+
|
|
+ final List<GameProfile> profiles = new ArrayList<>();
|
|
+ for (PlayerProfile profile : entries) {
|
|
+ /*
|
|
+ * Avoid null UUIDs/names since that will make the response invalid
|
|
+ * on the client.
|
|
+ * Instead, fall back to a fake/empty UUID and an empty string as name.
|
|
+ * This can be used to create custom lines in the player list that do not
|
|
+ * refer to a specific player.
|
|
+ */
|
|
+ if (profile.getId() != null && profile.getName() != null) {
|
|
+ profiles.add(CraftPlayerProfile.asAuthlib(profile));
|
|
+ } else {
|
|
+ profiles.add(new GameProfile(MoreObjects.firstNonNull(profile.getId(), FAKE_UUID), Strings.nullToEmpty(profile.getName())));
|
|
+ }
|
|
+ }
|
|
+ return profiles;
|
|
+ }
|
|
+
|
|
+ public static void processRequest(MinecraftServer server, Connection networkManager) {
|
|
+ StandardPaperServerListPingEventImpl event = new StandardPaperServerListPingEventImpl(server, networkManager, server.getStatus());
|
|
+ server.server.getPluginManager().callEvent(event);
|
|
+
|
|
+ // Close connection immediately if event is cancelled
|
|
+ if (event.isCancelled()) {
|
|
+ networkManager.disconnect(null);
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ // Setup response
|
|
+
|
|
+ // Description
|
|
+ final Component description = new AdventureComponent(event.motd());
|
|
+
|
|
+ // Players
|
|
+ final Optional<ServerStatus.Players> players;
|
|
+ if (!event.shouldHidePlayers()) {
|
|
+ players = Optional.of(new ServerStatus.Players(event.getMaxPlayers(), event.getNumPlayers(), event.getPlayerSampleHandle()));
|
|
+ } else {
|
|
+ players = Optional.empty();
|
|
+ }
|
|
+
|
|
+ // Version
|
|
+ final ServerStatus.Version version = new ServerStatus.Version(event.getVersion(), event.getProtocolVersion());
|
|
+
|
|
+ // Favicon
|
|
+ final Optional<ServerStatus.Favicon> favicon;
|
|
+ if (event.getServerIcon() != null) {
|
|
+ favicon = Optional.of(new ServerStatus.Favicon(((CraftIconCache) event.getServerIcon()).value));
|
|
+ } else {
|
|
+ favicon = Optional.empty();
|
|
+ }
|
|
+ final ServerStatus ping = new ServerStatus(description, players, Optional.of(version), favicon, server.enforceSecureProfile());
|
|
+
|
|
+ // Send response
|
|
+ networkManager.send(new ClientboundStatusResponsePacket(ping));
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
index 6587cd9ea257d0f6f1308ea8ca4d0245178b2870..0f3589ae1c5577c612b93289fc42cdb977486b6b 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -3,6 +3,9 @@ package net.minecraft.server;
|
|
import com.google.common.base.Preconditions;
|
|
import com.google.common.base.Splitter;
|
|
import com.google.common.collect.ImmutableList;
|
|
+import co.aikar.timings.Timings;
|
|
+import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
|
|
+import com.google.common.base.Stopwatch;
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Maps;
|
|
import com.google.common.collect.Sets;
|
|
@@ -1433,7 +1436,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
if (this.hidesOnlinePlayers()) {
|
|
return new ServerStatus.Players(i, list.size(), List.of());
|
|
} else {
|
|
- int j = Math.min(list.size(), 12);
|
|
+ int j = Math.min(list.size(), org.spigotmc.SpigotConfig.playerSample); // Paper - PaperServerListPingEvent
|
|
ObjectArrayList<GameProfile> objectarraylist = new ObjectArrayList(j);
|
|
int k = Mth.nextInt(this.random, 0, list.size() - j);
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerStatusPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerStatusPacketListenerImpl.java
|
|
index 7dd3dfd2ccc820d45849a89707239b7dbcaf44c3..e5006e7672ba79ed4bcf2c4173c5a9ed4c68395b 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerStatusPacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerStatusPacketListenerImpl.java
|
|
@@ -48,6 +48,8 @@ public class ServerStatusPacketListenerImpl implements ServerStatusPacketListene
|
|
this.connection.disconnect(ServerStatusPacketListenerImpl.DISCONNECT_REASON);
|
|
} else {
|
|
this.hasRequestedStatus = true;
|
|
+ // Paper start - Replace everything
|
|
+ /*
|
|
// CraftBukkit start
|
|
// this.connection.send(new PacketStatusOutServerInfo(this.status));
|
|
MinecraftServer server = MinecraftServer.getServer();
|
|
@@ -150,6 +152,9 @@ public class ServerStatusPacketListenerImpl implements ServerStatusPacketListene
|
|
|
|
this.connection.send(new ClientboundStatusResponsePacket(ping));
|
|
// CraftBukkit end
|
|
+ */
|
|
+ com.destroystokyo.paper.network.StandardPaperServerListPingEventImpl.processRequest(MinecraftServer.getServer(), this.connection);
|
|
+ // Paper end
|
|
}
|
|
}
|
|
|
|
diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java
|
|
index 0f391af1274926ef6316bd06458767a27640f54a..9c5c19ab9dc14d844631f47a93f3349409efdf43 100644
|
|
--- a/src/main/java/org/spigotmc/SpigotConfig.java
|
|
+++ b/src/main/java/org/spigotmc/SpigotConfig.java
|
|
@@ -289,7 +289,7 @@ public class SpigotConfig
|
|
public static int playerSample;
|
|
private static void playerSample()
|
|
{
|
|
- SpigotConfig.playerSample = SpigotConfig.getInt( "settings.sample-count", 12 );
|
|
+ SpigotConfig.playerSample = Math.max( SpigotConfig.getInt( "settings.sample-count", 12 ), 0 ); // Paper - Avoid negative counts
|
|
Bukkit.getLogger().log( Level.INFO, "Server Ping Player Sample Count: {0}", playerSample ); // Paper - Use logger
|
|
}
|
|
|