Skip to content

Commit

Permalink
Enhance WorldLoadCommand with persistence and save actions
Browse files Browse the repository at this point in the history
Added persistence status update and level data saving when a world is successfully loaded. This ensures the world's state is correctly saved and can be reliably restored on subsequent loads.
  • Loading branch information
NonSwag committed Aug 15, 2024
1 parent 91a13ec commit ba3762e
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,22 @@ class WorldLoadCommand {
private int load(CommandContext<CommandSourceStack> context) {
var name = context.getArgument("world", String.class);
var level = new File(plugin.getServer().getWorldContainer(), name);

var world = plugin.levelView().isLevel(level) ? plugin.levelView().loadLevel(level,
optional -> optional.map(extras -> !extras.enabled()).isPresent()) : null;

var message = world != null ? "world.load.success" : "world.load.failed";
plugin.bundle().sendMessage(context.getSource().getSender(), message,
Placeholder.parsed("world", world != null ? world.key().asString() : name));

if (world != null && context.getSource().getSender() instanceof Entity entity)
entity.teleportAsync(world.getSpawnLocation(), COMMAND);

if (world != null) {
plugin.persistStatus(world, true, true);
plugin.levelView().saveLevelData(world, true);
}

return world != null ? Command.SINGLE_SUCCESS : 0;
}
}

0 comments on commit ba3762e

Please sign in to comment.