use of org.spongepowered.api.world.storage.WorldProperties in project ProjectWorlds by trentech.
the class CommandKeepSpawnLoaded method getSuggestions.
@Override
public List<String> getSuggestions(CommandSource source, String arguments, Location<World> targetPosition) throws CommandException {
List<String> list = new ArrayList<>();
if (arguments.equalsIgnoreCase("keepspawnloaded")) {
return list;
}
String[] args = arguments.split(" ");
if (args.length == 1) {
for (WorldProperties world : Sponge.getServer().getAllWorldProperties()) {
if (world.getWorldName().equalsIgnoreCase(args[0])) {
list.add("true");
list.add("false");
return list;
}
if (world.getWorldName().toLowerCase().startsWith(args[0].toLowerCase())) {
list.add(world.getWorldName());
}
}
return list;
}
if (args.length == 2) {
if ("true".equalsIgnoreCase(args[1].toLowerCase()) || "false".equalsIgnoreCase(args[1].toLowerCase())) {
return list;
}
if ("true".startsWith(args[1].toLowerCase())) {
list.add("true");
}
if ("false".startsWith(args[1].toLowerCase())) {
list.add("false");
}
}
return list;
}
use of org.spongepowered.api.world.storage.WorldProperties 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();
}
use of org.spongepowered.api.world.storage.WorldProperties 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.storage.WorldProperties in project ProjectWorlds by trentech.
the class CommandPvp method getSuggestions.
@Override
public List<String> getSuggestions(CommandSource source, String arguments, Location<World> targetPosition) throws CommandException {
List<String> list = new ArrayList<>();
if (arguments.equalsIgnoreCase("pvp")) {
return list;
}
String[] args = arguments.split(" ");
if (args.length == 1) {
for (WorldProperties world : Sponge.getServer().getAllWorldProperties()) {
if (world.getWorldName().equalsIgnoreCase(args[0])) {
list.add("true");
list.add("false");
return list;
}
if (world.getWorldName().toLowerCase().startsWith(args[0].toLowerCase())) {
list.add(world.getWorldName());
}
}
return list;
}
if (args.length == 2) {
if ("true".equalsIgnoreCase(args[1].toLowerCase()) || "false".equalsIgnoreCase(args[1].toLowerCase())) {
return list;
}
if ("true".startsWith(args[1].toLowerCase())) {
list.add("true");
}
if ("false".startsWith(args[1].toLowerCase())) {
list.add("false");
}
}
return list;
}
use of org.spongepowered.api.world.storage.WorldProperties in project ProjectWorlds by trentech.
the class CommandPvp method process.
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
if (arguments.equalsIgnoreCase("pvp")) {
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.setPVPEnabled(Boolean.valueOf(bool));
}
Sponge.getServer().saveWorldProperties(world);
source.sendMessage(Text.of(TextColors.DARK_GREEN, "Set pvp of ", world.getWorldName(), " to ", TextColors.YELLOW, bool));
return CommandResult.success();
}
Aggregations