Entity Human Field Error

Discussion in 'Plugin Development' started by Jbitters3, Jul 22, 2013.

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

    Jbitters3

    Here is my code:
    Code:java
    1. private static void setName(Player player, String name) {
    2. Player cp = (Player) player;
    3. EntityPlayer cplayer = ((CraftPlayer)player).getHandle();
    4. cplayer.name = name;
    5. player.setPlayerListName(name);


    The error line cplayer.name = name;
    The errors is The field EntityHuman.name is not visible
     
  2. Offline

    xTrollxDudex

  3. Offline

    adam753

    The name field is private, which means other classes (I.E. you) can't use it. Instead you should use cplayer.getDisplayName() or any other function from the documentation.
     
  4. Offline

    Jbitters3

  5. Offline

    adam753

    Jbitters3 It's a joke.
    Code:
    cplayer.setDisplayName(name);
    
     
  6. Offline

    xTrollxDudex

    Its not :p

    Look it up. While i do some research.

    adam753
    Ok since its not a joke, lemme prove it to you :)
    PHP:
    cplayer.getClass().getDeclaredField("name").setAccessible(true);
    cplayer.getClass().getDeclaredField("name").set(cplayername);
    That should work

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  7. Offline

    Techy4198

    ...should work if you spell 'Accessible' correctly...
     
  8. Offline

    xTrollxDudex

    Click refresh. I see this:
     
  9. Offline

    Jbitters3

    @xTrollxDude like this?
    Code:java
    1. private static void setName(Player player, String name) {
    2. Player cp = (Player) player;
    3. EntityPlayer cplayer = ((CraftPlayer)player).getHandle();
    4. cplayer.setDisplayName(name);
    5. cplayer.getClass().getDeclaredField("name").setAccessible(true);
    6. cplayer.getClass().getDeclaredField("name").set(cplayer, name);
    7. player.setPlayerListName(name);
    8. }

    I still get an error: The method setDisplayName(String) is undefined for the type EntityPlayer

    Any more help?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  10. Offline

    adam753

  11. Offline

    Jbitters3

    adam753 it then causes another error if I delete it
     
  12. Offline

    adam753

    Jbitters3 What is an EntityPlayer anyway? I can't find any documentation. Why are you using it?
     
  13. Offline

    Jbitters3

    adam753 it is being used to name a player
     
  14. Offline

    adam753

    Jbitters3 Can you not just use player.setDisplayName(name)?
     
  15. Offline

    Jbitters3

    adam753 it wants me to define the type EntityPlayer still, that would not do it
     
  16. Offline

    xTrollxDudex

    Its NMS. Quick google it: mc-dev EntityPlayer. Make sure to click on the correct one though, the one by Bukkit.
    Jbitters3
    Dude, whats the error when you delete setDisplayName?
    Use player.setDisplayName like adam753 said, there should be no problem usin that
     
  17. Offline

    Jbitters3

    xTrollxDudex Using setDisplayName give this the method setDisplayName(String) is undefined for the type EntityPlayer

    Without it, it gives Unhandled exception type NoSuchFieldException
     
  18. Offline

    Scyntrus

  19. Offline

    Jbitters3

    Scyntrus Then why is it giving me the EntityPlayer error then.
     
  20. Offline

    psanker

    This is the kind of Bukkit dev I like: Bukkit hacking.

    Why do you have two references to the same Player instance (player and cp)?
     
  21. Offline

    Scyntrus

    This isn't hacking. One of the things that irritate me in life is when people call something hacking when it's not.

    cp is an instance of Player. cplayer is an instance of EntityPlayer. They are 2 completely different things. you can use setDisplayName on cp but not cplayer. Got it?
     
  22. Offline

    Chiller

    Jbitters3 They just changed the access in 1.6....
    And wouldn't changing their name mess up authentication?
     
  23. Offline

    Scyntrus

    Seeing as how he seems to be an inexperienced coder, I'm assuming he just wants to change the display name.
     
  24. Offline

    Chiller

    Ik, i just dont think he wants to do that though?!
     
    Jbitters3 likes this.
  25. Don't use craftbukkit and if you don't plan on using any NMS code. Just using Player and setting the name is a lot easier than that, if that is what OP wants.
     
  26. Offline

    Techy4198

    OFFTOPIC
    im noticing that almost every thread I pits in has at least one other brony...
     
  27. Offline

    molenzwiebel

    For the unhandled exception, add a try-catch statement
     
Thread Status:
Not open for further replies.

Share This Page