Saving a player's prefix?

Discussion in 'Plugin Development' started by ItsLeoFTW, Mar 15, 2014.

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

    ItsLeoFTW

    Hi!

    I'm working on a plugin to set player prefixes, but I am having one problem. If the user sets their prefix, when they leave, and join again, it will be gone. So what I would like to know how to do is saving a config structure like this:

    Players:
    player1:
    prefix: "[Prefix]"

    And then, when they do a command, say "/prefix off" it removes the "prefix" entry in the config just for them, resetting their name to the default name.

    Here's my command code:

    Code:java
    1. Player pla = (Player)s;
    2. if (alias.equalsIgnoreCase("prefix")){
    3. if (args.length < 1){
    4. s.sendMessage(ChatColor.GREEN + "Usage: /prefix <prefix>");
    5. }else{
    6. if (args.length == 1){
    7. String prefix = args[0];
    8. pla.setDisplayName(ChatColor.translateAlternateColorCodes('&', prefix.toString().replace("_", " ")) + pla.getName());
    9. s.sendMessage(ChatColor.GREEN + "You've changed your prefix!");
    10.  
    11. }
    12. if (args[0].equalsIgnoreCase("off")){
    13. pla.setDisplayName(pla.getName());
    14. s.sendMessage(ChatColor.GREEN + "You have removed your prefix.");
    15. }
    16. }
    17. }


    Please help! My players are getting annoyed that they lose their prefix when they leave!
     
  2. Offline

    AoH_Ruthless

    ItsLeoFTW
    Save the prefix to a config file.
     
  3. Offline

    ItsLeoFTW

    AoH_Ruthless Just thought of that. Gonna try it now. Thanks!
     
Thread Status:
Not open for further replies.

Share This Page