EntityPlayer name

Discussion in 'Plugin Development' started by ISHLCMinecraft, Oct 5, 2013.

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

    ISHLCMinecraft

    Hello everyone,
    I'm trying to show a nametag of player to another player, but I cant access the Name object in the EntityClass.
    Do anyone have a solution?
     
  2. Offline

    ISHLCMinecraft

  3. Offline

    Skyost

    Cast your EntityPlayer to a Player.
    Code:
    Entity entity;
    if(entity instanceof Player)
    Player player = (Player)entity;
     
  4. Offline

    Fozie

    Do you want the player tag to be viseble for all players
    just do {Player}.setCustomName
    Otherwise i don't know
     
  5. Offline

    ISHLCMinecraft

    Skyost You didn't realy understood the question.
    The question is how can I change the name variable in the EntityPlayer class.
    Fozie SetCustomName(String) only works for mobs that are not Playes.
     
  6. ISHLCMinecraft So you want to change the name field? I would use reflection to do so. Take a look at my reflection util, just copy-paste the class inside your plugin and then use it like this:
    Code:java
    1.  
    2. Object entityPlayer = ReflectionUtil.BukkitPlayerToEntityPlayer(player);
    3. try{
    4. Field f = entityPlayer.getClass().getDeclaredField("name");
    5. f.setAccessible(true);
    6.  
    7. f.set(entityPlayer, "Your_value_here");
    8. }catch(Exception e){
    9. e.printStacktrace();
    10. }
    11.  


    May I also ask you why you want to change that field? I don't think it's really safe to play around with that and also maybe there are better ways of doing it?
     
  7. Offline

    Skyost

Thread Status:
Not open for further replies.

Share This Page