SPIGOT-5217, SPIGOT-6183: Add RespawnReason to PlayerRespawnEvent

By: Jishuna <joshl5324@gmail.com>
This commit is contained in:
CraftBukkit/Spigot 2023-04-10 08:26:45 +10:00
parent 07453b7fc5
commit 178a84c8d6
3 changed files with 118 additions and 96 deletions

View file

@ -1,6 +1,6 @@
--- a/net/minecraft/server/network/PlayerConnection.java --- a/net/minecraft/server/network/PlayerConnection.java
+++ b/net/minecraft/server/network/PlayerConnection.java +++ b/net/minecraft/server/network/PlayerConnection.java
@@ -184,6 +184,67 @@ @@ -184,6 +184,68 @@
import net.minecraft.world.phys.shapes.VoxelShapes; import net.minecraft.world.phys.shapes.VoxelShapes;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -54,6 +54,7 @@
+import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerKickEvent;
+import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerMoveEvent;
+import org.bukkit.event.player.PlayerResourcePackStatusEvent; +import org.bukkit.event.player.PlayerResourcePackStatusEvent;
+import org.bukkit.event.player.PlayerRespawnEvent.RespawnReason;
+import org.bukkit.event.player.PlayerSwapHandItemsEvent; +import org.bukkit.event.player.PlayerSwapHandItemsEvent;
+import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.player.PlayerTeleportEvent;
+import org.bukkit.event.player.PlayerToggleFlightEvent; +import org.bukkit.event.player.PlayerToggleFlightEvent;
@ -68,7 +69,7 @@
public class PlayerConnection implements ServerPlayerConnection, TickablePacketListener, PacketListenerPlayIn { public class PlayerConnection implements ServerPlayerConnection, TickablePacketListener, PacketListenerPlayIn {
static final Logger LOGGER = LogUtils.getLogger(); static final Logger LOGGER = LogUtils.getLogger();
@@ -200,7 +261,9 @@ @@ -200,7 +262,9 @@
private long keepAliveTime; private long keepAliveTime;
private boolean keepAlivePending; private boolean keepAlivePending;
private long keepAliveChallenge; private long keepAliveChallenge;
@ -79,7 +80,7 @@
private int dropSpamTickCount; private int dropSpamTickCount;
private double firstGoodX; private double firstGoodX;
private double firstGoodY; private double firstGoodY;
@@ -246,8 +309,31 @@ @@ -246,8 +310,31 @@
this.keepAliveTime = SystemUtils.getMillis(); this.keepAliveTime = SystemUtils.getMillis();
entityplayer.getTextFilter().join(); entityplayer.getTextFilter().join();
this.signedMessageDecoder = minecraftserver.enforceSecureProfile() ? SignedMessageChain.b.REJECT_ALL : SignedMessageChain.b.unsigned(entityplayer.getUUID()); this.signedMessageDecoder = minecraftserver.enforceSecureProfile() ? SignedMessageChain.b.REJECT_ALL : SignedMessageChain.b.unsigned(entityplayer.getUUID());
@ -112,7 +113,7 @@
@Override @Override
public void tick() { public void tick() {
@@ -302,7 +388,7 @@ @@ -302,7 +389,7 @@
this.server.getProfiler().push("keepAlive"); this.server.getProfiler().push("keepAlive");
long i = SystemUtils.getMillis(); long i = SystemUtils.getMillis();
@ -121,7 +122,7 @@
if (this.keepAlivePending) { if (this.keepAlivePending) {
this.disconnect(IChatBaseComponent.translatable("disconnect.timeout")); this.disconnect(IChatBaseComponent.translatable("disconnect.timeout"));
} else { } else {
@@ -314,15 +400,21 @@ @@ -314,15 +401,21 @@
} }
this.server.getProfiler().pop(); this.server.getProfiler().pop();
@ -143,7 +144,7 @@
this.disconnect(IChatBaseComponent.translatable("multiplayer.disconnect.idling")); this.disconnect(IChatBaseComponent.translatable("multiplayer.disconnect.idling"));
} }
@@ -346,16 +438,67 @@ @@ -346,16 +439,67 @@
return this.server.isSingleplayerOwner(this.player.getGameProfile()); return this.server.isSingleplayerOwner(this.player.getGameProfile());
} }
@ -212,7 +213,7 @@
} }
private <T, R> CompletableFuture<R> filterTextPacket(T t0, BiFunction<ITextFilter, T, CompletableFuture<R>> bifunction) { private <T, R> CompletableFuture<R> filterTextPacket(T t0, BiFunction<ITextFilter, T, CompletableFuture<R>> bifunction) {
@@ -419,7 +562,34 @@ @@ -419,7 +563,34 @@
double d9 = entity.getDeltaMovement().lengthSqr(); double d9 = entity.getDeltaMovement().lengthSqr();
double d10 = d6 * d6 + d7 * d7 + d8 * d8; double d10 = d6 * d6 + d7 * d7 + d8 * d8;
@ -248,7 +249,7 @@
PlayerConnection.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", new Object[]{entity.getName().getString(), this.player.getName().getString(), d6, d7, d8}); PlayerConnection.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", new Object[]{entity.getName().getString(), this.player.getName().getString(), d6, d7, d8});
this.connection.send(new PacketPlayOutVehicleMove(entity)); this.connection.send(new PacketPlayOutVehicleMove(entity));
return; return;
@@ -451,14 +621,72 @@ @@ -451,14 +622,72 @@
} }
entity.absMoveTo(d3, d4, d5, f, f1); entity.absMoveTo(d3, d4, d5, f, f1);
@ -321,7 +322,7 @@
this.player.getLevel().getChunkSource().move(this.player); this.player.getLevel().getChunkSource().move(this.player);
this.player.checkMovementStatistics(this.player.getX() - d0, this.player.getY() - d1, this.player.getZ() - d2); this.player.checkMovementStatistics(this.player.getX() - d0, this.player.getY() - d1, this.player.getZ() - d2);
this.clientVehicleIsFloating = d11 >= -0.03125D && !flag1 && !this.server.isFlightAllowed() && !entity.isNoGravity() && this.noBlocksAround(entity); this.clientVehicleIsFloating = d11 >= -0.03125D && !flag1 && !this.server.isFlightAllowed() && !entity.isNoGravity() && this.noBlocksAround(entity);
@@ -492,6 +720,7 @@ @@ -492,6 +721,7 @@
} }
this.awaitingPositionFromClient = null; this.awaitingPositionFromClient = null;
@ -329,7 +330,7 @@
} }
} }
@@ -499,7 +728,7 @@ @@ -499,7 +729,7 @@
@Override @Override
public void handleRecipeBookSeenRecipePacket(PacketPlayInRecipeDisplayed packetplayinrecipedisplayed) { public void handleRecipeBookSeenRecipePacket(PacketPlayInRecipeDisplayed packetplayinrecipedisplayed) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinrecipedisplayed, this, this.player.getLevel()); PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinrecipedisplayed, this, this.player.getLevel());
@ -338,7 +339,7 @@
RecipeBookServer recipebookserver = this.player.getRecipeBook(); RecipeBookServer recipebookserver = this.player.getRecipeBook();
Objects.requireNonNull(recipebookserver); Objects.requireNonNull(recipebookserver);
@@ -529,6 +758,12 @@ @@ -529,6 +759,12 @@
@Override @Override
public void handleCustomCommandSuggestions(PacketPlayInTabComplete packetplayintabcomplete) { public void handleCustomCommandSuggestions(PacketPlayInTabComplete packetplayintabcomplete) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayintabcomplete, this, this.player.getLevel()); PlayerConnectionUtils.ensureRunningOnSameThread(packetplayintabcomplete, this, this.player.getLevel());
@ -351,7 +352,7 @@
StringReader stringreader = new StringReader(packetplayintabcomplete.getCommand()); StringReader stringreader = new StringReader(packetplayintabcomplete.getCommand());
if (stringreader.canRead() && stringreader.peek() == '/') { if (stringreader.canRead() && stringreader.peek() == '/') {
@@ -538,6 +773,7 @@ @@ -538,6 +774,7 @@
ParseResults<CommandListenerWrapper> parseresults = this.server.getCommands().getDispatcher().parse(stringreader, this.player.createCommandSourceStack()); ParseResults<CommandListenerWrapper> parseresults = this.server.getCommands().getDispatcher().parse(stringreader, this.player.createCommandSourceStack());
this.server.getCommands().getDispatcher().getCompletionSuggestions(parseresults).thenAccept((suggestions) -> { this.server.getCommands().getDispatcher().getCompletionSuggestions(parseresults).thenAccept((suggestions) -> {
@ -359,7 +360,7 @@
this.connection.send(new PacketPlayOutTabComplete(packetplayintabcomplete.getId(), suggestions)); this.connection.send(new PacketPlayOutTabComplete(packetplayintabcomplete.getId(), suggestions));
}); });
} }
@@ -787,6 +1023,13 @@ @@ -787,6 +1024,13 @@
if (container instanceof ContainerMerchant) { if (container instanceof ContainerMerchant) {
ContainerMerchant containermerchant = (ContainerMerchant) container; ContainerMerchant containermerchant = (ContainerMerchant) container;
@ -373,7 +374,7 @@
if (!containermerchant.stillValid(this.player)) { if (!containermerchant.stillValid(this.player)) {
PlayerConnection.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, containermerchant); PlayerConnection.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, containermerchant);
@@ -801,6 +1044,13 @@ @@ -801,6 +1045,13 @@
@Override @Override
public void handleEditBook(PacketPlayInBEdit packetplayinbedit) { public void handleEditBook(PacketPlayInBEdit packetplayinbedit) {
@ -387,7 +388,7 @@
int i = packetplayinbedit.getSlot(); int i = packetplayinbedit.getSlot();
if (PlayerInventory.isHotbarSlot(i) || i == 40) { if (PlayerInventory.isHotbarSlot(i) || i == 40) {
@@ -809,7 +1059,7 @@ @@ -809,7 +1060,7 @@
Objects.requireNonNull(list); Objects.requireNonNull(list);
optional.ifPresent(list::add); optional.ifPresent(list::add);
@ -396,7 +397,7 @@
Objects.requireNonNull(list); Objects.requireNonNull(list);
stream.forEach(list::add); stream.forEach(list::add);
@@ -827,7 +1077,7 @@ @@ -827,7 +1078,7 @@
ItemStack itemstack = this.player.getInventory().getItem(i); ItemStack itemstack = this.player.getInventory().getItem(i);
if (itemstack.is(Items.WRITABLE_BOOK)) { if (itemstack.is(Items.WRITABLE_BOOK)) {
@ -405,7 +406,7 @@
} }
} }
@@ -852,16 +1102,16 @@ @@ -852,16 +1103,16 @@
this.updateBookPages(list, (s) -> { this.updateBookPages(list, (s) -> {
return IChatBaseComponent.ChatSerializer.toJson(IChatBaseComponent.literal(s)); return IChatBaseComponent.ChatSerializer.toJson(IChatBaseComponent.literal(s));
@ -426,7 +427,7 @@
return NBTTagString.valueOf((String) unaryoperator.apply(filteredtext.filteredOrEmpty())); return NBTTagString.valueOf((String) unaryoperator.apply(filteredtext.filteredOrEmpty()));
}); });
@@ -887,6 +1137,7 @@ @@ -887,6 +1138,7 @@
} }
itemstack.addTagElement("pages", nbttaglist); itemstack.addTagElement("pages", nbttaglist);
@ -434,7 +435,7 @@
} }
@Override @Override
@@ -923,7 +1174,7 @@ @@ -923,7 +1175,7 @@
} else { } else {
WorldServer worldserver = this.player.getLevel(); WorldServer worldserver = this.player.getLevel();
@ -443,7 +444,7 @@
if (this.tickCount == 0) { if (this.tickCount == 0) {
this.resetPosition(); this.resetPosition();
} }
@@ -933,7 +1184,7 @@ @@ -933,7 +1185,7 @@
this.awaitingTeleportTime = this.tickCount; this.awaitingTeleportTime = this.tickCount;
this.teleport(this.awaitingPositionFromClient.x, this.awaitingPositionFromClient.y, this.awaitingPositionFromClient.z, this.player.getYRot(), this.player.getXRot()); this.teleport(this.awaitingPositionFromClient.x, this.awaitingPositionFromClient.y, this.awaitingPositionFromClient.z, this.player.getYRot(), this.player.getXRot());
} }
@ -452,7 +453,7 @@
} else { } else {
this.awaitingTeleportTime = this.tickCount; this.awaitingTeleportTime = this.tickCount;
double d0 = clampHorizontal(packetplayinflying.getX(this.player.getX())); double d0 = clampHorizontal(packetplayinflying.getX(this.player.getX()));
@@ -945,7 +1196,15 @@ @@ -945,7 +1197,15 @@
if (this.player.isPassenger()) { if (this.player.isPassenger()) {
this.player.absMoveTo(this.player.getX(), this.player.getY(), this.player.getZ(), f, f1); this.player.absMoveTo(this.player.getX(), this.player.getY(), this.player.getZ(), f, f1);
this.player.getLevel().getChunkSource().move(this.player); this.player.getLevel().getChunkSource().move(this.player);
@ -468,7 +469,7 @@
double d3 = this.player.getX(); double d3 = this.player.getX();
double d4 = this.player.getY(); double d4 = this.player.getY();
double d5 = this.player.getZ(); double d5 = this.player.getZ();
@@ -965,15 +1224,33 @@ @@ -965,15 +1225,33 @@
++this.receivedMovePacketCount; ++this.receivedMovePacketCount;
int i = this.receivedMovePacketCount - this.knownMovePacketCount; int i = this.receivedMovePacketCount - this.knownMovePacketCount;
@ -504,7 +505,7 @@
PlayerConnection.LOGGER.warn("{} moved too quickly! {},{},{}", new Object[]{this.player.getName().getString(), d7, d8, d9}); PlayerConnection.LOGGER.warn("{} moved too quickly! {},{},{}", new Object[]{this.player.getName().getString(), d7, d8, d9});
this.teleport(this.player.getX(), this.player.getY(), this.player.getZ(), this.player.getYRot(), this.player.getXRot()); this.teleport(this.player.getX(), this.player.getY(), this.player.getZ(), this.player.getYRot(), this.player.getXRot());
return; return;
@@ -994,6 +1271,7 @@ @@ -994,6 +1272,7 @@
boolean flag1 = this.player.verticalCollisionBelow; boolean flag1 = this.player.verticalCollisionBelow;
this.player.move(EnumMoveType.PLAYER, new Vec3D(d7, d8, d9)); this.player.move(EnumMoveType.PLAYER, new Vec3D(d7, d8, d9));
@ -512,7 +513,7 @@
double d12 = d8; double d12 = d8;
d7 = d0 - this.player.getX(); d7 = d0 - this.player.getX();
@@ -1013,9 +1291,72 @@ @@ -1013,9 +1292,72 @@
this.player.absMoveTo(d0, d1, d2, f, f1); this.player.absMoveTo(d0, d1, d2, f, f1);
if (!this.player.noPhysics && !this.player.isSleeping() && (flag2 && worldserver.noCollision(this.player, axisalignedbb) || this.isPlayerCollidingWithAnythingNew(worldserver, axisalignedbb))) { if (!this.player.noPhysics && !this.player.isSleeping() && (flag2 && worldserver.noCollision(this.player, axisalignedbb) || this.isPlayerCollidingWithAnythingNew(worldserver, axisalignedbb))) {
@ -586,7 +587,7 @@
this.clientIsFloating = d12 >= -0.03125D && !flag1 && this.player.gameMode.getGameModeForPlayer() != EnumGamemode.SPECTATOR && !this.server.isFlightAllowed() && !this.player.getAbilities().mayfly && !this.player.hasEffect(MobEffects.LEVITATION) && !this.player.isFallFlying() && !this.player.isAutoSpinAttack() && this.noBlocksAround(this.player); this.clientIsFloating = d12 >= -0.03125D && !flag1 && this.player.gameMode.getGameModeForPlayer() != EnumGamemode.SPECTATOR && !this.server.isFlightAllowed() && !this.player.getAbilities().mayfly && !this.player.hasEffect(MobEffects.LEVITATION) && !this.player.isFallFlying() && !this.player.isAutoSpinAttack() && this.noBlocksAround(this.player);
this.player.getLevel().getChunkSource().move(this.player); this.player.getLevel().getChunkSource().move(this.player);
this.player.doCheckFallDamage(this.player.getY() - d6, packetplayinflying.isOnGround()); this.player.doCheckFallDamage(this.player.getY() - d6, packetplayinflying.isOnGround());
@@ -1054,11 +1395,68 @@ @@ -1054,11 +1396,68 @@
return true; return true;
} }
@ -656,7 +657,7 @@
double d3 = set.contains(RelativeMovement.X) ? this.player.getX() : 0.0D; double d3 = set.contains(RelativeMovement.X) ? this.player.getX() : 0.0D;
double d4 = set.contains(RelativeMovement.Y) ? this.player.getY() : 0.0D; double d4 = set.contains(RelativeMovement.Y) ? this.player.getY() : 0.0D;
double d5 = set.contains(RelativeMovement.Z) ? this.player.getZ() : 0.0D; double d5 = set.contains(RelativeMovement.Z) ? this.player.getZ() : 0.0D;
@@ -1070,6 +1468,14 @@ @@ -1070,6 +1469,14 @@
this.awaitingTeleport = 0; this.awaitingTeleport = 0;
} }
@ -671,7 +672,7 @@
this.awaitingTeleportTime = this.tickCount; this.awaitingTeleportTime = this.tickCount;
this.player.absMoveTo(d0, d1, d2, f, f1); this.player.absMoveTo(d0, d1, d2, f, f1);
this.player.connection.send(new PacketPlayOutPosition(d0 - d3, d1 - d4, d2 - d5, f - f2, f1 - f3, set, this.awaitingTeleport)); this.player.connection.send(new PacketPlayOutPosition(d0 - d3, d1 - d4, d2 - d5, f - f2, f1 - f3, set, this.awaitingTeleport));
@@ -1078,6 +1484,7 @@ @@ -1078,6 +1485,7 @@
@Override @Override
public void handlePlayerAction(PacketPlayInBlockDig packetplayinblockdig) { public void handlePlayerAction(PacketPlayInBlockDig packetplayinblockdig) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinblockdig, this, this.player.getLevel()); PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinblockdig, this, this.player.getLevel());
@ -679,7 +680,7 @@
BlockPosition blockposition = packetplayinblockdig.getPos(); BlockPosition blockposition = packetplayinblockdig.getPos();
this.player.resetLastActionTime(); this.player.resetLastActionTime();
@@ -1088,14 +1495,46 @@ @@ -1088,14 +1496,46 @@
if (!this.player.isSpectator()) { if (!this.player.isSpectator()) {
ItemStack itemstack = this.player.getItemInHand(EnumHand.OFF_HAND); ItemStack itemstack = this.player.getItemInHand(EnumHand.OFF_HAND);
@ -728,7 +729,7 @@
this.player.drop(false); this.player.drop(false);
} }
@@ -1133,6 +1572,7 @@ @@ -1133,6 +1573,7 @@
@Override @Override
public void handleUseItemOn(PacketPlayInUseItem packetplayinuseitem) { public void handleUseItemOn(PacketPlayInUseItem packetplayinuseitem) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseitem, this, this.player.getLevel()); PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseitem, this, this.player.getLevel());
@ -736,7 +737,7 @@
this.player.connection.ackBlockChangesUpTo(packetplayinuseitem.getSequence()); this.player.connection.ackBlockChangesUpTo(packetplayinuseitem.getSequence());
WorldServer worldserver = this.player.getLevel(); WorldServer worldserver = this.player.getLevel();
EnumHand enumhand = packetplayinuseitem.getHand(); EnumHand enumhand = packetplayinuseitem.getHand();
@@ -1156,6 +1596,7 @@ @@ -1156,6 +1597,7 @@
if (blockposition.getY() < i) { if (blockposition.getY() < i) {
if (this.awaitingPositionFromClient == null && this.player.distanceToSqr((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D) < 64.0D && worldserver.mayInteract(this.player, blockposition)) { if (this.awaitingPositionFromClient == null && this.player.distanceToSqr((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D) < 64.0D && worldserver.mayInteract(this.player, blockposition)) {
@ -744,7 +745,7 @@
EnumInteractionResult enuminteractionresult = this.player.gameMode.useItemOn(this.player, worldserver, itemstack, enumhand, movingobjectpositionblock); EnumInteractionResult enuminteractionresult = this.player.gameMode.useItemOn(this.player, worldserver, itemstack, enumhand, movingobjectpositionblock);
if (enumdirection == EnumDirection.UP && !enuminteractionresult.consumesAction() && blockposition.getY() >= i - 1 && wasBlockPlacementAttempt(this.player, itemstack)) { if (enumdirection == EnumDirection.UP && !enuminteractionresult.consumesAction() && blockposition.getY() >= i - 1 && wasBlockPlacementAttempt(this.player, itemstack)) {
@@ -1184,6 +1625,7 @@ @@ -1184,6 +1626,7 @@
@Override @Override
public void handleUseItem(PacketPlayInBlockPlace packetplayinblockplace) { public void handleUseItem(PacketPlayInBlockPlace packetplayinblockplace) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinblockplace, this, this.player.getLevel()); PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinblockplace, this, this.player.getLevel());
@ -752,7 +753,7 @@
this.ackBlockChangesUpTo(packetplayinblockplace.getSequence()); this.ackBlockChangesUpTo(packetplayinblockplace.getSequence());
WorldServer worldserver = this.player.getLevel(); WorldServer worldserver = this.player.getLevel();
EnumHand enumhand = packetplayinblockplace.getHand(); EnumHand enumhand = packetplayinblockplace.getHand();
@@ -1191,6 +1633,49 @@ @@ -1191,6 +1634,49 @@
this.player.resetLastActionTime(); this.player.resetLastActionTime();
if (!itemstack.isEmpty() && itemstack.isItemEnabled(worldserver.enabledFeatures())) { if (!itemstack.isEmpty() && itemstack.isItemEnabled(worldserver.enabledFeatures())) {
@ -802,7 +803,7 @@
EnumInteractionResult enuminteractionresult = this.player.gameMode.useItem(this.player, worldserver, itemstack, enumhand); EnumInteractionResult enuminteractionresult = this.player.gameMode.useItem(this.player, worldserver, itemstack, enumhand);
if (enuminteractionresult.shouldSwing()) { if (enuminteractionresult.shouldSwing()) {
@@ -1211,7 +1696,7 @@ @@ -1211,7 +1697,7 @@
Entity entity = packetplayinspectate.getEntity(worldserver); Entity entity = packetplayinspectate.getEntity(worldserver);
if (entity != null) { if (entity != null) {
@ -811,7 +812,7 @@
return; return;
} }
} }
@@ -1226,6 +1711,7 @@ @@ -1226,6 +1712,7 @@
PlayerConnection.LOGGER.info("Disconnecting {} due to resource pack rejection", this.player.getName()); PlayerConnection.LOGGER.info("Disconnecting {} due to resource pack rejection", this.player.getName());
this.disconnect(IChatBaseComponent.translatable("multiplayer.requiredTexturePrompt.disconnect")); this.disconnect(IChatBaseComponent.translatable("multiplayer.requiredTexturePrompt.disconnect"));
} }
@ -819,7 +820,7 @@
} }
@@ -1247,12 +1733,27 @@ @@ -1247,12 +1734,27 @@
@Override @Override
public void onDisconnect(IChatBaseComponent ichatbasecomponent) { public void onDisconnect(IChatBaseComponent ichatbasecomponent) {
@ -848,7 +849,7 @@
this.player.getTextFilter().leave(); this.player.getTextFilter().leave();
if (this.isSingleplayerOwner()) { if (this.isSingleplayerOwner()) {
PlayerConnection.LOGGER.info("Stopping singleplayer server as player logged out"); PlayerConnection.LOGGER.info("Stopping singleplayer server as player logged out");
@@ -1275,6 +1776,15 @@ @@ -1275,6 +1777,15 @@
} }
public void send(Packet<?> packet, @Nullable PacketSendListener packetsendlistener) { public void send(Packet<?> packet, @Nullable PacketSendListener packetsendlistener) {
@ -864,7 +865,7 @@
try { try {
this.connection.send(packet, packetsendlistener); this.connection.send(packet, packetsendlistener);
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -1291,7 +1801,16 @@ @@ -1291,7 +1802,16 @@
@Override @Override
public void handleSetCarriedItem(PacketPlayInHeldItemSlot packetplayinhelditemslot) { public void handleSetCarriedItem(PacketPlayInHeldItemSlot packetplayinhelditemslot) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinhelditemslot, this, this.player.getLevel()); PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinhelditemslot, this, this.player.getLevel());
@ -881,7 +882,7 @@
if (this.player.getInventory().selected != packetplayinhelditemslot.getSlot() && this.player.getUsedItemHand() == EnumHand.MAIN_HAND) { if (this.player.getInventory().selected != packetplayinhelditemslot.getSlot() && this.player.getUsedItemHand() == EnumHand.MAIN_HAND) {
this.player.stopUsingItem(); this.player.stopUsingItem();
} }
@@ -1300,18 +1819,25 @@ @@ -1300,18 +1820,25 @@
this.player.resetLastActionTime(); this.player.resetLastActionTime();
} else { } else {
PlayerConnection.LOGGER.warn("{} tried to set an invalid carried item", this.player.getName().getString()); PlayerConnection.LOGGER.warn("{} tried to set an invalid carried item", this.player.getName().getString());
@ -908,7 +909,7 @@
PlayerChatMessage playerchatmessage; PlayerChatMessage playerchatmessage;
try { try {
@@ -1329,9 +1855,9 @@ @@ -1329,9 +1856,9 @@
PlayerChatMessage playerchatmessage1 = playerchatmessage.withUnsignedContent((IChatBaseComponent) completablefuture1.join()).filter(((FilteredText) completablefuture.join()).mask()); PlayerChatMessage playerchatmessage1 = playerchatmessage.withUnsignedContent((IChatBaseComponent) completablefuture1.join()).filter(((FilteredText) completablefuture.join()).mask());
this.broadcastChatMessage(playerchatmessage1); this.broadcastChatMessage(playerchatmessage1);
@ -920,7 +921,7 @@
} }
} }
@@ -1355,12 +1881,25 @@ @@ -1355,12 +1882,25 @@
} }
private void performChatCommand(ServerboundChatCommandPacket serverboundchatcommandpacket, LastSeenMessages lastseenmessages) { private void performChatCommand(ServerboundChatCommandPacket serverboundchatcommandpacket, LastSeenMessages lastseenmessages) {
@ -948,7 +949,7 @@
} catch (SignedMessageChain.a signedmessagechain_a) { } catch (SignedMessageChain.a signedmessagechain_a) {
this.handleMessageDecodeFailure(signedmessagechain_a); this.handleMessageDecodeFailure(signedmessagechain_a);
return; return;
@@ -1368,10 +1907,10 @@ @@ -1368,10 +1908,10 @@
CommandSigningContext.a commandsigningcontext_a = new CommandSigningContext.a(map); CommandSigningContext.a commandsigningcontext_a = new CommandSigningContext.a(map);
@ -961,7 +962,7 @@
} }
private void handleMessageDecodeFailure(SignedMessageChain.a signedmessagechain_a) { private void handleMessageDecodeFailure(SignedMessageChain.a signedmessagechain_a) {
@@ -1412,7 +1951,7 @@ @@ -1412,7 +1952,7 @@
} else { } else {
Optional<LastSeenMessages> optional = this.unpackAndApplyLastSeen(lastseenmessages_b); Optional<LastSeenMessages> optional = this.unpackAndApplyLastSeen(lastseenmessages_b);
@ -970,7 +971,7 @@
this.send(new ClientboundSystemChatPacket(IChatBaseComponent.translatable("chat.disabled.options").withStyle(EnumChatFormat.RED), false)); this.send(new ClientboundSystemChatPacket(IChatBaseComponent.translatable("chat.disabled.options").withStyle(EnumChatFormat.RED), false));
return Optional.empty(); return Optional.empty();
} else { } else {
@@ -1460,6 +1999,122 @@ @@ -1460,6 +2000,122 @@
return false; return false;
} }
@ -1093,7 +1094,7 @@
private PlayerChatMessage getSignedMessage(PacketPlayInChat packetplayinchat, LastSeenMessages lastseenmessages) throws SignedMessageChain.a { private PlayerChatMessage getSignedMessage(PacketPlayInChat packetplayinchat, LastSeenMessages lastseenmessages) throws SignedMessageChain.a {
SignedMessageBody signedmessagebody = new SignedMessageBody(packetplayinchat.message(), packetplayinchat.timeStamp(), packetplayinchat.salt(), lastseenmessages); SignedMessageBody signedmessagebody = new SignedMessageBody(packetplayinchat.message(), packetplayinchat.timeStamp(), packetplayinchat.salt(), lastseenmessages);
@@ -1467,13 +2122,33 @@ @@ -1467,13 +2123,33 @@
} }
private void broadcastChatMessage(PlayerChatMessage playerchatmessage) { private void broadcastChatMessage(PlayerChatMessage playerchatmessage) {
@ -1130,7 +1131,7 @@
this.disconnect(IChatBaseComponent.translatable("disconnect.spam")); this.disconnect(IChatBaseComponent.translatable("disconnect.spam"));
} }
@@ -1495,13 +2170,59 @@ @@ -1495,13 +2171,59 @@
@Override @Override
public void handleAnimate(PacketPlayInArmAnimation packetplayinarmanimation) { public void handleAnimate(PacketPlayInArmAnimation packetplayinarmanimation) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinarmanimation, this, this.player.getLevel()); PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinarmanimation, this, this.player.getLevel());
@ -1190,7 +1191,7 @@
this.player.resetLastActionTime(); this.player.resetLastActionTime();
Entity entity; Entity entity;
IJumpable ijumpable; IJumpable ijumpable;
@@ -1583,6 +2304,12 @@ @@ -1583,6 +2305,12 @@
} }
public void sendPlayerChatMessage(PlayerChatMessage playerchatmessage, ChatMessageType.a chatmessagetype_a) { public void sendPlayerChatMessage(PlayerChatMessage playerchatmessage, ChatMessageType.a chatmessagetype_a) {
@ -1203,7 +1204,7 @@
this.send(new ClientboundPlayerChatPacket(playerchatmessage.link().sender(), playerchatmessage.link().index(), playerchatmessage.signature(), playerchatmessage.signedBody().pack(this.messageSignatureCache), playerchatmessage.unsignedContent(), playerchatmessage.filterMask(), chatmessagetype_a.toNetwork(this.player.level.registryAccess()))); this.send(new ClientboundPlayerChatPacket(playerchatmessage.link().sender(), playerchatmessage.link().index(), playerchatmessage.signature(), playerchatmessage.signedBody().pack(this.messageSignatureCache), playerchatmessage.unsignedContent(), playerchatmessage.filterMask(), chatmessagetype_a.toNetwork(this.player.level.registryAccess())));
this.addPendingMessage(playerchatmessage); this.addPendingMessage(playerchatmessage);
} }
@@ -1598,6 +2325,7 @@ @@ -1598,6 +2326,7 @@
@Override @Override
public void handleInteract(PacketPlayInUseEntity packetplayinuseentity) { public void handleInteract(PacketPlayInUseEntity packetplayinuseentity) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseentity, this, this.player.getLevel()); PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseentity, this, this.player.getLevel());
@ -1211,7 +1212,7 @@
final WorldServer worldserver = this.player.getLevel(); final WorldServer worldserver = this.player.getLevel();
final Entity entity = packetplayinuseentity.getTarget(worldserver); final Entity entity = packetplayinuseentity.getTarget(worldserver);
@@ -1612,13 +2340,51 @@ @@ -1612,13 +2341,51 @@
if (axisalignedbb.distanceToSqr(this.player.getEyePosition()) < PlayerConnection.MAX_INTERACTION_DISTANCE) { if (axisalignedbb.distanceToSqr(this.player.getEyePosition()) < PlayerConnection.MAX_INTERACTION_DISTANCE) {
packetplayinuseentity.dispatch(new PacketPlayInUseEntity.c() { packetplayinuseentity.dispatch(new PacketPlayInUseEntity.c() {
@ -1264,7 +1265,7 @@
if (enuminteractionresult.consumesAction()) { if (enuminteractionresult.consumesAction()) {
CriterionTriggers.PLAYER_INTERACTED_WITH_ENTITY.trigger(PlayerConnection.this.player, itemstack1, entity); CriterionTriggers.PLAYER_INTERACTED_WITH_ENTITY.trigger(PlayerConnection.this.player, itemstack1, entity);
if (enuminteractionresult.shouldSwing()) { if (enuminteractionresult.shouldSwing()) {
@@ -1631,23 +2397,29 @@ @@ -1631,23 +2398,29 @@
@Override @Override
public void onInteraction(EnumHand enumhand) { public void onInteraction(EnumHand enumhand) {
@ -1297,7 +1298,24 @@
} }
} else { } else {
PlayerConnection.this.disconnect(IChatBaseComponent.translatable("multiplayer.disconnect.invalid_entity_attacked")); PlayerConnection.this.disconnect(IChatBaseComponent.translatable("multiplayer.disconnect.invalid_entity_attacked"));
@@ -1693,15 +2465,21 @@ @@ -1670,14 +2443,14 @@
case PERFORM_RESPAWN:
if (this.player.wonGame) {
this.player.wonGame = false;
- this.player = this.server.getPlayerList().respawn(this.player, true);
+ this.player = this.server.getPlayerList().respawn(this.player, true, RespawnReason.END_PORTAL);
CriterionTriggers.CHANGED_DIMENSION.trigger(this.player, World.END, World.OVERWORLD);
} else {
if (this.player.getHealth() > 0.0F) {
return;
}
- this.player = this.server.getPlayerList().respawn(this.player, false);
+ this.player = this.server.getPlayerList().respawn(this.player, false, RespawnReason.DEATH);
if (this.server.isHardcore()) {
this.player.setGameMode(EnumGamemode.SPECTATOR);
((GameRules.GameRuleBoolean) this.player.getLevel().getGameRules().getRule(GameRules.RULE_SPECTATORSGENERATECHUNKS)).set(false, this.server);
@@ -1693,15 +2466,21 @@
@Override @Override
public void handleContainerClose(PacketPlayInCloseWindow packetplayinclosewindow) { public void handleContainerClose(PacketPlayInCloseWindow packetplayinclosewindow) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinclosewindow, this, this.player.getLevel()); PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinclosewindow, this, this.player.getLevel());
@ -1321,7 +1339,7 @@
this.player.containerMenu.sendAllDataToRemote(); this.player.containerMenu.sendAllDataToRemote();
} else if (!this.player.containerMenu.stillValid(this.player)) { } else if (!this.player.containerMenu.stillValid(this.player)) {
PlayerConnection.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu); PlayerConnection.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu);
@@ -1714,7 +2492,284 @@ @@ -1714,7 +2493,284 @@
boolean flag = packetplayinwindowclick.getStateId() != this.player.containerMenu.getStateId(); boolean flag = packetplayinwindowclick.getStateId() != this.player.containerMenu.getStateId();
this.player.containerMenu.suppressRemoteUpdates(); this.player.containerMenu.suppressRemoteUpdates();
@ -1607,7 +1625,7 @@
ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packetplayinwindowclick.getChangedSlots()).iterator(); ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packetplayinwindowclick.getChangedSlots()).iterator();
while (objectiterator.hasNext()) { while (objectiterator.hasNext()) {
@@ -1754,6 +2809,7 @@ @@ -1754,6 +2810,7 @@
@Override @Override
public void handleContainerButtonClick(PacketPlayInEnchantItem packetplayinenchantitem) { public void handleContainerButtonClick(PacketPlayInEnchantItem packetplayinenchantitem) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinenchantitem, this, this.player.getLevel()); PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinenchantitem, this, this.player.getLevel());
@ -1615,7 +1633,7 @@
this.player.resetLastActionTime(); this.player.resetLastActionTime();
if (this.player.containerMenu.containerId == packetplayinenchantitem.getContainerId() && !this.player.isSpectator()) { if (this.player.containerMenu.containerId == packetplayinenchantitem.getContainerId() && !this.player.isSpectator()) {
if (!this.player.containerMenu.stillValid(this.player)) { if (!this.player.containerMenu.stillValid(this.player)) {
@@ -1796,6 +2852,43 @@ @@ -1796,6 +2853,43 @@
boolean flag1 = packetplayinsetcreativeslot.getSlotNum() >= 1 && packetplayinsetcreativeslot.getSlotNum() <= 45; boolean flag1 = packetplayinsetcreativeslot.getSlotNum() >= 1 && packetplayinsetcreativeslot.getSlotNum() <= 45;
boolean flag2 = itemstack.isEmpty() || itemstack.getDamageValue() >= 0 && itemstack.getCount() <= 64 && !itemstack.isEmpty(); boolean flag2 = itemstack.isEmpty() || itemstack.getDamageValue() >= 0 && itemstack.getCount() <= 64 && !itemstack.isEmpty();
@ -1659,7 +1677,7 @@
if (flag1 && flag2) { if (flag1 && flag2) {
this.player.inventoryMenu.getSlot(packetplayinsetcreativeslot.getSlotNum()).setByPlayer(itemstack); this.player.inventoryMenu.getSlot(packetplayinsetcreativeslot.getSlotNum()).setByPlayer(itemstack);
@@ -1818,6 +2911,7 @@ @@ -1818,6 +2912,7 @@
} }
private void updateSignText(PacketPlayInUpdateSign packetplayinupdatesign, List<FilteredText> list) { private void updateSignText(PacketPlayInUpdateSign packetplayinupdatesign, List<FilteredText> list) {
@ -1667,7 +1685,7 @@
this.player.resetLastActionTime(); this.player.resetLastActionTime();
WorldServer worldserver = this.player.getLevel(); WorldServer worldserver = this.player.getLevel();
BlockPosition blockposition = packetplayinupdatesign.getPos(); BlockPosition blockposition = packetplayinupdatesign.getPos();
@@ -1834,18 +2928,37 @@ @@ -1834,18 +2929,37 @@
if (!tileentitysign.isEditable() || !this.player.getUUID().equals(tileentitysign.getPlayerWhoMayEdit())) { if (!tileentitysign.isEditable() || !this.player.getUUID().equals(tileentitysign.getPlayerWhoMayEdit())) {
PlayerConnection.LOGGER.warn("Player {} just tried to change non-editable sign", this.player.getName().getString()); PlayerConnection.LOGGER.warn("Player {} just tried to change non-editable sign", this.player.getName().getString());
@ -1707,7 +1725,7 @@
tileentitysign.setChanged(); tileentitysign.setChanged();
worldserver.sendBlockUpdated(blockposition, iblockdata, iblockdata, 3); worldserver.sendBlockUpdated(blockposition, iblockdata, iblockdata, 3);
@@ -1855,6 +2968,7 @@ @@ -1855,6 +2969,7 @@
@Override @Override
public void handleKeepAlive(PacketPlayInKeepAlive packetplayinkeepalive) { public void handleKeepAlive(PacketPlayInKeepAlive packetplayinkeepalive) {
@ -1715,7 +1733,7 @@
if (this.keepAlivePending && packetplayinkeepalive.getId() == this.keepAliveChallenge) { if (this.keepAlivePending && packetplayinkeepalive.getId() == this.keepAliveChallenge) {
int i = (int) (SystemUtils.getMillis() - this.keepAliveTime); int i = (int) (SystemUtils.getMillis() - this.keepAliveTime);
@@ -1869,7 +2983,17 @@ @@ -1869,7 +2984,17 @@
@Override @Override
public void handlePlayerAbilities(PacketPlayInAbilities packetplayinabilities) { public void handlePlayerAbilities(PacketPlayInAbilities packetplayinabilities) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinabilities, this, this.player.getLevel()); PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinabilities, this, this.player.getLevel());
@ -1734,7 +1752,7 @@
} }
@Override @Override
@@ -1878,8 +3002,50 @@ @@ -1878,8 +3003,50 @@
this.player.updateOptions(packetplayinsettings); this.player.updateOptions(packetplayinsettings);
} }

View file

@ -1,6 +1,6 @@
--- a/net/minecraft/server/players/PlayerList.java --- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java +++ b/net/minecraft/server/players/PlayerList.java
@@ -108,6 +108,25 @@ @@ -108,6 +108,26 @@
import net.minecraft.world.scores.ScoreboardTeamBase; import net.minecraft.world.scores.ScoreboardTeamBase;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -21,12 +21,13 @@
+import org.bukkit.event.player.PlayerLoginEvent; +import org.bukkit.event.player.PlayerLoginEvent;
+import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerQuitEvent;
+import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.player.PlayerRespawnEvent;
+import org.bukkit.event.player.PlayerRespawnEvent.RespawnReason;
+// CraftBukkit end +// CraftBukkit end
+ +
public abstract class PlayerList { public abstract class PlayerList {
public static final File USERBANLIST_FILE = new File("banned-players.json"); public static final File USERBANLIST_FILE = new File("banned-players.json");
@@ -119,14 +138,16 @@ @@ -119,14 +139,16 @@
private static final int SEND_PLAYER_INFO_INTERVAL = 600; private static final int SEND_PLAYER_INFO_INTERVAL = 600;
private static final SimpleDateFormat BAN_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z"); private static final SimpleDateFormat BAN_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
private final MinecraftServer server; private final MinecraftServer server;
@ -46,7 +47,7 @@
public final WorldNBTStorage playerIo; public final WorldNBTStorage playerIo;
private boolean doWhiteList; private boolean doWhiteList;
private final LayeredRegistryAccess<RegistryLayer> registries; private final LayeredRegistryAccess<RegistryLayer> registries;
@@ -138,13 +159,23 @@ @@ -138,13 +160,23 @@
private static final boolean ALLOW_LOGOUTIVATOR = false; private static final boolean ALLOW_LOGOUTIVATOR = false;
private int sendAllPlayerInfoIn; private int sendAllPlayerInfoIn;
@ -72,7 +73,7 @@
this.server = minecraftserver; this.server = minecraftserver;
this.registries = layeredregistryaccess; this.registries = layeredregistryaccess;
this.synchronizedRegistries = (new IRegistryCustom.c(RegistrySynchronization.networkedRegistries(layeredregistryaccess))).freeze(); this.synchronizedRegistries = (new IRegistryCustom.c(RegistrySynchronization.networkedRegistries(layeredregistryaccess))).freeze();
@@ -161,9 +192,15 @@ @@ -161,9 +193,15 @@
usercache.add(gameprofile); usercache.add(gameprofile);
NBTTagCompound nbttagcompound = this.load(entityplayer); NBTTagCompound nbttagcompound = this.load(entityplayer);
ResourceKey resourcekey; ResourceKey resourcekey;
@ -89,7 +90,7 @@
Logger logger = PlayerList.LOGGER; Logger logger = PlayerList.LOGGER;
Objects.requireNonNull(logger); Objects.requireNonNull(logger);
@@ -190,7 +227,8 @@ @@ -190,7 +228,8 @@
s1 = networkmanager.getRemoteAddress().toString(); s1 = networkmanager.getRemoteAddress().toString();
} }
@ -99,7 +100,7 @@
WorldData worlddata = worldserver1.getLevelData(); WorldData worlddata = worldserver1.getLevelData();
entityplayer.loadGameTypes(nbttagcompound); entityplayer.loadGameTypes(nbttagcompound);
@@ -200,6 +238,7 @@ @@ -200,6 +239,7 @@
boolean flag1 = gamerules.getBoolean(GameRules.RULE_REDUCEDDEBUGINFO); boolean flag1 = gamerules.getBoolean(GameRules.RULE_REDUCEDDEBUGINFO);
playerconnection.send(new PacketPlayOutLogin(entityplayer.getId(), worlddata.isHardcore(), entityplayer.gameMode.getGameModeForPlayer(), entityplayer.gameMode.getPreviousGameModeForPlayer(), this.server.levelKeys(), this.synchronizedRegistries, worldserver1.dimensionTypeId(), worldserver1.dimension(), BiomeManager.obfuscateSeed(worldserver1.getSeed()), this.getMaxPlayers(), this.viewDistance, this.simulationDistance, flag1, !flag, worldserver1.isDebug(), worldserver1.isFlat(), entityplayer.getLastDeathLocation())); playerconnection.send(new PacketPlayOutLogin(entityplayer.getId(), worlddata.isHardcore(), entityplayer.gameMode.getGameModeForPlayer(), entityplayer.gameMode.getPreviousGameModeForPlayer(), this.server.levelKeys(), this.synchronizedRegistries, worldserver1.dimensionTypeId(), worldserver1.dimension(), BiomeManager.obfuscateSeed(worldserver1.getSeed()), this.getMaxPlayers(), this.viewDistance, this.simulationDistance, flag1, !flag, worldserver1.isDebug(), worldserver1.isFlat(), entityplayer.getLastDeathLocation()));
@ -107,7 +108,7 @@
playerconnection.send(new ClientboundUpdateEnabledFeaturesPacket(FeatureFlags.REGISTRY.toNames(worldserver1.enabledFeatures()))); playerconnection.send(new ClientboundUpdateEnabledFeaturesPacket(FeatureFlags.REGISTRY.toNames(worldserver1.enabledFeatures())));
playerconnection.send(new PacketPlayOutCustomPayload(PacketPlayOutCustomPayload.BRAND, (new PacketDataSerializer(Unpooled.buffer())).writeUtf(this.getServer().getServerModName()))); playerconnection.send(new PacketPlayOutCustomPayload(PacketPlayOutCustomPayload.BRAND, (new PacketDataSerializer(Unpooled.buffer())).writeUtf(this.getServer().getServerModName())));
playerconnection.send(new PacketPlayOutServerDifficulty(worlddata.getDifficulty(), worlddata.isDifficultyLocked())); playerconnection.send(new PacketPlayOutServerDifficulty(worlddata.getDifficulty(), worlddata.isDifficultyLocked()));
@@ -219,8 +258,10 @@ @@ -219,8 +259,10 @@
} else { } else {
ichatmutablecomponent = IChatBaseComponent.translatable("multiplayer.player.joined.renamed", entityplayer.getDisplayName(), s); ichatmutablecomponent = IChatBaseComponent.translatable("multiplayer.player.joined.renamed", entityplayer.getDisplayName(), s);
} }
@ -119,7 +120,7 @@
playerconnection.teleport(entityplayer.getX(), entityplayer.getY(), entityplayer.getZ(), entityplayer.getYRot(), entityplayer.getXRot()); playerconnection.teleport(entityplayer.getX(), entityplayer.getY(), entityplayer.getZ(), entityplayer.getYRot(), entityplayer.getXRot());
ServerPing serverping = this.server.getStatus(); ServerPing serverping = this.server.getStatus();
@@ -231,10 +272,61 @@ @@ -231,10 +273,61 @@
entityplayer.connection.send(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(this.players)); entityplayer.connection.send(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(this.players));
this.players.add(entityplayer); this.players.add(entityplayer);
this.playersByUUID.put(entityplayer.getUUID(), entityplayer); this.playersByUUID.put(entityplayer.getUUID(), entityplayer);
@ -184,7 +185,7 @@
this.server.getServerResourcePack().ifPresent((minecraftserver_serverresourcepackinfo) -> { this.server.getServerResourcePack().ifPresent((minecraftserver_serverresourcepackinfo) -> {
entityplayer.sendTexturePack(minecraftserver_serverresourcepackinfo.url(), minecraftserver_serverresourcepackinfo.hash(), minecraftserver_serverresourcepackinfo.isRequired(), minecraftserver_serverresourcepackinfo.prompt()); entityplayer.sendTexturePack(minecraftserver_serverresourcepackinfo.url(), minecraftserver_serverresourcepackinfo.hash(), minecraftserver_serverresourcepackinfo.isRequired(), minecraftserver_serverresourcepackinfo.prompt());
}); });
@@ -248,8 +340,11 @@ @@ -248,8 +341,11 @@
if (nbttagcompound != null && nbttagcompound.contains("RootVehicle", 10)) { if (nbttagcompound != null && nbttagcompound.contains("RootVehicle", 10)) {
NBTTagCompound nbttagcompound1 = nbttagcompound.getCompound("RootVehicle"); NBTTagCompound nbttagcompound1 = nbttagcompound.getCompound("RootVehicle");
@ -198,7 +199,7 @@
}); });
if (entity != null) { if (entity != null) {
@@ -292,6 +387,8 @@ @@ -292,6 +388,8 @@
} }
entityplayer.initInventoryMenu(); entityplayer.initInventoryMenu();
@ -207,7 +208,7 @@
} }
public void updateEntireScoreboard(ScoreboardServer scoreboardserver, EntityPlayer entityplayer) { public void updateEntireScoreboard(ScoreboardServer scoreboardserver, EntityPlayer entityplayer) {
@@ -324,30 +421,31 @@ @@ -324,30 +422,31 @@
} }
public void addWorldborderListener(WorldServer worldserver) { public void addWorldborderListener(WorldServer worldserver) {
@ -244,7 +245,7 @@
} }
@Override @Override
@@ -375,14 +473,15 @@ @@ -375,14 +474,15 @@
} }
protected void save(EntityPlayer entityplayer) { protected void save(EntityPlayer entityplayer) {
@ -262,7 +263,7 @@
if (advancementdataplayer != null) { if (advancementdataplayer != null) {
advancementdataplayer.save(); advancementdataplayer.save();
@@ -390,10 +489,24 @@ @@ -390,10 +490,24 @@
} }
@ -288,7 +289,7 @@
this.save(entityplayer); this.save(entityplayer);
if (entityplayer.isPassenger()) { if (entityplayer.isPassenger()) {
Entity entity = entityplayer.getRootVehicle(); Entity entity = entityplayer.getRootVehicle();
@@ -417,18 +530,66 @@ @@ -417,18 +531,66 @@
if (entityplayer1 == entityplayer) { if (entityplayer1 == entityplayer) {
this.playersByUUID.remove(uuid); this.playersByUUID.remove(uuid);
@ -361,7 +362,7 @@
GameProfileBanEntry gameprofilebanentry = (GameProfileBanEntry) this.bans.get(gameprofile); GameProfileBanEntry gameprofilebanentry = (GameProfileBanEntry) this.bans.get(gameprofile);
ichatmutablecomponent = IChatBaseComponent.translatable("multiplayer.disconnect.banned.reason", gameprofilebanentry.getReason()); ichatmutablecomponent = IChatBaseComponent.translatable("multiplayer.disconnect.banned.reason", gameprofilebanentry.getReason());
@@ -436,10 +597,12 @@ @@ -436,10 +598,12 @@
ichatmutablecomponent.append((IChatBaseComponent) IChatBaseComponent.translatable("multiplayer.disconnect.banned.expiration", PlayerList.BAN_DATE_FORMAT.format(gameprofilebanentry.getExpires()))); ichatmutablecomponent.append((IChatBaseComponent) IChatBaseComponent.translatable("multiplayer.disconnect.banned.expiration", PlayerList.BAN_DATE_FORMAT.format(gameprofilebanentry.getExpires())));
} }
@ -377,7 +378,7 @@
IpBanEntry ipbanentry = this.ipBans.get(socketaddress); IpBanEntry ipbanentry = this.ipBans.get(socketaddress);
ichatmutablecomponent = IChatBaseComponent.translatable("multiplayer.disconnect.banned_ip.reason", ipbanentry.getReason()); ichatmutablecomponent = IChatBaseComponent.translatable("multiplayer.disconnect.banned_ip.reason", ipbanentry.getReason());
@@ -447,13 +610,25 @@ @@ -447,13 +611,25 @@
ichatmutablecomponent.append((IChatBaseComponent) IChatBaseComponent.translatable("multiplayer.disconnect.banned_ip.expiration", PlayerList.BAN_DATE_FORMAT.format(ipbanentry.getExpires()))); ichatmutablecomponent.append((IChatBaseComponent) IChatBaseComponent.translatable("multiplayer.disconnect.banned_ip.expiration", PlayerList.BAN_DATE_FORMAT.format(ipbanentry.getExpires())));
} }
@ -406,21 +407,22 @@
UUID uuid = UUIDUtil.getOrCreatePlayerUUID(gameprofile); UUID uuid = UUIDUtil.getOrCreatePlayerUUID(gameprofile);
List<EntityPlayer> list = Lists.newArrayList(); List<EntityPlayer> list = Lists.newArrayList();
@@ -480,14 +655,24 @@ @@ -480,14 +656,24 @@
} }
return new EntityPlayer(this.server, this.server.overworld(), gameprofile); return new EntityPlayer(this.server, this.server.overworld(), gameprofile);
+ */ + */
+ return player; + return player;
+ // CraftBukkit end + // CraftBukkit end
}
+ // CraftBukkit start
public EntityPlayer respawn(EntityPlayer entityplayer, boolean flag) {
+ return this.respawn(entityplayer, this.server.getLevel(entityplayer.getRespawnDimension()), flag, null, true);
+ } + }
+ +
+ public EntityPlayer respawn(EntityPlayer entityplayer, WorldServer worldserver, boolean flag, Location location, boolean avoidSuffocation) { + // CraftBukkit start
+ public EntityPlayer respawn(EntityPlayer entityplayer, boolean flag, RespawnReason reason) {
+ return this.respawn(entityplayer, this.server.getLevel(entityplayer.getRespawnDimension()), flag, null, true, reason);
}
- public EntityPlayer respawn(EntityPlayer entityplayer, boolean flag) {
+ public EntityPlayer respawn(EntityPlayer entityplayer, WorldServer worldserver, boolean flag, Location location, boolean avoidSuffocation, RespawnReason reason) {
+ entityplayer.stopRiding(); // CraftBukkit + entityplayer.stopRiding(); // CraftBukkit
this.players.remove(entityplayer); this.players.remove(entityplayer);
entityplayer.getLevel().removePlayerImmediately(entityplayer, Entity.RemovalReason.DISCARDED); entityplayer.getLevel().removePlayerImmediately(entityplayer, Entity.RemovalReason.DISCARDED);
@ -431,7 +433,7 @@
WorldServer worldserver = this.server.getLevel(entityplayer.getRespawnDimension()); WorldServer worldserver = this.server.getLevel(entityplayer.getRespawnDimension());
Optional optional; Optional optional;
@@ -499,6 +684,11 @@ @@ -499,6 +685,11 @@
WorldServer worldserver1 = worldserver != null && optional.isPresent() ? worldserver : this.server.overworld(); WorldServer worldserver1 = worldserver != null && optional.isPresent() ? worldserver : this.server.overworld();
EntityPlayer entityplayer1 = new EntityPlayer(this.server, worldserver1, entityplayer.getGameProfile()); EntityPlayer entityplayer1 = new EntityPlayer(this.server, worldserver1, entityplayer.getGameProfile());
@ -443,7 +445,7 @@
entityplayer1.connection = entityplayer.connection; entityplayer1.connection = entityplayer.connection;
entityplayer1.restoreFrom(entityplayer, flag); entityplayer1.restoreFrom(entityplayer, flag);
@@ -514,50 +704,112 @@ @@ -514,50 +705,112 @@
boolean flag2 = false; boolean flag2 = false;
@ -506,7 +508,7 @@
- } else if (blockposition != null) { - } else if (blockposition != null) {
- entityplayer1.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.NO_RESPAWN_BLOCK_AVAILABLE, 0.0F)); - entityplayer1.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.NO_RESPAWN_BLOCK_AVAILABLE, 0.0F));
+ Player respawnPlayer = entityplayer1.getBukkitEntity(); + Player respawnPlayer = entityplayer1.getBukkitEntity();
+ PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(respawnPlayer, location, isBedSpawn && !flag2, flag2); + PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(respawnPlayer, location, isBedSpawn && !flag2, flag2, reason);
+ cserver.getPluginManager().callEvent(respawnEvent); + cserver.getPluginManager().callEvent(respawnEvent);
+ +
+ location = respawnEvent.getRespawnLocation(); + location = respawnEvent.getRespawnLocation();
@ -579,7 +581,7 @@
return entityplayer1; return entityplayer1;
} }
@@ -570,7 +822,18 @@ @@ -570,7 +823,18 @@
public void tick() { public void tick() {
if (++this.sendAllPlayerInfoIn > 600) { if (++this.sendAllPlayerInfoIn > 600) {
@ -599,7 +601,7 @@
this.sendAllPlayerInfoIn = 0; this.sendAllPlayerInfoIn = 0;
} }
@@ -587,6 +850,25 @@ @@ -587,6 +851,25 @@
} }
@ -625,7 +627,7 @@
public void broadcastAll(Packet<?> packet, ResourceKey<World> resourcekey) { public void broadcastAll(Packet<?> packet, ResourceKey<World> resourcekey) {
Iterator iterator = this.players.iterator(); Iterator iterator = this.players.iterator();
@@ -665,7 +947,7 @@ @@ -665,7 +948,7 @@
} }
public void deop(GameProfile gameprofile) { public void deop(GameProfile gameprofile) {
@ -634,7 +636,7 @@
EntityPlayer entityplayer = this.getPlayer(gameprofile.getId()); EntityPlayer entityplayer = this.getPlayer(gameprofile.getId());
if (entityplayer != null) { if (entityplayer != null) {
@@ -689,6 +971,7 @@ @@ -689,6 +972,7 @@
entityplayer.connection.send(new PacketPlayOutEntityStatus(entityplayer, b0)); entityplayer.connection.send(new PacketPlayOutEntityStatus(entityplayer, b0));
} }
@ -642,7 +644,7 @@
this.server.getCommands().sendCommands(entityplayer); this.server.getCommands().sendCommands(entityplayer);
} }
@@ -721,6 +1004,12 @@ @@ -721,6 +1005,12 @@
for (int i = 0; i < this.players.size(); ++i) { for (int i = 0; i < this.players.size(); ++i) {
EntityPlayer entityplayer = (EntityPlayer) this.players.get(i); EntityPlayer entityplayer = (EntityPlayer) this.players.get(i);
@ -655,7 +657,7 @@
if (entityplayer != entityhuman && entityplayer.level.dimension() == resourcekey) { if (entityplayer != entityhuman && entityplayer.level.dimension() == resourcekey) {
double d4 = d0 - entityplayer.getX(); double d4 = d0 - entityplayer.getX();
double d5 = d1 - entityplayer.getY(); double d5 = d1 - entityplayer.getY();
@@ -760,23 +1049,35 @@ @@ -760,23 +1050,35 @@
public void reloadWhiteList() {} public void reloadWhiteList() {}
public void sendLevelInfo(EntityPlayer entityplayer, WorldServer worldserver) { public void sendLevelInfo(EntityPlayer entityplayer, WorldServer worldserver) {
@ -696,7 +698,7 @@
} }
public int getPlayerCount() { public int getPlayerCount() {
@@ -832,12 +1133,22 @@ @@ -832,12 +1134,22 @@
} }
public void removeAll() { public void removeAll() {
@ -721,7 +723,7 @@
public void broadcastSystemMessage(IChatBaseComponent ichatbasecomponent, boolean flag) { public void broadcastSystemMessage(IChatBaseComponent ichatbasecomponent, boolean flag) {
this.broadcastSystemMessage(ichatbasecomponent, (entityplayer) -> { this.broadcastSystemMessage(ichatbasecomponent, (entityplayer) -> {
return ichatbasecomponent; return ichatbasecomponent;
@@ -895,16 +1206,23 @@ @@ -895,16 +1207,23 @@
return playerchatmessage.hasSignature() && !playerchatmessage.hasExpiredServer(Instant.now()); return playerchatmessage.hasSignature() && !playerchatmessage.hasExpiredServer(Instant.now());
} }
@ -749,7 +751,7 @@
Path path = file2.toPath(); Path path = file2.toPath();
if (FileUtils.isPathNormalized(path) && FileUtils.isPathPortable(path) && path.startsWith(file.getPath()) && file2.isFile()) { if (FileUtils.isPathNormalized(path) && FileUtils.isPathPortable(path) && path.startsWith(file.getPath()) && file2.isFile()) {
@@ -913,7 +1231,7 @@ @@ -913,7 +1232,7 @@
} }
serverstatisticmanager = new ServerStatisticManager(this.server, file1); serverstatisticmanager = new ServerStatisticManager(this.server, file1);
@ -758,7 +760,7 @@
} }
return serverstatisticmanager; return serverstatisticmanager;
@@ -921,13 +1239,13 @@ @@ -921,13 +1240,13 @@
public AdvancementDataPlayer getPlayerAdvancements(EntityPlayer entityplayer) { public AdvancementDataPlayer getPlayerAdvancements(EntityPlayer entityplayer) {
UUID uuid = entityplayer.getUUID(); UUID uuid = entityplayer.getUUID();
@ -774,7 +776,7 @@
} }
advancementdataplayer.setPlayer(entityplayer); advancementdataplayer.setPlayer(entityplayer);
@@ -978,13 +1296,20 @@ @@ -978,13 +1297,20 @@
} }
public void reloadResources() { public void reloadResources() {

View file

@ -145,6 +145,7 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerHideEntityEvent; import org.bukkit.event.player.PlayerHideEntityEvent;
import org.bukkit.event.player.PlayerRegisterChannelEvent; import org.bukkit.event.player.PlayerRegisterChannelEvent;
import org.bukkit.event.player.PlayerRespawnEvent.RespawnReason;
import org.bukkit.event.player.PlayerShowEntityEvent; import org.bukkit.event.player.PlayerShowEntityEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerUnregisterChannelEvent; import org.bukkit.event.player.PlayerUnregisterChannelEvent;
@ -955,7 +956,8 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
if (fromWorld == toWorld) { if (fromWorld == toWorld) {
entity.connection.teleport(to); entity.connection.teleport(to);
} else { } else {
server.getHandle().respawn(entity, toWorld, true, to, true); // The respawn reason should never be used if the passed location is non null.
server.getHandle().respawn(entity, toWorld, true, to, true, null);
} }
return true; return true;
} }