Drop carried item when player has disconnected

Fixes disappearance of held items, when a player gets disconnected and PlayerDropItemEvent is cancelled.
Closes #5036
This commit is contained in:
Dmitry Sidorov 2021-02-04 20:32:01 +03:00
parent 28e1766b3b
commit 06ee0e08d7

View File

@ -381,7 +381,7 @@
if (advancementdataplayer != null) {
advancementdataplayer.save();
@@ -334,95 +509,194 @@
@@ -334,95 +509,202 @@
}
@ -419,6 +419,14 @@
+ }
+ // Paper end - Configurable player collision
+
+ // Paper - Drop carried item when player has disconnected
+ if (!entityplayer.containerMenu.getCarried().isEmpty()) {
+ net.minecraft.world.item.ItemStack carried = entityplayer.containerMenu.getCarried();
+ entityplayer.containerMenu.setCarried(net.minecraft.world.item.ItemStack.EMPTY);
+ entityplayer.drop(carried, false);
+ }
+ // Paper end - Drop carried item when player has disconnected
+
+ this.save(entityplayer);
+ if (entityplayer.isPassenger()) {
+ Entity entity = entityplayer.getRootVehicle();
@ -614,7 +622,7 @@
if (entityplayer1 != null) {
set.add(entityplayer1);
@@ -431,72 +705,160 @@
@@ -431,72 +713,160 @@
Iterator iterator1 = set.iterator();
while (iterator1.hasNext()) {
@ -796,7 +804,7 @@
return entityplayer1;
}
@@ -516,15 +878,32 @@
@@ -516,15 +886,32 @@
}
public void sendPlayerPermissionLevel(ServerPlayer player) {
@ -831,7 +839,7 @@
this.sendAllPlayerInfoIn = 0;
}
@@ -541,6 +920,25 @@
@@ -541,6 +928,25 @@
}
@ -857,7 +865,7 @@
public void broadcastAll(Packet<?> packet, ResourceKey<Level> dimension) {
Iterator iterator = this.players.iterator();
@@ -554,7 +952,7 @@
@@ -554,7 +960,7 @@
}
@ -866,7 +874,7 @@
PlayerTeam scoreboardteam = source.getTeam();
if (scoreboardteam != null) {
@@ -573,7 +971,7 @@
@@ -573,7 +979,7 @@
}
}
@ -875,7 +883,7 @@
PlayerTeam scoreboardteam = source.getTeam();
if (scoreboardteam == null) {
@@ -619,7 +1017,7 @@
@@ -619,7 +1025,7 @@
}
public void deop(GameProfile profile) {
@ -884,7 +892,7 @@
ServerPlayer entityplayer = this.getPlayer(profile.getId());
if (entityplayer != null) {
@@ -629,6 +1027,11 @@
@@ -629,6 +1035,11 @@
}
private void sendPlayerPermissionLevel(ServerPlayer player, int permissionLevel) {
@ -896,7 +904,7 @@
if (player.connection != null) {
byte b0;
@@ -643,36 +1046,53 @@
@@ -643,36 +1054,53 @@
player.connection.send(new ClientboundEntityEventPacket(player, b0));
}
@ -963,7 +971,7 @@
if (entityplayer != player && entityplayer.level().dimension() == worldKey) {
double d4 = x - entityplayer.getX();
double d5 = y - entityplayer.getY();
@@ -687,10 +1107,12 @@
@@ -687,10 +1115,12 @@
}
public void saveAll() {
@ -976,7 +984,7 @@
}
public UserWhiteList getWhiteList() {
@@ -712,15 +1134,19 @@
@@ -712,15 +1142,19 @@
public void reloadWhiteList() {}
public void sendLevelInfo(ServerPlayer player, ServerLevel world) {
@ -1000,7 +1008,7 @@
}
player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.LEVEL_CHUNKS_LOAD_START, 0.0F));
@@ -729,8 +1155,16 @@
@@ -729,8 +1163,16 @@
public void sendAllPlayerInfo(ServerPlayer player) {
player.inventoryMenu.sendAllDataToRemote();
@ -1018,7 +1026,7 @@
}
public int getPlayerCount() {
@@ -746,6 +1180,7 @@
@@ -746,6 +1188,7 @@
}
public void setUsingWhiteList(boolean whitelistEnabled) {
@ -1026,7 +1034,7 @@
this.doWhiteList = whitelistEnabled;
}
@@ -786,12 +1221,36 @@
@@ -786,12 +1229,36 @@
}
public void removeAll() {
@ -1065,7 +1073,7 @@
public void broadcastSystemMessage(Component message, boolean overlay) {
this.broadcastSystemMessage(message, (entityplayer) -> {
return message;
@@ -819,24 +1278,43 @@
@@ -819,24 +1286,43 @@
}
public void broadcastChatMessage(PlayerChatMessage message, ServerPlayer sender, ChatType.Bound params) {
@ -1112,7 +1120,7 @@
}
if (flag1 && sender != null) {
@@ -845,20 +1323,27 @@
@@ -845,20 +1331,27 @@
}
@ -1145,7 +1153,7 @@
Path path = file2.toPath();
if (FileUtil.isPathNormalized(path) && FileUtil.isPathPortable(path) && path.startsWith(file.getPath()) && file2.isFile()) {
@@ -867,7 +1352,7 @@
@@ -867,7 +1360,7 @@
}
serverstatisticmanager = new ServerStatsCounter(this.server, file1);
@ -1154,7 +1162,7 @@
}
return serverstatisticmanager;
@@ -875,13 +1360,13 @@
@@ -875,13 +1368,13 @@
public PlayerAdvancements getPlayerAdvancements(ServerPlayer player) {
UUID uuid = player.getUUID();
@ -1170,7 +1178,7 @@
}
advancementdataplayer.setPlayer(player);
@@ -932,15 +1417,28 @@
@@ -932,15 +1425,28 @@
}
public void reloadResources() {