예제 #1
0
 void cancelTasks() {
   // plugin.getServer().getScheduler().cancelTasks(plugin);
   for (int i = 0; i < warningTimers.size(); i++) warningTimers.get(i).cancel();
   warningTimers.clear();
   if (rebootTimer != null) rebootTimer.cancel();
   rebootTimer = new Timer();
   plugin.autoRestart = false;
 }
예제 #2
0
  void scheduleTasks() {
    cancelTasks();
    // start the warning tasks
    for (int i = 0; i < warnTimes.size(); i++) {
      if (restartInterval * 60 - warnTimes.get(i) > 0) {
        // only do "positive" warning times
        // start the warning task
        final double warnTime = warnTimes.get(i);
        /*getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
        	public void run() {
        		getServer().broadcastMessage(processColours(warningMessage.replaceAll("%t", "" + warnTime)));
        		plugin.log.info("[SimpleRestart] " + stripColours(warningMessage.replaceAll("%t", "" + warnTime)));
        	}
        }, (long)((restartInterval * 60 - warnTimes.get(i)) * 60.0 * 20.0));

        log.info("[SimpleRestart] warning scheduled for " + (long)((restartInterval * 60 - warnTimes.get(i)) * 60.0) + " seconds from now!");*/
        Timer warnTimer = new Timer();
        warningTimers.add(warnTimer);
        warnTimer.schedule(
            new TimerTask() {
              @Override
              public void run() {
                getServer()
                    .broadcastMessage(
                        processColours(warningMessage.replaceAll("%t", "" + warnTime)));
                plugin.log.info(
                    "[SimpleRestart] "
                        + stripColours(warningMessage.replaceAll("%t", "" + warnTime)));
              }
            },
            (long) ((restartInterval * 60 - warnTimes.get(i)) * 60000.0));
        log.info(
            "[SimpleRestart] warning scheduled for "
                + (long) ((restartInterval * 60 - warnTimes.get(i)) * 60.0)
                + " seconds from now!");
      }
    }

    // start the restart task
    /*getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    	public void run() {
    		stopServer();
    	}
    }, (long)(restartInterval * 3600.0 * 20.0));*/
    rebootTimer = new Timer();
    rebootTimer.schedule(
        new TimerTask() {
          @Override
          public void run() {
            stopServer();
          }
        },
        (long) (restartInterval * 3600000.0));

    log.info(
        "[SimpleRestart] reboot scheduled for "
            + (long) (restartInterval * 3600.0)
            + " seconds from now!");
    plugin.autoRestart = true;
    plugin.startTimestamp = System.currentTimeMillis();
  }