Solved Config problems with onjoin

Discussion in 'Plugin Development' started by ProSl3nderMan, Aug 27, 2015.

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

    ProSl3nderMan

    Hey ya'll, found a little problem that I can't solve. For some reason it won't update the config but instead delete the section players. This is my code for OnJoin:
    Code:
       @EventHandler
        public void onJoin(PlayerJoinEvent event) {
           
           
            Player p = event.getPlayer();
           
            int x = AccessControl.plugin.getConfig().getInt("lobby.x");
            int y = AccessControl.plugin.getConfig().getInt("lobby.y");
            int z = AccessControl.plugin.getConfig().getInt("lobby.z");
            p.teleport(new Location(Bukkit.getWorld(AccessControl.plugin.getConfig().getString("lobby.world")), x, y, z));
            String uuid = p.getPlayer().getUniqueId().toString();
            if(AccessControl.plugin.getConfig().contains("players." + p.getPlayer().getUniqueId())) {
                AccessControl.plugin.getConfig().set("players." + p.getPlayer().getUniqueId() + ".IGN" , p.getName());
                AccessControl.plugin.saveConfig();
                AccessControl.plugin.reloadConfig();
            } else {
                AccessControl.plugin.getConfig().set("players." + p.getPlayer().getUniqueId() , uuid);
                AccessControl.plugin.getConfig().set("players." + p.getPlayer().getUniqueId() + ".IGN" , p.getName());
                AccessControl.plugin.getConfig().set("players." + p.getPlayer().getUniqueId() + ".game" , "0");
                AccessControl.plugin.getConfig().set("players." + p.getPlayer().getUniqueId() + ".cop" , "no");
                AccessControl.plugin.getConfig().set("players." + p.getPlayer().getUniqueId() + ".GamesWon", 0);
    
                AccessControl.plugin.saveConfig();
                AccessControl.plugin.reloadConfig();
            }
           
        }
    Any clue why it doesn't work?

    Well, it apparently isn't saving my work into the folder, anyone know any reason why it's not saving my work?

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

    au2001

    That isn't correct, especially the uuid part.

    You have to do something like that:
    Code:
    players:
        <uuid>:
            name: <name>
            game: 0
            wins: 0
            cop: false
    And why are you doing p.getPlayer().getUniqueId()? Just use p.getUniqueId().
    Then save it to a variably instead of getting it again and again...

    And you should save the lobby location outside of your even instead of getting the location each time a player joins, would be way more efficient.
    EDIT: You should probably save the config file too, since you get it at almost each line.

    Also, no need to reloadConfig after saving it. If you understand what those two method do, you'll understand why you don't need to do that too.
     
  3. Offline

    ProSl3nderMan

    It all works well, it was because my friend add an external jar to the build path that messed everything up. Sorry for the waste of a thread xP
     
  4. Offline

    au2001

    @ProSl3nderMan Don't worry for the thread, we're here to help you :p

    You should still take my post in consideration though ;)
     
Thread Status:
Not open for further replies.

Share This Page