how would i make nick command

Discussion in 'Plugin Development' started by ahuby09, Nov 17, 2012.

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

    ahuby09

    right how would i make it so you could give your self a nick name e.g /name lol

    bump

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

    jasalb236

    in the onCommand method, you first have to get the string of the nickname so something like: String nick = args[0]. Then, you have to set the Displayname of the player to the string, so: player.setDisplayName(nick)
     
  3. Offline

    fireblast709

    also, check:
    • if the commandSender is a player before you cast: if(sender instanceof Player)
    • if the args[] size > 0 (aka 1 or more arguments)
     
  4. Offline

    AddisCraft

    Could any of you post a code of what you just said? Im trying to do what you say, but I fail.


    and, would it be something like this, or am I completely wrong:
    Code:
            else if(commandLabel.equalsIgnoreCase("Nick")); {
                String nick = args[O];
                player.setDisplayName(nick);
            }
     
  5. Offline

    Drkmaster83

    Well, if you wanted color codes, you'd have to make it:
    Code:
    else if(commandLabel.equalsIgnoreCase("Nick"))
    {
        String playerNick = args[0];
        player.setDisplayName(playerNick.replaceAll("&a", "§a").replaceAll("&b", "§b")
                                .replaceAll("&c", "§c").replaceAll("&d", "§d").replaceAll("&e", "§e")
                                .replaceAll("&f", "§f").replaceAll("&k", "§k").replaceAll("&l", "§l")
                                .replaceAll("&m", "§m").replaceAll("&n", "§n").replaceAll("&o", "§o")
                                .replaceAll("&r", "§r").replaceAll("&A", "§a").replaceAll("&B", "§b")
                                .replaceAll("&C", "§c").replaceAll("&D", "§d").replaceAll("&E", "§e")
                                .replaceAll("&F", "§f").replaceAll("&K", "§k").replaceAll("&L", "§l")
                                .replaceAll("&M", "§m").replaceAll("&N", "§n").replaceAll("&O", "§o")
                                .replaceAll("&R", "§r").replaceAll("&1", "§1").replaceAll("&2", "§2")
                                .replaceAll("&3", "§3").replaceAll("&4", "§4").replaceAll("&5", "§5")
                                .replaceAll("&6", "§6").replaceAll("&7", "§7").replaceAll("&8", "§8")
                                .replaceAll("&9", "§9").replaceAll("&0", "§0"));
    }
    [/CODE
     
  6. Offline

    AddisCraft

    Thank you so much

    This may be a dumb question, but in:
    player.setDisplayName
    i get a red line under player, and if i do Player.setDisplayName (big P) then the hole text gets the red line
    NOTE: I have imported Player.

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

    gomeow

    Why not just do this:
    Code:
    .replaceAll("&", "§")
    It works for me
     
  8. Offline

    AddisCraft

    so would it be:
    Code:
    else if(commandLabel.equalsIgnoreCase("Nick"))
    {
        String playerNick = args[0];
        player.setDisplayName(playerNick.replaceAll("&a", "§a").replaceAll("&b", "§b")
                             
    }
    
    and how would the plugin.yml look like?
     
  9. Offline

    gomeow

    Code:java
    1. //Change it to this:
    2. else if(commandLabel.equalsIgnoreCase("Nick"))
    3. {
    4. String playerNick = args[0];
    5. player.setDisplayName(playerNick.replaceAll("&", "§");
    6.  
    7. }

    plugin.yml:
    http://wiki.bukkit.org/Plugin_YAML
     
  10. Offline

    AddisCraft

    would plugin.yml be:

    nick:
    description: change your name
    usage: '/<command> [player] <nickname|off>'
    ?
     
  11. Offline

    skipperguy12

    Read the link gomeow gave... That plugin.yml you gave is copied and pasted from another nick command. Where did off come from? Just read the plugin. As you can see in gomeow's example, if the player types /nick, then the nickname they want is the first arguement. So, this would be the usage:

    <command> <nickname>
     
  12. Offline

    AddisCraft

    thank you so much
     
  13. Offline

    Drkmaster83

    Well... I've had a bad experience with that. If you do &<anyletter>, it makes it &r, which I find annoying. So, I'd much rather just check for everything other than a singular &.
     
  14. Offline

    AddisCraft

    it worker for me, All i did was /nick &4 lol and it was "lol" It works with all of the colors, so, are you sure you did it right?
     
  15. Offline

    thescreem

    Uhhhh... you could just use regex codes to add formatting in one line like so:
    Code:JAVA
    1. String string = "&4Some &ostring&r &6with &afancy &9formatting&f";
    2. string = string.replaceAll("(&([a-fk-or0-9]))", "\u00A7$2");

    It would only replace the color codes (0 to 9 and a to f) as well as bolding, italics, underlining, etc (k to o and r). So if you have something like "&z" (without the quotation marks) it wouldn't be replaced because it's not a valid color/formatting code. Also, it only replaces the code if it has an ampersand (&) before it. Basically, every code listed here.
     
Thread Status:
Not open for further replies.

Share This Page