Solved How to schedule an updated data.yml check?

Discussion in 'Plugin Development' started by Evick, Aug 3, 2021.

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

    Evick

    Hi! I have this code that is meant to be run after 200 ticks. But is seems that updates to the data.yml file (after schedule definition) are not taken into account. How can I read an updated data.yml for scheduled code?
    Example:

    new BukkitRunnable(){
    public void run(){
    Bukkit.broadcastMessage("stat2:" + Main.plugin.getConfig().getInt("duell.status"));
    player.sendMessage(ChatColor.GREEN + "done!");
    }
    }.runTaskLater(Main.plugin, 200);

    So in this case the Main.plugin.getConfig().getInt("duell.status") is =0 when the new BukkitRunnable is run, however at the time the "done" message is sent, Main.plugin.getConfig().getInt("duell.status") is =1 yet the broadcast message becomes "stat2:0" when I expect a "stat2:1". How can I do this?
     
  2. Offline

    Kars

    I'm pretty sure the way you do it there, the string is constructed at the moment of creation. In other words, it is set to "stat2:0" instead of the dynamic Main.plugin.getConfig etc getting called at time of execution.

    I'm unsure at this moment how to resolve this.
     
  3. Offline

    c7dev

    The config will have to be reloaded if you want it to reflect any changes. If you don't want to constantly reload the config file, you can just keep a hashmap or local integer variables, and just save the config in onDisable().
     
    Evick likes this.
  4. Offline

    Evick

    I recon the config is allready reloaded when the value is changed from 0 to 1. I will try using a variable instead of config though.

    Update!
    You are totally right @c7dev ! I guess the config was not reloaded after all. However simply using variables instead of the data.yml works! Also I realized I don't even need to save this particular data over plugin reloads. (Although saving in onDisable() is a really good idea)
    Thanks!
     
    Last edited: Aug 5, 2021
    c7dev likes this.
Thread Status:
Not open for further replies.

Share This Page