Color code help?

Discussion in 'Plugin Development' started by Sizableshrimp0, Apr 1, 2015.

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

    Sizableshrimp0

    Hey, I'm making a plugin where someone does /setprefix (and they type in a prefix). I need to find out how they can use color codes in the typed prefix. Please help me :)
     
  2. Offline

    nverdier

    @Sizableshrimp0 Use ChatColor#translateAlternateColorCodes('&', PREFIX_HERE);
     
  3. Offline

    Sizableshrimp0

    @nverdier what if they type in their own prefix?
     
  4. Offline

    justin_393

    Code:
    @Override
        public boolean onCommand(CommandSender sender, Command cmd,
                String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("YOUR COMMAND")) {
                    String prefix = args[0];
                    ChatColor.translateAlternateColorCodes('&', prefix);
                return true;
            }
            return false;
        }
     
  5. Offline

    nverdier

  6. Offline

    Sizableshrimp0

    Sweet! I got it! Thanks for all your help.
     
  7. Offline

    nverdier

  8. Offline

    Sizableshrimp0

    @nverdier

    I have a problem, this is my code:

    Code:
    if(cmd.getName().equalsIgnoreCase("SetPrefix")){
                      if(p.hasPermission("SetPrefix.SetPrefix")){
                      if(args.length == 0){
                      p.sendMessage(ChatColor.RED + "Usage: /SetPrefix (Prefix)");
                    }else if(args.length == 1){
                          String msg= "";
                          for (int i = 0; i < args.length; i++) {
                                  msg = msg +args[i] + " ";
                                 String message = msg;
    ChatColor.translateAlternateColorCodes('&', message);
                      p.setDisplayName(msg + p.getName());
                      p.sendMessage(ChatColor.BLUE + "Your name's prefix is now " + msg);
    it doesnt work. Please help
     
  9. Offline

    justin_393

    What's the error?
     
  10. Offline

    Sizableshrimp0

  11. Offline

    Konato_K

    @Sizableshrimp0 Strings are immutable, so ChatColor#translatebla bla returns a new String.
     
  12. Offline

    Sizableshrimp0

    I just need to know how someone could do something like this. Ex: /SetPrefix &4[owner]
     
  13. Offline

    justin_393

    Well, what you've been shown up above would only apply for one message. If you're trying to make it permanent you'll have to save it to a file. And are you typing "&" before your messages? i.e /setprefix &4Owner
     
  14. Offline

    TheDiamond06

  15. Offline

    Sizableshrimp0

  16. Offline

    nverdier

    No, just use
    Code:
    ChatColor.translateAlternateColorCodes('&', args[0]);
     
  17. Offline

    Sizableshrimp0

    Last edited by a moderator: Apr 1, 2015
  18. Offline

    nverdier

    @Sizableshrimp0 What didn't work about it? Is there an error? Please post the error if so.
     
  19. Offline

    Sizableshrimp0

    @nverdier when i put in the prefix on my name it comes up as Ex: <&4Owner Sizableshrimp0>
     
  20. Offline

    justin_393

    First off, that won't work because "&" isn't a char, and why would you replace the String with §?
     
  21. Offline

    Sizableshrimp0

    @justin_393 im using ChatColor.translateAlternateColorCodes('&', args[0]);
     
  22. Offline

    justin_393

    Is there any color at all? Or is it literally printing "&4Owner Sizableshrimp0"
     
  23. Offline

    Sizableshrimp0

  24. Offline

    justin_393

    Is there any error in your console?
     
  25. Offline

    Sizableshrimp0

  26. Offline

    nverdier

    Because the § is the color code in Minecraft...


    @Sizableshrimp0 Please post your entire current code.
     
  27. Offline

    Sizableshrimp0

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){{
                  Player p = (Player) sender;
                 
                  if(cmd.getName().equalsIgnoreCase("SetPrefix")){
                      if(p.hasPermission("SetPrefix.SetPrefix")){
                      if(args.length == 0){
                      p.sendMessage(ChatColor.RED + "Usage: /SetPrefix (Prefix)");
                    }else if(args.length == 1){
                          String msg= "";
                          for (int i = 0; i < args.length; i++) {
                                  msg = msg +args[i] + " ";
                                  ChatColor.translateAlternateColorCodes('&', args[0]);
                      p.setDisplayName(msg + p.getName());
                      p.sendMessage(ChatColor.BLUE + "Your name's prefix is now " + msg);
     
  28. Offline

    justin_393

    Oh whoops, I read it wrong, I thought he was using ChatColor.TranslateAlternateColorCodes(char, String);
    Whoops, that's what I get for glancing
     
  29. Offline

    nverdier

    @Sizableshrimp0 Well you have to set 'msg' to what #translateAlternateColorCodes() returns.
     
  30. Offline

    Sizableshrimp0

Thread Status:
Not open for further replies.

Share This Page