SPIGOT-5794: Do not skip PlayerInteractEvent

This commit is contained in:
Brokkonaut 2020-08-29 14:07:32 +10:00 committed by md_5
parent 3f572834a6
commit 00bff02703
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
2 changed files with 32 additions and 40 deletions

View File

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

View File

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