SPIGOT-6122: Revert "SPIGOT-5794: Do not skip PlayerInteractEvent"

This reverts commit 00bff02703.
This commit is contained in:
md_5 2020-09-04 06:39:01 +10:00
parent 1d74403327
commit a05df28a78
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
2 changed files with 40 additions and 32 deletions

View File

@ -682,7 +682,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)) {
@@ -855,12 +1263,46 @@
@@ -855,12 +1263,51 @@
@Override
public void a(PacketPlayInBlockPlace packetplayinblockplace) {
PlayerConnectionUtils.ensureMainThread(packetplayinblockplace, this, this.player.getWorldServer());
@ -717,9 +717,14 @@
+ org.bukkit.event.player.PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.RIGHT_CLICK_AIR, itemstack, enumhand);
+ cancelled = event.useItemInHand() == Event.Result.DENY;
+ } else {
+ MovingObjectPositionBlock movingobjectpositionblock = (MovingObjectPositionBlock) movingobjectposition;
+ org.bukkit.event.player.PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, movingobjectpositionblock.getBlockPosition(), movingobjectpositionblock.getDirection(), itemstack, true, enumhand);
+ cancelled = event.useItemInHand() == Event.Result.DENY;
+ if (player.playerInteractManager.firedInteract) {
+ player.playerInteractManager.firedInteract = false;
+ cancelled = player.playerInteractManager.interactResult;
+ } else {
+ MovingObjectPositionBlock movingobjectpositionblock = (MovingObjectPositionBlock) movingobjectposition;
+ org.bukkit.event.player.PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, movingobjectpositionblock.getBlockPosition(), movingobjectpositionblock.getDirection(), itemstack, true, enumhand);
+ cancelled = event.useItemInHand() == Event.Result.DENY;
+ }
+ }
+
+ if (cancelled) {
@ -729,7 +734,7 @@
EnumInteractionResult enuminteractionresult = this.player.playerInteractManager.a(this.player, worldserver, itemstack, enumhand);
if (enuminteractionresult.b()) {
@@ -881,7 +1323,7 @@
@@ -881,7 +1328,7 @@
Entity entity = packetplayinspectate.a(worldserver);
if (entity != null) {
@ -738,7 +743,7 @@
return;
}
}
@@ -890,7 +1332,12 @@
@@ -890,7 +1337,12 @@
}
@Override
@ -752,7 +757,7 @@
@Override
public void a(PacketPlayInBoatMove packetplayinboatmove) {
@@ -905,11 +1352,26 @@
@@ -905,11 +1357,26 @@
@Override
public void a(IChatBaseComponent ichatbasecomponent) {
@ -780,7 +785,7 @@
if (this.isExemptPlayer()) {
PlayerConnection.LOGGER.info("Stopping singleplayer server as player logged out");
this.minecraftServer.safeShutdown(false);
@@ -935,6 +1397,15 @@
@@ -935,6 +1402,15 @@
}
}
@ -796,7 +801,7 @@
try {
this.networkManager.sendPacket(packet, genericfuturelistener);
} catch (Throwable throwable) {
@@ -951,7 +1422,16 @@
@@ -951,7 +1427,16 @@
@Override
public void a(PacketPlayInHeldItemSlot packetplayinhelditemslot) {
PlayerConnectionUtils.ensureMainThread(packetplayinhelditemslot, this, this.player.getWorldServer());
@ -813,7 +818,7 @@
if (this.player.inventory.itemInHandIndex != packetplayinhelditemslot.b() && this.player.getRaisedHand() == EnumHand.MAIN_HAND) {
this.player.clearActiveItem();
}
@@ -960,13 +1440,24 @@
@@ -960,13 +1445,24 @@
this.player.resetIdleTimer();
} else {
PlayerConnection.LOGGER.warn("{} tried to set an invalid carried item", this.player.getDisplayName().getString());
@ -840,7 +845,7 @@
this.sendPacket(new PacketPlayOutChat((new ChatMessage("chat.cannotSend")).a(EnumChatFormat.RED), ChatMessageType.SYSTEM, SystemUtils.b));
} else {
this.player.resetIdleTimer();
@@ -974,41 +1465,254 @@
@@ -974,41 +1470,254 @@
for (int i = 0; i < s.length(); ++i) {
if (!SharedConstants.isAllowedChatCharacter(s.charAt(i))) {
@ -1102,7 +1107,7 @@
this.player.resetIdleTimer();
IJumpable ijumpable;
@@ -1066,6 +1770,7 @@
@@ -1066,6 +1775,7 @@
@Override
public void a(PacketPlayInUseEntity packetplayinuseentity) {
PlayerConnectionUtils.ensureMainThread(packetplayinuseentity, this, this.player.getWorldServer());
@ -1110,7 +1115,7 @@
WorldServer worldserver = this.player.getWorldServer();
Entity entity = packetplayinuseentity.a((World) worldserver);
@@ -1079,18 +1784,72 @@
@@ -1079,18 +1789,72 @@
ItemStack itemstack = enumhand != null ? this.player.b(enumhand).cloneItemStack() : ItemStack.b;
Optional<EnumInteractionResult> optional = Optional.empty();
@ -1184,7 +1189,7 @@
}
if (optional.isPresent() && ((EnumInteractionResult) optional.get()).a()) {
@@ -1137,15 +1896,21 @@
@@ -1137,15 +1901,21 @@
@Override
public void a(PacketPlayInCloseWindow packetplayinclosewindow) {
PlayerConnectionUtils.ensureMainThread(packetplayinclosewindow, this, this.player.getWorldServer());
@ -1208,7 +1213,7 @@
NonNullList<ItemStack> nonnulllist = NonNullList.a();
for (int i = 0; i < this.player.activeContainer.slots.size(); ++i) {
@@ -1154,8 +1919,274 @@
@@ -1154,8 +1924,274 @@
this.player.a(this.player.activeContainer, nonnulllist);
} else {
@ -1220,7 +1225,7 @@
+
+ InventoryView inventory = this.player.activeContainer.getBukkitView();
+ SlotType type = inventory.getSlotType(packetplayinwindowclick.c());
+
+ InventoryClickEvent event;
+ ClickType click = ClickType.UNKNOWN;
+ InventoryAction action = InventoryAction.UNKNOWN;
@ -1417,7 +1422,7 @@
+ if (this.player.activeContainer != oldContainer) {
+ return;
+ }
+
+ switch (event.getResult()) {
+ case ALLOW:
+ case DEFAULT:
@ -1484,7 +1489,7 @@
if (ItemStack.matches(packetplayinwindowclick.f(), itemstack)) {
this.player.playerConnection.sendPacket(new PacketPlayOutTransaction(packetplayinwindowclick.b(), packetplayinwindowclick.e(), true));
this.player.e = true;
@@ -1195,6 +2226,7 @@
@@ -1195,6 +2231,7 @@
@Override
public void a(PacketPlayInEnchantItem packetplayinenchantitem) {
PlayerConnectionUtils.ensureMainThread(packetplayinenchantitem, this, this.player.getWorldServer());
@ -1492,7 +1497,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());
@@ -1227,6 +2259,43 @@
@@ -1227,6 +2264,43 @@
boolean flag1 = packetplayinsetcreativeslot.b() >= 1 && packetplayinsetcreativeslot.b() <= 45;
boolean flag2 = itemstack.isEmpty() || itemstack.getDamage() >= 0 && itemstack.getCount() <= 64 && !itemstack.isEmpty();
@ -1536,7 +1541,7 @@
if (flag1 && flag2) {
if (itemstack.isEmpty()) {
@@ -1248,6 +2317,7 @@
@@ -1248,6 +2322,7 @@
@Override
public void a(PacketPlayInTransaction packetplayintransaction) {
PlayerConnectionUtils.ensureMainThread(packetplayintransaction, this, this.player.getWorldServer());
@ -1544,7 +1549,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()) {
@@ -1259,6 +2329,7 @@
@@ -1259,6 +2334,7 @@
@Override
public void a(PacketPlayInUpdateSign packetplayinupdatesign) {
PlayerConnectionUtils.ensureMainThread(packetplayinupdatesign, this, this.player.getWorldServer());
@ -1552,7 +1557,7 @@
this.player.resetIdleTimer();
WorldServer worldserver = this.player.getWorldServer();
BlockPosition blockposition = packetplayinupdatesign.b();
@@ -1275,14 +2346,30 @@
@@ -1275,14 +2351,30 @@
if (!tileentitysign.d() || tileentitysign.f() != this.player) {
PlayerConnection.LOGGER.warn("Player {} just tried to change non-editable sign", this.player.getDisplayName().getString());
@ -1584,7 +1589,7 @@
tileentitysign.update();
worldserver.notify(blockposition, iblockdata, iblockdata, 3);
@@ -1292,6 +2379,7 @@
@@ -1292,6 +2384,7 @@
@Override
public void a(PacketPlayInKeepAlive packetplayinkeepalive) {
@ -1592,7 +1597,7 @@
if (this.awaitingKeepAlive && packetplayinkeepalive.b() == this.h) {
int i = (int) (SystemUtils.getMonotonicMillis() - this.lastKeepAlive);
@@ -1306,7 +2394,17 @@
@@ -1306,7 +2399,17 @@
@Override
public void a(PacketPlayInAbilities packetplayinabilities) {
PlayerConnectionUtils.ensureMainThread(packetplayinabilities, this, this.player.getWorldServer());
@ -1611,7 +1616,7 @@
}
@Override
@@ -1315,8 +2413,50 @@
@@ -1315,8 +2418,50 @@
this.player.a(packetplayinsettings);
}

View File

@ -162,10 +162,10 @@
+ if (nmsBlock != null && !event.isCancelled() && !this.isCreative() && this.player.hasBlock(nmsBlock.getBlockData())) {
+ event.setExpToDrop(nmsBlock.getExpDrop(nmsData, this.world, blockposition, itemstack));
+ }
+
+ this.world.getServer().getPluginManager().callEvent(event);
- if (!this.player.getItemInMainHand().getItem().a(iblockdata, (World) this.world, blockposition, (EntityHuman) this.player)) {
+ this.world.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ if (isSwordNoBreak) {
+ return false;
@ -243,11 +243,13 @@
}
}
}
@@ -287,12 +423,37 @@
@@ -287,12 +423,40 @@
}
}
+ // CraftBukkit start - whole method
+ public boolean interactResult = false;
+ public boolean firedInteract = false;
public EnumInteractionResult a(EntityPlayer entityplayer, World world, ItemStack itemstack, EnumHand enumhand, MovingObjectPositionBlock movingobjectpositionblock) {
BlockPosition blockposition = movingobjectpositionblock.getBlockPosition();
IBlockData iblockdata = world.getType(blockposition);
@ -264,7 +266,8 @@
+ }
+
+ PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(entityplayer, Action.RIGHT_CLICK_BLOCK, blockposition, movingobjectpositionblock.getDirection(), itemstack, cancelledBlock, enumhand);
+ boolean interactResult = event.useItemInHand() == Event.Result.DENY;
+ firedInteract = true;
+ interactResult = event.useItemInHand() == Event.Result.DENY;
+
+ if (event.useInteractedBlock() == Event.Result.DENY) {
+ // If we denied a door from opening, we need to send a correcting update to the client, as it already opened the door.
@ -281,7 +284,7 @@
if (itileinventory != null) {
entityplayer.openContainer(itileinventory);
@@ -306,7 +467,7 @@
@@ -306,7 +470,7 @@
ItemStack itemstack1 = itemstack.cloneItemStack();
if (!flag1) {
@ -290,7 +293,7 @@
if (enuminteractionresult.a()) {
CriterionTriggers.M.a(entityplayer, blockposition, itemstack1);
@@ -314,17 +475,17 @@
@@ -314,17 +478,17 @@
}
}
@ -311,7 +314,7 @@
}
if (enuminteractionresult1.a()) {
@@ -332,10 +493,10 @@
@@ -332,10 +496,10 @@
}
return enuminteractionresult1;