Solved Make code run at certain game time

Discussion in 'Plugin Development' started by soshimee, Jan 6, 2021.

  1. Offline

    soshimee

    I've searched for this, but I couldn't find any good information about game time, but they all talked about real time. So I tried checking the time every second. This is the code I have:
    Code:
    public class Main extends JavaPlugin {
    boolean isNight = false; boolean lastIsNight = true;@Overridepublic void onEnable() {
    getLogger().info("Loading..."); new BukkitRunnable() {
    @Overridepublic void run() {
    Server server = getServer(); long time = server.getWorld("wild").getTime(); if (time > 14000 || time < 1000) {
    isNight = true; if (lastIsNight == false) {
    Bukkit.broadcastMessage("It's night!");lastIsNight = true;}
    } else {
    isNight = false; if (lastIsNight == true) {
    Bukkit.broadcastMessage("It's day!");lastIsNight = false;}
    }
    }
    }.runTaskTimer(this, 20, 20);getLogger().info("Loaded!");}
    
    @Overridepublic void onDisable() {
    getLogger().info("Bye!");}
    }
    
    (Bukkit forums for some reason removed some newlines, my code might be hard to read, sorry!)

    And now this spams NPE every second. Any ideas?
     
  2. Offline

    timtower Administrator Administrator Moderator

    @soshimee Do you have a world called "wild" ?
     
  3. Offline

    soshimee

    Oh, my testing server was different from the server that will be actually used, thanks!

    Edit: It works after making the world name editable on config.yml!
     
    Last edited: Jan 6, 2021
    timtower likes this.

Share This Page