Commits

Thinkofname authored ea28011f10c
SPIGOT-697: Force metadata updates when interact events are cancelled
No tags

nms-patches/PlayerConnection.patch

Modified
1 ---- /home/matt/mc-dev-private//net/minecraft/server/PlayerConnection.java 2015-04-15 16:28:51.340916968 +0100
2 -+++ src/main/java/net/minecraft/server/PlayerConnection.java 2015-04-15 16:28:51.344916968 +0100
1 +--- /home/matt/mc-dev-private//net/minecraft/server/PlayerConnection.java 2015-04-15 17:35:03.688828804 +0100
2 ++++ src/main/java/net/minecraft/server/PlayerConnection.java 2015-04-15 17:35:03.692828804 +0100
3 3 @@ -17,6 +17,48 @@
4 4 import org.apache.logging.log4j.LogManager;
5 5 import org.apache.logging.log4j.Logger;
6 6
7 7 +// CraftBukkit start
8 8 +import java.util.concurrent.ExecutionException;
9 9 +import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
10 10 +import java.util.HashSet;
11 11 +
12 12 +import org.bukkit.craftbukkit.entity.CraftPlayer;
892 892
893 893 case 6:
894 894 @@ -640,6 +1188,7 @@
895 895 }
896 896
897 897 public void a(PacketPlayInUseEntity packetplayinuseentity) {
898 898 + if (this.player.dead) return; // CraftBukkit
899 899 PlayerConnectionUtils.ensureMainThread(packetplayinuseentity, this, this.player.u());
900 900 WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
901 901 Entity entity = packetplayinuseentity.a((World) worldserver);
902 -@@ -654,18 +1203,71 @@
902 +@@ -654,18 +1203,67 @@
903 903 }
904 904
905 905 if (this.player.h(entity) < d0) {
906 906 + ItemStack itemInHand = this.player.inventory.getItemInHand(); // CraftBukkit
907 907 +
908 908 + if (packetplayinuseentity.a() == PacketPlayInUseEntity.EnumEntityUseAction.INTERACT
909 909 + || packetplayinuseentity.a() == PacketPlayInUseEntity.EnumEntityUseAction.INTERACT_AT) {
910 910 + // CraftBukkit start
911 -+ boolean triggerTagUpdate = itemInHand != null && itemInHand.getItem() == Items.NAME_TAG && entity instanceof EntityInsentient;
912 -+ boolean triggerChestUpdate = itemInHand != null && itemInHand.getItem() == Item.getItemOf(Blocks.CHEST) && entity instanceof EntityHorse;
913 911 + boolean triggerLeashUpdate = itemInHand != null && itemInHand.getItem() == Items.LEAD && entity instanceof EntityInsentient;
912 ++ Item origItem = this.player.inventory.getItemInHand() == null ? null : this.player.inventory.getItemInHand().getItem();
914 913 + PlayerInteractEntityEvent event;
915 914 + if (packetplayinuseentity.a() == PacketPlayInUseEntity.EnumEntityUseAction.INTERACT) {
916 915 + event = new PlayerInteractEntityEvent((Player) this.getPlayer(), entity.getBukkitEntity());
917 916 + } else {
918 917 + Vec3D target = packetplayinuseentity.b();
919 918 + event = new PlayerInteractAtEntityEvent((Player) this.getPlayer(), entity.getBukkitEntity(), new org.bukkit.util.Vector(target.a, target.b, target.c));
920 919 + }
921 920 + this.server.getPluginManager().callEvent(event);
922 921 +
923 922 + if (triggerLeashUpdate && (event.isCancelled() || this.player.inventory.getItemInHand() == null || this.player.inventory.getItemInHand().getItem() != Items.LEAD)) {
924 923 + // Refresh the current leash state
925 924 + this.sendPacket(new PacketPlayOutAttachEntity(1, entity, ((EntityInsentient) entity).getLeashHolder()));
926 925 + }
927 926 +
928 -+ if (triggerTagUpdate && (event.isCancelled() || this.player.inventory.getItemInHand() == null || this.player.inventory.getItemInHand().getItem() != Items.NAME_TAG)) {
927 ++ if (event.isCancelled() || this.player.inventory.getItemInHand() == null || this.player.inventory.getItemInHand().getItem() != origItem) {
929 928 + // Refresh the current entity metadata
930 929 + this.sendPacket(new PacketPlayOutEntityMetadata(entity.getId(), entity.datawatcher, true));
931 930 + }
932 -+ if (triggerChestUpdate && (event.isCancelled() || this.player.inventory.getItemInHand() == null || this.player.inventory.getItemInHand().getItem() != Item.getItemOf(Blocks.CHEST))) {
933 -+ this.sendPacket(new PacketPlayOutEntityMetadata(entity.getId(), entity.datawatcher, true));
934 -+ }
935 931 +
936 932 + if (event.isCancelled()) {
937 933 + return;
938 934 + }
939 935 + // CraftBukkit end
940 936 + }
941 937 if (packetplayinuseentity.a() == PacketPlayInUseEntity.EnumEntityUseAction.INTERACT) {
942 938 this.player.u(entity);
943 939 +
944 940 + // CraftBukkit start
965 961 this.player.attack(entity);
966 962 +
967 963 + // CraftBukkit start
968 964 + if (itemInHand != null && itemInHand.count <= -1) {
969 965 + this.player.updateInventory(this.player.activeContainer);
970 966 + }
971 967 + // CraftBukkit end
972 968 }
973 969 }
974 970 }
975 -@@ -680,7 +1282,8 @@
971 +@@ -680,7 +1278,8 @@
976 972 switch (PlayerConnection.SyntheticClass_1.c[packetplayinclientcommand_enumclientcommand.ordinal()]) {
977 973 case 1:
978 974 if (this.player.viewingCredits) {
979 975 - this.player = this.minecraftServer.getPlayerList().moveToWorld(this.player, 0, true);
980 976 + // this.player = this.minecraftServer.getPlayerList().moveToWorld(this.player, 0, true);
981 977 + this.minecraftServer.getPlayerList().changeDimension(this.player, 0, PlayerTeleportEvent.TeleportCause.END_PORTAL); // CraftBukkit - reroute logic through custom portal management
982 978 } else if (this.player.u().getWorldData().isHardcore()) {
983 979 if (this.minecraftServer.S() && this.player.getName().equals(this.minecraftServer.R())) {
984 980 this.player.playerConnection.disconnect("You have died. Game over, man, it\'s game over!");
985 -@@ -711,15 +1314,21 @@
981 +@@ -711,15 +1310,21 @@
986 982 }
987 983
988 984 public void a(PacketPlayInCloseWindow packetplayinclosewindow) {
989 985 + if (this.player.dead) return; // CraftBukkit
990 986 PlayerConnectionUtils.ensureMainThread(packetplayinclosewindow, this, this.player.u());
991 987 +
992 988 + CraftEventFactory.handleInventoryCloseEvent(this.player); // CraftBukkit
993 989 +
994 990 this.player.p();
995 991 }
998 994 + if (this.player.dead) return; // CraftBukkit
999 995 PlayerConnectionUtils.ensureMainThread(packetplayinwindowclick, this, this.player.u());
1000 996 this.player.z();
1001 997 if (this.player.activeContainer.windowId == packetplayinwindowclick.a() && this.player.activeContainer.c(this.player)) {
1002 998 - if (this.player.v()) {
1003 999 + boolean cancelled = this.player.v(); // CraftBukkit - see below if
1004 1000 + if (false) { // CraftBukkit this.player.v()) {
1005 1001 ArrayList arraylist = Lists.newArrayList();
1006 1002
1007 1003 for (int i = 0; i < this.player.activeContainer.c.size(); ++i) {
1008 -@@ -728,7 +1337,270 @@
1004 +@@ -728,7 +1333,270 @@
1009 1005
1010 1006 this.player.a(this.player.activeContainer, (List) arraylist);
1011 1007 } else {
1012 1008 - ItemStack itemstack = this.player.activeContainer.clickItem(packetplayinwindowclick.b(), packetplayinwindowclick.c(), packetplayinwindowclick.f(), this.player);
1013 1009 + // ItemStack itemstack = this.player.activeContainer.clickItem(packetplayinwindowclick.b(), packetplayinwindowclick.c(), packetplayinwindowclick.f(), this.player);
1014 1010 + // CraftBukkit start - Call InventoryClickEvent
1015 1011 + if (packetplayinwindowclick.b() < -1 && packetplayinwindowclick.b() != -999) {
1016 1012 + return;
1017 1013 + }
1018 1014 +
1270 1266 + if (event instanceof CraftItemEvent) {
1271 1267 + // Need to update the inventory on crafting to
1272 1268 + // correctly support custom recipes
1273 1269 + player.updateInventory(player.activeContainer);
1274 1270 + }
1275 1271 + }
1276 1272 + // CraftBukkit end
1277 1273
1278 1274 if (ItemStack.matches(packetplayinwindowclick.e(), itemstack)) {
1279 1275 this.player.playerConnection.sendPacket(new PacketPlayOutTransaction(packetplayinwindowclick.a(), packetplayinwindowclick.d(), true));
1280 -@@ -789,8 +1661,48 @@
1276 +@@ -789,8 +1657,48 @@
1281 1277 }
1282 1278
1283 1279 boolean flag1 = packetplayinsetcreativeslot.a() >= 1 && packetplayinsetcreativeslot.a() < 36 + PlayerInventory.getHotbarSize();
1284 1280 - boolean flag2 = itemstack == null || itemstack.getItem() != null;
1285 1281 + // CraftBukkit - Add invalidItems check
1286 1282 + boolean flag2 = itemstack == null || itemstack.getItem() != null && !invalidItems.contains(Item.getId(itemstack.getItem()));
1287 1283 boolean flag3 = itemstack == null || itemstack.getData() >= 0 && itemstack.count <= 64 && itemstack.count > 0;
1288 1284 + // CraftBukkit start - Call click event
1289 1285 + if (flag || (flag1 && !ItemStack.matches(this.player.defaultContainer.getSlot(packetplayinsetcreativeslot.a()).getItem(), packetplayinsetcreativeslot.getItemStack()))) { // Insist on valid slot
1290 1286 +
1320 1316 + this.player.playerConnection.sendPacket(new PacketPlayOutSetSlot(this.player.defaultContainer.windowId, packetplayinsetcreativeslot.a(), this.player.defaultContainer.getSlot(packetplayinsetcreativeslot.a()).getItem()));
1321 1317 + this.player.playerConnection.sendPacket(new PacketPlayOutSetSlot(-1, -1, null));
1322 1318 + }
1323 1319 + return;
1324 1320 + }
1325 1321 + }
1326 1322 + // CraftBukkit end
1327 1323
1328 1324 if (flag1 && flag2 && flag3) {
1329 1325 if (itemstack == null) {
1330 -@@ -813,6 +1725,7 @@
1326 +@@ -813,6 +1721,7 @@
1331 1327 }
1332 1328
1333 1329 public void a(PacketPlayInTransaction packetplayintransaction) {
1334 1330 + if (this.player.dead) return; // CraftBukkit
1335 1331 PlayerConnectionUtils.ensureMainThread(packetplayintransaction, this, this.player.u());
1336 1332 Short oshort = (Short) this.n.get(this.player.activeContainer.windowId);
1337 1333
1338 -@@ -823,6 +1736,7 @@
1334 +@@ -823,6 +1732,7 @@
1339 1335 }
1340 1336
1341 1337 public void a(PacketPlayInUpdateSign packetplayinupdatesign) {
1342 1338 + if (this.player.dead) return; // CraftBukkit
1343 1339 PlayerConnectionUtils.ensureMainThread(packetplayinupdatesign, this, this.player.u());
1344 1340 this.player.z();
1345 1341 WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
1346 -@@ -839,14 +1753,30 @@
1342 +@@ -839,14 +1749,30 @@
1347 1343
1348 1344 if (!tileentitysign.b() || tileentitysign.c() != this.player) {
1349 1345 this.minecraftServer.warning("Player " + this.player.getName() + " just tried to change non-editable sign");
1350 1346 + this.sendPacket(new PacketPlayOutUpdateSign(tileentity.world, packetplayinupdatesign.a(), tileentitysign.lines)); // CraftBukkit
1351 1347 return;
1352 1348 }
1353 1349
1354 1350 IChatBaseComponent[] aichatbasecomponent = packetplayinupdatesign.b();
1355 1351
1356 1352 + // CraftBukkit start
1368 1364 +
1369 1365 + if (!event.isCancelled()) {
1370 1366 + System.arraycopy(org.bukkit.craftbukkit.block.CraftSign.sanitizeLines(event.getLines()), 0, tileentitysign.lines, 0, 4);
1371 1367 + tileentitysign.isEditable = false;
1372 1368 }
1373 1369 + // System.arraycopy(packetplayinupdatesign.b(), 0, tileentitysign.lines, 0, 4);
1374 1370 + // CraftBukkit end
1375 1371
1376 1372 tileentitysign.update();
1377 1373 worldserver.notify(blockposition);
1378 -@@ -869,11 +1799,27 @@
1374 +@@ -869,11 +1795,27 @@
1379 1375
1380 1376 public void a(PacketPlayInAbilities packetplayinabilities) {
1381 1377 PlayerConnectionUtils.ensureMainThread(packetplayinabilities, this, this.player.u());
1382 1378 - this.player.abilities.isFlying = packetplayinabilities.isFlying() && this.player.abilities.canFly;
1383 1379 + // CraftBukkit start
1384 1380 + if (this.player.abilities.canFly && this.player.abilities.isFlying != packetplayinabilities.isFlying()) {
1385 1381 + PlayerToggleFlightEvent event = new PlayerToggleFlightEvent(this.server.getPlayer(this.player), packetplayinabilities.isFlying());
1386 1382 + this.server.getPluginManager().callEvent(event);
1387 1383 + if (!event.isCancelled()) {
1388 1384 + this.player.abilities.isFlying = packetplayinabilities.isFlying(); // Actually set the player's flying status
1397 1393 PlayerConnectionUtils.ensureMainThread(packetplayintabcomplete, this, this.player.u());
1398 1394 + // CraftBukkit start
1399 1395 + if (chatSpamField.addAndGet(this, 10) > 500 && !this.minecraftServer.getPlayerList().isOp(this.player.getProfile())) {
1400 1396 + this.disconnect("disconnect.spam");
1401 1397 + return;
1402 1398 + }
1403 1399 + // CraftBukkit end
1404 1400 ArrayList arraylist = Lists.newArrayList();
1405 1401 Iterator iterator = this.minecraftServer.tabCompleteCommand(this.player, packetplayintabcomplete.a(), packetplayintabcomplete.b()).iterator();
1406 1402
1407 -@@ -913,13 +1859,16 @@
1403 +@@ -913,13 +1855,16 @@
1408 1404 itemstack1 = this.player.inventory.getItemInHand();
1409 1405 if (itemstack1 != null) {
1410 1406 if (itemstack.getItem() == Items.WRITABLE_BOOK && itemstack.getItem() == itemstack1.getItem()) {
1411 1407 + itemstack1 = new ItemStack(Items.WRITABLE_BOOK); // CraftBukkit
1412 1408 itemstack1.a("pages", (NBTBase) itemstack.getTag().getList("pages", 8));
1413 1409 + CraftEventFactory.handleEditBookEvent(player, itemstack1); // CraftBukkit
1414 1410 }
1415 1411
1416 1412 return;
1417 1413 }
1418 1414 } catch (Exception exception) {
1419 1415 PlayerConnection.c.error("Couldn\'t handle book info", exception);
1420 1416 + this.disconnect("Invalid book data!"); // CraftBukkit
1421 1417 return;
1422 1418 } finally {
1423 1419 packetdataserializer.release();
1424 -@@ -942,16 +1891,21 @@
1420 +@@ -942,16 +1887,21 @@
1425 1421 itemstack1 = this.player.inventory.getItemInHand();
1426 1422 if (itemstack1 != null) {
1427 1423 if (itemstack.getItem() == Items.WRITTEN_BOOK && itemstack1.getItem() == Items.WRITABLE_BOOK) {
1428 1424 + // CraftBukkit start
1429 1425 + itemstack1 = new ItemStack(Items.WRITTEN_BOOK);
1430 1426 itemstack1.a("author", (NBTBase) (new NBTTagString(this.player.getName())));
1431 1427 itemstack1.a("title", (NBTBase) (new NBTTagString(itemstack.getTag().getString("title"))));
1432 1428 itemstack1.a("pages", (NBTBase) itemstack.getTag().getList("pages", 8));
1433 1429 itemstack1.setItem(Items.WRITTEN_BOOK);
1434 1430 + CraftEventFactory.handleEditBookEvent(player, itemstack1);
1435 1431 + // CraftBukkit end
1436 1432 }
1437 1433
1438 1434 return;
1439 1435 }
1440 1436 } catch (Exception exception1) {
1441 1437 PlayerConnection.c.error("Couldn\'t sign book", exception1);
1442 1438 + this.disconnect("Invalid book data!"); // CraftBukkit
1443 1439 return;
1444 1440 } finally {
1445 1441 packetdataserializer.release();
1446 -@@ -968,11 +1922,12 @@
1442 +@@ -968,11 +1918,12 @@
1447 1443 }
1448 1444 } catch (Exception exception2) {
1449 1445 PlayerConnection.c.error("Couldn\'t select trade", exception2);
1450 1446 + this.disconnect("Invalid trade data!"); // CraftBukkit
1451 1447 }
1452 1448 } else if ("MC|AdvCdm".equals(packetplayincustompayload.a())) {
1453 1449 if (!this.minecraftServer.getEnableCommandBlock()) {
1454 1450 this.player.sendMessage(new ChatMessage("advMode.notEnabled", new Object[0]));
1455 1451 - } else if (this.player.a(2, "") && this.player.abilities.canInstantlyBuild) {
1456 1452 + } else if (this.player.getBukkitEntity().isOp() && this.player.abilities.canInstantlyBuild) { // CraftBukkit - Change to Bukkit OP versus Vanilla OP
1457 1453 packetdataserializer = packetplayincustompayload.b();
1458 1454
1459 1455 try {
1460 -@@ -1008,6 +1963,7 @@
1456 +@@ -1008,6 +1959,7 @@
1461 1457 }
1462 1458 } catch (Exception exception3) {
1463 1459 PlayerConnection.c.error("Couldn\'t set command block", exception3);
1464 1460 + this.disconnect("Invalid CommandBlock data!"); // CraftBukkit
1465 1461 } finally {
1466 1462 packetdataserializer.release();
1467 1463 }
1468 -@@ -1033,6 +1989,7 @@
1464 +@@ -1033,6 +1985,7 @@
1469 1465 }
1470 1466 } catch (Exception exception4) {
1471 1467 PlayerConnection.c.error("Couldn\'t set beacon", exception4);
1472 1468 + this.disconnect("Invalid beacon data!"); // CraftBukkit
1473 1469 }
1474 1470 }
1475 1471 } else if ("MC|ItemName".equals(packetplayincustompayload.a()) && this.player.activeContainer instanceof ContainerAnvil) {
1476 -@@ -1048,7 +2005,28 @@
1472 +@@ -1048,7 +2001,28 @@
1477 1473 containeranvil.a("");
1478 1474 }
1479 1475 }
1480 1476 + // CraftBukkit start
1481 1477 + else if (packetplayincustompayload.a().equals("REGISTER")) {
1482 1478 + String channels = packetplayincustompayload.b().toString(com.google.common.base.Charsets.UTF_8);
1483 1479 + for (String channel : channels.split("\0")) {
1484 1480 + getPlayer().addChannel(channel);
1485 1481 + }
1486 1482 + } else if (packetplayincustompayload.a().equals("UNREGISTER")) {

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut