Solved How to use a string list?

Discussion in 'Plugin Development' started by OkinawaBoss, Oct 3, 2015.

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

    OkinawaBoss

    So I'm trying to read usernames from my config file. I'm trying to figure out how to use a string list. Right now it only reads the one player. Can anybody explain how to use it properly? Or if a String List isn't the correct way to do it, can you point me in the right direction?
    Code:
    if(sender.getName().equalsIgnoreCase(getConfig().getString("player"))){
     
  2. Offline

    oceantheskatr

    First of all, you should be storing UUIDs instead of names. This is because people can change their names but not their UUIDs. If you're using names instead then when someone changes their username they'll lose all the data associated with that name.

    So you'd want to do something like this:

    player:
    - player1uuid
    - player2uuid
    - player3uuid

    And you'd change that line of code to the following:

    if(getConfig().getList("player").contains(player.getUniqueId().toString()))){
    // Do stuff
    }

    Make sure to check if the sender is a player, and then cast sender to Player and then do this stuff.
     
  3. Offline

    OkinawaBoss

    @oceantheskatr That was perfect. I'm still really new to this (obviously). And thanks for showing me UUID's. I know of them I just wasn't sure how to implement it.
     
  4. Offline

    oceantheskatr

    I'm glad I could help! UUIDs are definitely important to use :) Good luck!
     
Thread Status:
Not open for further replies.

Share This Page