13
0
geforkt von Mirrors/Paper

Don't send updates over large distances

By: md_5 <git@md-5.net>
Dieser Commit ist enthalten in:
CraftBukkit/Spigot 2022-02-07 08:35:20 +11:00
Ursprung 765eadbac1
Commit f01afaf08f

Datei anzeigen

@ -1,6 +1,6 @@
--- a/net/minecraft/server/network/PlayerConnection.java
+++ b/net/minecraft/server/network/PlayerConnection.java
@@ -156,6 +156,63 @@
@@ -156,6 +156,62 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -58,13 +58,12 @@
+import org.bukkit.inventory.EquipmentSlot;
+import org.bukkit.inventory.InventoryView;
+import org.bukkit.inventory.SmithingInventory;
+import org.bukkit.util.NumberConversions;
+// CraftBukkit end
+
public class PlayerConnection implements ServerPlayerConnection, PacketListenerPlayIn {
static final Logger LOGGER = LogManager.getLogger();
@@ -167,7 +224,9 @@
@@ -167,7 +223,9 @@
private long keepAliveTime;
private boolean keepAlivePending;
private long keepAliveChallenge;
@ -75,7 +74,7 @@
private int dropSpamTickCount;
private double firstGoodX;
private double firstGoodY;
@@ -202,7 +261,33 @@
@@ -202,7 +260,31 @@
entityplayer.connection = this;
this.keepAliveTime = SystemUtils.getMillis();
entityplayer.getTextFilter().join();
@ -91,8 +90,6 @@
+ private int lastDropTick = MinecraftServer.currentTick;
+ private int lastBookTick = MinecraftServer.currentTick;
+ private int dropCount = 0;
+ private static final int SURVIVAL_PLACE_DISTANCE_SQUARED = 6 * 6;
+ private static final int CREATIVE_PLACE_DISTANCE_SQUARED = 7 * 7;
+
+ // Get position of last block hit for BlockDamageLevel.STOPPED
+ private double lastPosX = Double.MAX_VALUE;
@ -109,7 +106,7 @@
public void tick() {
this.resetPosition();
@@ -251,7 +336,7 @@
@@ -251,7 +333,7 @@
this.server.getProfiler().push("keepAlive");
long i = SystemUtils.getMillis();
@ -118,7 +115,7 @@
if (this.keepAlivePending) {
this.disconnect(new ChatMessage("disconnect.timeout"));
} else {
@@ -263,15 +348,21 @@
@@ -263,15 +345,21 @@
}
this.server.getProfiler().pop();
@ -140,7 +137,7 @@
this.disconnect(new ChatMessage("multiplayer.disconnect.idling"));
}
@@ -295,16 +386,46 @@
@@ -295,16 +383,46 @@
return this.server.isSingleplayerOwner(this.player.getGameProfile());
}
@ -188,7 +185,7 @@
}
private <T, R> void filterTextPacket(T t0, Consumer<R> consumer, BiFunction<ITextFilter, T, CompletableFuture<R>> bifunction) {
@@ -371,7 +492,34 @@
@@ -371,7 +489,34 @@
double d9 = entity.getDeltaMovement().lengthSqr();
double d10 = d6 * d6 + d7 * d7 + d8 * d8;
@ -224,7 +221,7 @@
PlayerConnection.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", entity.getName().getString(), this.player.getName().getString(), d6, d7, d8);
this.connection.send(new PacketPlayOutVehicleMove(entity));
return;
@@ -401,14 +549,72 @@
@@ -401,14 +546,72 @@
}
entity.absMoveTo(d3, d4, d5, f, f1);
@ -297,7 +294,7 @@
this.player.getLevel().getChunkSource().move(this.player);
this.player.checkMovementStatistics(this.player.getX() - d0, this.player.getY() - d1, this.player.getZ() - d2);
this.clientVehicleIsFloating = d11 >= -0.03125D && !this.server.isFlightAllowed() && this.noBlocksAround(entity);
@@ -427,7 +633,7 @@
@@ -427,7 +630,7 @@
@Override
public void handleAcceptTeleportPacket(PacketPlayInTeleportAccept packetplayinteleportaccept) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinteleportaccept, this, this.player.getLevel());
@ -306,7 +303,7 @@
this.player.absMoveTo(this.awaitingPositionFromClient.x, this.awaitingPositionFromClient.y, this.awaitingPositionFromClient.z, this.player.getYRot(), this.player.getXRot());
this.lastGoodX = this.awaitingPositionFromClient.x;
this.lastGoodY = this.awaitingPositionFromClient.y;
@@ -437,6 +643,7 @@
@@ -437,6 +640,7 @@
}
this.awaitingPositionFromClient = null;
@ -314,7 +311,7 @@
}
}
@@ -444,7 +651,7 @@
@@ -444,7 +648,7 @@
@Override
public void handleRecipeBookSeenRecipePacket(PacketPlayInRecipeDisplayed packetplayinrecipedisplayed) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinrecipedisplayed, this, this.player.getLevel());
@ -323,7 +320,7 @@
RecipeBookServer recipebookserver = this.player.getRecipeBook();
Objects.requireNonNull(recipebookserver);
@@ -474,6 +681,12 @@
@@ -474,6 +678,12 @@
@Override
public void handleCustomCommandSuggestions(PacketPlayInTabComplete packetplayintabcomplete) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayintabcomplete, this, this.player.getLevel());
@ -336,7 +333,7 @@
StringReader stringreader = new StringReader(packetplayintabcomplete.getCommand());
if (stringreader.canRead() && stringreader.peek() == '/') {
@@ -483,6 +696,7 @@
@@ -483,6 +693,7 @@
ParseResults<CommandListenerWrapper> parseresults = this.server.getCommands().getDispatcher().parse(stringreader, this.player.createCommandSourceStack());
this.server.getCommands().getDispatcher().getCompletionSuggestions(parseresults).thenAccept((suggestions) -> {
@ -344,7 +341,7 @@
this.connection.send(new PacketPlayOutTabComplete(packetplayintabcomplete.getId(), suggestions));
});
}
@@ -715,6 +929,13 @@
@@ -715,6 +926,13 @@
if (container instanceof ContainerMerchant) {
ContainerMerchant containermerchant = (ContainerMerchant) container;
@ -358,7 +355,7 @@
containermerchant.setSelectionHint(i);
containermerchant.tryMoveItems(i);
@@ -724,6 +945,13 @@
@@ -724,6 +942,13 @@
@Override
public void handleEditBook(PacketPlayInBEdit packetplayinbedit) {
@ -372,7 +369,7 @@
int i = packetplayinbedit.getSlot();
if (PlayerInventory.isHotbarSlot(i) || i == 40) {
@@ -732,7 +960,7 @@
@@ -732,7 +957,7 @@
Objects.requireNonNull(list);
optional.ifPresent(list::add);
@ -381,7 +378,7 @@
Objects.requireNonNull(list);
stream.forEach(list::add);
@@ -748,7 +976,7 @@
@@ -748,7 +973,7 @@
ItemStack itemstack = this.player.getInventory().getItem(i);
if (itemstack.is(Items.WRITABLE_BOOK)) {
@ -390,7 +387,7 @@
}
}
@@ -773,16 +1001,16 @@
@@ -773,16 +998,16 @@
this.updateBookPages(list, (s) -> {
return IChatBaseComponent.ChatSerializer.toJson(new ChatComponentText(s));
@ -411,7 +408,7 @@
return NBTTagString.valueOf((String) unaryoperator.apply(itextfilter_a.getFiltered()));
});
@@ -810,6 +1038,7 @@
@@ -810,6 +1035,7 @@
}
itemstack.addTagElement("pages", nbttaglist);
@ -419,7 +416,7 @@
}
@Override
@@ -846,7 +1075,7 @@
@@ -846,7 +1072,7 @@
} else {
WorldServer worldserver = this.player.getLevel();
@ -428,7 +425,7 @@
if (this.tickCount == 0) {
this.resetPosition();
}
@@ -856,7 +1085,7 @@
@@ -856,7 +1082,7 @@
this.awaitingTeleportTime = this.tickCount;
this.teleport(this.awaitingPositionFromClient.x, this.awaitingPositionFromClient.y, this.awaitingPositionFromClient.z, this.player.getYRot(), this.player.getXRot());
}
@ -437,7 +434,7 @@
} else {
this.awaitingTeleportTime = this.tickCount;
double d0 = clampHorizontal(packetplayinflying.getX(this.player.getX()));
@@ -868,7 +1097,15 @@
@@ -868,7 +1094,15 @@
if (this.player.isPassenger()) {
this.player.absMoveTo(this.player.getX(), this.player.getY(), this.player.getZ(), f, f1);
this.player.getLevel().getChunkSource().move(this.player);
@ -453,7 +450,7 @@
double d3 = this.player.getX();
double d4 = this.player.getY();
double d5 = this.player.getZ();
@@ -888,15 +1125,33 @@
@@ -888,15 +1122,33 @@
++this.receivedMovePacketCount;
int i = this.receivedMovePacketCount - this.knownMovePacketCount;
@ -489,7 +486,7 @@
PlayerConnection.LOGGER.warn("{} moved too quickly! {},{},{}", this.player.getName().getString(), d7, d8, d9);
this.teleport(this.player.getX(), this.player.getY(), this.player.getZ(), this.player.getYRot(), this.player.getXRot());
return;
@@ -915,6 +1170,7 @@
@@ -915,6 +1167,7 @@
}
this.player.move(EnumMoveType.PLAYER, new Vec3D(d7, d8, d9));
@ -497,7 +494,7 @@
double d12 = d8;
d7 = d0 - this.player.getX();
@@ -936,7 +1192,71 @@
@@ -936,7 +1189,71 @@
if (!this.player.noPhysics && !this.player.isSleeping() && (flag1 && worldserver.noCollision(this.player, axisalignedbb) || this.isPlayerCollidingWithAnythingNew(worldserver, axisalignedbb))) {
this.teleport(d3, d4, d5, f, f1);
} else {
@ -570,7 +567,7 @@
this.player.getLevel().getChunkSource().move(this.player);
this.player.doCheckFallDamage(this.player.getY() - d6, packetplayinflying.isOnGround());
this.player.setOnGround(packetplayinflying.isOnGround());
@@ -974,19 +1294,80 @@
@@ -974,19 +1291,80 @@
return true;
}
@ -655,7 +652,7 @@
double d3 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.X) ? this.player.getX() : 0.0D;
double d4 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.Y) ? this.player.getY() : 0.0D;
double d5 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.Z) ? this.player.getZ() : 0.0D;
@@ -998,6 +1379,14 @@
@@ -998,6 +1376,14 @@
this.awaitingTeleport = 0;
}
@ -670,7 +667,7 @@
this.awaitingTeleportTime = this.tickCount;
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, flag));
@@ -1006,6 +1395,7 @@
@@ -1006,6 +1392,7 @@
@Override
public void handlePlayerAction(PacketPlayInBlockDig packetplayinblockdig) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinblockdig, this, this.player.getLevel());
@ -678,7 +675,7 @@
BlockPosition blockposition = packetplayinblockdig.getPos();
this.player.resetLastActionTime();
@@ -1016,14 +1406,46 @@
@@ -1016,14 +1403,46 @@
if (!this.player.isSpectator()) {
ItemStack itemstack = this.player.getItemInHand(EnumHand.OFF_HAND);
@ -727,7 +724,7 @@
this.player.drop(false);
}
@@ -1060,6 +1482,7 @@
@@ -1060,6 +1479,7 @@
@Override
public void handleUseItemOn(PacketPlayInUseItem packetplayinuseitem) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseitem, this, this.player.getLevel());
@ -735,22 +732,25 @@
WorldServer worldserver = this.player.getLevel();
EnumHand enumhand = packetplayinuseitem.getHand();
ItemStack itemstack = this.player.getItemInHand(enumhand);
@@ -1072,6 +1495,14 @@
@@ -1069,9 +1489,16 @@
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)) {
+ // CraftBukkit start - Check if we can actually do something over this large a distance
+ Location eyeLoc = this.getCraftPlayer().getEyeLocation();
+ double reachDistance = NumberConversions.square(eyeLoc.getX() - blockposition.getX()) + NumberConversions.square(eyeLoc.getY() - blockposition.getY()) + NumberConversions.square(eyeLoc.getZ() - blockposition.getZ());
+ if (reachDistance > (this.getCraftPlayer().getGameMode() == org.bukkit.GameMode.CREATIVE ? CREATIVE_PLACE_DISTANCE_SQUARED : SURVIVAL_PLACE_DISTANCE_SQUARED)) {
this.player.resetLastActionTime();
int i = this.player.level.getMaxBuildHeight();
+ // CraftBukkit start
+ double distanceSqr = this.player.distanceToSqr((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D);
+ if (distanceSqr > 100.0D) {
+ return;
+ }
+ this.player.stopUsingItem(); // SPIGOT-4706
+ // CraftBukkit end
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 && distanceSqr < 64.0D && worldserver.mayInteract(this.player, blockposition)) { // CraftBukkit - reuse value
+ this.player.stopUsingItem(); // CraftBukkit - SPIGOT-4706
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)) {
@@ -1095,12 +1526,51 @@
@@ -1095,12 +1522,51 @@
@Override
public void handleUseItem(PacketPlayInBlockPlace packetplayinblockplace) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinblockplace, this, this.player.getLevel());
@ -802,7 +802,7 @@
EnumInteractionResult enuminteractionresult = this.player.gameMode.useItem(this.player, worldserver, itemstack, enumhand);
if (enuminteractionresult.shouldSwing()) {
@@ -1121,7 +1591,7 @@
@@ -1121,7 +1587,7 @@
Entity entity = packetplayinspectate.getEntity(worldserver);
if (entity != null) {
@ -811,7 +811,7 @@
return;
}
}
@@ -1136,6 +1606,7 @@
@@ -1136,6 +1602,7 @@
PlayerConnection.LOGGER.info("Disconnecting {} due to resource pack rejection", this.player.getName());
this.disconnect(new ChatMessage("multiplayer.requiredTexturePrompt.disconnect"));
}
@ -819,7 +819,7 @@
}
@@ -1155,11 +1626,26 @@
@@ -1155,11 +1622,26 @@
@Override
public void onDisconnect(IChatBaseComponent ichatbasecomponent) {
@ -847,7 +847,7 @@
this.player.getTextFilter().leave();
if (this.isSingleplayerOwner()) {
PlayerConnection.LOGGER.info("Stopping singleplayer server as player logged out");
@@ -1174,6 +1660,15 @@
@@ -1174,6 +1656,15 @@
}
public void send(Packet<?> packet, @Nullable GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
@ -863,7 +863,7 @@
try {
this.connection.send(packet, genericfuturelistener);
} catch (Throwable throwable) {
@@ -1190,7 +1685,16 @@
@@ -1190,7 +1681,16 @@
@Override
public void handleSetCarriedItem(PacketPlayInHeldItemSlot packetplayinhelditemslot) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinhelditemslot, this, this.player.getLevel());
@ -880,7 +880,7 @@
if (this.player.getInventory().selected != packetplayinhelditemslot.getSlot() && this.player.getUsedItemHand() == EnumHand.MAIN_HAND) {
this.player.stopUsingItem();
}
@@ -1199,11 +1703,18 @@
@@ -1199,11 +1699,18 @@
this.player.resetLastActionTime();
} else {
PlayerConnection.LOGGER.warn("{} tried to set an invalid carried item", this.player.getName().getString());
@ -899,7 +899,7 @@
String s = StringUtils.normalizeSpace(packetplayinchat.getMessage());
for (int i = 0; i < s.length(); ++i) {
@@ -1217,20 +1728,42 @@
@@ -1217,20 +1724,42 @@
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinchat, this, this.player.getLevel());
this.handleChat(ITextFilter.a.passThrough(s));
} else {
@ -946,7 +946,7 @@
} else {
String s1 = itextfilter_a.getFiltered();
ChatMessage chatmessage = s1.isEmpty() ? null : new ChatMessage("chat.type.text", new Object[]{this.player.getDisplayName(), s1});
@@ -1241,28 +1774,198 @@
@@ -1241,28 +1770,198 @@
}, ChatMessageType.CHAT, this.player.getUUID());
}
@ -1149,7 +1149,7 @@
this.player.resetLastActionTime();
IJumpable ijumpable;
@@ -1320,6 +2023,7 @@
@@ -1320,6 +2019,7 @@
@Override
public void handleInteract(PacketPlayInUseEntity packetplayinuseentity) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseentity, this, this.player.getLevel());
@ -1157,7 +1157,7 @@
WorldServer worldserver = this.player.getLevel();
final Entity entity = packetplayinuseentity.getTarget(worldserver);
@@ -1334,10 +2038,44 @@
@@ -1334,10 +2034,44 @@
if (this.player.distanceToSqr(entity) < 36.0D) {
packetplayinuseentity.dispatch(new PacketPlayInUseEntity.c() {
@ -1203,7 +1203,7 @@
if (enuminteractionresult.consumesAction()) {
CriterionTriggers.PLAYER_INTERACTED_WITH_ENTITY.trigger(PlayerConnection.this.player, itemstack, entity);
if (enuminteractionresult.shouldSwing()) {
@@ -1349,20 +2087,27 @@
@@ -1349,20 +2083,27 @@
@Override
public void onInteraction(EnumHand enumhand) {
@ -1234,7 +1234,7 @@
} else {
PlayerConnection.this.disconnect(new ChatMessage("multiplayer.disconnect.invalid_entity_attacked"));
PlayerConnection.LOGGER.warn("Player {} tried to attack an invalid entity", PlayerConnection.this.player.getName().getString());
@@ -1407,21 +2152,304 @@
@@ -1407,21 +2148,304 @@
@Override
public void handleContainerClose(PacketPlayInCloseWindow packetplayinclosewindow) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinclosewindow, this, this.player.getLevel());
@ -1542,7 +1542,7 @@
ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packetplayinwindowclick.getChangedSlots()).iterator();
while (objectiterator.hasNext()) {
@@ -1456,6 +2484,7 @@
@@ -1456,6 +2480,7 @@
@Override
public void handleContainerButtonClick(PacketPlayInEnchantItem packetplayinenchantitem) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinenchantitem, this, this.player.getLevel());
@ -1550,7 +1550,7 @@
this.player.resetLastActionTime();
if (this.player.containerMenu.containerId == packetplayinenchantitem.getContainerId() && !this.player.isSpectator()) {
this.player.containerMenu.clickMenuButton(this.player, packetplayinenchantitem.getButtonId());
@@ -1483,6 +2512,43 @@
@@ -1483,6 +2508,43 @@
boolean flag1 = packetplayinsetcreativeslot.getSlotNum() >= 1 && packetplayinsetcreativeslot.getSlotNum() <= 45;
boolean flag2 = itemstack.isEmpty() || itemstack.getDamageValue() >= 0 && itemstack.getCount() <= 64 && !itemstack.isEmpty();
@ -1594,7 +1594,7 @@
if (flag1 && flag2) {
this.player.inventoryMenu.getSlot(packetplayinsetcreativeslot.getSlotNum()).set(itemstack);
@@ -1505,6 +2571,7 @@
@@ -1505,6 +2567,7 @@
}
private void updateSignText(PacketPlayInUpdateSign packetplayinupdatesign, List<ITextFilter.a> list) {
@ -1602,7 +1602,7 @@
this.player.resetLastActionTime();
WorldServer worldserver = this.player.getLevel();
BlockPosition blockposition = packetplayinupdatesign.getPos();
@@ -1521,18 +2588,37 @@
@@ -1521,18 +2584,37 @@
if (!tileentitysign.isEditable() || !this.player.getUUID().equals(tileentitysign.getPlayerWhoMayEdit())) {
PlayerConnection.LOGGER.warn("Player {} just tried to change non-editable sign", this.player.getName().getString());
@ -1642,7 +1642,7 @@
tileentitysign.setChanged();
worldserver.sendBlockUpdated(blockposition, iblockdata, iblockdata, 3);
@@ -1542,6 +2628,7 @@
@@ -1542,6 +2624,7 @@
@Override
public void handleKeepAlive(PacketPlayInKeepAlive packetplayinkeepalive) {
@ -1650,7 +1650,7 @@
if (this.keepAlivePending && packetplayinkeepalive.getId() == this.keepAliveChallenge) {
int i = (int) (SystemUtils.getMillis() - this.keepAliveTime);
@@ -1556,7 +2643,17 @@
@@ -1556,7 +2639,17 @@
@Override
public void handlePlayerAbilities(PacketPlayInAbilities packetplayinabilities) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinabilities, this, this.player.getLevel());
@ -1669,7 +1669,7 @@
}
@Override
@@ -1565,8 +2662,50 @@
@@ -1565,8 +2658,50 @@
this.player.updateOptions(packetplayinsettings);
}