Changing name above character

Discussion in 'Resources' started by Acrobot, Jul 4, 2011.

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

    Acrobot

    This is a little function that may help you with changing player's label:

    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;
        }
    
    Just change yourPluginMainClass to, well, your plugin's main class.

    EDIT: It seems like the only issue is random spazzing, that doesn't affect anything, but is just visual respawn.
     
  2. Offline

    desmin88

    @Acrobot
    Why do you put this code in an asnyc task?
    Also, why does it need to constantly be sent?
     
  3. Offline

    Acrobot

    @desmin88
    If player joins, you must change the name on his client too, unless you want to change the player name permanently, so iConomy accounts, etc. will change too.
     
  4. Offline

    Styx Reborn

    [​IMG]
    I'm a dev and I approve this method. Were dupes an unwanted side-effect? :DD
    [05:40] <SmilingDevil> CLONES EVERYWHERE

    What I have found:
    Skin goes to default :(
    Might duplicate player ??
     
  5. Offline

    Sleaker

    This method will conflict with any plugin that sets a player invisible as it sends spawn packets to other clients. Also because you never send Packet29 to destroy the original entity, you are going to send multiple spawn packets to the clients thus you get the clones everywhere.

    The only time the entity needs to be updated is when another player comes near the player, so you could realistically only send the update packet when a player is within about ~= 20 chunks. or a 320 block radius.
     
  6. Offline

    RawCode

    we need some way to alter vanilla packets to make this (and many other things) without any side effects.
     
  7. Offline

    Acrobot

    @Styx Reborn
    Dupes - nope, I have no clue :p
    And I can't fix the skin - it's the client that chooses it :/

    @Sleaker
    Yes, I'll be improving this.

    EDIT: I will be probably modifying netServerHandler.
     
  8. Offline

    desmin88

    @Acrobot
    You get dupes because you spawn new entitys without destroying the old ones.
     
  9. Offline

    Acrobot

    @desmin88
    I know, I will be fixing that, however, I need to find the function that send the Packet20NamedEntitySpawn to override it.
     
  10. Offline

    desmin88

  11. Offline

    Acrobot

    @desmin88
    Yep, I know that. But how can I override this?
    Only by modifying Bukkit.

    I am now making version that works nicely, I only have problems with disconnecting, but expect it to be fixed soon.
     
  12. Offline

    Styx Reborn

    Disconnecting... erhm? Related to string length? Yes.
     
  13. Offline

    Acrobot

    @Styx Reborn
    Not exactly, PM me and I'll give you my server's ip :p
     
  14. Offline

    desmin88

    @Acrobot
    Can you PM me with the IP?
     
  15. Offline

    Acrobot

    @desmin88
    I'm sorry, it was hosted on my PC, pm me when I'm online :p
    Also, I tested it with @Styx Reborn, it was fun until player with changed name disconnected :/ It duplicated him.
     
  16. Offline

    desmin88

    @Acrobot
    My plugin MobDisguise achieves this. Flawless victory.
     
  17. Offline

    Acrobot

    @desmin88
    Nice one :)
    This was using no BukkitContrib, I believe your does =)
     
  18. Offline

    desmin88

    @Acrobot
    For a totally different thing. This doesn't need the client side bukkitcontrib either. The name changing part does not use it
     
  19. Offline

    Jaxkr

    I think that this would be a LOT easier with Spout.
     
  20. Offline

    Acrobot

    @Jaxkr
    It is.
    But Spout wasn't that popular than, and I'm not reviving this thread ATM. (maybe later)
     
  21. Offline

    Tauryuu

    Please do. D:
     
  22. Offline

    wirher

    Is it possible to add colours to nicks above head using this method?
     
  23. Offline

    xGhOsTkiLLeRx

    wirher

    Yes it is.
    Somehow I'm loosing the current skin with this method :(
     
  24. Offline

    Cirno

    Reason for this is because since you send a new packet to a client with the new user, the client will pick it up and go "Get me this user's skin" and wa-la, you get someone else's skin.
     
  25. Offline

    xGhOsTkiLLeRx

    Yeah. Already thought about this point.
    Normally I join -> name is xGhOsTkiLLeRx -> MC fetches skin for the user (name)
    The I create a new "fake" user called -> ChatColor.RED + xGhOsTkiLLeRx -> means §cxGhOsTkiLLeRx -> name does not have a custom skin -> default...
     
  26. Offline

    B3NW

    I believe essentials gets around this somehow, AFAIK essentials is open source, look how they do it.
     
  27. Offline

    xGhOsTkiLLeRx

    Yeah? I thought essentials doesn't do anything with skins?
    Or do you mean SpoutEssentials?
     
  28. Offline

    wirher

    Essentials only changes chat names and tab players with /nick commands.
    But if you mean Spout plugin there is almost everything possible but not normal-player-friendly.
     
  29. Offline

    Wulfspider

    Players shouldn't be using SpoutPlugin, as it's used by server owners. ;)
    It's just the base API, so I don't see how it would have to be that friendly to use, as there isn't anything really to configure. It's the job of other developers to make their plugins "friendly" for admin to use.

    If you're talking about the Spoutcraft client, then it's not really hard to use. They simply download and run it.
     
  30. Offline

    wirher

    Of course I was talking about Spoutcraft. Many of normal players don't want to log in in another client than official because they are afraid of losing account.
    1. Why there isn't any server that requires Spoutcraft and have 200 users online?
    2. Spoutcraft startup is very long.
    3. You have to wait very long for recommended build because dev builds have many bugs.

    I was fan of Spout but it is too bad for big servers.
     
Thread Status:
Not open for further replies.

Share This Page