use of org.bukkit.event.player.PlayerFishEvent in project Glowstone by GlowstoneMC.
the class GlowFishingHook method reelIn.
/**
* Removes this fishing hook. Drops loot and xp if a player is fishing.
*/
public void reelIn() {
if (location.getBlock().getType() == Material.WATER) {
ProjectileSource shooter = getShooter();
if (shooter instanceof Player) {
PlayerFishEvent fishEvent = new PlayerFishEvent((Player) shooter, this, null, CAUGHT_FISH);
fishEvent.setExpToDrop(ThreadLocalRandom.current().nextInt(1, 7));
fishEvent = EventFactory.getInstance().callEvent(fishEvent);
if (!fishEvent.isCancelled()) {
// TODO: Item should "fly" towards player
world.dropItemNaturally(((Player) getShooter()).getLocation(), getRewardItem());
((Player) getShooter()).giveExp(fishEvent.getExpToDrop());
}
}
}
remove();
}
Aggregations