geforkt von Mirrors/Paper
a207d14a0e
Signed-off-by: Mariell Hoversholm <proximyst@proximyst.com>
64 Zeilen
5.2 KiB
Diff
64 Zeilen
5.2 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Mariell Hoversholm <proximyst@proximyst.com>
|
|
Date: Sat, 14 Nov 2020 16:19:52 +0100
|
|
Subject: [PATCH] Add API for quit reason
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java
|
|
index 6f7cbce5a049d87d4a0ed7cc4517cb4e8694efb5..3ba9c38fc44a8edba9b504112a383249052a0035 100644
|
|
--- a/src/main/java/net/minecraft/network/Connection.java
|
|
+++ b/src/main/java/net/minecraft/network/Connection.java
|
|
@@ -137,12 +137,15 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
|
|
|
this.handlingFault = true;
|
|
if (this.channel.isOpen()) {
|
|
+ ServerPlayer player = this.getPlayer(); // Paper
|
|
if (throwable instanceof TimeoutException) {
|
|
Connection.LOGGER.debug("Timeout", throwable);
|
|
+ if (player != null) player.quitReason = org.bukkit.event.player.PlayerQuitEvent.QuitReason.TIMED_OUT; // Paper
|
|
this.disconnect(new TranslatableComponent("disconnect.timeout"));
|
|
} else {
|
|
TranslatableComponent chatmessage = new TranslatableComponent("disconnect.genericReason", new Object[]{"Internal Exception: " + throwable});
|
|
|
|
+ if (player != null) player.quitReason = org.bukkit.event.player.PlayerQuitEvent.QuitReason.ERRONEOUS_STATE; // Paper
|
|
if (flag) {
|
|
Connection.LOGGER.debug("Failed to sent packet", throwable);
|
|
this.send(new ClientboundDisconnectPacket(chatmessage), (future) -> {
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
index bd4d4ace35e966e819aa461d3962fe06ff402be7..1b5f24920c46cd238a79f5a2857d26fa1c12b983 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -258,6 +258,7 @@ public class ServerPlayer extends Player implements ContainerListener {
|
|
double lastEntitySpawnRadiusSquared; // Paper - optimise isOutsideRange, this field is in blocks
|
|
|
|
boolean needsChunkCenterUpdate; // Paper - no-tick view distance
|
|
+ public org.bukkit.event.player.PlayerQuitEvent.QuitReason quitReason = null; // Paper - there are a lot of changes to do if we change all methods leading to the event
|
|
|
|
public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile, ServerPlayerGameMode interactionManager) {
|
|
super(world, world.getSpawn(), world.getSharedSpawnAngle(), profile);
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
index 3a114bec14fcc6c1e1045e2b99178a6adb25f387..ccfe5a1ec1e9895f7462b7c676fee80903502a88 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -447,6 +447,7 @@ public class ServerGamePacketListenerImpl implements ServerGamePacketListener {
|
|
final Component ichatbasecomponent = PaperAdventure.asVanilla(event.reason()); // Paper - Adventure
|
|
// CraftBukkit end
|
|
|
|
+ this.player.quitReason = org.bukkit.event.player.PlayerQuitEvent.QuitReason.KICKED; // Paper
|
|
this.connection.send(new ClientboundDisconnectPacket(ichatbasecomponent), (future) -> {
|
|
this.connection.disconnect(ichatbasecomponent);
|
|
});
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index 7e44c911f4abc5c7d0e89513bf2cfc3516f13492..cda21726f4929b03191e912550d4e4b1232b3b0b 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -586,7 +586,7 @@ public abstract class PlayerList {
|
|
entityplayer.closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.DISCONNECT); // Paper
|
|
}
|
|
|
|
- PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(cserver.getPlayer(entityplayer), net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, com.destroystokyo.paper.PaperConfig.useDisplayNameInQuit ? entityplayer.getBukkitEntity().displayName() : net.kyori.adventure.text.Component.text(entityplayer.getScoreboardName())));
|
|
+ PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(cserver.getPlayer(entityplayer), net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, com.destroystokyo.paper.PaperConfig.useDisplayNameInQuit ? entityplayer.getBukkitEntity().displayName() : net.kyori.adventure.text.Component.text(entityplayer.getScoreboardName())), entityplayer.quitReason); // Paper - quit reason
|
|
if (entityplayer.didPlayerJoinEvent) cserver.getPluginManager().callEvent(playerQuitEvent); // Paper - if we disconnected before join ever fired, don't fire quit
|
|
entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage());
|
|
|