--- a/net/minecraft/world/item/EnderpearlItem.java +++ b/net/minecraft/world/item/EnderpearlItem.java @@ -21,22 +_,32 @@ @Override public InteractionResult use(Level level, Player player, InteractionHand hand) { ItemStack itemInHand = player.getItemInHand(hand); - level.playSound( - null, - player.getX(), - player.getY(), - player.getZ(), - SoundEvents.ENDER_PEARL_THROW, - SoundSource.NEUTRAL, - 0.5F, - 0.4F / (level.getRandom().nextFloat() * 0.4F + 0.8F) - ); if (level instanceof ServerLevel serverLevel) { - Projectile.spawnProjectileFromRotation(ThrownEnderpearl::new, serverLevel, itemInHand, player, 0.0F, PROJECTILE_SHOOT_POWER, 1.0F); + // CraftBukkit start + // Paper start - PlayerLaunchProjectileEvent + final Projectile.Delayed thrownEnderpearl = Projectile.spawnProjectileFromRotationDelayed(ThrownEnderpearl::new, serverLevel, itemInHand, player, 0.0F, EnderpearlItem.PROJECTILE_SHOOT_POWER, 1.0F); + com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) player.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemInHand), (org.bukkit.entity.Projectile) thrownEnderpearl.projectile().getBukkitEntity()); + if (event.callEvent() && thrownEnderpearl.attemptSpawn()) { + if (event.shouldConsume()) { + itemInHand.consume(1, player); + } else if (player instanceof net.minecraft.server.level.ServerPlayer) { + ((net.minecraft.server.level.ServerPlayer) player).getBukkitEntity().updateInventory(); + } + + serverLevel.playSound((Player) null, player.getX(), player.getY(), player.getZ(), SoundEvents.ENDER_PEARL_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (serverLevel.getRandom().nextFloat() * 0.4F + 0.8F)); + player.awardStat(Stats.ITEM_USED.get(this)); + } else { + // Paper end - PlayerLaunchProjectileEvent + if (player instanceof net.minecraft.server.level.ServerPlayer) { + ((net.minecraft.server.level.ServerPlayer) player).getBukkitEntity().updateInventory(); + } + return InteractionResult.FAIL; + } } + level.playSound((Player) null, player.getX(), player.getY(), player.getZ(), SoundEvents.ENDER_PEARL_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (level.getRandom().nextFloat() * 0.4F + 0.8F)); + // CraftBukkit end - player.awardStat(Stats.ITEM_USED.get(this)); - itemInHand.consume(1, player); + // Paper - PlayerLaunchProjectileEvent - moved up return InteractionResult.SUCCESS; } }