#1107: Add getHand() to all relevant events

By: Parker Hawke <hawkeboyz2@hotmail.com>
This commit is contained in:
CraftBukkit/Spigot
2022-10-02 09:07:14 +11:00
parent 34ab403aa0
commit 159ae52462
17 changed files with 145 additions and 82 deletions

View File

@@ -20,7 +20,7 @@
if (!world.isClientSide) {
- world.addFreshEntity(entityboat);
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPlaceEvent(world, movingobjectpositionblock.getBlockPos(), movingobjectpositionblock.getDirection(), entityhuman, entityboat).isCancelled()) {
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPlaceEvent(world, movingobjectpositionblock.getBlockPos(), movingobjectpositionblock.getDirection(), entityhuman, entityboat, enumhand).isCancelled()) {
+ return InteractionResultWrapper.fail(itemstack);
+ }
+

View File

@@ -24,7 +24,7 @@
+ // CraftBukkit start
+ ItemStack dummyFluid = ifluidsource.pickupBlock(DummyGeneratorAccess.INSTANCE, blockposition, iblockdata);
+ if (dummyFluid.isEmpty()) return InteractionResultWrapper.fail(itemstack); // Don't fire event if the bucket won't be filled.
+ PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((WorldServer) world, entityhuman, blockposition, blockposition, movingobjectpositionblock.getDirection(), itemstack, dummyFluid.getItem());
+ PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((WorldServer) world, entityhuman, blockposition, blockposition, movingobjectpositionblock.getDirection(), itemstack, dummyFluid.getItem(), enumhand);
+
+ if (event.isCancelled()) {
+ ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutBlockChange(world, blockposition)); // SPIGOT-5163 (see PlayerInteractManager)
@@ -49,29 +49,30 @@
BlockPosition blockposition2 = iblockdata.getBlock() instanceof IFluidContainer && this.content == FluidTypes.WATER ? blockposition : blockposition1;
- if (this.emptyContents(entityhuman, world, blockposition2, movingobjectpositionblock)) {
+ if (this.emptyContents(entityhuman, world, blockposition2, movingobjectpositionblock, movingobjectpositionblock.getDirection(), blockposition, itemstack)) { // CraftBukkit
+ if (this.emptyContents(entityhuman, world, blockposition2, movingobjectpositionblock, movingobjectpositionblock.getDirection(), blockposition, itemstack, enumhand)) { // CraftBukkit
this.checkExtraContent(entityhuman, world, itemstack, blockposition2);
if (entityhuman instanceof EntityPlayer) {
CriterionTriggers.PLACED_BLOCK.trigger((EntityPlayer) entityhuman, blockposition2, itemstack);
@@ -110,6 +131,11 @@
@@ -110,6 +131,12 @@
@Override
public boolean emptyContents(@Nullable EntityHuman entityhuman, World world, BlockPosition blockposition, @Nullable MovingObjectPositionBlock movingobjectpositionblock) {
+ return emptyContents(entityhuman, world, blockposition, movingobjectpositionblock, null, null, null);
+ // CraftBukkit start
+ return emptyContents(entityhuman, world, blockposition, movingobjectpositionblock, null, null, null, EnumHand.MAIN_HAND);
+ }
+
+ public boolean emptyContents(EntityHuman entityhuman, World world, BlockPosition blockposition, @Nullable MovingObjectPositionBlock movingobjectpositionblock, EnumDirection enumdirection, BlockPosition clicked, ItemStack itemstack) {
+ public boolean emptyContents(EntityHuman entityhuman, World world, BlockPosition blockposition, @Nullable MovingObjectPositionBlock movingobjectpositionblock, EnumDirection enumdirection, BlockPosition clicked, ItemStack itemstack, EnumHand enumhand) {
+ // CraftBukkit end
if (!(this.content instanceof FluidTypeFlowing)) {
return false;
} else {
@@ -119,8 +145,18 @@
@@ -119,8 +146,18 @@
boolean flag = iblockdata.canBeReplaced(this.content);
boolean flag1 = iblockdata.isAir() || flag || block instanceof IFluidContainer && ((IFluidContainer) block).canPlaceLiquid(world, blockposition, iblockdata, this.content);
+ // CraftBukkit start
+ if (flag1 && entityhuman != null) {
+ PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent((WorldServer) world, entityhuman, blockposition, clicked, enumdirection, itemstack);
+ PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent((WorldServer) world, entityhuman, blockposition, clicked, enumdirection, itemstack, enumhand);
+ if (event.isCancelled()) {
+ ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutBlockChange(world, blockposition)); // SPIGOT-4238: needed when looking through entity
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); // SPIGOT-4541
@@ -81,7 +82,7 @@
+ // CraftBukkit end
if (!flag1) {
- return movingobjectpositionblock != null && this.emptyContents(entityhuman, world, movingobjectpositionblock.getBlockPos().relative(movingobjectpositionblock.getDirection()), (MovingObjectPositionBlock) null);
+ return movingobjectpositionblock != null && this.emptyContents(entityhuman, world, movingobjectpositionblock.getBlockPos().relative(movingobjectpositionblock.getDirection()), (MovingObjectPositionBlock) null, enumdirection, clicked, itemstack); // CraftBukkit
+ return movingobjectpositionblock != null && this.emptyContents(entityhuman, world, movingobjectpositionblock.getBlockPos().relative(movingobjectpositionblock.getDirection()), (MovingObjectPositionBlock) null, enumdirection, clicked, itemstack, enumhand); // CraftBukkit
} else if (world.dimensionType().ultraWarm() && this.content.is(TagsFluid.WATER)) {
int i = blockposition.getX();
int j = blockposition.getY();

View File

@@ -1,15 +1,18 @@
--- a/net/minecraft/world/item/ItemFishingRod.java
+++ b/net/minecraft/world/item/ItemFishingRod.java
@@ -11,6 +11,8 @@
@@ -11,6 +11,11 @@
import net.minecraft.world.level.World;
import net.minecraft.world.level.gameevent.GameEvent;
+import org.bukkit.event.player.PlayerFishEvent; // CraftBukkit
+// CraftBukkit start
+import org.bukkit.event.player.PlayerFishEvent;
+import org.bukkit.craftbukkit.CraftEquipmentSlot;
+// CraftBukkit end
+
public class ItemFishingRod extends Item implements ItemVanishable {
public ItemFishingRod(Item.Info item_info) {
@@ -33,12 +35,23 @@
@@ -33,12 +38,23 @@
world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.FISHING_BOBBER_RETRIEVE, SoundCategory.NEUTRAL, 1.0F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
entityhuman.gameEvent(GameEvent.ITEM_INTERACT_FINISH);
} else {
@@ -22,7 +25,7 @@
- world.addFreshEntity(new EntityFishingHook(entityhuman, world, j, i));
+ // CraftBukkit start
+ EntityFishingHook entityfishinghook = new EntityFishingHook(entityhuman, world, j, i);
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), null, (org.bukkit.entity.FishHook) entityfishinghook.getBukkitEntity(), PlayerFishEvent.State.FISHING);
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), null, (org.bukkit.entity.FishHook) entityfishinghook.getBukkitEntity(), CraftEquipmentSlot.getHand(enumhand), PlayerFishEvent.State.FISHING);
+ world.getCraftServer().getPluginManager().callEvent(playerFishEvent);
+
+ if (playerFishEvent.isCancelled()) {

View File

@@ -12,7 +12,7 @@
public class ItemHanging extends Item {
private final EntityTypes<? extends EntityHanging> type;
@@ -65,6 +70,18 @@
@@ -65,6 +70,19 @@
if (((EntityHanging) object).survives()) {
if (!world.isClientSide) {
@@ -20,8 +20,9 @@
+ Player who = (itemactioncontext.getPlayer() == null) ? null : (Player) itemactioncontext.getPlayer().getBukkitEntity();
+ org.bukkit.block.Block blockClicked = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ org.bukkit.block.BlockFace blockFace = org.bukkit.craftbukkit.block.CraftBlock.notchToBlockFace(enumdirection);
+ org.bukkit.inventory.EquipmentSlot hand = org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(itemactioncontext.getHand());
+
+ HangingPlaceEvent event = new HangingPlaceEvent((org.bukkit.entity.Hanging) ((EntityHanging) object).getBukkitEntity(), who, blockClicked, blockFace, org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemstack));
+ HangingPlaceEvent event = new HangingPlaceEvent((org.bukkit.entity.Hanging) ((EntityHanging) object).getBukkitEntity(), who, blockClicked, blockFace, hand, org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemstack));
+ world.getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {

View File

@@ -1,21 +1,43 @@
--- a/net/minecraft/world/item/ItemLeash.java
+++ b/net/minecraft/world/item/ItemLeash.java
@@ -15,6 +15,8 @@
@@ -15,6 +15,11 @@
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.AxisAlignedBB;
+import org.bukkit.event.hanging.HangingPlaceEvent; // CraftBukkit
+// CraftBukkit start
+import org.bukkit.craftbukkit.CraftEquipmentSlot;
+import org.bukkit.event.hanging.HangingPlaceEvent;
+// CraftBukkit end
+
public class ItemLeash extends Item {
public ItemLeash(Item.Info item_info) {
@@ -57,9 +59,25 @@
@@ -31,7 +36,7 @@
EntityHuman entityhuman = itemactioncontext.getPlayer();
if (!world.isClientSide && entityhuman != null) {
- bindPlayerMobs(entityhuman, world, blockposition);
+ bindPlayerMobs(entityhuman, world, blockposition, itemactioncontext.getHand()); // CraftBukkit - Pass hand
}
world.gameEvent(GameEvent.BLOCK_ATTACH, blockposition, GameEvent.a.of((Entity) entityhuman));
@@ -41,7 +46,7 @@
}
}
- public static EnumInteractionResult bindPlayerMobs(EntityHuman entityhuman, World world, BlockPosition blockposition) {
+ public static EnumInteractionResult bindPlayerMobs(EntityHuman entityhuman, World world, BlockPosition blockposition, net.minecraft.world.EnumHand enumhand) { // CraftBukkit - Add EnumHand
EntityLeash entityleash = null;
boolean flag = false;
double d0 = 7.0D;
@@ -57,9 +62,26 @@
if (entityinsentient.getLeashHolder() == entityhuman) {
if (entityleash == null) {
entityleash = EntityLeash.getOrCreateKnot(world, blockposition);
+
+ // CraftBukkit start - fire HangingPlaceEvent
+ HangingPlaceEvent event = new HangingPlaceEvent((org.bukkit.entity.Hanging) entityleash.getBukkitEntity(), entityhuman != null ? (org.bukkit.entity.Player) entityhuman.getBukkitEntity() : null, world.getWorld().getBlockAt(i, j, k), org.bukkit.block.BlockFace.SELF);
+ org.bukkit.inventory.EquipmentSlot hand = CraftEquipmentSlot.getHand(enumhand);
+ HangingPlaceEvent event = new HangingPlaceEvent((org.bukkit.entity.Hanging) entityleash.getBukkitEntity(), entityhuman != null ? (org.bukkit.entity.Player) entityhuman.getBukkitEntity() : null, world.getWorld().getBlockAt(i, j, k), org.bukkit.block.BlockFace.SELF, hand);
+ world.getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
@@ -27,7 +49,7 @@
}
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerLeashEntityEvent(entityinsentient, entityleash, entityhuman).isCancelled()) {
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerLeashEntityEvent(entityinsentient, entityleash, entityhuman, enumhand).isCancelled()) {
+ continue;
+ }
+ // CraftBukkit end
@@ -35,3 +57,14 @@
entityinsentient.setLeashedTo(entityleash, true);
flag = true;
}
@@ -67,4 +89,10 @@
return flag ? EnumInteractionResult.SUCCESS : EnumInteractionResult.PASS;
}
+
+ // CraftBukkit start
+ public static EnumInteractionResult bindPlayerMobs(EntityHuman entityhuman, World world, BlockPosition blockposition) {
+ return bindPlayerMobs(entityhuman, world, blockposition, net.minecraft.world.EnumHand.MAIN_HAND);
+ }
+ // CraftBukkit end
}