Solved String List...

Discussion in 'Plugin Development' started by Raydond123, Jan 21, 2015.

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

    Raydond123

    Hello there!
    I'm trying to store a list of players upon login...
    Not sure whether my code is correct so far, but this is what I use to store the players:
    Code:
                    java.util.List<String> staffList = getConfig().getStringList("staff");
                    staffList.add(Player);
    Could someone please verify that his is correct?
    Above this code, I've defined that "Player" is a string that is equal to the player's name.
     
  2. Offline

    Skionz

    @Raydond123 What is Player? Are you just not following naming conventions?
     
  3. Offline

    Raydond123

    @Skionz I'm pretty sure I am...
    Here's what Player is.
    Code:
    Player player = e.getPlayer();
            String Player = player.getName();
     
  4. Offline

    Skionz

    @Raydond123 It looks fine besides the naming conventions assuming this is in a class that extends JavaPlugin or you wrote your own getConfig method.
     
  5. Offline

    Raydond123

    @Skionz What do you mean by my own getConfig method?
     
  6. Offline

    WesJD

    Writing your own getConfig method to get the config from your main class extending JavaPlugin.
     
  7. Offline

    Raydond123

    @WesJD
    Uh...
    Welp... I don't think I did that.
    I just did:

    Code:
        public void onEnable() {
            saveConfig();
            getServer().getPluginManager().registerEvents(this, this);
        }
    Can someone please tell me what I'm doing wrong?
    I've removed the PlayerJoinEvent and then added a new command.
    Here's the code for it:
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if(commandLabel.equalsIgnoreCase("test")) {
             if(args.length == 0) {
                
             }
             if(args.length == 1) {
                List<String> staffList = getConfig().getStringList("staff");
                staffList.add(args[0]);
                this.getConfig().set("staff", staffList);
             }
            }
            return false;
        }
    Okay so, if I did /test test it does nothing, even though I set it to add a string to the stringlist.
    What am I doing wrong?

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

    SuperOriginal

    Don't use commandLabel, use cmd.getName()

    The if(args==0) block is completely useless

    You don't save the config after you set it
     
  9. Offline

    Raydond123

    OHHHH
    THATS WHY THANKS!
     
Thread Status:
Not open for further replies.

Share This Page