Repackage NMS

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2021-03-16 09:00:00 +11:00
parent 18496e998f
commit 9da047989c
968 changed files with 5448 additions and 5050 deletions

View File

@@ -1,12 +1,23 @@
--- a/net/minecraft/server/PlayerConnection.java
+++ b/net/minecraft/server/PlayerConnection.java
@@ -24,6 +24,48 @@
--- a/net/minecraft/server/network/PlayerConnection.java
+++ b/net/minecraft/server/network/PlayerConnection.java
@@ -158,6 +158,59 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
+import net.minecraft.network.protocol.game.PacketPlayOutAttachEntity;
+import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
+import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntityLiving;
+import net.minecraft.network.protocol.game.PacketPlayOutSpawnPosition;
+import net.minecraft.util.MathHelper;
+import net.minecraft.world.entity.EntityInsentient;
+import net.minecraft.world.entity.animal.EntityFish;
+import net.minecraft.world.inventory.InventoryClickType;
+import net.minecraft.world.item.crafting.IRecipe;
+import net.minecraft.world.level.RayTrace;
+import net.minecraft.world.phys.MovingObjectPosition;
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.entity.CraftPlayer;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
@@ -49,7 +60,7 @@
public class PlayerConnection implements PacketListenerPlayIn {
private static final Logger LOGGER = LogManager.getLogger();
@@ -34,7 +76,10 @@
@@ -168,7 +221,10 @@
private long lastKeepAlive;
private boolean awaitingKeepAlive;
private long h;
@@ -61,7 +72,7 @@
private int j;
private final Int2ShortMap k = new Int2ShortOpenHashMap();
private double l;
@@ -72,8 +117,33 @@
@@ -206,8 +262,33 @@
itextfilter.a();
}
@@ -95,7 +106,7 @@
public void tick() {
this.syncPosition();
this.player.lastX = this.player.locX();
@@ -121,7 +191,7 @@
@@ -255,7 +336,7 @@
this.minecraftServer.getMethodProfiler().enter("keepAlive");
long i = SystemUtils.getMonotonicMillis();
@@ -104,7 +115,7 @@
if (this.awaitingKeepAlive) {
this.disconnect(new ChatMessage("disconnect.timeout"));
} else {
@@ -133,15 +203,21 @@
@@ -267,15 +348,21 @@
}
this.minecraftServer.getMethodProfiler().exit();
@@ -126,7 +137,7 @@
this.disconnect(new ChatMessage("multiplayer.disconnect.idling"));
}
@@ -165,16 +241,46 @@
@@ -299,16 +386,46 @@
return this.minecraftServer.a(this.player.getProfile());
}
@@ -174,7 +185,7 @@
}
private <T> void a(T t0, Consumer<T> consumer, BiFunction<ITextFilter, T, CompletableFuture<Optional<T>>> bifunction) {
@@ -190,7 +296,7 @@
@@ -324,7 +441,7 @@
ITextFilter itextfilter = this.player.Q();
if (itextfilter != null) {
@@ -183,7 +194,7 @@
optional.ifPresent(consumer1);
}, iasynctaskhandler);
} else {
@@ -247,7 +353,34 @@
@@ -381,7 +498,34 @@
double d9 = entity.getMot().g();
double d10 = d6 * d6 + d7 * d7 + d8 * d8;
@@ -219,7 +230,7 @@
PlayerConnection.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", entity.getDisplayName().getString(), this.player.getDisplayName().getString(), d6, d7, d8);
this.networkManager.sendPacket(new PacketPlayOutVehicleMove(entity));
return;
@@ -277,14 +410,72 @@
@@ -411,14 +555,72 @@
}
entity.setLocation(d3, d4, d5, f, f1);
@@ -292,7 +303,7 @@
this.player.getWorldServer().getChunkProvider().movePlayer(this.player);
this.player.checkMovement(this.player.locX() - d0, this.player.locY() - d1, this.player.locZ() - d2);
this.D = d11 >= -0.03125D && !this.minecraftServer.getAllowFlight() && this.a(entity);
@@ -303,7 +494,7 @@
@@ -437,7 +639,7 @@
@Override
public void a(PacketPlayInTeleportAccept packetplayinteleportaccept) {
PlayerConnectionUtils.ensureMainThread(packetplayinteleportaccept, this, this.player.getWorldServer());
@@ -301,7 +312,7 @@
this.player.setLocation(this.teleportPos.x, this.teleportPos.y, this.teleportPos.z, this.player.yaw, this.player.pitch);
this.o = this.teleportPos.x;
this.p = this.teleportPos.y;
@@ -313,6 +504,7 @@
@@ -447,6 +649,7 @@
}
this.teleportPos = null;
@@ -309,7 +320,7 @@
}
}
@@ -320,7 +512,7 @@
@@ -454,7 +657,7 @@
@Override
public void a(PacketPlayInRecipeDisplayed packetplayinrecipedisplayed) {
PlayerConnectionUtils.ensureMainThread(packetplayinrecipedisplayed, this, this.player.getWorldServer());
@@ -318,7 +329,7 @@
RecipeBookServer recipebookserver = this.player.getRecipeBook();
optional.ifPresent(recipebookserver::e);
@@ -349,6 +541,12 @@
@@ -483,6 +686,12 @@
@Override
public void a(PacketPlayInTabComplete packetplayintabcomplete) {
PlayerConnectionUtils.ensureMainThread(packetplayintabcomplete, this, this.player.getWorldServer());
@@ -331,7 +342,7 @@
StringReader stringreader = new StringReader(packetplayintabcomplete.c());
if (stringreader.canRead() && stringreader.peek() == '/') {
@@ -358,6 +556,7 @@
@@ -492,6 +701,7 @@
ParseResults<CommandListenerWrapper> parseresults = this.minecraftServer.getCommandDispatcher().a().parse(stringreader, this.player.getCommandListener());
this.minecraftServer.getCommandDispatcher().a().getCompletionSuggestions(parseresults).thenAccept((suggestions) -> {
@@ -339,7 +350,7 @@
this.networkManager.sendPacket(new PacketPlayOutTabComplete(packetplayintabcomplete.b(), suggestions));
});
}
@@ -586,6 +785,7 @@
@@ -720,6 +930,7 @@
if (container instanceof ContainerMerchant) {
ContainerMerchant containermerchant = (ContainerMerchant) container;
@@ -347,7 +358,7 @@
containermerchant.d(i);
containermerchant.g(i);
@@ -595,6 +795,13 @@
@@ -729,6 +940,13 @@
@Override
public void a(PacketPlayInBEdit packetplayinbedit) {
@@ -361,7 +372,7 @@
ItemStack itemstack = packetplayinbedit.b();
if (itemstack.getItem() == Items.WRITABLE_BOOK) {
@@ -610,13 +817,15 @@
@@ -744,13 +962,15 @@
NBTTagList nbttaglist = nbttagcompound.getList("pages", 8);
@@ -380,7 +391,7 @@
if (PlayerInventory.d(i) || i == 40) {
this.a((List) list, flag ? (list1) -> {
this.a((String) list1.get(0), list1.subList(1, list1.size()), i);
@@ -635,7 +844,9 @@
@@ -769,7 +989,9 @@
NBTTagList nbttaglist = new NBTTagList();
list.stream().map(NBTTagString::a).forEach(nbttaglist::add);
@@ -390,7 +401,7 @@
}
}
@@ -664,7 +875,7 @@
@@ -798,7 +1020,7 @@
}
itemstack1.a("pages", (NBTBase) nbttaglist);
@@ -399,7 +410,7 @@
}
}
@@ -702,7 +913,7 @@
@@ -836,7 +1058,7 @@
} else {
WorldServer worldserver = this.player.getWorldServer();
@@ -408,7 +419,7 @@
if (this.e == 0) {
this.syncPosition();
}
@@ -712,13 +923,21 @@
@@ -846,13 +1068,21 @@
this.A = this.e;
this.a(this.teleportPos.x, this.teleportPos.y, this.teleportPos.z, this.player.yaw, this.player.pitch);
}
@@ -431,7 +442,7 @@
double d0 = this.player.locX();
double d1 = this.player.locY();
double d2 = this.player.locZ();
@@ -743,15 +962,33 @@
@@ -877,15 +1107,33 @@
++this.receivedMovePackets;
int i = this.receivedMovePackets - this.processedMovePackets;
@@ -467,7 +478,7 @@
PlayerConnection.LOGGER.warn("{} moved too quickly! {},{},{}", this.player.getDisplayName().getString(), d7, d8, d9);
this.a(this.player.locX(), this.player.locY(), this.player.locZ(), this.player.yaw, this.player.pitch);
return;
@@ -770,6 +1007,7 @@
@@ -904,6 +1152,7 @@
}
this.player.move(EnumMoveType.PLAYER, new Vec3D(d7, d8, d9));
@@ -475,7 +486,7 @@
double d12 = d8;
d7 = d4 - this.player.locX();
@@ -791,10 +1029,74 @@
@@ -925,10 +1174,74 @@
if (!this.player.noclip && !this.player.isSleeping() && (flag1 && worldserver.getCubes(this.player, axisalignedbb) || this.a((IWorldReader) worldserver, axisalignedbb))) {
this.a(d0, d1, d2, f, f1);
} else {
@@ -552,7 +563,7 @@
if (flag) {
this.player.fallDistance = 0.0F;
}
@@ -823,10 +1125,66 @@
@@ -957,10 +1270,66 @@
}
public void a(double d0, double d1, double d2, float f, float f1) {
@@ -620,7 +631,7 @@
double d3 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.X) ? this.player.locX() : 0.0D;
double d4 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.Y) ? this.player.locY() : 0.0D;
double d5 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.Z) ? this.player.locZ() : 0.0D;
@@ -838,6 +1196,14 @@
@@ -972,6 +1341,14 @@
this.teleportAwait = 0;
}
@@ -635,7 +646,7 @@
this.A = this.e;
this.player.setLocation(d0, d1, d2, f, f1);
this.player.playerConnection.sendPacket(new PacketPlayOutPosition(d0 - d3, d1 - d4, d2 - d5, f - f2, f1 - f3, set, this.teleportAwait));
@@ -846,6 +1212,7 @@
@@ -980,6 +1357,7 @@
@Override
public void a(PacketPlayInBlockDig packetplayinblockdig) {
PlayerConnectionUtils.ensureMainThread(packetplayinblockdig, this, this.player.getWorldServer());
@@ -643,7 +654,7 @@
BlockPosition blockposition = packetplayinblockdig.b();
this.player.resetIdleTimer();
@@ -856,14 +1223,46 @@
@@ -990,14 +1368,46 @@
if (!this.player.isSpectator()) {
ItemStack itemstack = this.player.b(EnumHand.OFF_HAND);
@@ -692,7 +703,7 @@
this.player.dropItem(false);
}
@@ -900,6 +1299,7 @@
@@ -1034,6 +1444,7 @@
@Override
public void a(PacketPlayInUseItem packetplayinuseitem) {
PlayerConnectionUtils.ensureMainThread(packetplayinuseitem, this, this.player.getWorldServer());
@@ -700,7 +711,7 @@
WorldServer worldserver = this.player.getWorldServer();
EnumHand enumhand = packetplayinuseitem.b();
ItemStack itemstack = this.player.b(enumhand);
@@ -910,6 +1310,14 @@
@@ -1044,6 +1455,14 @@
this.player.resetIdleTimer();
if (blockposition.getY() < this.minecraftServer.getMaxBuildHeight()) {
if (this.teleportPos == null && this.player.h((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D) < 64.0D && worldserver.a((EntityHuman) this.player, blockposition)) {
@@ -715,7 +726,7 @@
EnumInteractionResult enuminteractionresult = this.player.playerInteractManager.a(this.player, worldserver, itemstack, enumhand, movingobjectpositionblock);
if (enumdirection == EnumDirection.UP && !enuminteractionresult.a() && blockposition.getY() >= this.minecraftServer.getMaxBuildHeight() - 1 && a(this.player, itemstack)) {
@@ -933,12 +1341,51 @@
@@ -1067,12 +1486,51 @@
@Override
public void a(PacketPlayInBlockPlace packetplayinblockplace) {
PlayerConnectionUtils.ensureMainThread(packetplayinblockplace, this, this.player.getWorldServer());
@@ -767,7 +778,7 @@
EnumInteractionResult enuminteractionresult = this.player.playerInteractManager.a(this.player, worldserver, itemstack, enumhand);
if (enuminteractionresult.b()) {
@@ -959,7 +1406,7 @@
@@ -1093,7 +1551,7 @@
Entity entity = packetplayinspectate.a(worldserver);
if (entity != null) {
@@ -776,7 +787,7 @@
return;
}
}
@@ -968,7 +1415,12 @@
@@ -1102,7 +1560,12 @@
}
@Override
@@ -790,7 +801,7 @@
@Override
public void a(PacketPlayInBoatMove packetplayinboatmove) {
@@ -983,11 +1435,26 @@
@@ -1117,11 +1580,26 @@
@Override
public void a(IChatBaseComponent ichatbasecomponent) {
@@ -818,7 +829,7 @@
ITextFilter itextfilter = this.player.Q();
if (itextfilter != null) {
@@ -1019,6 +1486,15 @@
@@ -1153,6 +1631,15 @@
}
}
@@ -834,7 +845,7 @@
try {
this.networkManager.sendPacket(packet, genericfuturelistener);
} catch (Throwable throwable) {
@@ -1035,7 +1511,16 @@
@@ -1169,7 +1656,16 @@
@Override
public void a(PacketPlayInHeldItemSlot packetplayinhelditemslot) {
PlayerConnectionUtils.ensureMainThread(packetplayinhelditemslot, this, this.player.getWorldServer());
@@ -851,7 +862,7 @@
if (this.player.inventory.itemInHandIndex != packetplayinhelditemslot.b() && this.player.getRaisedHand() == EnumHand.MAIN_HAND) {
this.player.clearActiveItem();
}
@@ -1044,65 +1529,286 @@
@@ -1178,65 +1674,286 @@
this.player.resetIdleTimer();
} else {
PlayerConnection.LOGGER.warn("{} tried to set an invalid carried item", this.player.getDisplayName().getString());
@@ -1147,7 +1158,7 @@
this.player.resetIdleTimer();
IJumpable ijumpable;
@@ -1160,6 +1866,7 @@
@@ -1294,6 +2011,7 @@
@Override
public void a(PacketPlayInUseEntity packetplayinuseentity) {
PlayerConnectionUtils.ensureMainThread(packetplayinuseentity, this, this.player.getWorldServer());
@@ -1155,7 +1166,7 @@
WorldServer worldserver = this.player.getWorldServer();
Entity entity = packetplayinuseentity.a((World) worldserver);
@@ -1173,18 +1880,72 @@
@@ -1307,18 +2025,72 @@
ItemStack itemstack = enumhand != null ? this.player.b(enumhand).cloneItemStack() : ItemStack.b;
Optional<EnumInteractionResult> optional = Optional.empty();
@@ -1188,7 +1199,7 @@
+
+ if (event.isCancelled() || this.player.inventory.getItemInHand() == null || this.player.inventory.getItemInHand().getItem() != origItem) {
+ // Refresh the current entity metadata
+ this.sendPacket(new PacketPlayOutEntityMetadata(entity.getId(), entity.datawatcher, true));
+ this.sendPacket(new PacketPlayOutEntityMetadata(entity.getId(), entity.getDataWatcher(), true));
+ }
+
+ if (event.isCancelled()) {
@@ -1229,7 +1240,7 @@
}
if (optional.isPresent() && ((EnumInteractionResult) optional.get()).a()) {
@@ -1231,15 +1992,21 @@
@@ -1365,15 +2137,21 @@
@Override
public void a(PacketPlayInCloseWindow packetplayinclosewindow) {
PlayerConnectionUtils.ensureMainThread(packetplayinclosewindow, this, this.player.getWorldServer());
@@ -1253,7 +1264,7 @@
NonNullList<ItemStack> nonnulllist = NonNullList.a();
for (int i = 0; i < this.player.activeContainer.slots.size(); ++i) {
@@ -1248,8 +2015,274 @@
@@ -1382,8 +2160,274 @@
this.player.a(this.player.activeContainer, nonnulllist);
} else {
@@ -1529,7 +1540,7 @@
if (ItemStack.matches(packetplayinwindowclick.f(), itemstack)) {
this.player.playerConnection.sendPacket(new PacketPlayOutTransaction(packetplayinwindowclick.b(), packetplayinwindowclick.e(), true));
this.player.e = true;
@@ -1289,6 +2322,7 @@
@@ -1423,6 +2467,7 @@
@Override
public void a(PacketPlayInEnchantItem packetplayinenchantitem) {
PlayerConnectionUtils.ensureMainThread(packetplayinenchantitem, this, this.player.getWorldServer());
@@ -1537,7 +1548,7 @@
this.player.resetIdleTimer();
if (this.player.activeContainer.windowId == packetplayinenchantitem.b() && this.player.activeContainer.c(this.player) && !this.player.isSpectator()) {
this.player.activeContainer.a((EntityHuman) this.player, packetplayinenchantitem.c());
@@ -1321,6 +2355,43 @@
@@ -1455,6 +2500,43 @@
boolean flag1 = packetplayinsetcreativeslot.b() >= 1 && packetplayinsetcreativeslot.b() <= 45;
boolean flag2 = itemstack.isEmpty() || itemstack.getDamage() >= 0 && itemstack.getCount() <= 64 && !itemstack.isEmpty();
@@ -1581,7 +1592,7 @@
if (flag1 && flag2) {
if (itemstack.isEmpty()) {
@@ -1342,6 +2413,7 @@
@@ -1476,6 +2558,7 @@
@Override
public void a(PacketPlayInTransaction packetplayintransaction) {
PlayerConnectionUtils.ensureMainThread(packetplayintransaction, this, this.player.getWorldServer());
@@ -1589,7 +1600,7 @@
int i = this.player.activeContainer.windowId;
if (i == packetplayintransaction.b() && this.k.getOrDefault(i, (short) (packetplayintransaction.c() + 1)) == packetplayintransaction.c() && !this.player.activeContainer.c(this.player) && !this.player.isSpectator()) {
@@ -1360,6 +2432,7 @@
@@ -1494,6 +2577,7 @@
}
private void a(PacketPlayInUpdateSign packetplayinupdatesign, List<String> list) {
@@ -1597,7 +1608,7 @@
this.player.resetIdleTimer();
WorldServer worldserver = this.player.getWorldServer();
BlockPosition blockposition = packetplayinupdatesign.b();
@@ -1376,12 +2449,28 @@
@@ -1510,12 +2594,28 @@
if (!tileentitysign.d() || tileentitysign.f() != this.player) {
PlayerConnection.LOGGER.warn("Player {} just tried to change non-editable sign", this.player.getDisplayName().getString());
@@ -1627,7 +1638,7 @@
tileentitysign.update();
worldserver.notify(blockposition, iblockdata, iblockdata, 3);
@@ -1391,6 +2480,7 @@
@@ -1525,6 +2625,7 @@
@Override
public void a(PacketPlayInKeepAlive packetplayinkeepalive) {
@@ -1635,7 +1646,7 @@
if (this.awaitingKeepAlive && packetplayinkeepalive.b() == this.h) {
int i = (int) (SystemUtils.getMonotonicMillis() - this.lastKeepAlive);
@@ -1405,7 +2495,17 @@
@@ -1539,7 +2640,17 @@
@Override
public void a(PacketPlayInAbilities packetplayinabilities) {
PlayerConnectionUtils.ensureMainThread(packetplayinabilities, this, this.player.getWorldServer());
@@ -1654,7 +1665,7 @@
}
@Override
@@ -1414,8 +2514,50 @@
@@ -1548,8 +2659,50 @@
this.player.a(packetplayinsettings);
}