How to go from entity to player

Discussion in 'Plugin Development' started by Arangaduy, Dec 7, 2020.

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

    Arangaduy

    Hello people. I need your help writing a plugin.
    I need to go from entity to player. Help me please!
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Arangaduy Check if it is a player, if so: cast to player
     
  3. Offline

    Arangaduy

    I tried, but I don't know how to write it in the code

    My code:
    Player p = e.getEntityType().getName();

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Dec 7, 2020
  4. Offline

    timtower Administrator Administrator Moderator

    @Arangaduy
    Player p = e;
    Will give an error, hover your mouse over it
     
  5. Offline

    Arangaduy

    I understand that I need to get an error from entity to player!
     
  6. Offline

    timtower Administrator Administrator Moderator

    @Arangaduy Eclipse (or whatever you are using) will tell you that you can't do that, that is why you get the error.
    Hovering your mouse over it should give you quick fixes.
     
  7. Offline

    Arangaduy

    I do this, but it offers many ways and they do not work for me because I do not know how to do it.
     
  8. Offline

    timtower Administrator Administrator Moderator

    @Arangaduy Might want to consider a java tutorial in that case.
    This is basic class casting.
    Player p = (Player) e;
     
  9. Offline

    Arangaduy

    I need to go from entity to player and not from player to player
     
  10. Offline

    timtower Administrator Administrator Moderator

    @Arangaduy Try it please, it does not go from Player to Player.
    This is called "class casting"
     
  11. Offline

    Arangaduy

    I need to switch from entity to player write just a line for this please
     
  12. Offline

    timtower Administrator Administrator Moderator

    I already did!
    Put that line in your code.
     
    Newdel likes this.
Thread Status:
Not open for further replies.

Share This Page