Solved Fish Type from PlayerFishEvent

Discussion in 'Plugin Development' started by Jombi, Mar 6, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Jombi

    Is it possible to get the type of fish from PlayerFishEvent? I know how to get the state and check that, but I'm not sure where to start for grabbing the type of fish a player hooks.
     
  2. Offline

    97WaterPolo

    Jombi

    Yes, as the rest of the fish come down from the original one this should work. This goes under the player fish event

    Code:
    Item item = (Item)event.getCaught();
                    if ((item.getItemStack().getType().equals(Material.RAW_FISH)))
                    {
                        //Code to do something
                    }
     
    Jombi likes this.
  3. Offline

    Jombi

    Very nice. Thank you!
     
  4. Offline

    Barinade

    [​IMG]
    Code:
                @EventHandler
                public void playerFish(PlayerFishEvent e) {
                    if (!(e.getCaught() instanceof Item)) return; //no catch
                    if (((Item) e.getCaught()).getItemStack().getType() != Material.RAW_FISH) return; //not a fish
                    e.getPlayer().sendMessage("You caught a fish with data " +((Item)e.getCaught()).getItemStack().getData().getData());
                }
                @EventHandler
                public void smackBlockWithFish(PlayerInteractEvent e) {
                    if (e.getAction() == Action.LEFT_CLICK_BLOCK && e.getPlayer().getItemInHand() != null) {
                        if (e.getPlayer().getItemInHand().getType() == Material.RAW_FISH) {
                            byte data = e.getPlayer().getItemInHand().getData().getData();
                            e.getPlayer().sendMessage("You show that block! Smack it with fish data " + data + "!");
                        }
                    }
                }
     
Thread Status:
Not open for further replies.

Share This Page