Replace Bukkit schedulers in SaveTimerTask.java

This commit is contained in:
Rockyers 2023-08-13 19:58:04 -07:00
parent 0603faff33
commit 7f64987585
2 changed files with 17 additions and 13 deletions

View File

@ -644,7 +644,7 @@ public class mcMMO extends JavaPlugin {
long saveIntervalTicks = Math.max(minute, generalConfig.getSaveInterval() * minute);
new SaveTimerTask().runTaskTimer(this, saveIntervalTicks, saveIntervalTicks);
new SaveTimerTask().runTaskTimer(saveIntervalTicks, saveIntervalTicks);
// Cleanup the backups folder
new CleanBackupsTask().runTaskAsynchronously(mcMMO.p);

View File

@ -5,22 +5,26 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.runnables.player.PlayerProfileSaveTask;
import com.gmail.nossr50.util.LogUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.player.UserManager;
import org.bukkit.scheduler.BukkitRunnable;
import com.tcoded.folialib.wrapper.WrappedTask;
public class SaveTimerTask extends BukkitRunnable {
@Override
public void run() {
LogUtils.debug(mcMMO.p.getLogger(), "[User Data] Saving...");
// All player data will be saved periodically through this
int count = 1;
import java.util.concurrent.TimeUnit;
for (McMMOPlayer mcMMOPlayer : UserManager.getPlayers()) {
new PlayerProfileSaveTask(mcMMOPlayer.getProfile(), false).runTaskLaterAsynchronously(mcMMO.p, count);
count++;
}
public class SaveTimerTask {
public WrappedTask runTaskTimer(long delay, long period) {
return mcMMO.p.getFoliaLib().getImpl().runTimer(() -> {
LogUtils.debug(mcMMO.p.getLogger(), "[User Data] Saving...");
// All player data will be saved periodically through this
int count = 1;
for (McMMOPlayer mcMMOPlayer : UserManager.getPlayers()) {
new PlayerProfileSaveTask(mcMMOPlayer.getProfile(), false).runTaskLaterAsynchronously(mcMMO.p, count);
count++;
}
PartyManager.saveParties();
PartyManager.saveParties();
}, delay * Misc.TICK_CONVERSION_FACTOR, period * Misc.TICK_CONVERSION_FACTOR, TimeUnit.MILLISECONDS);
}
}