use of org.spongepowered.api.world.gen.WorldGeneratorModifier in project ProjectWorlds by trentech.
the class CommandImport method getSuggestions.
@Override
public List<String> getSuggestions(CommandSource source, String arguments, Location<World> targetPosition) throws CommandException {
List<String> list = new ArrayList<>();
if (arguments.equalsIgnoreCase("import")) {
return list;
}
String[] args = arguments.split(" ");
if (args.length == 1) {
for (WorldProperties world : Sponge.getServer().getAllWorldProperties()) {
if (world.getWorldName().equalsIgnoreCase(args[0])) {
for (DimensionType type : Sponge.getRegistry().getAllOf(DimensionType.class)) {
list.add(type.getId());
}
return list;
}
if (world.getWorldName().toLowerCase().startsWith(args[0].toLowerCase())) {
list.add(world.getWorldName());
}
}
}
if (args.length == 2) {
for (DimensionType type : Sponge.getRegistry().getAllOf(DimensionType.class)) {
if (type.getId().equalsIgnoreCase(args[1])) {
for (GeneratorType genType : Sponge.getRegistry().getAllOf(GeneratorType.class)) {
list.add(genType.getId());
}
return list;
}
if (type.getId().toLowerCase().startsWith(args[1].toLowerCase())) {
list.add(type.getId());
}
}
}
if (args.length == 3) {
for (GeneratorType type : Sponge.getRegistry().getAllOf(GeneratorType.class)) {
if (type.getId().equalsIgnoreCase(args[1])) {
for (WorldGeneratorModifier modType : Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class)) {
list.add(modType.getId());
}
return list;
}
if (type.getId().toLowerCase().startsWith(args[1].toLowerCase())) {
list.add(type.getId());
}
}
}
if (args.length >= 4) {
for (WorldGeneratorModifier type : Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class)) {
if (type.getId().equalsIgnoreCase(args[1])) {
for (WorldGeneratorModifier modType : Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class)) {
list.add(modType.getId());
}
return list;
}
if (type.getId().toLowerCase().startsWith(args[1].toLowerCase())) {
list.add(type.getId());
}
}
}
return list;
}
use of org.spongepowered.api.world.gen.WorldGeneratorModifier 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 org.spongepowered.api.world.gen.WorldGeneratorModifier in project ProjectWorlds by trentech.
the class CommandModifier method process.
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
if (arguments.equalsIgnoreCase("modifier")) {
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 mod;
try {
worldName = args[0];
} catch (Exception e) {
throw new CommandException(getHelp().getUsageText());
}
Optional<WorldProperties> optionalWorld = Sponge.getServer().getWorldProperties(worldName);
if (!optionalWorld.isPresent()) {
throw new CommandException(Text.of(TextColors.RED, worldName, " does not exist"), false);
}
WorldProperties world = optionalWorld.get();
Collection<WorldGeneratorModifier> modifiers = world.getGeneratorModifiers();
try {
mod = args[1];
} catch (Exception e) {
List<Text> list = new ArrayList<>();
for (WorldGeneratorModifier modifier : modifiers) {
list.add(Text.of(TextColors.WHITE, modifier.getId()));
}
if (source instanceof Player) {
PaginationList.Builder pages = PaginationList.builder();
pages.title(Text.builder().color(TextColors.DARK_GREEN).append(Text.of(TextColors.GREEN, "Current Modifiers")).build());
pages.contents(list);
pages.sendTo(source);
} else {
for (Text text : list) {
source.sendMessage(text);
}
}
return CommandResult.success();
}
Optional<WorldGeneratorModifier> optionalModifier = Sponge.getRegistry().getType(WorldGeneratorModifier.class, mod);
if (!optionalModifier.isPresent()) {
source.sendMessage(Text.of(TextColors.YELLOW, mod, " is not a valid WorldGeneratorModifier"));
throw new CommandException(getHelp().getUsageText());
}
WorldGeneratorModifier modifier = optionalModifier.get();
try {
if (args[2].equalsIgnoreCase("-r")) {
modifiers.remove(modifier);
world.setGeneratorModifiers(modifiers);
source.sendMessage(Text.of(TextColors.DARK_GREEN, "Removed modifier ", modifier.getId(), " to ", world.getWorldName()));
} else {
throw new CommandException(getHelp().getUsageText());
}
} catch (Exception e) {
modifiers.add(modifier);
world.setGeneratorModifiers(modifiers);
source.sendMessage(Text.of(TextColors.DARK_GREEN, "Added modifier ", modifier.getId(), " to ", world.getWorldName()));
}
return CommandResult.success();
}
use of org.spongepowered.api.world.gen.WorldGeneratorModifier in project ProjectWorlds by trentech.
the class EventManager method onLoadWorldEvent.
@Listener
public void onLoadWorldEvent(LoadWorldEvent event) {
World world = event.getTargetWorld();
WorldProperties properties = world.getProperties();
List<WorldGeneratorModifier> modifiers = new ArrayList<>();
boolean b = false;
if (!properties.getGeneratorModifiers().isEmpty()) {
for (WorldGeneratorModifier modifier : properties.getGeneratorModifiers()) {
if (modifier.getId().equals("pjw:void")) {
modifiers.add(Sponge.getRegistry().getType(WorldGeneratorModifier.class, "sponge:void").get());
b = true;
} else {
modifiers.add(modifier);
}
}
}
if (b) {
properties.setGeneratorModifiers(modifiers);
}
if (!properties.getGameRule("spawnOnDeath").isPresent()) {
properties.setGameRule("spawnOnDeath", "default");
}
if (!properties.getGameRule("doWeatherCycle").isPresent()) {
properties.setGameRule("doWeatherCycle", "true");
}
if (!properties.getGameRule("netherPortal").isPresent()) {
properties.setGameRule("netherPortal", "default");
}
if (!properties.getGameRule("endPortal").isPresent()) {
properties.setGameRule("endPortal", "default");
}
if (!properties.getGameRule("forceGamemode").isPresent()) {
properties.setGameRule("forceGamemode", "false");
}
}
use of org.spongepowered.api.world.gen.WorldGeneratorModifier in project LanternServer by LanternPowered.
the class LanternWorldProperties method updateWorldGenModifiers.
public void updateWorldGenModifiers(List<String> modifiers) {
final ImmutableSet.Builder<WorldGeneratorModifier> genModifiers = ImmutableSet.builder();
final GameRegistry registry = Sponge.getRegistry();
for (String modifier : modifiers) {
Optional<WorldGeneratorModifier> genModifier = registry.getType(WorldGeneratorModifier.class, modifier);
if (genModifier.isPresent()) {
genModifiers.add(genModifier.get());
} else {
Lantern.getLogger().error("World generator modifier with id " + modifier + " not found. Missing plugin?");
}
}
this.generatorModifiers = genModifiers.build();
}
Aggregations