Check if fishing rod has been pulled back

Discussion in 'Spigot Plugin Development' started by yhl, Aug 5, 2018.

  1. yhl


    I want to check if player has clicked twice on a fishing rod and not sure how to do it.
  2. Try this:
    Code (Java):
    /* keep track of every player that has fishing rod thrown */
    List<UUID> players = new ArrayList<>();

    public void onInteract(PlayerInteractEvent event){
        Player player = event.getPlayer();
        if(player.getItemInHand().getType() == Material.FISHING_ROD){
            /* check if they have thrown it */
            else {
                /* they've retracted the fishing rod, do stuff */

    You might want to check if they change their selected hotbar slot as well, but that is the basic that I can think of.
  3. yhl


    nah idk if that would work but I found PlayerFishEvent and I think e.getState == State.FAILED_ATTEMPT might work but idk

    EDIT: it did :D
  4. PlayerFishEvent

    @iabuse_ should at least use a Set, which is generally faster for contains and remove operations compared to Set :p
  5. I think you could utilize the PlayerFishEvent, specifically when the event is called with the FISHING state to handle when a player initially casts the line. You would store the user's UUID in some sort of List, array, or even a Set then in the PlayerInteractEvent you would see if a player in the container you've created has clicked again with a fishing rod.
  6. You mean compared to a List? Thanks for the tip.
  7. yhl


    How would I get the direction the fishing rod was thrown? e.getHook().getLocation().getDirection() doesn't work because for some reason in some directions it's reversed.
  8. Correct. Lists are good for iteration and duplicates, Sets are good for contains checks and fast removal.
    Maybe try to get the direction from the location of the hook, relative to your own location.
  9. yhl


    How would that work?
  10. Get the location of the hook as Vector, subtract the location of the player (as Vector), and boom, you have a Vector from the player to the hook.

    You can normalize it as well (making it a Vector with length 1, which might be required for some math?)