Solved How I save the player to the config and then check if is in the config?

Discussion in 'Plugin Development' started by tigres810, Feb 20, 2017.

Thread Status:
Not open for further replies.
  1. Hi guys, my probles is idk how to save the player to the config and then when I click a block ("SKULL_ITEM"),
    I do if(getConfig().getString("GuardiaSpawn.Player") == p.getName()) {
    -- Stuff here
    }
    If doesn't work, someone told me to do a ArrayList but idk how,
    and I want when I clicked that Skull.item to teleport im or something :/ any help?
     
  2. Offline

    timtower Administrator Administrator Moderator

    @tigres810 Strings are compared with equals, not with ==
    And based on that other person:
    getStringList().contains(p.getName())
     
  3. Offline

    timtower Administrator Administrator Moderator

  4. Offline

    Zombie_Striker

    @tigres810
    The string is null for the replace method on line 109 of the onInteract method. The code you posted before is not the correct class or has been modified since you posted it. Just make sure that you nullcheck objects before you use them.
     
  5. But the line 109 is a message and it works :/
     
  6. Offline

    Zombie_Striker

    @tigres810
    What is the line where you use the "replace" method a string? Are you sure both the code and the error message are up to date?
     
  7. Yes all works now I need to make a ArrayList and save players name when I click in the egg how I do it?
    and I want that arraylist in the config if it's possible pls :)

    Guys, how I do it. I can't if you don't help me :/

    No all works just I need to make a arrayList and when I click the egg save the player name how I do it?

    Now I need to make a arrayList and when I click the egg save the player name sorry for the spam but im new in the page :/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Feb 22, 2017
  8. Offline

    Zombie_Striker

    @tigres810
    Do not double post. Wait 24 hours before bumping the thread.

    Did you fix the error yet?
     
  9. Yes it was in the config just change the int to 1 and it works fine but now I need to make the arrayList and when click the egg save the player name How I do it? sorry Im new in the page din't know :/
     
  10. Offline

    Zombie_Striker

    @tigres810
    Do you want to create a new arraylist for each player, or have an arraylist that stores players?
     
  11. I have this ArrayList: public static ArrayList<Player> jugadores = new ArrayList<Player>(); and when I store a player I do: jugadores.add(p); and jugadores.remove(p); but Idk if it saves when I reload the server or onenable it resets and how I choose all players in that list?
     
  12. Offline

    Zombie_Striker

    @tigres810
    It does not. You will have to save the list to the config and reload it in the onEnable.

    Also, do not store players inside of collections. This will cause memory leaks. Instead, store their UUID.

    For loop through all the contents of the array. If you did what said above, after for looping through the UUIDs, use Bukkit.getPlayer(UUID) to get the player's instance.
     
  13. How I save their UUID? Can you make me a code or something?
     
  14. Offline

    Zombie_Striker

    @tigres810
    Code:
    List<String> list = new ArrayList<>();
    for(UUID uuid: YOU_LIST){
     list.add(uuid.toString());
    }
    getConfig().set("Path.to.uuids",list);
    Use the above to save uuids. What it does is it converts each uuid to a string, put the string into a list, and saves the stringlist.


    Code:
    List<String> list = getConfig().get("Path.to.uuids");
    for(String uuid: list){
     YOUR_LIST.add(UUID.fromString(uuid));
    }
    Use this to load the uuids. This gets the stringlist, loops through all the strings, and adds the UUID version of each string.
     
  15. How I do this when I click the egg?
     
  16. Offline

    Zombie_Striker

    @tigres810
    PlayerInteractEvent. Check if the item in the main hand is not null and that it is equal to an egg.
     
  17. I get the next error when I added YOUR_LIST.add(UUID.fromString(uuid));
    The method add(String) in the type List<String> is not applicable for the arguments (UUID)
     
  18. Offline

    Zombie_Striker

    @tigres810
    That is because the list you provide is not the right list. You need to provide the one that stores UUIDs.
     
Thread Status:
Not open for further replies.

Share This Page