Certain time execute

Discussion in 'Spigot Plugin Development' started by JustPrimed, May 12, 2017.

  1. Hello spigot, I'm trying to make my server reboot every night at 12 PM PST. (I tested it last night, doesnt work.)
    I've made some code up but it doesn't seem to work. I have it in my onEnable.

    Here is the code:
    Code (Text):
            new BukkitRunnable() {
                public void run() {
                    DateFormat dateformat = new SimpleDateFormat("HH:mm:ss");
                    Date date = new Date();
                    if (dateformat.format(date) == "22:50:00") {
                        Bukkit.broadcastMessage(ChatColor.RED + "Server is rebooting in 10 minutes.");
                    } else if (dateformat.format(date) == "22:55:00") {
                        Bukkit.broadcastMessage(ChatColor.RED + "Server is rebooting in 5 minutes.");
                    } else if (dateformat.format(date) == "23:00:00") {
                        Bukkit.broadcastMessage(ChatColor.RED + "Server is rebooting now.");
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "stop");
                    }
                }
            }.runTaskTimer(this, 0L, 20L);

    I would appreciate if I could get this working, Thanks Primed.
    BTW, Sorry if this is in the wrong thread.
     
  2. Is the issue the server stopping or starting back up

    Sent from my SAMSUNG-SM-G935A using Tapatalk
     
  3. The issue is when the time comes up to the certain time it doesn't do anything, It doesn't stop or anything.
     
  4. Does the .format return a String?
    Use equals instead of == to compare strings.
     
    • Agree Agree x 2
  5. ^ i would also keep the SimpleDateFormat as a static instance to avoid having to garage collect the object every second.
     
  6. Thanks I will try this when I get back!
     
  7. Thanks it worked.
     
  8. Remember to mark the thread as solved