#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

@@ -59,7 +59,7 @@
ItemStack itemstack = (ItemStack) entry.getValue();
int j = Math.min(this.xpToDurability(this.value), itemstack.getDamageValue());
+ // CraftBukkit start
+ org.bukkit.event.player.PlayerItemMendEvent event = CraftEventFactory.callPlayerItemMendEvent(entityhuman, this, itemstack, j);
+ org.bukkit.event.player.PlayerItemMendEvent event = CraftEventFactory.callPlayerItemMendEvent(entityhuman, this, itemstack, entry.getKey(), j);
+ j = event.getRepairAmount();
+ if (event.isCancelled()) {
+ return i;

View File

@@ -188,7 +188,7 @@
return EnumInteractionResult.PASS;
} else if (this.getLeashHolder() == entityhuman) {
+ // CraftBukkit start - fire PlayerUnleashEntityEvent
+ if (CraftEventFactory.callPlayerUnleashEntityEvent(this, entityhuman).isCancelled()) {
+ if (CraftEventFactory.callPlayerUnleashEntityEvent(this, entityhuman, enumhand).isCancelled()) {
+ ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutAttachEntity(this, this.getLeashHolder()));
+ return EnumInteractionResult.PASS;
+ }
@@ -201,7 +201,7 @@
if (itemstack.is(Items.LEAD) && this.canBeLeashed(entityhuman)) {
+ // CraftBukkit start - fire PlayerLeashEntityEvent
+ if (CraftEventFactory.callPlayerLeashEntityEvent(this, entityhuman, entityhuman).isCancelled()) {
+ if (CraftEventFactory.callPlayerLeashEntityEvent(this, entityhuman, entityhuman, enumhand).isCancelled()) {
+ ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutAttachEntity(this, this.getLeashHolder()));
+ return EnumInteractionResult.PASS;
+ }

View File

@@ -431,11 +431,12 @@
this.hurtDir = 0.0F;
Entity entity1 = damagesource.getEntity();
@@ -1258,19 +1485,29 @@
@@ -1258,19 +1485,32 @@
EnumHand[] aenumhand = EnumHand.values();
int i = aenumhand.length;
+ // CraftBukkit start
+ EnumHand hand = null;
+ ItemStack itemstack1 = ItemStack.EMPTY;
for (int j = 0; j < i; ++j) {
EnumHand enumhand = aenumhand[j];
@@ -443,6 +444,7 @@
+ itemstack1 = this.getItemInHand(enumhand);
if (itemstack1.is(Items.TOTEM_OF_UNDYING)) {
+ hand = enumhand; // CraftBukkit
itemstack = itemstack1.copy();
- itemstack1.shrink(1);
+ // itemstack1.subtract(1); // CraftBukkit
@@ -452,7 +454,8 @@
- if (itemstack != null) {
- if (this instanceof EntityPlayer) {
+ EntityResurrectEvent event = new EntityResurrectEvent((LivingEntity) this.getBukkitEntity());
+ org.bukkit.inventory.EquipmentSlot handSlot = (hand != null) ? org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(hand) : null;
+ EntityResurrectEvent event = new EntityResurrectEvent((LivingEntity) this.getBukkitEntity(), handSlot);
+ event.setCancelled(itemstack == null);
+ this.level.getCraftServer().getPluginManager().callEvent(event);
+
@@ -465,7 +468,7 @@
EntityPlayer entityplayer = (EntityPlayer) this;
entityplayer.awardStat(StatisticList.ITEM_USED.get(Items.TOTEM_OF_UNDYING));
@@ -1278,14 +1515,16 @@
@@ -1278,14 +1518,16 @@
}
this.setHealth(1.0F);
@@ -487,7 +490,7 @@
}
}
@@ -1390,14 +1629,22 @@
@@ -1390,14 +1632,22 @@
IBlockData iblockdata = Blocks.WITHER_ROSE.defaultBlockState();
if (this.level.getBlockState(blockposition).isAir() && iblockdata.canSurvive(this.level, blockposition)) {
@@ -512,7 +515,7 @@
this.level.addFreshEntity(entityitem);
}
}
@@ -1417,21 +1664,40 @@
@@ -1417,21 +1667,40 @@
boolean flag = this.lastHurtByPlayerTime > 0;
@@ -556,7 +559,7 @@
}
@@ -1504,6 +1770,28 @@
@@ -1504,6 +1773,28 @@
return itemstack.getEatingSound();
}
@@ -585,7 +588,7 @@
@Override
public void setOnGround(boolean flag) {
super.setOnGround(flag);
@@ -1559,9 +1847,14 @@
@@ -1559,9 +1850,14 @@
int i = this.calculateFallDamage(f, f1);
if (i > 0) {
@@ -601,7 +604,7 @@
return true;
} else {
return flag;
@@ -1610,7 +1903,7 @@
@@ -1610,7 +1906,7 @@
protected float getDamageAfterArmorAbsorb(DamageSource damagesource, float f) {
if (!damagesource.isBypassArmor()) {
@@ -610,7 +613,7 @@
f = CombatMath.getDamageAfterAbsorb(f, (float) this.getArmorValue(), (float) this.getAttributeValue(GenericAttributes.ARMOR_TOUGHNESS));
}
@@ -1623,7 +1916,8 @@
@@ -1623,7 +1919,8 @@
} else {
int i;
@@ -620,7 +623,7 @@
i = (this.getEffect(MobEffects.DAMAGE_RESISTANCE).getAmplifier() + 1) * 5;
int j = 25 - i;
float f1 = f * (float) j;
@@ -1656,29 +1950,172 @@
@@ -1656,29 +1953,172 @@
}
}
@@ -803,7 +806,7 @@
}
public CombatTracker getCombatTracker() {
@@ -1699,9 +2136,19 @@
@@ -1699,9 +2139,19 @@
}
public final void setArrowCount(int i) {
@@ -824,7 +827,7 @@
public final int getStingerCount() {
return (Integer) this.entityData.get(EntityLiving.DATA_STINGER_COUNT_ID);
}
@@ -1996,6 +2443,12 @@
@@ -1996,6 +2446,12 @@
public abstract ItemStack getItemBySlot(EnumItemSlot enumitemslot);
@@ -837,7 +840,7 @@
@Override
public abstract void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack);
@@ -2239,6 +2692,7 @@
@@ -2239,6 +2695,7 @@
}
if (this.onGround && !this.level.isClientSide) {
@@ -845,7 +848,7 @@
this.setSharedFlag(7, false);
}
} else {
@@ -2772,6 +3226,7 @@
@@ -2772,6 +3229,7 @@
}
if (!this.level.isClientSide) {
@@ -853,7 +856,7 @@
this.setSharedFlag(7, flag);
}
@@ -2931,14 +3386,21 @@
@@ -2931,14 +3389,21 @@
@Override
public boolean isPickable() {
@@ -877,7 +880,7 @@
@Override
public float getYHeadRot() {
return this.yHeadRot;
@@ -3133,7 +3595,25 @@
@@ -3133,7 +3598,26 @@
} else {
if (!this.useItem.isEmpty() && this.isUsingItem()) {
this.triggerItemUseEffects(this.useItem, 16);
@@ -886,7 +889,8 @@
+ ItemStack itemstack;
+ if (this instanceof EntityPlayer) {
+ org.bukkit.inventory.ItemStack craftItem = CraftItemStack.asBukkitCopy(this.useItem);
+ PlayerItemConsumeEvent event = new PlayerItemConsumeEvent((Player) this.getBukkitEntity(), craftItem);
+ org.bukkit.inventory.EquipmentSlot hand = org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(enumhand);
+ PlayerItemConsumeEvent event = new PlayerItemConsumeEvent((Player) this.getBukkitEntity(), craftItem, hand);
+ level.getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
@@ -904,7 +908,7 @@
if (itemstack != this.useItem) {
this.setItemInHand(enumhand, itemstack);
@@ -3211,6 +3691,12 @@
@@ -3211,6 +3695,12 @@
}
public boolean randomTeleport(double d0, double d1, double d2, boolean flag) {
@@ -917,7 +921,7 @@
double d3 = this.getX();
double d4 = this.getY();
double d5 = this.getZ();
@@ -3235,16 +3721,41 @@
@@ -3235,16 +3725,41 @@
}
if (flag2) {
@@ -962,7 +966,7 @@
} else {
if (flag) {
world.broadcastEntityEvent(this, (byte) 46);
@@ -3254,7 +3765,7 @@
@@ -3254,7 +3769,7 @@
((EntityCreature) this).getNavigation().stop();
}
@@ -971,7 +975,7 @@
}
}
@@ -3337,7 +3848,7 @@
@@ -3337,7 +3852,7 @@
}
public void stopSleeping() {
@@ -980,7 +984,7 @@
World world = this.level;
java.util.Objects.requireNonNull(this.level);
@@ -3369,7 +3880,7 @@
@@ -3369,7 +3884,7 @@
@Nullable
public EnumDirection getBedOrientation() {
@@ -989,7 +993,7 @@
return blockposition != null ? BlockBed.getBedOrientation(this.level, blockposition) : null;
}
@@ -3417,7 +3928,7 @@
@@ -3417,7 +3932,7 @@
Pair<MobEffect, Float> pair = (Pair) iterator.next();
if (!world.isClientSide && pair.getFirst() != null && world.random.nextFloat() < (Float) pair.getSecond()) {

View File

@@ -26,7 +26,7 @@
((Bucketable) t0).saveToBucketTag(itemstack1);
+
+ PlayerBucketEntityEvent playerBucketFishEvent = CraftEventFactory.callPlayerFishBucketEvent(t0, entityhuman, itemstack, itemstack1);
+ PlayerBucketEntityEvent playerBucketFishEvent = CraftEventFactory.callPlayerFishBucketEvent(t0, entityhuman, itemstack, itemstack1, enumhand);
+ itemstack1 = CraftItemStack.asNMSCopy(playerBucketFishEvent.getEntityBucket());
+ if (playerBucketFishEvent.isCancelled()) {
+ ((EntityPlayer) entityhuman).containerMenu.sendAllDataToRemote(); // We need to update inventory to resync client's bucket

View File

@@ -17,7 +17,7 @@
if (itemstack.is(Items.BUCKET) && !this.isBaby()) {
+ // CraftBukkit start - Got milk?
+ org.bukkit.event.player.PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((WorldServer) entityhuman.level, entityhuman, this.blockPosition(), this.blockPosition(), null, itemstack, Items.MILK_BUCKET);
+ org.bukkit.event.player.PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((WorldServer) entityhuman.level, entityhuman, this.blockPosition(), this.blockPosition(), null, itemstack, Items.MILK_BUCKET, enumhand);
+
+ if (event.isCancelled()) {
+ return EnumInteractionResult.PASS;

View File

@@ -26,7 +26,7 @@
if (itemstack.is(Items.BUCKET) && !this.isBaby()) {
+ // CraftBukkit start - Got milk?
+ org.bukkit.event.player.PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((WorldServer) entityhuman.level, entityhuman, this.blockPosition(), this.blockPosition(), null, itemstack, Items.MILK_BUCKET);
+ org.bukkit.event.player.PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((WorldServer) entityhuman.level, entityhuman, this.blockPosition(), this.blockPosition(), null, itemstack, Items.MILK_BUCKET, enumhand);
+
+ if (event.isCancelled()) {
+ return EnumInteractionResult.PASS;

View File

@@ -53,7 +53,7 @@
}
}
@@ -402,6 +425,21 @@
@@ -402,6 +425,22 @@
return false;
} else {
ItemStack itemstack2;
@@ -65,7 +65,8 @@
+ ArmorStand self = (ArmorStand) this.getBukkitEntity();
+
+ EquipmentSlot slot = CraftEquipmentSlot.getSlot(enumitemslot);
+ PlayerArmorStandManipulateEvent armorStandManipulateEvent = new PlayerArmorStandManipulateEvent(player,self,playerHeldItem,armorStandItem,slot);
+ EquipmentSlot hand = CraftEquipmentSlot.getHand(enumhand);
+ PlayerArmorStandManipulateEvent armorStandManipulateEvent = new PlayerArmorStandManipulateEvent(player,self,playerHeldItem,armorStandItem,slot,hand);
+ this.level.getCraftServer().getPluginManager().callEvent(armorStandManipulateEvent);
+
+ if (armorStandManipulateEvent.isCancelled()) {
@@ -75,7 +76,7 @@
if (entityhuman.getAbilities().instabuild && itemstack1.isEmpty() && !itemstack.isEmpty()) {
itemstack2 = itemstack.copy();
@@ -430,9 +468,19 @@
@@ -430,9 +469,19 @@
public boolean hurt(DamageSource damagesource, float f) {
if (!this.level.isClientSide && !this.isRemoved()) {
if (DamageSource.OUT_OF_WORLD.equals(damagesource)) {
@@ -96,7 +97,7 @@
if (damagesource.isExplosion()) {
this.brokenByAnything(damagesource);
this.kill();
@@ -472,7 +520,7 @@
@@ -472,7 +521,7 @@
} else {
this.brokenByPlayer(damagesource);
this.showBreakingParticles();
@@ -105,7 +106,7 @@
}
return true;
@@ -533,13 +581,13 @@
@@ -533,13 +582,13 @@
}
private void brokenByPlayer(DamageSource damagesource) {
@@ -121,7 +122,7 @@
ItemStack itemstack;
int i;
@@ -547,7 +595,7 @@
@@ -547,7 +596,7 @@
for (i = 0; i < this.handItems.size(); ++i) {
itemstack = (ItemStack) this.handItems.get(i);
if (!itemstack.isEmpty()) {
@@ -130,7 +131,7 @@
this.handItems.set(i, ItemStack.EMPTY);
}
}
@@ -555,10 +603,11 @@
@@ -555,10 +604,11 @@
for (i = 0; i < this.armorItems.size(); ++i) {
itemstack = (ItemStack) this.armorItems.get(i);
if (!itemstack.isEmpty()) {
@@ -143,7 +144,7 @@
}
@@ -659,8 +708,16 @@
@@ -659,8 +709,16 @@
return this.isSmall();
}

View File

@@ -18,7 +18,7 @@
entityinsentient = (EntityInsentient) iterator.next();
if (entityinsentient.getLeashHolder() == entityhuman) {
+ // CraftBukkit start
+ if (CraftEventFactory.callPlayerLeashEntityEvent(entityinsentient, this, entityhuman).isCancelled()) {
+ if (CraftEventFactory.callPlayerLeashEntityEvent(entityinsentient, this, entityhuman, enumhand).isCancelled()) {
+ ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutAttachEntity(entityinsentient, entityinsentient.getLeashHolder()));
+ continue;
+ }
@@ -43,7 +43,7 @@
if (entityinsentient.isLeashed() && entityinsentient.getLeashHolder() == this) {
- entityinsentient.dropLeash(true, false);
+ // CraftBukkit start
+ if (CraftEventFactory.callPlayerUnleashEntityEvent(entityinsentient, entityhuman).isCancelled()) {
+ if (CraftEventFactory.callPlayerUnleashEntityEvent(entityinsentient, entityhuman, enumhand).isCancelled()) {
+ die = false;
+ continue;
+ }