use of org.spongepowered.api.world.storage.WorldProperties in project ProjectWorlds by trentech.
the class CommandGamemode method process.
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
if (arguments.equalsIgnoreCase("gamemode")) {
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 gm;
try {
worldName = args[0];
} catch (Exception e) {
throw new CommandException(getHelp().getUsageText());
}
try {
gm = args[1];
} 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();
Optional<GameMode> optionalGameMode = Gamemode.get(gm);
if (!optionalGameMode.isPresent()) {
try {
optionalGameMode = Gamemode.get(Integer.parseInt(gm));
} catch (Exception e) {
source.sendMessage(Text.of(TextColors.YELLOW, gm, " is not a valid GameMode"));
throw new CommandException(getHelp().getUsageText());
}
if (!optionalGameMode.isPresent()) {
source.sendMessage(Text.of(TextColors.YELLOW, gm, " is not a valid GameMode"));
throw new CommandException(getHelp().getUsageText());
}
}
GameMode gameMode = optionalGameMode.get();
world.setGameMode(gameMode);
Sponge.getServer().saveWorldProperties(world);
source.sendMessage(Text.of(TextColors.DARK_GREEN, "Set gamemode of ", world.getWorldName(), " to ", TextColors.YELLOW, gameMode.getTranslation().get().toUpperCase()));
return CommandResult.success();
}
use of org.spongepowered.api.world.storage.WorldProperties in project ProjectWorlds by trentech.
the class CommandGamerule method process.
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
if (arguments.equalsIgnoreCase("gamerule")) {
throw new CommandException(getHelp().getUsageText());
}
String[] args = arguments.split(" ");
if (args[args.length - 1].equalsIgnoreCase("--help")) {
getHelp().execute(source);
return CommandResult.success();
}
String worldName;
try {
worldName = args[0];
} catch (Exception e) {
throw new CommandException(getHelp().getUsageText());
}
Optional<WorldProperties> optionalProperties = Sponge.getServer().getWorldProperties(worldName);
if (!optionalProperties.isPresent()) {
throw new CommandException(Text.of(TextColors.RED, worldName, " does not exist"), false);
}
WorldProperties properties = optionalProperties.get();
String rule;
try {
rule = args[1];
if (!validGamerule(properties, rule)) {
source.sendMessage(Text.of(TextColors.YELLOW, rule, " is not a valid Gamerule"));
throw new CommandException(getHelp().getUsageText());
}
} catch (Exception e) {
List<Text> list = new ArrayList<>();
for (Entry<String, String> gamerule : properties.getGameRules().entrySet()) {
list.add(Text.of(TextColors.GREEN, gamerule.getKey(), ": ", TextColors.WHITE, gamerule.getValue()));
}
if (source instanceof Player) {
PaginationList.Builder pages = PaginationList.builder();
pages.title(Text.builder().color(TextColors.DARK_GREEN).append(Text.of(TextColors.GREEN, properties.getWorldName())).build());
pages.contents(list);
pages.sendTo(source);
} else {
for (Text text : list) {
source.sendMessage(text);
}
}
return CommandResult.success();
}
String value;
try {
value = args[2];
if (!isValid(rule, value)) {
source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid Value for Gamerule ", rule));
throw new CommandException(getHelp().getUsageText());
}
} catch (Exception e) {
source.sendMessage(Text.of(TextColors.GREEN, rule, ": ", TextColors.WHITE, properties.getGameRule(rule).get()));
return CommandResult.success();
}
properties.setGameRule(rule, value.toLowerCase());
Sponge.getServer().saveWorldProperties(properties);
source.sendMessage(Text.of(TextColors.DARK_GREEN, "Set gamerule ", rule, " to ", value));
return CommandResult.success();
}
use of org.spongepowered.api.world.storage.WorldProperties 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.storage.WorldProperties 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.storage.WorldProperties in project ProjectWorlds by trentech.
the class CommandKeepSpawnLoaded method process.
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
if (arguments.equalsIgnoreCase("keepspawnloaded")) {
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 bool;
try {
worldName = args[0];
} catch (Exception e) {
throw new CommandException(getHelp().getUsageText());
}
try {
bool = args[1];
} 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();
if (bool.equalsIgnoreCase("true") || bool.equalsIgnoreCase("false")) {
world.setKeepSpawnLoaded(Boolean.valueOf(bool));
}
Sponge.getServer().saveWorldProperties(world);
source.sendMessage(Text.of(TextColors.DARK_GREEN, "Set keep spawn loaded of ", world.getWorldName(), " to ", TextColors.YELLOW, bool));
return CommandResult.success();
}
Aggregations