Solved Caught treasure

Discussion in 'Spigot Plugin Development' started by ExpDev, May 16, 2017.

  1. I am trying to listen to the PlayerFishEvent, in order to prevent the player to get fish and treasures (like books and other items). However, cancelling the event all in is not a solution (players won't be able to damage/pull each other with hooks/fishing rods). Any solutions? Just fish and treasures, not other entities such as pigs and mobs.

    EDIT:
    Actually I'm pretty sure the State.CAUGHT_FISH is called when a treasure is called so yeye
     
    #1 ExpDev, May 16, 2017
    Last edited: May 16, 2017
  2. Basically you can check the state of the fish event and cancel it if your required state has been passed.
    Example for "BITE"

    Code (Text):

    @EventHandler
    public void fishEvent(PlayerFishEvent e){
        if(e.getState() == PlayerFishEvent.State.BITE){
            e.setCancelled(true);
        }
    }
     
    A list of available State 's is here
     
  3. I don't know, if this works, i haven't tryed it yet:
    Code (Text):

    Entity entity = event.getCaught();
    if (entity instanceof Item) {
        event.setCancelled(true);
    }
     
     
  4. I am aware, but a treasure doesn't bite? I'm talking about items like enchanted books and swords (treasures) u get. There's no way to check if it it is a treasure.