Solved Change the player's name's color

Discussion in 'Plugin Development' started by Robin Bi, Nov 22, 2014.

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

    Robin Bi

    Hey :3


    I have an ArrayList with Players in it. Every Player who's in that ArrayList shall have a colored name in chat.

    So for testing I've written this piece of code:
    Code:java
    1. boolean color = true;
    2.  
    3. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    4. Player p = (Player) sender;
    5. if (cmd.getName().equalsIgnoreCase("color")) {
    6. p.sendMessage(ChatColor.GREEN + "Done.");
    7. color = !color;
    8. if (color) p.setDisplayName("ยง2" + p.getName());
    9. else p.setDisplayName(p.getName());
    10. }
    11. return true;
    12. }

    Yes i know that's very filthy code, but i just use it for testing purposes, so no nullchecks etc. necessary.


    Unfortunately, this seems to do just nothing. I get the "Done."-message and no exceptions, but my name's color doesn't change.



    Maybe someone can help meh? <3

    Lel i checked it yesterday and it doesn't work, today it does.... My fault, i guess.

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

    mine-care

    Player p = (Player) sender;

    Ouch! my eye! read my signature. The fact that is a test plugin doesn't mean you dont have to be carefull with your code, Thats for either the future if you decide to release it to the public it will take you loads of time to trace and fix issues in your code to secure it, or to avoid errors that will mess you up when you test it. Or even to keep your skills up and not get used to sh... programing rather than good and efficient programing.

    i hope you mean your chat display name right? A better practice i encouraged was to use AsyncPlayerChatEvent and change it this way. :) Otherwise i think it should work fine unless there is another plugin to mess with name color like essentials chat ect.
     
Thread Status:
Not open for further replies.

Share This Page