diff --git a/src/main/java/net/minecraft/server/EntityFish.java b/src/main/java/net/minecraft/server/EntityFish.java index 74bcf35e97..ed704a9c00 100644 --- a/src/main/java/net/minecraft/server/EntityFish.java +++ b/src/main/java/net/minecraft/server/EntityFish.java @@ -6,6 +6,7 @@ import java.util.List; import org.bukkit.entity.Projectile; import org.bukkit.event.entity.EntityDamageByProjectileEvent; import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.player.PlayerFishEvent; // CraftBukkit end public class EntityFish extends Entity { @@ -336,6 +337,16 @@ public class EntityFish extends Entity { byte b0 = 0; if (this.c != null) { + // CraftBukkit start + PlayerFishEvent playerFishEvent = new PlayerFishEvent((org.bukkit.entity.Player) this.owner.getBukkitEntity(), this.c.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_ENTITY); + this.world.getServer().getPluginManager().callEvent(playerFishEvent); + + if (playerFishEvent.isCancelled()) { + this.die(); + this.owner.hookedFish = null; + return 0; + } + // CraftBukkit end double d0 = this.owner.locX - this.locX; double d1 = this.owner.locY - this.locY; double d2 = this.owner.locZ - this.locZ; @@ -348,6 +359,16 @@ public class EntityFish extends Entity { b0 = 3; } else if (this.k > 0) { EntityItem entityitem = new EntityItem(this.world, this.locX, this.locY, this.locZ, new ItemStack(Item.RAW_FISH)); + // CraftBukkit start + PlayerFishEvent playerFishEvent = new PlayerFishEvent((org.bukkit.entity.Player) this.owner.getBukkitEntity(), entityitem.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_FISH); + this.world.getServer().getPluginManager().callEvent(playerFishEvent); + + if (playerFishEvent.isCancelled()) { + this.die(); + this.owner.hookedFish = null; + return 0; + } + // CraftBukkit end double d5 = this.owner.locX - this.locX; double d6 = this.owner.locY - this.locY; double d7 = this.owner.locZ - this.locZ; @@ -363,9 +384,25 @@ public class EntityFish extends Entity { } if (this.h) { + // CraftBukkit start + PlayerFishEvent playerFishEvent = new PlayerFishEvent((org.bukkit.entity.Player) this.owner.getBukkitEntity(), null, PlayerFishEvent.State.IN_GROUND); + this.world.getServer().getPluginManager().callEvent(playerFishEvent); + + if (playerFishEvent.isCancelled()) { + this.die(); + this.owner.hookedFish = null; + return 0; + } + // CraftBukkit end b0 = 2; } + // CraftBukkit start + if (b0 == 0) { + PlayerFishEvent playerFishEvent = new PlayerFishEvent((org.bukkit.entity.Player) this.owner.getBukkitEntity(), null, PlayerFishEvent.State.FAILED_ATTEMPT); + this.world.getServer().getPluginManager().callEvent(playerFishEvent); + } + // CraftBukkit end this.die(); this.owner.hookedFish = null; return b0; diff --git a/src/main/java/net/minecraft/server/ItemFishingRod.java b/src/main/java/net/minecraft/server/ItemFishingRod.java new file mode 100644 index 0000000000..9bcf2e2f0d --- /dev/null +++ b/src/main/java/net/minecraft/server/ItemFishingRod.java @@ -0,0 +1,38 @@ +package net.minecraft.server; + +import org.bukkit.event.player.PlayerFishEvent; // CraftBukkit + +public class ItemFishingRod extends Item { + + public ItemFishingRod(int i) { + super(i); + this.d(64); + this.c(1); + } + + public ItemStack a(ItemStack itemstack, World world, EntityHuman entityhuman) { + if (entityhuman.hookedFish != null) { + int i = entityhuman.hookedFish.h(); + + itemstack.damage(i, entityhuman); + entityhuman.w(); + } else { + // CraftBukkit start + PlayerFishEvent playerFishEvent = new PlayerFishEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), null,PlayerFishEvent.State.FISHING); + world.getServer().getPluginManager().callEvent(playerFishEvent); + + if (playerFishEvent.isCancelled()) { + return itemstack; + } + // CraftBukkit end + world.makeSound(entityhuman, "random.bow", 0.5F, 0.4F / (b.nextFloat() * 0.4F + 0.8F)); + if (!world.isStatic) { + world.addEntity(new EntityFish(world, entityhuman)); + } + + entityhuman.w(); + } + + return itemstack; + } +}