Ensure that PlayerMoveEvent is always fired where applicable

Adapted and improved version of Spigot commit eb9e4c0460a8acd55ccd58bd54b0b82473876591
This commit is contained in:
md_5 2023-12-28 07:56:30 +11:00
parent 7df18510f6
commit 33a2d87739
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11

View File

@ -103,7 +103,7 @@
+ private int lastBookTick = MinecraftServer.currentTick; + private int lastBookTick = MinecraftServer.currentTick;
+ private int dropCount = 0; + private int dropCount = 0;
+ +
+ // Get position of last block hit for BlockDamageLevel.STOPPED + private boolean hasMoved = false;
+ private double lastPosX = Double.MAX_VALUE; + private double lastPosX = Double.MAX_VALUE;
+ private double lastPosY = Double.MAX_VALUE; + private double lastPosY = Double.MAX_VALUE;
+ private double lastPosZ = Double.MAX_VALUE; + private double lastPosZ = Double.MAX_VALUE;
@ -137,12 +137,25 @@
this.disconnect(IChatBaseComponent.translatable("multiplayer.disconnect.idling")); this.disconnect(IChatBaseComponent.translatable("multiplayer.disconnect.idling"));
} }
@@ -392,7 +477,34 @@ @@ -378,6 +463,13 @@
if (entity != this.player && entity.getControllingPassenger() == this.player && entity == this.lastVehicle) {
WorldServer worldserver = this.player.serverLevel();
+ // CraftBukkit - store current player position
+ double prevX = player.getX();
+ double prevY = player.getY();
+ double prevZ = player.getZ();
+ float prevYaw = player.getYRot();
+ float prevPitch = player.getXRot();
+ // CraftBukkit end
double d0 = entity.getX();
double d1 = entity.getY();
double d2 = entity.getZ();
@@ -392,7 +484,33 @@
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;
- if (d10 - d9 > 100.0D && !this.isSingleplayerOwner()) { - if (d10 - d9 > 100.0D && !this.isSingleplayerOwner()) {
+
+ // CraftBukkit start - handle custom speeds and skipped ticks + // CraftBukkit start - handle custom speeds and skipped ticks
+ this.allowedPlayerTicks += (System.currentTimeMillis() / 50) - this.lastTick; + this.allowedPlayerTicks += (System.currentTimeMillis() / 50) - this.lastTick;
+ this.allowedPlayerTicks = Math.max(this.allowedPlayerTicks, 1); + this.allowedPlayerTicks = Math.max(this.allowedPlayerTicks, 1);
@ -173,7 +186,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.send(new PacketPlayOutVehicleMove(entity)); this.send(new PacketPlayOutVehicleMove(entity));
return; return;
@@ -432,14 +544,72 @@ @@ -432,14 +550,76 @@
} }
entity.absMoveTo(d3, d4, d5, f, f1); entity.absMoveTo(d3, d4, d5, f, f1);
@ -189,6 +202,14 @@
+ // CraftBukkit start - fire PlayerMoveEvent + // CraftBukkit start - fire PlayerMoveEvent
+ Player player = this.getCraftPlayer(); + Player player = this.getCraftPlayer();
+ if (!this.hasMoved) {
+ this.lastPosX = prevX;
+ this.lastPosY = prevY;
+ this.lastPosZ = prevZ;
+ this.lastYaw = prevYaw;
+ this.lastPitch = prevPitch;
+ this.hasMoved = true;
+ }
+ Location from = new Location(player.getWorld(), lastPosX, lastPosY, lastPosZ, lastYaw, lastPitch); // Get the Players previous Event location. + Location from = new Location(player.getWorld(), lastPosX, lastPosY, lastPosZ, lastYaw, lastPitch); // Get the Players previous Event location.
+ Location to = player.getLocation().clone(); // Start off the To location as the Players current location. + Location to = player.getLocation().clone(); // Start off the To location as the Players current location.
+ +
@ -197,7 +218,6 @@
+ to.setY(packetplayinvehiclemove.getY()); + to.setY(packetplayinvehiclemove.getY());
+ to.setZ(packetplayinvehiclemove.getZ()); + to.setZ(packetplayinvehiclemove.getZ());
+ +
+
+ // If the packet contains look information then we update the To location with the correct Yaw & Pitch. + // If the packet contains look information then we update the To location with the correct Yaw & Pitch.
+ to.setYaw(packetplayinvehiclemove.getYRot()); + to.setYaw(packetplayinvehiclemove.getYRot());
+ to.setPitch(packetplayinvehiclemove.getXRot()); + to.setPitch(packetplayinvehiclemove.getXRot());
@ -213,32 +233,29 @@
+ this.lastYaw = to.getYaw(); + this.lastYaw = to.getYaw();
+ this.lastPitch = to.getPitch(); + this.lastPitch = to.getPitch();
+ +
+ // Skip the first time we do this + Location oldTo = to.clone();
+ if (from.getX() != Double.MAX_VALUE) { + PlayerMoveEvent event = new PlayerMoveEvent(player, from, to);
+ Location oldTo = to.clone(); + this.cserver.getPluginManager().callEvent(event);
+ PlayerMoveEvent event = new PlayerMoveEvent(player, from, to);
+ this.cserver.getPluginManager().callEvent(event);
+ +
+ // If the event is cancelled we move the player back to their old location. + // If the event is cancelled we move the player back to their old location.
+ if (event.isCancelled()) { + if (event.isCancelled()) {
+ teleport(from); + teleport(from);
+ return; + return;
+ } + }
+ +
+ // If a Plugin has changed the To destination then we teleport the Player + // If a Plugin has changed the To destination then we teleport the Player
+ // there to avoid any 'Moved wrongly' or 'Moved too quickly' errors. + // there to avoid any 'Moved wrongly' or 'Moved too quickly' errors.
+ // We only do this if the Event was not cancelled. + // We only do this if the Event was not cancelled.
+ if (!oldTo.equals(event.getTo()) && !event.isCancelled()) { + if (!oldTo.equals(event.getTo()) && !event.isCancelled()) {
+ this.player.getBukkitEntity().teleport(event.getTo(), PlayerTeleportEvent.TeleportCause.PLUGIN); + this.player.getBukkitEntity().teleport(event.getTo(), PlayerTeleportEvent.TeleportCause.PLUGIN);
+ return; + return;
+ } + }
+ +
+ // Check to see if the Players Location has some how changed during the call of the event. + // Check to see if the Players Location has some how changed during the call of the event.
+ // This can happen due to a plugin teleporting the player instead of using .setTo() + // This can happen due to a plugin teleporting the player instead of using .setTo()
+ if (!from.equals(this.getCraftPlayer().getLocation()) && this.justTeleported) { + if (!from.equals(this.getCraftPlayer().getLocation()) && this.justTeleported) {
+ this.justTeleported = false; + this.justTeleported = false;
+ return; + return;
+ }
+ } + }
+ } + }
+ // CraftBukkit end + // CraftBukkit end
@ -246,7 +263,7 @@
this.player.serverLevel().getChunkSource().move(this.player); this.player.serverLevel().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);
@@ -473,6 +643,7 @@ @@ -473,6 +653,7 @@
} }
this.awaitingPositionFromClient = null; this.awaitingPositionFromClient = null;
@ -254,7 +271,7 @@
} }
} }
@@ -480,7 +651,7 @@ @@ -480,7 +661,7 @@
@Override @Override
public void handleRecipeBookSeenRecipePacket(PacketPlayInRecipeDisplayed packetplayinrecipedisplayed) { public void handleRecipeBookSeenRecipePacket(PacketPlayInRecipeDisplayed packetplayinrecipedisplayed) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinrecipedisplayed, this, this.player.serverLevel()); PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinrecipedisplayed, this, this.player.serverLevel());
@ -263,7 +280,7 @@
RecipeBookServer recipebookserver = this.player.getRecipeBook(); RecipeBookServer recipebookserver = this.player.getRecipeBook();
Objects.requireNonNull(recipebookserver); Objects.requireNonNull(recipebookserver);
@@ -490,6 +661,7 @@ @@ -490,6 +671,7 @@
@Override @Override
public void handleRecipeBookChangeSettingsPacket(PacketPlayInRecipeSettings packetplayinrecipesettings) { public void handleRecipeBookChangeSettingsPacket(PacketPlayInRecipeSettings packetplayinrecipesettings) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinrecipesettings, this, this.player.serverLevel()); PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinrecipesettings, this, this.player.serverLevel());
@ -271,7 +288,7 @@
this.player.getRecipeBook().setBookSetting(packetplayinrecipesettings.getBookType(), packetplayinrecipesettings.isOpen(), packetplayinrecipesettings.isFiltering()); this.player.getRecipeBook().setBookSetting(packetplayinrecipesettings.getBookType(), packetplayinrecipesettings.isOpen(), packetplayinrecipesettings.isFiltering());
} }
@@ -510,6 +682,12 @@ @@ -510,6 +692,12 @@
@Override @Override
public void handleCustomCommandSuggestions(PacketPlayInTabComplete packetplayintabcomplete) { public void handleCustomCommandSuggestions(PacketPlayInTabComplete packetplayintabcomplete) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayintabcomplete, this, this.player.serverLevel()); PlayerConnectionUtils.ensureRunningOnSameThread(packetplayintabcomplete, this, this.player.serverLevel());
@ -284,7 +301,7 @@
StringReader stringreader = new StringReader(packetplayintabcomplete.getCommand()); StringReader stringreader = new StringReader(packetplayintabcomplete.getCommand());
if (stringreader.canRead() && stringreader.peek() == '/') { if (stringreader.canRead() && stringreader.peek() == '/') {
@@ -519,6 +697,7 @@ @@ -519,6 +707,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) -> {
@ -292,7 +309,7 @@
this.send(new PacketPlayOutTabComplete(packetplayintabcomplete.getId(), suggestions)); this.send(new PacketPlayOutTabComplete(packetplayintabcomplete.getId(), suggestions));
}); });
} }
@@ -766,6 +945,13 @@ @@ -766,6 +955,13 @@
if (container instanceof ContainerMerchant) { if (container instanceof ContainerMerchant) {
ContainerMerchant containermerchant = (ContainerMerchant) container; ContainerMerchant containermerchant = (ContainerMerchant) container;
@ -306,7 +323,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);
@@ -780,6 +966,13 @@ @@ -780,6 +976,13 @@
@Override @Override
public void handleEditBook(PacketPlayInBEdit packetplayinbedit) { public void handleEditBook(PacketPlayInBEdit packetplayinbedit) {
@ -320,7 +337,7 @@
int i = packetplayinbedit.getSlot(); int i = packetplayinbedit.getSlot();
if (PlayerInventory.isHotbarSlot(i) || i == 40) { if (PlayerInventory.isHotbarSlot(i) || i == 40) {
@@ -788,7 +981,7 @@ @@ -788,7 +991,7 @@
Objects.requireNonNull(list); Objects.requireNonNull(list);
optional.ifPresent(list::add); optional.ifPresent(list::add);
@ -329,7 +346,7 @@
Objects.requireNonNull(list); Objects.requireNonNull(list);
stream.forEach(list::add); stream.forEach(list::add);
@@ -806,7 +999,7 @@ @@ -806,7 +1009,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)) {
@ -338,7 +355,7 @@
} }
} }
@@ -831,16 +1024,16 @@ @@ -831,16 +1034,16 @@
this.updateBookPages(list, (s) -> { this.updateBookPages(list, (s) -> {
return IChatBaseComponent.ChatSerializer.toJson(IChatBaseComponent.literal(s)); return IChatBaseComponent.ChatSerializer.toJson(IChatBaseComponent.literal(s));
@ -359,7 +376,7 @@
return NBTTagString.valueOf((String) unaryoperator.apply(filteredtext.filteredOrEmpty())); return NBTTagString.valueOf((String) unaryoperator.apply(filteredtext.filteredOrEmpty()));
}); });
@@ -866,6 +1059,7 @@ @@ -866,6 +1069,7 @@
} }
itemstack.addTagElement("pages", nbttaglist); itemstack.addTagElement("pages", nbttaglist);
@ -367,7 +384,7 @@
} }
@Override @Override
@@ -922,7 +1116,7 @@ @@ -922,7 +1126,7 @@
} else { } else {
WorldServer worldserver = this.player.serverLevel(); WorldServer worldserver = this.player.serverLevel();
@ -376,16 +393,15 @@
if (this.tickCount == 0) { if (this.tickCount == 0) {
this.resetPosition(); this.resetPosition();
} }
@@ -932,7 +1126,7 @@ @@ -932,6 +1136,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());
} }
-
+ this.allowedPlayerTicks = 20; // CraftBukkit + this.allowedPlayerTicks = 20; // CraftBukkit
} else { } else {
this.awaitingTeleportTime = this.tickCount; this.awaitingTeleportTime = this.tickCount;
double d0 = clampHorizontal(packetplayinflying.getX(this.player.getX())); @@ -944,7 +1149,15 @@
@@ -944,7 +1138,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.serverLevel().getChunkSource().move(this.player); this.player.serverLevel().getChunkSource().move(this.player);
@ -401,7 +417,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();
@@ -964,15 +1166,33 @@ @@ -964,15 +1177,33 @@
++this.receivedMovePacketCount; ++this.receivedMovePacketCount;
int i = this.receivedMovePacketCount - this.knownMovePacketCount; int i = this.receivedMovePacketCount - this.knownMovePacketCount;
@ -437,7 +453,7 @@
PlayerConnection.LOGGER.warn("{} moved too quickly! {},{},{}", new Object[]{this.player.getName().getString(), d6, d7, d8}); PlayerConnection.LOGGER.warn("{} moved too quickly! {},{},{}", new Object[]{this.player.getName().getString(), d6, d7, d8});
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 +1214,7 @@ @@ -994,6 +1225,7 @@
boolean flag1 = this.player.verticalCollisionBelow; boolean flag1 = this.player.verticalCollisionBelow;
this.player.move(EnumMoveType.PLAYER, new Vec3D(d6, d7, d8)); this.player.move(EnumMoveType.PLAYER, new Vec3D(d6, d7, d8));
@ -445,7 +461,7 @@
double d11 = d7; double d11 = d7;
d6 = d0 - this.player.getX(); d6 = d0 - this.player.getX();
@@ -1012,9 +1233,70 @@ @@ -1012,9 +1244,75 @@
} }
if (!this.player.noPhysics && !this.player.isSleeping() && (flag2 && worldserver.noCollision(this.player, axisalignedbb) || this.isPlayerCollidingWithAnythingNew(worldserver, axisalignedbb, d0, d1, d2))) { if (!this.player.noPhysics && !this.player.isSleeping() && (flag2 && worldserver.noCollision(this.player, axisalignedbb) || this.isPlayerCollidingWithAnythingNew(worldserver, axisalignedbb, d0, d1, d2))) {
@ -458,6 +474,14 @@
+ this.player.absMoveTo(prevX, prevY, prevZ, prevYaw, prevPitch); + this.player.absMoveTo(prevX, prevY, prevZ, prevYaw, prevPitch);
+ +
+ Player player = this.getCraftPlayer(); + Player player = this.getCraftPlayer();
+ if (!this.hasMoved) {
+ this.lastPosX = prevX;
+ this.lastPosY = prevY;
+ this.lastPosZ = prevZ;
+ this.lastYaw = prevYaw;
+ this.lastPitch = prevPitch;
+ this.hasMoved = true;
+ }
+ Location from = new Location(player.getWorld(), lastPosX, lastPosY, lastPosZ, lastYaw, lastPitch); // Get the Players previous Event location. + Location from = new Location(player.getWorld(), lastPosX, lastPosY, lastPosZ, lastYaw, lastPitch); // Get the Players previous Event location.
+ Location to = player.getLocation().clone(); // Start off the To location as the Players current location. + Location to = player.getLocation().clone(); // Start off the To location as the Players current location.
+ +
@ -485,39 +509,36 @@
+ this.lastYaw = to.getYaw(); + this.lastYaw = to.getYaw();
+ this.lastPitch = to.getPitch(); + this.lastPitch = to.getPitch();
+ +
+ // Skip the first time we do this + Location oldTo = to.clone();
+ if (from.getX() != Double.MAX_VALUE) { + PlayerMoveEvent event = new PlayerMoveEvent(player, from, to);
+ Location oldTo = to.clone(); + this.cserver.getPluginManager().callEvent(event);
+ PlayerMoveEvent event = new PlayerMoveEvent(player, from, to);
+ this.cserver.getPluginManager().callEvent(event);
+ +
+ // If the event is cancelled we move the player back to their old location. + // If the event is cancelled we move the player back to their old location.
+ if (event.isCancelled()) { + if (event.isCancelled()) {
+ teleport(from); + teleport(from);
+ return; + return;
+ } + }
+ +
+ // If a Plugin has changed the To destination then we teleport the Player + // If a Plugin has changed the To destination then we teleport the Player
+ // there to avoid any 'Moved wrongly' or 'Moved too quickly' errors. + // there to avoid any 'Moved wrongly' or 'Moved too quickly' errors.
+ // We only do this if the Event was not cancelled. + // We only do this if the Event was not cancelled.
+ if (!oldTo.equals(event.getTo()) && !event.isCancelled()) { + if (!oldTo.equals(event.getTo()) && !event.isCancelled()) {
+ this.player.getBukkitEntity().teleport(event.getTo(), PlayerTeleportEvent.TeleportCause.PLUGIN); + this.player.getBukkitEntity().teleport(event.getTo(), PlayerTeleportEvent.TeleportCause.PLUGIN);
+ return; + return;
+ } + }
+ +
+ // Check to see if the Players Location has some how changed during the call of the event. + // Check to see if the Players Location has some how changed during the call of the event.
+ // This can happen due to a plugin teleporting the player instead of using .setTo() + // This can happen due to a plugin teleporting the player instead of using .setTo()
+ if (!from.equals(this.getCraftPlayer().getLocation()) && this.justTeleported) { + if (!from.equals(this.getCraftPlayer().getLocation()) && this.justTeleported) {
+ this.justTeleported = false; + this.justTeleported = false;
+ return; + return;
+ }
+ } + }
+ } + }
+ // CraftBukkit end + // CraftBukkit end
this.player.absMoveTo(d0, d1, d2, f, f1); this.player.absMoveTo(d0, d1, d2, f, f1);
this.clientIsFloating = d11 >= -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 = d11 >= -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.serverLevel().getChunkSource().move(this.player); this.player.serverLevel().getChunkSource().move(this.player);
@@ -1055,11 +1337,68 @@ @@ -1055,11 +1353,68 @@
return true; return true;
} }
@ -587,7 +608,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;
@@ -1071,6 +1410,14 @@ @@ -1071,6 +1426,14 @@
this.awaitingTeleport = 0; this.awaitingTeleport = 0;
} }
@ -602,7 +623,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));
@@ -1079,6 +1426,7 @@ @@ -1079,6 +1442,7 @@
@Override @Override
public void handlePlayerAction(PacketPlayInBlockDig packetplayinblockdig) { public void handlePlayerAction(PacketPlayInBlockDig packetplayinblockdig) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinblockdig, this, this.player.serverLevel()); PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinblockdig, this, this.player.serverLevel());
@ -610,7 +631,7 @@
BlockPosition blockposition = packetplayinblockdig.getPos(); BlockPosition blockposition = packetplayinblockdig.getPos();
this.player.resetLastActionTime(); this.player.resetLastActionTime();
@@ -1089,14 +1437,46 @@ @@ -1089,14 +1453,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);
@ -659,7 +680,7 @@
this.player.drop(false); this.player.drop(false);
} }
@@ -1134,6 +1514,7 @@ @@ -1134,6 +1530,7 @@
@Override @Override
public void handleUseItemOn(PacketPlayInUseItem packetplayinuseitem) { public void handleUseItemOn(PacketPlayInUseItem packetplayinuseitem) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseitem, this, this.player.serverLevel()); PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseitem, this, this.player.serverLevel());
@ -667,7 +688,7 @@
this.player.connection.ackBlockChangesUpTo(packetplayinuseitem.getSequence()); this.player.connection.ackBlockChangesUpTo(packetplayinuseitem.getSequence());
WorldServer worldserver = this.player.serverLevel(); WorldServer worldserver = this.player.serverLevel();
EnumHand enumhand = packetplayinuseitem.getHand(); EnumHand enumhand = packetplayinuseitem.getHand();
@@ -1157,6 +1538,7 @@ @@ -1157,6 +1554,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)) {
@ -675,7 +696,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)) {
@@ -1185,6 +1567,7 @@ @@ -1185,6 +1583,7 @@
@Override @Override
public void handleUseItem(PacketPlayInBlockPlace packetplayinblockplace) { public void handleUseItem(PacketPlayInBlockPlace packetplayinblockplace) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinblockplace, this, this.player.serverLevel()); PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinblockplace, this, this.player.serverLevel());
@ -683,7 +704,7 @@
this.ackBlockChangesUpTo(packetplayinblockplace.getSequence()); this.ackBlockChangesUpTo(packetplayinblockplace.getSequence());
WorldServer worldserver = this.player.serverLevel(); WorldServer worldserver = this.player.serverLevel();
EnumHand enumhand = packetplayinblockplace.getHand(); EnumHand enumhand = packetplayinblockplace.getHand();
@@ -1192,6 +1575,49 @@ @@ -1192,6 +1591,49 @@
this.player.resetLastActionTime(); this.player.resetLastActionTime();
if (!itemstack.isEmpty() && itemstack.isItemEnabled(worldserver.enabledFeatures())) { if (!itemstack.isEmpty() && itemstack.isItemEnabled(worldserver.enabledFeatures())) {
@ -733,7 +754,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()) {
@@ -1212,7 +1638,7 @@ @@ -1212,7 +1654,7 @@
Entity entity = packetplayinspectate.getEntity(worldserver); Entity entity = packetplayinspectate.getEntity(worldserver);
if (entity != null) { if (entity != null) {
@ -742,7 +763,7 @@
return; return;
} }
} }
@@ -1235,6 +1661,13 @@ @@ -1235,6 +1677,13 @@
@Override @Override
public void onDisconnect(IChatBaseComponent ichatbasecomponent) { public void onDisconnect(IChatBaseComponent ichatbasecomponent) {
@ -756,7 +777,7 @@
PlayerConnection.LOGGER.info("{} lost connection: {}", this.player.getName().getString(), ichatbasecomponent.getString()); PlayerConnection.LOGGER.info("{} lost connection: {}", this.player.getName().getString(), ichatbasecomponent.getString());
this.removePlayerFromWorld(); this.removePlayerFromWorld();
super.onDisconnect(ichatbasecomponent); super.onDisconnect(ichatbasecomponent);
@@ -1242,10 +1675,18 @@ @@ -1242,10 +1691,18 @@
private void removePlayerFromWorld() { private void removePlayerFromWorld() {
this.chatMessageChain.close(); this.chatMessageChain.close();
@ -776,7 +797,7 @@
this.player.getTextFilter().leave(); this.player.getTextFilter().leave();
} }
@@ -1260,7 +1701,16 @@ @@ -1260,7 +1717,16 @@
@Override @Override
public void handleSetCarriedItem(PacketPlayInHeldItemSlot packetplayinhelditemslot) { public void handleSetCarriedItem(PacketPlayInHeldItemSlot packetplayinhelditemslot) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinhelditemslot, this, this.player.serverLevel()); PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinhelditemslot, this, this.player.serverLevel());
@ -793,7 +814,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();
} }
@@ -1269,18 +1719,25 @@ @@ -1269,18 +1735,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());
@ -820,7 +841,7 @@
PlayerChatMessage playerchatmessage; PlayerChatMessage playerchatmessage;
try { try {
@@ -1290,7 +1747,7 @@ @@ -1290,7 +1763,7 @@
return; return;
} }
@ -829,7 +850,7 @@
IChatBaseComponent ichatbasecomponent = this.server.getChatDecorator().decorate(this.player, playerchatmessage.decoratedContent()); IChatBaseComponent ichatbasecomponent = this.server.getChatDecorator().decorate(this.player, playerchatmessage.decoratedContent());
this.chatMessageChain.append(completablefuture, (filteredtext) -> { this.chatMessageChain.append(completablefuture, (filteredtext) -> {
@@ -1298,7 +1755,7 @@ @@ -1298,7 +1771,7 @@
this.broadcastChatMessage(playerchatmessage1); this.broadcastChatMessage(playerchatmessage1);
}); });
@ -838,7 +859,7 @@
} }
} }
@@ -1313,6 +1770,12 @@ @@ -1313,6 +1786,12 @@
if (optional.isPresent()) { if (optional.isPresent()) {
this.server.submit(() -> { this.server.submit(() -> {
@ -851,7 +872,7 @@
this.performChatCommand(serverboundchatcommandpacket, (LastSeenMessages) optional.get()); this.performChatCommand(serverboundchatcommandpacket, (LastSeenMessages) optional.get());
this.detectRateSpam(); this.detectRateSpam();
}); });
@@ -1322,12 +1785,25 @@ @@ -1322,12 +1801,25 @@
} }
private void performChatCommand(ServerboundChatCommandPacket serverboundchatcommandpacket, LastSeenMessages lastseenmessages) { private void performChatCommand(ServerboundChatCommandPacket serverboundchatcommandpacket, LastSeenMessages lastseenmessages) {
@ -879,7 +900,7 @@
} catch (SignedMessageChain.a signedmessagechain_a) { } catch (SignedMessageChain.a signedmessagechain_a) {
this.handleMessageDecodeFailure(signedmessagechain_a); this.handleMessageDecodeFailure(signedmessagechain_a);
return; return;
@@ -1335,10 +1811,10 @@ @@ -1335,10 +1827,10 @@
CommandSigningContext.a commandsigningcontext_a = new CommandSigningContext.a(map); CommandSigningContext.a commandsigningcontext_a = new CommandSigningContext.a(map);
@ -892,7 +913,7 @@
} }
private void handleMessageDecodeFailure(SignedMessageChain.a signedmessagechain_a) { private void handleMessageDecodeFailure(SignedMessageChain.a signedmessagechain_a) {
@@ -1375,7 +1851,7 @@ @@ -1375,7 +1867,7 @@
private Optional<LastSeenMessages> tryHandleChat(LastSeenMessages.b lastseenmessages_b) { private Optional<LastSeenMessages> tryHandleChat(LastSeenMessages.b lastseenmessages_b) {
Optional<LastSeenMessages> optional = this.unpackAndApplyLastSeen(lastseenmessages_b); Optional<LastSeenMessages> optional = this.unpackAndApplyLastSeen(lastseenmessages_b);
@ -901,7 +922,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 {
@@ -1409,6 +1885,116 @@ @@ -1409,6 +1901,116 @@
return false; return false;
} }
@ -1018,7 +1039,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);
@@ -1416,13 +2002,33 @@ @@ -1416,13 +2018,33 @@
} }
private void broadcastChatMessage(PlayerChatMessage playerchatmessage) { private void broadcastChatMessage(PlayerChatMessage playerchatmessage) {
@ -1055,7 +1076,7 @@
this.disconnect(IChatBaseComponent.translatable("disconnect.spam")); this.disconnect(IChatBaseComponent.translatable("disconnect.spam"));
} }
@@ -1444,13 +2050,62 @@ @@ -1444,13 +2066,62 @@
@Override @Override
public void handleAnimate(PacketPlayInArmAnimation packetplayinarmanimation) { public void handleAnimate(PacketPlayInArmAnimation packetplayinarmanimation) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinarmanimation, this, this.player.serverLevel()); PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinarmanimation, this, this.player.serverLevel());
@ -1118,7 +1139,7 @@
this.player.resetLastActionTime(); this.player.resetLastActionTime();
Entity entity; Entity entity;
IJumpable ijumpable; IJumpable ijumpable;
@@ -1532,6 +2187,12 @@ @@ -1532,6 +2203,12 @@
} }
public void sendPlayerChatMessage(PlayerChatMessage playerchatmessage, ChatMessageType.a chatmessagetype_a) { public void sendPlayerChatMessage(PlayerChatMessage playerchatmessage, ChatMessageType.a chatmessagetype_a) {
@ -1131,7 +1152,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);
} }
@@ -1558,6 +2219,7 @@ @@ -1558,6 +2235,7 @@
@Override @Override
public void handleInteract(PacketPlayInUseEntity packetplayinuseentity) { public void handleInteract(PacketPlayInUseEntity packetplayinuseentity) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseentity, this, this.player.serverLevel()); PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseentity, this, this.player.serverLevel());
@ -1139,7 +1160,7 @@
final WorldServer worldserver = this.player.serverLevel(); final WorldServer worldserver = this.player.serverLevel();
final Entity entity = packetplayinuseentity.getTarget(worldserver); final Entity entity = packetplayinuseentity.getTarget(worldserver);
@@ -1572,13 +2234,51 @@ @@ -1572,13 +2250,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() {
@ -1192,7 +1213,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()) {
@@ -1591,23 +2291,29 @@ @@ -1591,23 +2307,29 @@
@Override @Override
public void onInteraction(EnumHand enumhand) { public void onInteraction(EnumHand enumhand) {
@ -1225,7 +1246,7 @@
} }
} else { } else {
PlayerConnection.this.disconnect(IChatBaseComponent.translatable("multiplayer.disconnect.invalid_entity_attacked")); PlayerConnection.this.disconnect(IChatBaseComponent.translatable("multiplayer.disconnect.invalid_entity_attacked"));
@@ -1630,14 +2336,14 @@ @@ -1630,14 +2352,14 @@
case PERFORM_RESPAWN: case PERFORM_RESPAWN:
if (this.player.wonGame) { if (this.player.wonGame) {
this.player.wonGame = false; this.player.wonGame = false;
@ -1242,7 +1263,7 @@
if (this.server.isHardcore()) { if (this.server.isHardcore()) {
this.player.setGameMode(EnumGamemode.SPECTATOR); this.player.setGameMode(EnumGamemode.SPECTATOR);
((GameRules.GameRuleBoolean) this.player.level().getGameRules().getRule(GameRules.RULE_SPECTATORSGENERATECHUNKS)).set(false, this.server); ((GameRules.GameRuleBoolean) this.player.level().getGameRules().getRule(GameRules.RULE_SPECTATORSGENERATECHUNKS)).set(false, this.server);
@@ -1653,15 +2359,21 @@ @@ -1653,15 +2375,21 @@
@Override @Override
public void handleContainerClose(PacketPlayInCloseWindow packetplayinclosewindow) { public void handleContainerClose(PacketPlayInCloseWindow packetplayinclosewindow) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinclosewindow, this, this.player.serverLevel()); PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinclosewindow, this, this.player.serverLevel());
@ -1266,7 +1287,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);
@@ -1674,7 +2386,284 @@ @@ -1674,7 +2402,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();
@ -1552,7 +1573,7 @@
ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packetplayinwindowclick.getChangedSlots()).iterator(); ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packetplayinwindowclick.getChangedSlots()).iterator();
while (objectiterator.hasNext()) { while (objectiterator.hasNext()) {
@@ -1704,9 +2693,18 @@ @@ -1704,9 +2709,18 @@
if (!this.player.containerMenu.stillValid(this.player)) { 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);
} else { } else {
@ -1573,7 +1594,7 @@
} }
} }
} }
@@ -1714,6 +2712,7 @@ @@ -1714,6 +2728,7 @@
@Override @Override
public void handleContainerButtonClick(PacketPlayInEnchantItem packetplayinenchantitem) { public void handleContainerButtonClick(PacketPlayInEnchantItem packetplayinenchantitem) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinenchantitem, this, this.player.serverLevel()); PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinenchantitem, this, this.player.serverLevel());
@ -1581,7 +1602,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)) {
@@ -1756,6 +2755,43 @@ @@ -1756,6 +2771,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();
@ -1625,7 +1646,7 @@
if (flag1 && flag2) { if (flag1 && flag2) {
this.player.inventoryMenu.getSlot(packetplayinsetcreativeslot.getSlotNum()).setByPlayer(itemstack); this.player.inventoryMenu.getSlot(packetplayinsetcreativeslot.getSlotNum()).setByPlayer(itemstack);
@@ -1778,6 +2814,7 @@ @@ -1778,6 +2830,7 @@
} }
private void updateSignText(PacketPlayInUpdateSign packetplayinupdatesign, List<FilteredText> list) { private void updateSignText(PacketPlayInUpdateSign packetplayinupdatesign, List<FilteredText> list) {
@ -1633,7 +1654,7 @@
this.player.resetLastActionTime(); this.player.resetLastActionTime();
WorldServer worldserver = this.player.serverLevel(); WorldServer worldserver = this.player.serverLevel();
BlockPosition blockposition = packetplayinupdatesign.getPos(); BlockPosition blockposition = packetplayinupdatesign.getPos();
@@ -1799,7 +2836,17 @@ @@ -1799,7 +2852,17 @@
@Override @Override
public void handlePlayerAbilities(PacketPlayInAbilities packetplayinabilities) { public void handlePlayerAbilities(PacketPlayInAbilities packetplayinabilities) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinabilities, this, this.player.serverLevel()); PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinabilities, this, this.player.serverLevel());
@ -1652,7 +1673,7 @@
} }
@Override @Override
@@ -1858,7 +2905,7 @@ @@ -1858,7 +2921,7 @@
if (!this.waitingForSwitchToConfig) { if (!this.waitingForSwitchToConfig) {
throw new IllegalStateException("Client acknowledged config, but none was requested"); throw new IllegalStateException("Client acknowledged config, but none was requested");
} else { } else {