From b2936da79e6ec84b206d28d2f6a08e83cc65d3a7 Mon Sep 17 00:00:00 2001 From: Luna Date: Thu, 17 Aug 2023 19:07:38 -0300 Subject: [PATCH] Re-introduce autosave enabler --- src/main/java/pw/kaboom/extras/Main.java | 2 ++ .../extras/modules/server/ServerGameRule.java | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/main/java/pw/kaboom/extras/Main.java b/src/main/java/pw/kaboom/extras/Main.java index 37d6c0e..505525d 100644 --- a/src/main/java/pw/kaboom/extras/Main.java +++ b/src/main/java/pw/kaboom/extras/Main.java @@ -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); diff --git a/src/main/java/pw/kaboom/extras/modules/server/ServerGameRule.java b/src/main/java/pw/kaboom/extras/modules/server/ServerGameRule.java index 22c7e8d..f891c69 100644 --- a/src/main/java/pw/kaboom/extras/modules/server/ServerGameRule.java +++ b/src/main/java/pw/kaboom/extras/modules/server/ServerGameRule.java @@ -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 + } }