diff --git a/lib/statemachine.dart b/lib/statemachine.dart index 60107d1..583fb25 100644 --- a/lib/statemachine.dart +++ b/lib/statemachine.dart @@ -252,10 +252,36 @@ class StateMachine { if (settings.inst!.pterodactylMode) { // Shut down the server processes now PacketServer.socket!.close(); + + // Check if the shutdown reason was for a Mod Update + if (SessionData.shutDownReason == ShutDownReason.MODS) { + // Delete the old Mods Folder + Directory mods = Directory(settings.getModPath()); + await mods.delete(recursive: true); + Directory jail = Directory(settings.getModJailPath()); + await jail.rename(settings.getModPath()); + + File modsTxt = settings.getModListFile(); + await modsTxt.delete(); + } + exit(0); } else { resetKillswitch(); SessionData.timer = settings.inst!.timer.time.copy(); + + // Check if the shutdown reason was for a Mod Update + if (SessionData.shutDownReason == ShutDownReason.MODS) { + // Delete the old Mods Folder + Directory mods = Directory(settings.getModPath()); + await mods.delete(recursive: true); + Directory jail = Directory(settings.getModJailPath()); + await jail.rename(settings.getModPath()); + + File modsTxt = settings.getModListFile(); + await modsTxt.delete(); + } + await pollModUpdates(); changeState(States.PreStart); SessionData.enableRestartTimer = settings.inst!.timer.enabled; @@ -383,6 +409,7 @@ class StateMachine { print( "Scheduling restart for mod updates: ${updatedMods.join(', ')}"); SessionData.enableRestartTimer = true; + SessionData.shutDownReason = ShutDownReason.MODS; // Send discord alert! DiscordHookHelper.sendWebHook( diff --git a/lib/structs/SessionData.dart b/lib/structs/SessionData.dart index 2bd829f..eff11fb 100644 --- a/lib/structs/SessionData.dart +++ b/lib/structs/SessionData.dart @@ -47,4 +47,8 @@ class SessionData { static List IE_SNAPSHOTS = []; static bool IS_FIRST_MOD_CHECK = true; + + static ShutDownReason shutDownReason = ShutDownReason.NORMAL; } + +enum ShutDownReason { MODS, NORMAL } diff --git a/lib/structs/settings.dart b/lib/structs/settings.dart index 0b49573..55bc423 100644 --- a/lib/structs/settings.dart +++ b/lib/structs/settings.dart @@ -112,7 +112,7 @@ class Settings { Future Read() async { if (!server) return; try { - var tag = await NbtIo.read(ABSOLUTE_PATH); + var tag = await NbtIo.read(ABSOLUTE_PATH) as CompoundTag; inst = SettingsEntry.deserialize(tag.get("entry") as CompoundTag); diff --git a/pubspec.yaml b/pubspec.yaml index 9591cc5..3e92f94 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.1.010425+1753 +version: 1.1.030225+1906 environment: sdk: ">=3.1.4 <4.0.0"