Skip to content

Commit

Permalink
Merge pull request #4 from SFTMedia/bluetigeresw/issue3
Browse files Browse the repository at this point in the history
World saving isn't working
  • Loading branch information
bluetigeresw committed May 6, 2023
2 parents ebcff97 + 9582a7c commit 3af2d81
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v1.0.1
release_name: Release v1.0.1
tag_name: v1.0.2
release_name: Release v1.0.2
draft: false
prerelease: false

Expand Down
24 changes: 22 additions & 2 deletions src/RestartWarning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace RestartWarning
{
[BepInPlugin("com.bluetigeresw.RestartWarning", "Restart Warning", "1.0.1")]
[BepInPlugin("com.bluetigeresw.RestartWarning", "Restart Warning", "1.0.2")]
public class RestartWarning : BaseUnityPlugin
{
private const string MESSAGE = "[RestartWarning] Server will restart in 5 minutes! Saving world...";
Expand All @@ -18,7 +18,6 @@ public void Awake()
// Hook the Chat event to detect when a chat message is sent
Logger.LogInfo("Loading Restart Warning...");


// Set up a timer to trigger at a set time every day
TimeSpan triggerTime = new TimeSpan(3, 55, 0); // 3:55:00 AM
TimeSpan currentTime = DateTime.Now.TimeOfDay;
Expand All @@ -33,6 +32,27 @@ private void OnTimerElapsed(object sender, ElapsedEventArgs e)
// Broadcast a message to all players in the game
ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "ChatMessage", MESSAGE);

// Check if the game is running on a dedicated server
if (ZNet.instance.IsServer())
{
// Get a reference to the game console
var console = Console.instance;

if (console != null)
{
// Execute the command to save world
console.TryRunCommand("save");
}
else
{
Debug.LogWarning("Could not find game console");
}
}
else
{
Debug.LogWarning("Plugin can only be run on a dedicated server");
}

// Reset the timer for the next trigger
timer.Interval = TimeSpan.FromDays(1).TotalMilliseconds;
}
Expand Down

0 comments on commit 3af2d81

Please sign in to comment.