Solved Yml Config doesn't save?

Discussion in 'Plugin Development' started by MrSpyMan, Dec 7, 2014.

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

    MrSpyMan

    I am trying to do this anti spammer thing, so whenever a player joins and doesn't have a config thing, one will be made for the player and it works, but when a player moves it should set it to true yet it doesn't...
    \
    Code:
        @EventHandler
        public void onJoin(PlayerJoinEvent event) {
     
            String playerid = event.getPlayer().getUniqueId().toString();
            Player player = (Player) event.getPlayer();
     
            if (this.getConfig().get(playerid) != null) {
                this.getConfig().set(playerid + ".userdata.chatperms", false);
            }
        }
     
        @EventHandler
        public void onMove(PlayerMoveEvent event) {
            Player player = (Player) event.getPlayer();
            String playerid = player.getUniqueId().toString();
            if (this.getConfig()
                    .getBoolean(playerid + ".userdata.chatperms", false)) {
                this.getConfig().set(playerid + ".userdata.chatperms", true);
            }
        }
     
  2. Offline

    Tehmaker

    saveConfig();

    This method should be called whenever you want the config to be saved.
     
  3. Offline

    ROTN

    I hope listening to this is on PlayerMoveEvent is for debugging only...
    A good practice would be to load everything you need from the config into memory, and then save the edits on disabling (not a very good idea if you are story a lot of data however). IO (input/output) calls are relatively slow, and should be done sparingly.

    Also, mrCookieSlime, please make a note when you edit a post, if you don't, it makes everything seem a tad stingy
     
  4. Offline

    mrCookieSlime

    ROTN
    I always make notes when I edit something. However "edit" also has the same meaning as "approve" on this site.
    I simply approved his post.
     
  5. Offline

    mine-care

    MrSpyMan I think your thread is solved but a question, why is e.getplayer() cast to player? It returns player obj already
     
  6. Offline

    MrSpyMan

    Tehmaker The Player Move Event is a debug thing, if I load the config into memory I can make changes and stuff but what if someone new joins... then the config will make a new section for the new player and it won't be loaded into memory.

    mine-care Thats just something I always do. I guess I don't need to do that but it dosn't really matter.

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

    mine-care

    MrSpyMan well it makes no sense. its like giving you a apple and telling you "hey you know what! this is an aple! i asure you about that!" :3 its a good practice not to use excess things in your code;
     
  8. Offline

    AronTheGamer

    There are no IO calls until you hit saveConfig();. You can save things directly to the config object, although I don't recommend it as it may look a little bit unoragnized.
     
Thread Status:
Not open for further replies.

Share This Page