Search in sources :

Example 1 with Zip

use of com.gmail.trentech.pjw.utils.Zip in project ProjectWorlds by trentech.

the class CommandRemove method process.

@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
    if (arguments.equalsIgnoreCase("remove")) {
        throw new CommandException(getHelp().getUsageText());
    }
    if (arguments.equalsIgnoreCase("--help")) {
        help.execute(source);
        return CommandResult.success();
    }
    Optional<WorldProperties> optionalWorld = Sponge.getServer().getWorldProperties(arguments);
    if (!optionalWorld.isPresent()) {
        throw new CommandException(Text.of(TextColors.RED, arguments, " does not exist"), false);
    }
    WorldProperties world = optionalWorld.get();
    if (Sponge.getServer().getWorld(world.getWorldName()).isPresent()) {
        throw new CommandException(Text.of(TextColors.RED, world.getWorldName(), " must be unloaded before you can delete"), false);
    }
    new Zip(world.getWorldName()).save();
    try {
        if (Sponge.getServer().deleteWorld(world).get()) {
            source.sendMessage(Text.of(TextColors.DARK_GREEN, world.getWorldName(), " deleted successfully"));
            return CommandResult.success();
        }
    } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace();
        throw new CommandException(Text.of(TextColors.RED, "Something went wrong. Check server log for details"), false);
    }
    source.sendMessage(Text.of(TextColors.RED, "Could not delete ", world.getWorldName()));
    return CommandResult.empty();
}
Also used : Zip(com.gmail.trentech.pjw.utils.Zip) CommandException(org.spongepowered.api.command.CommandException) ExecutionException(java.util.concurrent.ExecutionException) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Aggregations

Zip (com.gmail.trentech.pjw.utils.Zip)1 ExecutionException (java.util.concurrent.ExecutionException)1 CommandException (org.spongepowered.api.command.CommandException)1 WorldProperties (org.spongepowered.api.world.storage.WorldProperties)1