Player Chat

Discussion in 'Plugin Development' started by badboysteee98, Apr 15, 2014.

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

    badboysteee98

    I was making a plugin for Player Chat and when then do /colour white it will change there name to white as I made this it works with the command and so on but when I do the command the name doesn't changed

    My Code:
    Code:java
    1. if(args[0].equalsIgnoreCase("white")) {
    2. p.sendMessage(ChatColor.YELLOW + "You name color was changed to" + ChatColor.WHITE + " white");
    3. p.setDisplayName(ChatColor.WHITE + p.getName());
    4. }
    5. }
     
  2. Offline

    VictoryShot


    Code:java
    1. p.setDisplayName(ChatColor.WHITE + p.getName());


    Try this

    Code:java
    1. p.setDisplayName(ChatColor.WHITE + "" + p.getName());


    Also are you using essentials in your plugins?
     
  3. Offline

    badboysteee98

    VictoryShot No that doesn't work sorry and yea

    VictoryShot Okay that works when I disabled the thing in essentials but it doesn't show what rank I am in

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

    VictoryShot

    What are you using for ranks?
     
  5. Offline

    MrAwellstein

    Essentials might change the Custom Name, so what you can do is player.setDisplayName(player.getDisplayName + "stuff");
    (not entirely sure, havent checked, never had to work with essentials)
     
  6. Offline

    badboysteee98

    VictoryShot GroupManager for the Prefix and so on

    MrAwellstein This doesn't seem to work

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

    MrAwellstein


    Weird. I'd check some other plugin like McJobs or something, because I remember it doing what you need to do.
     
  8. Offline

    badboysteee98

  9. Offline

    BillyGalbreath

    Just a side note: Instead of having them specify a color word, you can let them specify the color/style codes themselves with minimal code on your part (if you wanted):

    Code:java
    1.  
    2. @Override
    3. public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
    4. if (!cmd.getName().equalsIgnoreCase("colour"))
    5. return true; // not the right command. do nothing.
    6. if (!(cs instanceof Player)) {
    7. cs.sendMessage("Only players may access this command.");
    8. return true;
    9. }
    10. Player player = (Player) cs;
    11. if (args.length() == 0) {
    12. player.sendMessage("Only players may access this command.");
    13. return true;
    14. }
    15. String colourCode = args[0].trim();
    16. if (!colourCode.matches("(?i)&([a-f0-9k-or])")) { // check for valid color/style codes
    17. player.sendMessage("Not a valid color code.");
    18. return true;
    19. }
    20. String newName = ChatColor.translateAlternateColorCodes('&', colourCode + player.getName());
    21. player.sendMessage("Your name has been changed to " + newName);
    22. player.setDisplayName(newName);
    23. return true;
    24. }
    25.  


    This example uses the & symbol for color codes. It can be changed to anything, even a value set from the config.yml easily.
     
Thread Status:
Not open for further replies.

Share This Page