Search in sources :

Example 1 with PlayerFishEvent

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();
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) Player(org.bukkit.entity.Player) PlayerFishEvent(org.bukkit.event.player.PlayerFishEvent) ProjectileSource(org.bukkit.projectiles.ProjectileSource)

Aggregations

GlowPlayer (net.glowstone.entity.GlowPlayer)1 Player (org.bukkit.entity.Player)1 PlayerFishEvent (org.bukkit.event.player.PlayerFishEvent)1 ProjectileSource (org.bukkit.projectiles.ProjectileSource)1