#718: Add consumed item, hand and consumeItem boolean to EntityShootBowEvent

This commit is contained in:
Parker Hawke 2020-08-31 18:39:12 +10:00 committed by md_5
parent 6008e6660a
commit 927200a961
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
4 changed files with 11 additions and 8 deletions

View File

@ -5,7 +5,7 @@
entityarrow.shoot(d0, d1 + d3 * 0.20000000298023224D, d2, 1.6F, (float) (14 - this.world.getDifficulty().a() * 4)); entityarrow.shoot(d0, d1 + d3 * 0.20000000298023224D, d2, 1.6F, (float) (14 - this.world.getDifficulty().a() * 4));
+ // CraftBukkit start + // CraftBukkit start
+ org.bukkit.event.entity.EntityShootBowEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(this, this.getItemInMainHand(), entityarrow, 0.8F); + org.bukkit.event.entity.EntityShootBowEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(this, this.getItemInMainHand(), null, entityarrow, EnumHand.MAIN_HAND, 0.8F, true);
+ if (event.isCancelled()) { + if (event.isCancelled()) {
+ event.getProjectile().remove(); + event.getProjectile().remove();
+ return; + return;

View File

@ -1,20 +1,21 @@
--- a/net/minecraft/server/ItemBow.java --- a/net/minecraft/server/ItemBow.java
+++ b/net/minecraft/server/ItemBow.java +++ b/net/minecraft/server/ItemBow.java
@@ -50,6 +50,13 @@ @@ -50,6 +50,14 @@
if (EnchantmentManager.getEnchantmentLevel(Enchantments.ARROW_FIRE, itemstack) > 0) { if (EnchantmentManager.getEnchantmentLevel(Enchantments.ARROW_FIRE, itemstack) > 0) {
entityarrow.setOnFire(100); entityarrow.setOnFire(100);
} }
+ // CraftBukkit start + // CraftBukkit start
+ org.bukkit.event.entity.EntityShootBowEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(entityhuman, itemstack, entityarrow, f); + org.bukkit.event.entity.EntityShootBowEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(entityhuman, itemstack, itemstack1, entityarrow, entityhuman.getRaisedHand(), f, !flag1);
+ if (event.isCancelled()) { + if (event.isCancelled()) {
+ event.getProjectile().remove(); + event.getProjectile().remove();
+ return; + return;
+ } + }
+ flag1 = !event.shouldConsumeItem();
+ // CraftBukkit end + // CraftBukkit end
itemstack.damage(1, entityhuman, (entityhuman1) -> { itemstack.damage(1, entityhuman, (entityhuman1) -> {
entityhuman1.broadcastItemBreak(entityhuman.getRaisedHand()); entityhuman1.broadcastItemBreak(entityhuman.getRaisedHand());
@@ -58,7 +65,16 @@ @@ -58,7 +66,16 @@
entityarrow.fromPlayer = EntityArrow.PickupStatus.CREATIVE_ONLY; entityarrow.fromPlayer = EntityArrow.PickupStatus.CREATIVE_ONLY;
} }

View File

@ -17,7 +17,7 @@
((IProjectile) object).shoot((double) vector3fa.a(), (double) vector3fa.b(), (double) vector3fa.c(), f1, f2); ((IProjectile) object).shoot((double) vector3fa.a(), (double) vector3fa.b(), (double) vector3fa.c(), f1, f2);
} }
+ // CraftBukkit start + // CraftBukkit start
+ org.bukkit.event.entity.EntityShootBowEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(entityliving, itemstack, (Entity) object, f); + org.bukkit.event.entity.EntityShootBowEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(entityliving, itemstack, itemstack1, (Entity) object, entityliving.getRaisedHand(), f, true);
+ if (event.isCancelled()) { + if (event.isCancelled()) {
+ event.getProjectile().remove(); + event.getProjectile().remove();
+ return; + return;

View File

@ -507,16 +507,18 @@ public class CraftEventFactory {
/** /**
* EntityShootBowEvent * EntityShootBowEvent
*/ */
public static EntityShootBowEvent callEntityShootBowEvent(EntityLiving who, ItemStack itemstack, Entity entityArrow, float force) { public static EntityShootBowEvent callEntityShootBowEvent(EntityLiving who, ItemStack bow, ItemStack consumableItem, Entity entityArrow, EnumHand hand, float force, boolean consumeItem) {
LivingEntity shooter = (LivingEntity) who.getBukkitEntity(); LivingEntity shooter = (LivingEntity) who.getBukkitEntity();
CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack); CraftItemStack itemInHand = CraftItemStack.asCraftMirror(bow);
CraftItemStack itemConsumable = CraftItemStack.asCraftMirror(consumableItem);
org.bukkit.entity.Entity arrow = entityArrow.getBukkitEntity(); org.bukkit.entity.Entity arrow = entityArrow.getBukkitEntity();
EquipmentSlot handSlot = (hand == EnumHand.MAIN_HAND) ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND;
if (itemInHand != null && (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0)) { if (itemInHand != null && (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0)) {
itemInHand = null; itemInHand = null;
} }
EntityShootBowEvent event = new EntityShootBowEvent(shooter, itemInHand, arrow, force); EntityShootBowEvent event = new EntityShootBowEvent(shooter, itemInHand, itemConsumable, arrow, handSlot, force, consumeItem);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
return event; return event;