use of com.gmail.trentech.pjw.io.SpongeData in project ProjectWorlds by trentech.
the class CommandImport method process.
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
if (arguments.equalsIgnoreCase("import")) {
throw new CommandException(getHelp().getUsageText());
}
String[] args = arguments.split(" ");
if (args[args.length - 1].equalsIgnoreCase("--help")) {
help.execute(source);
return CommandResult.success();
}
String worldName;
String genType;
String dimType;
try {
worldName = args[0];
} catch (Exception e) {
throw new CommandException(getHelp().getUsageText());
}
if (Sponge.getServer().getWorld(worldName).isPresent()) {
throw new CommandException(Text.of(TextColors.RED, worldName, " is already loaded"), false);
}
WorldData worldData = new WorldData(worldName);
if (!worldData.exists()) {
throw new CommandException(Text.of(TextColors.RED, worldName, " is not a valid world"), false);
}
SpongeData spongeData = new SpongeData(worldName);
if (spongeData.exists()) {
source.sendMessage(Text.of(TextColors.RED, "Sponge world detected"));
source.sendMessage(Text.builder().color(TextColors.YELLOW).onHover(TextActions.showText(Text.of("Click command for more information "))).onClick(TextActions.runCommand("/pjw:world load")).append(Text.of(" /world load")).build());
return CommandResult.success();
}
try {
dimType = args[1];
} catch (Exception e) {
throw new CommandException(getHelp().getUsageText());
}
Optional<DimensionType> optionalDimensionType = Sponge.getRegistry().getType(DimensionType.class, dimType);
if (!optionalDimensionType.isPresent()) {
source.sendMessage(Text.of(TextColors.YELLOW, dimType, " is not a valid DimensionType"));
throw new CommandException(getHelp().getUsageText());
}
DimensionType dimensionType = optionalDimensionType.get();
try {
genType = args[2];
} catch (Exception e) {
throw new CommandException(getHelp().getUsageText());
}
Optional<GeneratorType> optionalGeneratorType = Sponge.getRegistry().getType(GeneratorType.class, genType);
if (!optionalGeneratorType.isPresent()) {
source.sendMessage(Text.of(TextColors.YELLOW, genType, " is not a valid GeneratorType"));
throw new CommandException(getHelp().getUsageText());
}
GeneratorType generatorType = optionalGeneratorType.get();
WorldArchetype.Builder builder = WorldArchetype.builder().dimension(dimensionType).generator(generatorType).enabled(true).keepsSpawnLoaded(true).loadsOnStartup(true);
Collection<WorldGeneratorModifier> modifiers = Collections.<WorldGeneratorModifier>emptyList();
if (args.length >= 4) {
for (int i = 3; i < args.length - 3; i++) {
Optional<WorldGeneratorModifier> optionalModifier = Sponge.getRegistry().getType(WorldGeneratorModifier.class, args[i]);
if (!optionalModifier.isPresent()) {
source.sendMessage(Text.of(TextColors.YELLOW, args[i], " is not a valid WorldGeneratorModifier"));
throw new CommandException(getHelp().getUsageText());
}
modifiers.add(optionalModifier.get());
}
}
WorldArchetype settings = builder.build(worldName, worldName);
WorldProperties properties;
try {
properties = Sponge.getServer().createWorldProperties(worldName, settings);
properties.setGeneratorModifiers(modifiers);
} catch (IOException e) {
e.printStackTrace();
throw new CommandException(Text.of(TextColors.RED, "Something went wrong. Check server log for details"), false);
}
Sponge.getServer().saveWorldProperties(properties);
source.sendMessage(Text.of(TextColors.DARK_GREEN, worldName, " imported successfully"));
return CommandResult.success();
}
use of com.gmail.trentech.pjw.io.SpongeData in project ProjectWorlds by trentech.
the class CommandLoad method process.
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
if (arguments.equalsIgnoreCase("load")) {
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.getUniqueId()).isPresent()) {
throw new CommandException(Text.of(TextColors.RED, world.getWorldName(), " is already loaded"), false);
}
WorldData worldData = new WorldData(world.getWorldName());
if (!worldData.exists()) {
throw new CommandException(Text.of(TextColors.RED, world.getWorldName(), " does not exist"), false);
}
SpongeData spongeData = new SpongeData(world.getWorldName());
if (!spongeData.exists()) {
source.sendMessage(Text.of(TextColors.RED, "Foriegn world detected"));
source.sendMessage(Text.builder().color(TextColors.YELLOW).onHover(TextActions.showText(Text.of("Click command for more information "))).onClick(TextActions.runCommand("/pjw:world import")).append(Text.of(" /world import")).build());
return CommandResult.success();
}
source.sendMessage(Text.of(TextColors.YELLOW, "Preparing spawn area. This may take a minute."));
Task.builder().delayTicks(20).execute(c -> {
Optional<World> load = Sponge.getServer().loadWorld(world);
if (!load.isPresent()) {
source.sendMessage(Text.of(TextColors.RED, "Could not load ", world.getWorldName()));
return;
}
if (CommandCreate.worlds.contains(world.getWorldName())) {
Utils.createPlatform(load.get().getSpawnLocation().getRelative(Direction.DOWN));
CommandCreate.worlds.remove(world.getWorldName());
}
source.sendMessage(Text.of(TextColors.DARK_GREEN, world.getWorldName(), " loaded successfully"));
}).submit(Main.getPlugin());
return CommandResult.success();
}
Aggregations