3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 20:40:08 +01:00

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

This reverts commit 00bff02703.
Dieser Commit ist enthalten in:
md_5 2020-09-04 06:39:01 +10:00
Ursprung 1d74403327
Commit a05df28a78
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: E8E901AC7C617C11
2 geänderte Dateien mit 40 neuen und 32 gelöschten Zeilen

Datei anzeigen

@ -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,46 @@ @@ -855,12 +1263,51 @@
@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,9 +717,14 @@
+ 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 {
+ MovingObjectPositionBlock movingobjectpositionblock = (MovingObjectPositionBlock) movingobjectposition; + if (player.playerInteractManager.firedInteract) {
+ org.bukkit.event.player.PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, movingobjectpositionblock.getBlockPosition(), movingobjectpositionblock.getDirection(), itemstack, true, enumhand); + player.playerInteractManager.firedInteract = false;
+ cancelled = event.useItemInHand() == Event.Result.DENY; + 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) { + if (cancelled) {
@ -729,7 +734,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 +1323,7 @@ @@ -881,7 +1328,7 @@
Entity entity = packetplayinspectate.a(worldserver); Entity entity = packetplayinspectate.a(worldserver);
if (entity != null) { if (entity != null) {
@ -738,7 +743,7 @@
return; return;
} }
} }
@@ -890,7 +1332,12 @@ @@ -890,7 +1337,12 @@
} }
@Override @Override
@ -752,7 +757,7 @@
@Override @Override
public void a(PacketPlayInBoatMove packetplayinboatmove) { public void a(PacketPlayInBoatMove packetplayinboatmove) {
@@ -905,11 +1352,26 @@ @@ -905,11 +1357,26 @@
@Override @Override
public void a(IChatBaseComponent ichatbasecomponent) { public void a(IChatBaseComponent ichatbasecomponent) {
@ -780,7 +785,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 +1397,15 @@ @@ -935,6 +1402,15 @@
} }
} }
@ -796,7 +801,7 @@
try { try {
this.networkManager.sendPacket(packet, genericfuturelistener); this.networkManager.sendPacket(packet, genericfuturelistener);
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -951,7 +1422,16 @@ @@ -951,7 +1427,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());
@ -813,7 +818,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 +1440,24 @@ @@ -960,13 +1445,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());
@ -840,7 +845,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 +1465,254 @@ @@ -974,41 +1470,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))) {
@ -1102,7 +1107,7 @@
this.player.resetIdleTimer(); this.player.resetIdleTimer();
IJumpable ijumpable; IJumpable ijumpable;
@@ -1066,6 +1770,7 @@ @@ -1066,6 +1775,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());
@ -1110,7 +1115,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 +1784,72 @@ @@ -1079,18 +1789,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();
@ -1184,7 +1189,7 @@
} }
if (optional.isPresent() && ((EnumInteractionResult) optional.get()).a()) { if (optional.isPresent() && ((EnumInteractionResult) optional.get()).a()) {
@@ -1137,15 +1896,21 @@ @@ -1137,15 +1901,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());
@ -1208,7 +1213,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 +1919,274 @@ @@ -1154,8 +1924,274 @@
this.player.a(this.player.activeContainer, nonnulllist); this.player.a(this.player.activeContainer, nonnulllist);
} else { } else {
@ -1220,7 +1225,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;
@ -1417,7 +1422,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:
@ -1484,7 +1489,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 +2226,7 @@ @@ -1195,6 +2231,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());
@ -1492,7 +1497,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 +2259,43 @@ @@ -1227,6 +2264,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();
@ -1536,7 +1541,7 @@
if (flag1 && flag2) { if (flag1 && flag2) {
if (itemstack.isEmpty()) { if (itemstack.isEmpty()) {
@@ -1248,6 +2317,7 @@ @@ -1248,6 +2322,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());
@ -1544,7 +1549,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 +2329,7 @@ @@ -1259,6 +2334,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());
@ -1552,7 +1557,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 +2346,30 @@ @@ -1275,14 +2351,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());
@ -1584,7 +1589,7 @@
tileentitysign.update(); tileentitysign.update();
worldserver.notify(blockposition, iblockdata, iblockdata, 3); worldserver.notify(blockposition, iblockdata, iblockdata, 3);
@@ -1292,6 +2379,7 @@ @@ -1292,6 +2384,7 @@
@Override @Override
public void a(PacketPlayInKeepAlive packetplayinkeepalive) { public void a(PacketPlayInKeepAlive packetplayinkeepalive) {
@ -1592,7 +1597,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 +2394,17 @@ @@ -1306,7 +2399,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());
@ -1611,7 +1616,7 @@
} }
@Override @Override
@@ -1315,8 +2413,50 @@ @@ -1315,8 +2418,50 @@
this.player.a(packetplayinsettings); this.player.a(packetplayinsettings);
} }

Datei anzeigen

@ -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,11 +243,13 @@
} }
} }
} }
@@ -287,12 +423,37 @@ @@ -287,12 +423,40 @@
} }
} }
+ // 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);
@ -264,7 +266,8 @@
+ } + }
+ +
+ 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);
+ boolean interactResult = event.useItemInHand() == Event.Result.DENY; + firedInteract = true;
+ 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.
@ -281,7 +284,7 @@
if (itileinventory != null) { if (itileinventory != null) {
entityplayer.openContainer(itileinventory); entityplayer.openContainer(itileinventory);
@@ -306,7 +467,7 @@ @@ -306,7 +470,7 @@
ItemStack itemstack1 = itemstack.cloneItemStack(); ItemStack itemstack1 = itemstack.cloneItemStack();
if (!flag1) { if (!flag1) {
@ -290,7 +293,7 @@
if (enuminteractionresult.a()) { if (enuminteractionresult.a()) {
CriterionTriggers.M.a(entityplayer, blockposition, itemstack1); CriterionTriggers.M.a(entityplayer, blockposition, itemstack1);
@@ -314,17 +475,17 @@ @@ -314,17 +478,17 @@
} }
} }
@ -311,7 +314,7 @@
} }
if (enuminteractionresult1.a()) { if (enuminteractionresult1.a()) {
@@ -332,10 +493,10 @@ @@ -332,10 +496,10 @@
} }
return enuminteractionresult1; return enuminteractionresult1;