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();
}
Aggregations