Minecraft check if player has thrown out a fishing rod?

Discussion in 'Plugin Development' started by Didi1150, Apr 30, 2020.

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

    Didi1150

    So I want to know, if the Player has already pulled the fishing rod out.
     
  2. Offline

    KarimAKL

    @Didi1150 I think you can listen to the PlayerFishEvent, and then check if the State is REEL_IN.

    I'm just assuming that's what you want.

    If not, there's also other states related to the fishing rod.
     
  3. Offline

    Banjer_HD

    You could write a listener (PlayerFishEvent) and store all te playernames that started to fish in a list and remove them when they are done fishing. (Dont know if it will call stop fishing when a player leaves the server, otherwise also listen for PlayerQuitEvent)

    Then use this function:
    Code:
    public boolean isPlayerFishing(String playername) {
        return list.contains(playername);
    }
     
  4. Offline

    Didi1150

    Thx, and how do u add velocity to the player, so that he flies into the hook direction?

    And there is no state called reel_in

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 1, 2020
  5. Offline

    KarimAKL

    Use Entity#setVelocity(Vector)

    I linked you to the javadocs. Which version are you building for?
     
  6. Offline

    Didi1150

    1.8
    and if i use p.setVelocity(event.getHook.getLocation.toVector());
    the player will start flying straight up into the air, and not to the hook position
     
  7. Offline

    timtower Moderator Moderator

    @Didi1150 Because that is not relative to the player. That is an absolute value.
     
  8. Offline

    Didi1150

    How do i make him launch towards the hook then?

    help

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 2, 2020
  9. Offline

    KarimAKL

    @Didi1150 Subtract the player's location's vector from the hook's location's vector.
     
  10. Offline

    Didi1150

    and then?
     
  11. Offline

    KarimAKL

    @Didi1150 Then set the player's vector to the returned vector. :p
     
  12. Offline

    Didi1150

    thx, u solved my problem. I have another question, how do u teleport a player five blocks in the direction he is looking?
     
  13. Offline

    KarimAKL

    @Didi1150 Never tried it but, i think multiplying the Vector returning from Player#getLocation()#getDirection() by the amount of blocks you want them to teleport, and then adding that vector to the player's location using Player#getLocation()#add(Vector) should work.

    Of course you'd need to teleport the player to the location returned by the Location#add(Vector) method.
     
  14. Offline

    Didi1150

    And, how to check if there is any block in this range, so the player doesn't get stuck?
     
  15. Offline

    KarimAKL

    @Didi1150 You could check the blocks around the returned location.
     
  16. Offline

    Didi1150

    but then, the block in the side would be counted too
     
  17. Offline

    KarimAKL

    @Didi1150 That depends on how you do it. :p Just do some tests, and if you still can't get it working, post your progress and what you've tried here.
     
  18. Offline

    Didi1150

    i did the location he gets tped, and then check if the block is air or not. But my problem is still the sound. It says nosuchfield and I'm using Sound.ENTITY_ENDERMAN_TELEPORT
     
  19. Offline

    KarimAKL

    @Didi1150 Sound#ENTITY_ENDERMAN_TELEPORT doesn't exist in version 1.8, it's just called ENDERMAN_TELEPORT.
     
  20. Offline

    Didi1150

    oh i solved it, I'm using maven, and i had spigot 1.15 lib instead of 1.8
     
Thread Status:
Not open for further replies.

Share This Page