Skip to content

Commit

Permalink
add save/30s
Browse files Browse the repository at this point in the history
  • Loading branch information
AIDA64S committed Sep 8, 2024
1 parent 98768c0 commit 6f1aedd
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion fabric/src/main/java/top/mcmtr/mod/Init.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
public class Init implements Utilities {
private static MSDMain main;
private static int serverPort;
private static long lastSavedMillis;
public static final String MOD_ID = "msd";
public static final Logger MSD_LOGGER = LogManager.getLogger("MTR-Station-Decoration");
public static final Registry REGISTRY = new Registry();
private static final ObjectArrayList<String> WORLD_ID_LIST = new ObjectArrayList<>();
private static final RequestHelper REQUEST_HELPER = new RequestHelper(false);
public static final int AUTOSAVE_INTERVAL = 30000;

public static void init() {
Blocks.init();
Expand All @@ -53,12 +55,20 @@ public static void init() {
REGISTRY.eventRegistry.registerServerStarted(minecraftServer -> {
WORLD_ID_LIST.clear();
MinecraftServerHelper.iterateWorlds(minecraftServer, serverWorld -> WORLD_ID_LIST.add(getWorldId(new World(serverWorld.data))));

lastSavedMillis = System.currentTimeMillis();
final int defaultPort = getDefaultPortFromConfig(minecraftServer);
serverPort = findFreePort(defaultPort);
main = new MSDMain(minecraftServer.getSavePath(WorldSavePath.getRootMapped()).resolve("msd"), serverPort, WORLD_ID_LIST.toArray(new String[0]));
});

REGISTRY.eventRegistry.registerStartServerTick(() -> {
final long currentMillis = System.currentTimeMillis();
if (currentMillis - lastSavedMillis > AUTOSAVE_INTERVAL) {
main.save();
lastSavedMillis = currentMillis;
}
});

REGISTRY.eventRegistry.registerPlayerDisconnect((minecraftServer, serverPlayerEntity) -> {
if (main != null) {
main.save();
Expand Down

0 comments on commit 6f1aedd

Please sign in to comment.