use of org.spongepowered.api.world.storage.WorldProperties in project ProjectWorlds by trentech.
the class CommandGamerule method getSuggestions.
@Override
public List<String> getSuggestions(CommandSource source, String arguments, Location<World> targetPosition) throws CommandException {
List<String> list = new ArrayList<>();
if (arguments.equalsIgnoreCase("gamerule")) {
return list;
}
String[] args = arguments.split(" ");
if (args.length == 1) {
for (WorldProperties world : Sponge.getServer().getAllWorldProperties()) {
if (world.getWorldName().equalsIgnoreCase(args[0])) {
for (Entry<String, String> entry : world.getGameRules().entrySet()) {
list.add(entry.getKey());
}
return list;
}
if (world.getWorldName().toLowerCase().startsWith(args[0].toLowerCase())) {
list.add(world.getWorldName());
}
}
}
if (args.length == 2) {
for (Entry<String, String> entry : Sponge.getServer().getWorldProperties(args[0]).get().getGameRules().entrySet()) {
if (entry.getKey().toLowerCase().equalsIgnoreCase(args[1].toLowerCase())) {
return list;
}
if (entry.getKey().toLowerCase().startsWith(args[1].toLowerCase())) {
list.add(entry.getKey());
}
}
}
return list;
}
use of org.spongepowered.api.world.storage.WorldProperties in project ProjectWorlds by trentech.
the class CommandHardcore method getSuggestions.
@Override
public List<String> getSuggestions(CommandSource source, String arguments, Location<World> targetPosition) throws CommandException {
List<String> list = new ArrayList<>();
if (arguments.equalsIgnoreCase("hardcore")) {
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 CommandHardcore method process.
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
if (arguments.equalsIgnoreCase("hardcore")) {
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.setHardcore(Boolean.valueOf(bool));
}
Sponge.getServer().saveWorldProperties(world);
source.sendMessage(Text.of(TextColors.DARK_GREEN, "Set hardcore of ", world.getWorldName(), " to ", TextColors.YELLOW, bool));
return CommandResult.success();
}
use of org.spongepowered.api.world.storage.WorldProperties in project ProjectWorlds by trentech.
the class CommandList method process.
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
if (arguments.equalsIgnoreCase("--help")) {
help.execute(source);
return CommandResult.success();
}
List<Text> list = new ArrayList<>();
for (WorldProperties properties : Sponge.getServer().getAllWorldProperties()) {
Optional<World> optionalWorld = Sponge.getServer().getWorld(properties.getUniqueId());
if (optionalWorld.isPresent()) {
World world = optionalWorld.get();
Builder builder = Text.builder().color(TextColors.GREEN).onHover(TextActions.showText(Text.of(TextColors.WHITE, "Click to view properies")));
builder.onClick(TextActions.runCommand("/pjw:world properties " + world.getName())).append(Text.of(TextColors.GREEN, world.getName(), ": ", Lists.newArrayList(world.getLoadedChunks()).size(), " Loaded chunks, ", world.getEntities().size(), " Entities"));
list.add(builder.build());
} else {
Builder builder = Text.builder().color(TextColors.GREEN).onHover(TextActions.showText(Text.of(TextColors.WHITE, "Click to load world")));
builder.onClick(TextActions.runCommand("/pjw:world load " + properties.getWorldName())).append(Text.of(TextColors.GREEN, properties.getWorldName(), ": ", TextColors.GRAY, " Unloaded"));
list.add(builder.build());
}
}
if (source instanceof Player) {
PaginationList.Builder pages = PaginationList.builder();
pages.title(Text.builder().color(TextColors.DARK_GREEN).append(Text.of(TextColors.GREEN, "Worlds")).build());
pages.contents(list);
pages.sendTo(source);
} else {
for (Text text : list) {
source.sendMessage(text);
}
}
return CommandResult.success();
}
use of org.spongepowered.api.world.storage.WorldProperties in project ProjectWorlds by trentech.
the class CommandLoadOnStartup method getSuggestions.
@Override
public List<String> getSuggestions(CommandSource source, String arguments, Location<World> targetPosition) throws CommandException {
List<String> list = new ArrayList<>();
if (arguments.equalsIgnoreCase("loadonstartup")) {
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;
}
Aggregations