Changing Names

Discussion in 'Plugin Development' started by geekygenius, Mar 15, 2012.

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

    geekygenius

    So, we all are very familiar with the floating text above a player's head that resembles a name, right? I know its possible to change it to you're liking, a few plugins, like citizens, do it with NPCs. I know you can change the "List name" and the "Friendly name" of a player, but this doesn't change the name above their head.does anyone have any ideas?
     
  2. Offline

    HON95

    Don't know how, but then the server would have to send a different player to the client, which would cause that the client wouldn't try to load the real players skin... Without any clientmods, like spout, anyways.
     
  3. Offline

    dsmyth1915

    I believe it is setDisplayName()
     
  4. Offline

    Zanzikahn

    I have been looking into it, and without an addon, I doubt you would be able to change the variables of player names without affecting the integrity of the variable search.
     
  5. Offline

    HON95

    That only changes their chat names.
     
  6. Offline

    dsmyth1915

    Okay, then look through the plugin called MobDesguise. That changes the players look, appearance chat and and floatname. There is bound to be answers in there.
     
  7. Offline

    HON95

    The server sends the name of the player you are disguised as instead of your name, so the client gets that player's skin from the minecraft skin database.
     
  8. Offline

    dsmyth1915

    Well then... I guess there may not be a way to do what your asking... If you can find something on it let everyone know, I'm sure it will come in handy
     
  9. Offline

    geekygenius

    Well, what I'm basically trying to do is making the floating names colored. An example of this in a Bukkit server can be found at this IP: a.mcctf.com. So, it must be possible...
     
  10. Offline

    psanker

    A server - client bridge must be set up, for most cases.

    I believe Packet201PlayerInfo might have this information, yet I'm not entirely sure.
     
  11. Offline

    Sorroko

    You can change the players name using reflection but you will lose your skin and other plugins will think you are a different player. It is not recommended ;)
     
  12. I'm pretty sure it's Packet20NamedEntitySpawn...
     
  13. Offline

    Father Of Time

    I’ve done a great deal of research into this subject, and the simple answer is that at this point it is not possible without a client mod, 100% sure of this.

    If you look in craftbukkit inside RenderPlayer there is a function called RenderName, inside the render name it either handles the rendering in that function if you are sneaking, or passes the rendering off to another function in RenderLivingEntity to render the normal name. Here is the catch…

    The actual line of code that renders a player’s name takes 2 arguments, the string to be displayed above the players head which is hard coded to playerentity.name, and the Hexadecimal color you want the name to appear as, which is also hard coded to 0x00ffffff, or a semitransparent white.

    Now I am not saying it can’t be done, I accomplished this by storing a map on the client side that stored all players title and name color, and every time a person logged in or changed their color/tag info I would resend the packet to all logged in players to make sure every client had the same nameplate information, because not doing so would result in the color and content of the nameplate to be client unique.

    Long story short, this is a great deal harder than you would think; and no, there is no easier way to do this. Hopefully they will someday realize this horribly inefficient way of handling nameplates and offer control over the color and content from the server side, but until then you will only be able to handle this by modifying your client.

    Sorry for the bad news, but the upside is that at least you won't spend days looking for something that can't be done.

    EDIT: p.s. I am reciting ALL of this information from memory, so there is a strong likelihood that the class names, function names, and variable names I listed above are incorrect; but the concept and the functionality of the nameplate is 100% accurate.
     
    HON95 likes this.
  14. Offline

    geekygenius

    Well, I was thinking, when MC renders text, it goes character by character because of how you must render text in OpenGL. If it sees the color symbol, (a section marker) then it looks at its code and begins rendering the text in that color. Basically, if I were to color my name, I would want to set it to "[sectionsymbol]4geekygenius". Ill look into packets 201 and 20 though.
     
  15. Offline

    Sorroko

    I would like to prove you wrong ;) Here is some hackish unrecommended code but it does what you need:
    Code:
    public static void changePlayerName (final Player player, final String newName){
            final String oldPlayerName = player.getName();
     
              int interval = 40;
     
            getBukkitServer().getScheduler().scheduleAsyncRepeatingTask(new yourPluginMainClass(), new Runnable() {
                public void run() {
                    EntityPlayer ePlayer = ((CraftPlayer) player).getHandle();
                    ePlayer.name = newName;
                    try{
                        for(Player p : getBukkitServer().getOnlinePlayers()){
                            if(p != player){
                                ((CraftPlayer) p).getHandle().netServerHandler.sendPacket(new Packet20NamedEntitySpawn(ePlayer));
                            }
                        }
                    } catch (Exception ignored){};
                    ePlayer.name = oldPlayerName;
                }
            }, 100L, interval*20L);
        }
        public static Server getBukkitServer() {
            return server;
        }
     
  16. Offline

    geekygenius

    Seems legit. It looks like it could be quite laggy when you get many players connected though, with it sending an update every 40 seconds (40?). CraftPlayer isn't included in the Bukkit API though...
     
  17. Offline

    Sorroko

    I am afraid its that or spout :/
     
  18. Offline

    ItsHarry

    It CAN be done without a client mod.
    What you need to do is cancel the player packets sent by the server, and send your own modified packets instead.
     
  19. Offline

    Sorroko

    You must use Craftbukkit for that method
     
  20. Offline

    Father Of Time

    I'm not sure how this proves me wrong in any way; explain to me how this changes the color of the name display, which was the request of the original poster.

    Also, as stated by other posters, doing it this way will cause all hell to break lost on most servers because many systems use playernames as unique identifiers, allowing them to send a packet that changes the player entities name would cause many plug-ins to malfunction.

    You need a hashmap storage or something of that nature that stores information client side that can hold the nameplate content and color instead of overriding the players name directly. Then in the render classes you can simply use this hashmap information for the nameplate display and color without ever touching the player name itself, leaving plug-ins in tact.

    I just think your "hackish" method as you call it is poor advice and not in the best interest of the original poster.
     
  21. Offline

    Sorroko

    I am pretty sure it is as it changes the name tag and it also changes back the name of the player server side to try to not screw up plugins. The request was not to use client mods, and it doesn't.
     
  22. Offline

    geekygenius

    All I want is an easy way to change names. Something that doesn't lag preferably. Sending a packet every 40 seconds though isn't that bad. I think Ill try it. Ryan, do you change your "external Jar" from Bukkit.jar to CraftBukkit.jar, or just add craftbukkit.jar?
     
  23. Offline

    jamietech

    If you have to use CraftAnything you'll want craftbukkit.jar not bukkit.jar ;)
     
  24. Well it is not needed to send te packet every xx seconds iirc.

    Just send Packet29DestroyEntity packet first and afterwards send a Packet20NamedEntitySpawn with the same data except name changed. That way the old player will be removed from the list and the new one added.

    Only drawback is, that your skin is changed with this process. I am also not sure if this works when you die. it could be that this resets the whole process... But that could be solved through listening to the event and again send those 2 packets if needed.
     
  25. Offline

    geekygenius

    Ok. Thanks! I tried just putting his code in, but it didn't work... D: Maybe I'll try putting the destroy entity and entity spawn packets in their events. Just thinking, I put the send packet in the player login event... maybe it didn't work because there wasn't an entity yet. Just thinking... Thanks!
     
  26. Offline

    geekygenius

    After some testing, I found that you need to send it just after the player joins. This code ended up working, it sent out the name change to ALL ONLINE PLAYERS. If a player joins, the online players will have their name still. An update needs to be sent to them as well. Here is my final code:
    Code:
    public static void changePlayerName(final Player player, final String newName) {
        final String oldPlayerName = player.getName();
       
        EntityPlayer ePlayer = ((CraftPlayer) player).getHandle();
        ePlayer.name = newName;
       
        System.out.println("Changing name!");
            int interval = 40;
     
            IGame.getInstance().getServer().getScheduler().scheduleAsyncDelayedTask(IGame.getInstance(), new Runnable() {
              public void run() {
                  EntityPlayer ePlayer = ((CraftPlayer) player).getHandle();
                  ePlayer.name = newName;
                  try{
                      for(Player p : IGame.getInstance().getServer().getOnlinePlayers()){
                          if(p != player){
                      System.out.println("Sending packet to:"+p.getName());
                      ((CraftPlayer) p).getHandle().netServerHandler.sendPacket(new Packet29DestroyEntity(player.getEntityId()));
                              ((CraftPlayer) p).getHandle().netServerHandler.sendPacket(new Packet20NamedEntitySpawn(ePlayer));
                          }
                      }
                  } catch (Exception ignored){};
                  ePlayer.name = oldPlayerName;
              }
          });
        }
     
  27. Offline

    AmberK

    I modified the craftbukkit file EntityHuman (net.minecraft.server.), from this:
    Code:
    /*      */  public String getLocalizedName() {
    /* 1227 */    return this.name;
    /*      */  }

    Code:
    /*      */  public String getLocalizedName() {
    /* 1227 */    if (this.name.equals("LulzAdmin"))
    /*      */    return (ChatColor.GREEN + "LulzAdmin" + ChatColor.WHITE);
    /*      */    else return this.name;
    /*      */  }
    
    And got the result without a changed skin.

    I feel like this copy/pasted wrong, one sec...
    It did.
     
    Cirno and HON95 like this.
  28. Offline

    Sorroko

    AmberK Thats a good solution but it cant be done from a plugin, instead each person must download an edited craftbukkit. Not the best way to do this.
     
  29. Offline

    AmberK

    Well, so far, it's my favorite method :)

    It's also easy if you have craftbukkit decompiled and in eclipse.
     
  30. Offline

    Sorroko

    AmberK I suppose, not the best way though ;)
     
Thread Status:
Not open for further replies.

Share This Page