Можно подробнее?Можешь джавовский таймер заюзать, можешь считать тики в ServerTickEvent.
//планировщик
ScheduledExecutorService schedulerService = Executors.newScheduledThreadPool(1);
//таск
Runnable task = ()->{
//your code here
};
//планировка выполнения каждый час со стартовой задержкой в 1 час
schedulerService.scheduleAtFixedRate(task, 1L, 1L, TimeUnit.HOURS);
ZonedDateTime
currentTime = ZonedDateTime.now(ZoneId.of("Europe/Moscow")),
initialExecutionTime = currentTime.plusHours(1L).withMinute(0).withSecond(0);
long initalDelaySeconds = Duration.between(currentTime, initialExecutionTime).getSeconds();
//планировка выполнения каждый час со стартом в начале слудующего часа
schedulerService.scheduleAtFixedRate(task, initalDelaySeconds, TimeUnit.HOURS.toSeconds(1L), TimeUnit.SECONDS);
Runnable task;
//server
FMLCommonHandler.instance().getMinecraftServerInstance().addScheduledTask(task);
//client
Minecraft.getMinecraft().addScheduledTask(task);
Runnable task = ()->{
FMLCommonHandler.instance().getMinecraftServerInstance().addScheduledTask(()->{
//your server code here
});
};
schedulerService.scheduleAtFixedRate(task, 1L, 1L, TimeUnit.HOURS);
private boolean running;
private long nextExecutionTime;
//запуск
public void start() {
this.nextExecutionTime = System.currentTimeMillis() + TimeUnit.HOURS.toMillis(1L);
this.running = true;
}
//в тикире
public void run() {
if (this.running) {
if (System.currentTimeMillis() >= this.nextExecutionTime) {
//выполнение периодической задачи
this.nextExecutionTime = System.currentTimeMillis() + TimeUnit.HOURS.toMillis(1L);
}
}
}
Т.е. подсчёт через System.currentTimeMillis() будет верным вне зависимости от лагов сервера?Из-за изменяющегося тпс(лаги) подсчет времени через тики может быть ошибочным