SPIGOT-7979: PlayerInteractEvent does not fire in Adventure mode for LEFT_CLICK_BLOCK actions
This commit is contained in:
parent
669b413938
commit
57f48e54c2
@ -8,7 +8,6 @@
|
|||||||
+import com.mojang.datafixers.util.Pair;
|
+import com.mojang.datafixers.util.Pair;
|
||||||
+import java.util.Arrays;
|
+import java.util.Arrays;
|
||||||
+import java.util.concurrent.ExecutionException;
|
+import java.util.concurrent.ExecutionException;
|
||||||
+import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
+import java.util.function.Function;
|
+import java.util.function.Function;
|
||||||
+import net.minecraft.network.chat.OutgoingChatMessage;
|
+import net.minecraft.network.chat.OutgoingChatMessage;
|
||||||
+import net.minecraft.network.protocol.game.PacketPlayOutAttachEntity;
|
+import net.minecraft.network.protocol.game.PacketPlayOutAttachEntity;
|
||||||
@ -25,6 +24,7 @@
|
|||||||
+import net.minecraft.world.level.RayTrace;
|
+import net.minecraft.world.level.RayTrace;
|
||||||
+import net.minecraft.world.phys.MovingObjectPosition;
|
+import net.minecraft.world.phys.MovingObjectPosition;
|
||||||
+import org.bukkit.Location;
|
+import org.bukkit.Location;
|
||||||
|
+import org.bukkit.block.Block;
|
||||||
+import org.bukkit.craftbukkit.CraftInput;
|
+import org.bukkit.craftbukkit.CraftInput;
|
||||||
+import org.bukkit.craftbukkit.entity.CraftEntity;
|
+import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||||
+import org.bukkit.craftbukkit.entity.CraftPlayer;
|
+import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||||
@ -34,7 +34,6 @@
|
|||||||
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
|
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
|
||||||
+import org.bukkit.craftbukkit.util.CraftChatMessage;
|
+import org.bukkit.craftbukkit.util.CraftChatMessage;
|
||||||
+import org.bukkit.craftbukkit.util.CraftLocation;
|
+import org.bukkit.craftbukkit.util.CraftLocation;
|
||||||
+import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
|
||||||
+import org.bukkit.craftbukkit.util.LazyPlayerSet;
|
+import org.bukkit.craftbukkit.util.LazyPlayerSet;
|
||||||
+import org.bukkit.craftbukkit.util.Waitable;
|
+import org.bukkit.craftbukkit.util.Waitable;
|
||||||
+import org.bukkit.entity.Player;
|
+import org.bukkit.entity.Player;
|
||||||
@ -67,6 +66,7 @@
|
|||||||
+import org.bukkit.inventory.EquipmentSlot;
|
+import org.bukkit.inventory.EquipmentSlot;
|
||||||
+import org.bukkit.inventory.InventoryView;
|
+import org.bukkit.inventory.InventoryView;
|
||||||
+import org.bukkit.inventory.SmithingInventory;
|
+import org.bukkit.inventory.SmithingInventory;
|
||||||
|
+import org.bukkit.util.Vector;
|
||||||
+// CraftBukkit end
|
+// CraftBukkit end
|
||||||
+
|
+
|
||||||
public class PlayerConnection extends ServerCommonPacketListenerImpl implements PacketListenerPlayIn, ServerPlayerConnection, TickablePacketListener {
|
public class PlayerConnection extends ServerCommonPacketListenerImpl implements PacketListenerPlayIn, ServerPlayerConnection, TickablePacketListener {
|
||||||
@ -1064,7 +1064,7 @@
|
|||||||
this.disconnect((IChatBaseComponent) IChatBaseComponent.translatable("disconnect.spam"));
|
this.disconnect((IChatBaseComponent) IChatBaseComponent.translatable("disconnect.spam"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1601,7 +2235,33 @@
|
@@ -1601,7 +2235,39 @@
|
||||||
@Override
|
@Override
|
||||||
public void handleAnimate(PacketPlayInArmAnimation packetplayinarmanimation) {
|
public void handleAnimate(PacketPlayInArmAnimation packetplayinarmanimation) {
|
||||||
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinarmanimation, this, this.player.serverLevel());
|
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinarmanimation, this, this.player.serverLevel());
|
||||||
@ -1087,6 +1087,12 @@
|
|||||||
+ });
|
+ });
|
||||||
+ if (result == null) {
|
+ if (result == null) {
|
||||||
+ CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_AIR, this.player.getInventory().getSelected(), EnumHand.MAIN_HAND);
|
+ CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_AIR, this.player.getInventory().getSelected(), EnumHand.MAIN_HAND);
|
||||||
|
+ } else if (this.player.gameMode.getGameModeForPlayer() == EnumGamemode.ADVENTURE) {
|
||||||
|
+ Block block = result.getHitBlock();
|
||||||
|
+ if (block != null) {
|
||||||
|
+ Vector hitPosition = result.getHitPosition().subtract(block.getLocation().toVector());
|
||||||
|
+ CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, block, result.getHitBlockFace(), this.player.getInventory().getSelected(), true, EnumHand.MAIN_HAND, hitPosition);
|
||||||
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ // Arm swing animation
|
+ // Arm swing animation
|
||||||
@ -1098,7 +1104,7 @@
|
|||||||
this.player.swing(packetplayinarmanimation.getHand());
|
this.player.swing(packetplayinarmanimation.getHand());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1609,6 +2269,29 @@
|
@@ -1609,6 +2275,29 @@
|
||||||
public void handlePlayerCommand(PacketPlayInEntityAction packetplayinentityaction) {
|
public void handlePlayerCommand(PacketPlayInEntityAction packetplayinentityaction) {
|
||||||
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinentityaction, this, this.player.serverLevel());
|
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinentityaction, this, this.player.serverLevel());
|
||||||
if (this.player.hasClientLoaded()) {
|
if (this.player.hasClientLoaded()) {
|
||||||
@ -1128,7 +1134,7 @@
|
|||||||
this.player.resetLastActionTime();
|
this.player.resetLastActionTime();
|
||||||
Entity entity;
|
Entity entity;
|
||||||
IJumpable ijumpable;
|
IJumpable ijumpable;
|
||||||
@@ -1691,6 +2374,12 @@
|
@@ -1691,6 +2380,12 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendPlayerChatMessage(PlayerChatMessage playerchatmessage, ChatMessageType.a chatmessagetype_a) {
|
public void sendPlayerChatMessage(PlayerChatMessage playerchatmessage, ChatMessageType.a chatmessagetype_a) {
|
||||||
@ -1141,7 +1147,7 @@
|
|||||||
this.send(new ClientboundPlayerChatPacket(playerchatmessage.link().sender(), playerchatmessage.link().index(), playerchatmessage.signature(), playerchatmessage.signedBody().pack(this.messageSignatureCache), playerchatmessage.unsignedContent(), playerchatmessage.filterMask(), chatmessagetype_a));
|
this.send(new ClientboundPlayerChatPacket(playerchatmessage.link().sender(), playerchatmessage.link().index(), playerchatmessage.signature(), playerchatmessage.signedBody().pack(this.messageSignatureCache), playerchatmessage.unsignedContent(), playerchatmessage.filterMask(), chatmessagetype_a));
|
||||||
this.addPendingMessage(playerchatmessage);
|
this.addPendingMessage(playerchatmessage);
|
||||||
}
|
}
|
||||||
@@ -1718,6 +2407,7 @@
|
@@ -1718,6 +2413,7 @@
|
||||||
@Override
|
@Override
|
||||||
public void handleInteract(PacketPlayInUseEntity packetplayinuseentity) {
|
public void handleInteract(PacketPlayInUseEntity packetplayinuseentity) {
|
||||||
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseentity, this, this.player.serverLevel());
|
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseentity, this, this.player.serverLevel());
|
||||||
@ -1149,7 +1155,7 @@
|
|||||||
if (this.player.hasClientLoaded()) {
|
if (this.player.hasClientLoaded()) {
|
||||||
final WorldServer worldserver = this.player.serverLevel();
|
final WorldServer worldserver = this.player.serverLevel();
|
||||||
final Entity entity = packetplayinuseentity.getTarget(worldserver);
|
final Entity entity = packetplayinuseentity.getTarget(worldserver);
|
||||||
@@ -1733,13 +2423,51 @@
|
@@ -1733,13 +2429,51 @@
|
||||||
|
|
||||||
if (this.player.canInteractWithEntity(axisalignedbb, 3.0D)) {
|
if (this.player.canInteractWithEntity(axisalignedbb, 3.0D)) {
|
||||||
packetplayinuseentity.dispatch(new PacketPlayInUseEntity.c() {
|
packetplayinuseentity.dispatch(new PacketPlayInUseEntity.c() {
|
||||||
@ -1202,7 +1208,7 @@
|
|||||||
if (enuminteractionresult instanceof EnumInteractionResult.d) {
|
if (enuminteractionresult instanceof EnumInteractionResult.d) {
|
||||||
EnumInteractionResult.d enuminteractionresult_d = (EnumInteractionResult.d) enuminteractionresult;
|
EnumInteractionResult.d enuminteractionresult_d = (EnumInteractionResult.d) enuminteractionresult;
|
||||||
ItemStack itemstack2 = enuminteractionresult_d.wasItemInteraction() ? itemstack1 : ItemStack.EMPTY;
|
ItemStack itemstack2 = enuminteractionresult_d.wasItemInteraction() ? itemstack1 : ItemStack.EMPTY;
|
||||||
@@ -1755,19 +2483,20 @@
|
@@ -1755,19 +2489,20 @@
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInteraction(EnumHand enumhand) {
|
public void onInteraction(EnumHand enumhand) {
|
||||||
@ -1226,7 +1232,7 @@
|
|||||||
label23:
|
label23:
|
||||||
{
|
{
|
||||||
if (entity instanceof EntityArrow) {
|
if (entity instanceof EntityArrow) {
|
||||||
@@ -1785,6 +2514,11 @@
|
@@ -1785,6 +2520,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerConnection.this.player.attack(entity);
|
PlayerConnection.this.player.attack(entity);
|
||||||
@ -1238,7 +1244,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1809,7 +2543,7 @@
|
@@ -1809,7 +2549,7 @@
|
||||||
case PERFORM_RESPAWN:
|
case PERFORM_RESPAWN:
|
||||||
if (this.player.wonGame) {
|
if (this.player.wonGame) {
|
||||||
this.player.wonGame = false;
|
this.player.wonGame = false;
|
||||||
@ -1247,7 +1253,7 @@
|
|||||||
this.resetPosition();
|
this.resetPosition();
|
||||||
CriterionTriggers.CHANGED_DIMENSION.trigger(this.player, World.END, World.OVERWORLD);
|
CriterionTriggers.CHANGED_DIMENSION.trigger(this.player, World.END, World.OVERWORLD);
|
||||||
} else {
|
} else {
|
||||||
@@ -1817,11 +2551,11 @@
|
@@ -1817,11 +2557,11 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1261,7 +1267,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1834,15 +2568,21 @@
|
@@ -1834,15 +2574,21 @@
|
||||||
@Override
|
@Override
|
||||||
public void handleContainerClose(PacketPlayInCloseWindow packetplayinclosewindow) {
|
public void handleContainerClose(PacketPlayInCloseWindow packetplayinclosewindow) {
|
||||||
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinclosewindow, this, this.player.serverLevel());
|
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinclosewindow, this, this.player.serverLevel());
|
||||||
@ -1285,7 +1291,7 @@
|
|||||||
this.player.containerMenu.sendAllDataToRemote();
|
this.player.containerMenu.sendAllDataToRemote();
|
||||||
} else if (!this.player.containerMenu.stillValid(this.player)) {
|
} else if (!this.player.containerMenu.stillValid(this.player)) {
|
||||||
PlayerConnection.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu);
|
PlayerConnection.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu);
|
||||||
@@ -1855,7 +2595,284 @@
|
@@ -1855,7 +2601,284 @@
|
||||||
boolean flag = packetplayinwindowclick.getStateId() != this.player.containerMenu.getStateId();
|
boolean flag = packetplayinwindowclick.getStateId() != this.player.containerMenu.getStateId();
|
||||||
|
|
||||||
this.player.containerMenu.suppressRemoteUpdates();
|
this.player.containerMenu.suppressRemoteUpdates();
|
||||||
@ -1571,7 +1577,7 @@
|
|||||||
ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packetplayinwindowclick.getChangedSlots()).iterator();
|
ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packetplayinwindowclick.getChangedSlots()).iterator();
|
||||||
|
|
||||||
while (objectiterator.hasNext()) {
|
while (objectiterator.hasNext()) {
|
||||||
@@ -1901,7 +2918,21 @@
|
@@ -1901,7 +2924,21 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1594,7 +1600,7 @@
|
|||||||
|
|
||||||
if (containerrecipebook_a == ContainerRecipeBook.a.PLACE_GHOST_RECIPE) {
|
if (containerrecipebook_a == ContainerRecipeBook.a.PLACE_GHOST_RECIPE) {
|
||||||
this.player.connection.send(new PacketPlayOutAutoRecipe(this.player.containerMenu.containerId, craftingmanager_d.display().display()));
|
this.player.connection.send(new PacketPlayOutAutoRecipe(this.player.containerMenu.containerId, craftingmanager_d.display().display()));
|
||||||
@@ -1917,6 +2948,7 @@
|
@@ -1917,6 +2954,7 @@
|
||||||
@Override
|
@Override
|
||||||
public void handleContainerButtonClick(PacketPlayInEnchantItem packetplayinenchantitem) {
|
public void handleContainerButtonClick(PacketPlayInEnchantItem packetplayinenchantitem) {
|
||||||
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinenchantitem, this, this.player.serverLevel());
|
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinenchantitem, this, this.player.serverLevel());
|
||||||
@ -1602,7 +1608,7 @@
|
|||||||
this.player.resetLastActionTime();
|
this.player.resetLastActionTime();
|
||||||
if (this.player.containerMenu.containerId == packetplayinenchantitem.containerId() && !this.player.isSpectator()) {
|
if (this.player.containerMenu.containerId == packetplayinenchantitem.containerId() && !this.player.isSpectator()) {
|
||||||
if (!this.player.containerMenu.stillValid(this.player)) {
|
if (!this.player.containerMenu.stillValid(this.player)) {
|
||||||
@@ -1945,6 +2977,43 @@
|
@@ -1945,6 +2983,43 @@
|
||||||
|
|
||||||
boolean flag1 = packetplayinsetcreativeslot.slotNum() >= 1 && packetplayinsetcreativeslot.slotNum() <= 45;
|
boolean flag1 = packetplayinsetcreativeslot.slotNum() >= 1 && packetplayinsetcreativeslot.slotNum() <= 45;
|
||||||
boolean flag2 = itemstack.isEmpty() || itemstack.getCount() <= itemstack.getMaxStackSize();
|
boolean flag2 = itemstack.isEmpty() || itemstack.getCount() <= itemstack.getMaxStackSize();
|
||||||
@ -1646,7 +1652,7 @@
|
|||||||
|
|
||||||
if (flag1 && flag2) {
|
if (flag1 && flag2) {
|
||||||
this.player.inventoryMenu.getSlot(packetplayinsetcreativeslot.slotNum()).setByPlayer(itemstack);
|
this.player.inventoryMenu.getSlot(packetplayinsetcreativeslot.slotNum()).setByPlayer(itemstack);
|
||||||
@@ -1972,6 +3041,7 @@
|
@@ -1972,6 +3047,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSignText(PacketPlayInUpdateSign packetplayinupdatesign, List<FilteredText> list) {
|
private void updateSignText(PacketPlayInUpdateSign packetplayinupdatesign, List<FilteredText> list) {
|
||||||
@ -1654,7 +1660,7 @@
|
|||||||
this.player.resetLastActionTime();
|
this.player.resetLastActionTime();
|
||||||
WorldServer worldserver = this.player.serverLevel();
|
WorldServer worldserver = this.player.serverLevel();
|
||||||
BlockPosition blockposition = packetplayinupdatesign.getPos();
|
BlockPosition blockposition = packetplayinupdatesign.getPos();
|
||||||
@@ -1993,7 +3063,17 @@
|
@@ -1993,7 +3069,17 @@
|
||||||
@Override
|
@Override
|
||||||
public void handlePlayerAbilities(PacketPlayInAbilities packetplayinabilities) {
|
public void handlePlayerAbilities(PacketPlayInAbilities packetplayinabilities) {
|
||||||
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinabilities, this, this.player.serverLevel());
|
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinabilities, this, this.player.serverLevel());
|
||||||
@ -1673,7 +1679,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -2058,7 +3138,7 @@
|
@@ -2058,7 +3144,7 @@
|
||||||
if (!this.waitingForSwitchToConfig) {
|
if (!this.waitingForSwitchToConfig) {
|
||||||
throw new IllegalStateException("Client acknowledged config, but none was requested");
|
throw new IllegalStateException("Client acknowledged config, but none was requested");
|
||||||
} else {
|
} else {
|
||||||
@ -1682,7 +1688,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2083,8 +3163,10 @@
|
@@ -2083,8 +3169,10 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -542,21 +542,24 @@ public class CraftEventFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static PlayerInteractEvent callPlayerInteractEvent(EntityHuman who, Action action, BlockPosition position, EnumDirection direction, ItemStack itemstack, boolean cancelledBlock, EnumHand hand, Vec3D targetPos) {
|
public static PlayerInteractEvent callPlayerInteractEvent(EntityHuman who, Action action, BlockPosition position, EnumDirection direction, ItemStack itemstack, boolean cancelledBlock, EnumHand hand, Vec3D targetPos) {
|
||||||
Player player = (who == null) ? null : (Player) who.getBukkitEntity();
|
|
||||||
CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
|
|
||||||
|
|
||||||
Vector clickedPos = null;
|
Vector clickedPos = null;
|
||||||
if (position != null && targetPos != null) {
|
if (position != null && targetPos != null) {
|
||||||
clickedPos = CraftVector.toBukkit(targetPos.subtract(Vec3D.atLowerCornerOf(position)));
|
clickedPos = CraftVector.toBukkit(targetPos.subtract(Vec3D.atLowerCornerOf(position)));
|
||||||
}
|
}
|
||||||
|
|
||||||
CraftWorld craftWorld = (CraftWorld) player.getWorld();
|
|
||||||
CraftServer craftServer = (CraftServer) player.getServer();
|
|
||||||
|
|
||||||
Block blockClicked = null;
|
Block blockClicked = null;
|
||||||
if (position != null) {
|
if (position != null) {
|
||||||
blockClicked = craftWorld.getBlockAt(position.getX(), position.getY(), position.getZ());
|
blockClicked = CraftBlock.at(who.level(), position);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
return callPlayerInteractEvent(who, action, blockClicked, CraftBlock.notchToBlockFace(direction), itemstack, cancelledBlock, hand, clickedPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlayerInteractEvent callPlayerInteractEvent(EntityHuman who, Action action, Block blockClicked, BlockFace blockFace, ItemStack itemstack, boolean cancelledBlock, EnumHand hand, Vector clickedPos) {
|
||||||
|
Player player = (Player) who.getBukkitEntity();
|
||||||
|
CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
|
||||||
|
|
||||||
|
if (blockClicked == null) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case LEFT_CLICK_BLOCK:
|
case LEFT_CLICK_BLOCK:
|
||||||
action = Action.LEFT_CLICK_AIR;
|
action = Action.LEFT_CLICK_AIR;
|
||||||
@ -566,7 +569,6 @@ public class CraftEventFactory {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BlockFace blockFace = CraftBlock.notchToBlockFace(direction);
|
|
||||||
|
|
||||||
if (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0) {
|
if (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0) {
|
||||||
itemInHand = null;
|
itemInHand = null;
|
||||||
@ -576,7 +578,7 @@ public class CraftEventFactory {
|
|||||||
if (cancelledBlock) {
|
if (cancelledBlock) {
|
||||||
event.setUseInteractedBlock(Event.Result.DENY);
|
event.setUseInteractedBlock(Event.Result.DENY);
|
||||||
}
|
}
|
||||||
craftServer.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user