Re-introduce autosave enabler

This commit is contained in:
Luna 2023-08-17 19:07:38 -03:00
parent b5e1aa0ac0
commit b2936da79e
2 changed files with 18 additions and 0 deletions

View file

@ -80,6 +80,8 @@ public final class Main extends JavaPlugin {
this.getServer().getPluginManager().registerEvents(new PlayerPrefix(), this);
/* Server-related modules */
ServerGameRule.init(this);
this.getServer().getPluginManager().registerEvents(new ServerCommand(), this);
this.getServer().getPluginManager().registerEvents(new ServerGameRule(), this);
this.getServer().getPluginManager().registerEvents(new ServerTabComplete(), this);

View file

@ -1,9 +1,13 @@
package pw.kaboom.extras.modules.server;
import io.papermc.paper.event.world.WorldGameRuleChangeEvent;
import org.bukkit.Bukkit;
import org.bukkit.GameRule;
import org.bukkit.World;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.scheduler.BukkitScheduler;
import pw.kaboom.extras.Main;
public final class ServerGameRule implements Listener {
@EventHandler
@ -19,4 +23,16 @@ public final class ServerGameRule implements Listener {
event.setCancelled(true);
}
}
private static void enableAutoSave() {
for (final World world: Bukkit.getWorlds()) {
world.setAutoSave(true);
}
}
public static void init(final Main main) {
final BukkitScheduler scheduler = Bukkit.getScheduler();
scheduler.runTaskTimer(main, ServerGameRule::enableAutoSave, 0L, 600L); // 30 seconds
}
}