Changing name colors

Discussion in 'Spigot Plugin Development' started by Karatechimp29, May 23, 2015.

Thread Status:
Not open for further replies.
  1. hey guys, i have set up a fancy gui with different colored wool for different name colors. i know how to set the actions to them but i have no idea what i need to put in order for it to ONLY change the players name color, not change name letters (eg, nickname). only the displayname color in chat. really need this sorted asap!

    thanks all!!

    - karatechimp29
     
  2. Couldn't you just use
    Code (Text):
    String name = p.getDisplayName();
    p.setDisplayName(color + name);
     
  3. I'll give it a shot, I was trying to do:

    Code (Text):
    player.setDisplayName(ChatColor.GOLD+player.getName()+ChatColor.RESET);
    But even then, would it not just go back to normal on every reload?
     
    • Useful Useful x 1
  4. You would need to store it somewhere if you want the colour to stay on a reload/restart.
    Code (Text):
    player.setDisplayName(ChatColor.RED + player.getName() + ChatColor.RESET);
     
  5. Mind explaining this, can I store this in a hash map? Or are physical files better? If so please explain some code to me. Thanks! :D

    Also, I take it that this should work if the colours are stored properly?

    Code (Text):

    player.setDisplayName(ChatColor.RED + player.getName() + ChatColor.RESET);
     
    EDIT: probably config right, as hash maps get reset on server restart?
     
    #5 Karatechimp29, May 23, 2015
    Last edited: May 23, 2015
  6. I'm pretty sure setDisplayName doesn't work. My idea is to use protocollib, listen for a spawnentity packet, if that is spawning an entityplayer, get the profile and set the name.
     
  7. I was hoping to make my plugin standalone
     
  8. Any help would be great, how can I store my name color data
     
  9. @GGhost You don't need protocollib for something as simple as this....

    When you say change the color of their name. Do you mean the name displayed in chat or like from a command or from TAB?
    @Karatechimp29
     
  10. @ES359 I was merely bouncing ideas on how to do this because I haven't attempted this since 1.6
     
    • Like Like x 1
  11. Gotcha.

    EDIT:
    @Karatechimp29 I would suggest using configuration, or the chat event to set the names.
     
  12. You can save your colors in a config file. Just use the Bukkit/Spigot configuration. The config allows you to save/read values. Even if the server restarts are they still in the config file and you can easily read them into your plugin.
    Here's a link that will prepare you to use the configuration!:)
    http://wiki.bukkit.org/Configuration_API_Reference
     
  13. I am going for only ingame, I was thinking above head too but that would require tagAPI. the config idea confused me as I don't know what variable to save in the config for each color to be called on reloads.
     
  14. Best way you could do it, is through § symbol. For example, "§4%playername%§f"
     
    #14 SlowFxx, May 24, 2015
    Last edited: Jul 29, 2015
  15. Ok so I'm a little confused here. I remember seeing a .replaceAll() method somewhere in the past. Maybe that would apply here. Can I have an example code?
     
  16. To translate color codes, use "ChatColor.translateAlternateColorCodes", and for String replacements have a look at the String apidocs.
     
  17. Did I miss something?
     
    • Winner Winner x 1
  18. Ok so if I do that and then use the standard colour Codes in my code for coloring conventions?
     
  19. Special characters can be used in yaml formatted files as long as you use "s correctly.
     
    • Like Like x 1
  20. Change color in chat:
    Code (Java):
        @EventHandler
        public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
            Player p = event.getPlayer();
            ChatColor color = ChatColor.valueOf(path);
            // Define the color of their name above. Fetch the color from wherever. (E.G. yml file, MySQL database...)
            p.setDisplayName(color + p.getDisplayName());
        }
    Change color above head:
    Read - https://bukkit.org/threads/tagapi-change-color-the-name-over-peoples-heads.99485/

    Change color in tab list:
    Code (Java):
    p.setPlayerListName(color + p.getDisplayName());
     
    • Agree Agree x 1
    • Winner Winner x 1
    • Useful Useful x 1
Thread Status:
Not open for further replies.