Ensure spawn.yml is properly deleted when overwritten, close #400

This commit is contained in:
William278 committed 2023-05-22 12:30:13 +01:00
1 parent aeff866b48
commit cb9d4808f2
3 files changed
+19 -4

No files matched your search

@@ -327,7 +327,12 @@ public class FabricHuskHomes implements DedicatedServerModInitializer, HuskHomes
@Override
public void setServerSpawn(@NotNull Location location) {
try {
this.serverSpawn = Annotaml.create(new File(getDataFolder(), "spawn.yml"), new Spawn(location)).get();
// Create or update the spawn.yml file
final File spawnFile = new File(getDataFolder(), "spawn.yml");
if (spawnFile.exists() && !spawnFile.delete()) {
log(Level.WARNING, "Failed to delete the existing spawn.yml file");
}
this.serverSpawn = Annotaml.create(spawnFile, new Spawn(location)).get();
// Update the world spawn location, too
minecraftServer.getWorlds().forEach(world -> {