Removing Data from String List

Discussion in 'Plugin Development' started by Piesrgr8, May 21, 2018.

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

    Piesrgr8

    I am making a mailing system, where messages to a play can be stored in a yml and then once they have been shown (I might change it so it would be up to the player to clear the mail), it will remove the messages from the yml. But, I have tried several things like a for loop and such, but none of it seems to work. My main point here is that the data that I am trying to remove is the messages that exist in the string list in the yml, but the method I am using isn't doing anything at all.

    Code:
        public static void clearMessageList(Player p) {
            YamlConfiguration yaml = getYaml(p);
            List<String> ex = new ArrayList<String>();
            yaml.set(p.getName() + ".messagelist", ex);
            save(p);
        }
    This method goes through just fine. It even saves after executed.
     
  2. Online

    timtower Ninja on the waves Moderator

  3. Offline

    Piesrgr8

    There's the one that I did at the top, a for loop that looks at everything in the section, and I did the same thing with the clear() method, but I would leave out the variable and just get the string list and set it to null.
     
  4. Online

    timtower Ninja on the waves Moderator

    @Piesrgr8 Then you clear the list, you don't remove a single value with that.
     
  5. Offline

    Tabuu_

    Alright first of all you should not use the player name to store the messages but the players UUID.

    And since you are trying to remove all messages at once after they have been displayed you can just use this:

    Code:
    yaml.set(p.getUniqueId() + ".messagelist", null);
    this will remove the message list.
     
  6. Offline

    Piesrgr8

    Does sound like I need to change the players name to the uuid in the file. I already have that for the file name so that I could avoid creating new files over and over again.

    Also, that’s the method that I tried before, and it actually will save, but no changes will be made.
     
Thread Status:
Not open for further replies.

Share This Page