Search in sources :

Example 16 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project ProjectWorlds by trentech.

the class CommandLoadOnStartup method process.

@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
    if (arguments.equalsIgnoreCase("loadonstartup")) {
        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.setLoadOnStartup(Boolean.valueOf(bool));
    }
    Sponge.getServer().saveWorldProperties(world);
    source.sendMessage(Text.of(TextColors.DARK_GREEN, "Set load on startup of ", world.getWorldName(), " to ", TextColors.YELLOW, bool));
    return CommandResult.success();
}
Also used : CommandException(org.spongepowered.api.command.CommandException) CommandException(org.spongepowered.api.command.CommandException) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 17 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project ProjectWorlds by trentech.

the class CommandModifier method getSuggestions.

@Override
public List<String> getSuggestions(CommandSource source, String arguments, Location<World> targetPosition) throws CommandException {
    List<String> list = new ArrayList<>();
    if (arguments.equalsIgnoreCase("modifier")) {
        return list;
    }
    String[] args = arguments.split(" ");
    if (args.length == 1) {
        for (WorldProperties world : Sponge.getServer().getAllWorldProperties()) {
            if (world.getWorldName().equalsIgnoreCase(args[0])) {
                for (WorldGeneratorModifier modifier : Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class)) {
                    list.add(modifier.getId());
                }
                return list;
            }
            if (world.getWorldName().toLowerCase().startsWith(args[0].toLowerCase())) {
                list.add(world.getWorldName());
            }
        }
    }
    if (args.length >= 2) {
        for (WorldGeneratorModifier modifier : Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class)) {
            if (modifier.getId().equalsIgnoreCase(args[1])) {
                return list;
            }
            if (modifier.getId().toLowerCase().startsWith(args[1].toLowerCase())) {
                list.add(modifier.getId());
            }
        }
    }
    return list;
}
Also used : WorldGeneratorModifier(org.spongepowered.api.world.gen.WorldGeneratorModifier) ArrayList(java.util.ArrayList) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 18 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project ProjectWorlds by trentech.

the class CommandProperties method process.

@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
    if (arguments.equalsIgnoreCase("properties")) {
        throw new CommandException(getHelp().getUsageText());
    }
    if (arguments.equalsIgnoreCase("--help")) {
        help.execute(source);
        return CommandResult.success();
    }
    Optional<WorldProperties> optionalProperties = Sponge.getServer().getWorldProperties(arguments);
    if (!optionalProperties.isPresent()) {
        throw new CommandException(Text.of(TextColors.RED, arguments, " does not exist"), false);
    }
    WorldProperties properties = optionalProperties.get();
    List<Text> list = new ArrayList<>();
    Optional<World> optionalWorld = Sponge.getServer().getWorld(properties.getUniqueId());
    if (optionalWorld.isPresent()) {
        list.add(Text.of(TextColors.GREEN, "Name: ", TextColors.WHITE, properties.getWorldName(), TextColors.GREEN, ", DimId: ", TextColors.WHITE, (int) properties.getAdditionalProperties().getView(DataQuery.of("SpongeData")).get().get(DataQuery.of("dimensionId")).get(), TextColors.GREEN, ", Loaded: ", TextColors.WHITE, "true", TextColors.GREEN, ", Enabled: ", TextColors.WHITE, properties.isEnabled()));
    } else {
        list.add(Text.of(TextColors.GREEN, "Name: ", TextColors.WHITE, properties.getWorldName(), TextColors.GREEN, ", Loaded: ", TextColors.WHITE, "false", TextColors.GREEN, ", Enabled: ", TextColors.WHITE, properties.isEnabled()));
    }
    list.add(Text.of(TextColors.GREEN, "Generator: ", TextColors.WHITE, properties.getGeneratorType().getName().toLowerCase(), TextColors.GREEN, ", Dimension: ", TextColors.WHITE, properties.getDimensionType().getName().toLowerCase()));
    Collection<WorldGeneratorModifier> modifiers = properties.getGeneratorModifiers();
    if (!modifiers.isEmpty()) {
        list.add(Text.of(TextColors.GREEN, "Generator Modifiers: "));
    }
    for (WorldGeneratorModifier modifier : modifiers) {
        list.add(Text.of(TextColors.GREEN, "  - ", TextColors.WHITE, modifier.getId()));
    }
    list.add(Text.of(TextColors.GREEN, "GameMode: ", TextColors.WHITE, properties.getGameMode().getTranslation().get().toLowerCase(), TextColors.GREEN, ", Difficulty: ", TextColors.WHITE, properties.getDifficulty().getTranslation().get().toLowerCase(), TextColors.GREEN, ", PVP: ", TextColors.WHITE, properties.isPVPEnabled()));
    list.add(Text.of(TextColors.GREEN, "Keep Spawn Loaded: ", TextColors.WHITE, properties.doesKeepSpawnLoaded(), TextColors.GREEN, ", Load on Startup: ", TextColors.WHITE, properties.loadOnStartup()));
    list.add(Text.of(TextColors.GREEN, "Bonus Chest: ", TextColors.WHITE, properties.doesGenerateBonusChest(), TextColors.GREEN, " Map Features: ", TextColors.WHITE, properties.usesMapFeatures()));
    if (optionalWorld.isPresent()) {
        list.add(Text.of(TextColors.GREEN, "Time: ", TextColors.WHITE, Utils.getTime(properties.getWorldTime()), TextColors.GREEN, ", Ticks: ", TextColors.WHITE, (properties.getWorldTime() % 24000), TextColors.GREEN, ", Weather: ", TextColors.WHITE, optionalWorld.get().getWeather().getName()));
    } else {
        list.add(Text.of(TextColors.GREEN, "Time: ", TextColors.WHITE, Utils.getTime(properties.getWorldTime()), TextColors.GREEN, ", Ticks: ", TextColors.WHITE, (properties.getWorldTime() % 24000)));
    }
    list.add(Text.of(TextColors.GREEN, "UUID: ", TextColors.WHITE, properties.getUniqueId().toString()));
    list.add(Text.of(TextColors.GREEN, "Seed: ", TextColors.WHITE, properties.getSeed()));
    if (source instanceof Player) {
        PaginationList.Builder pages = PaginationList.builder();
        pages.title(Text.builder().color(TextColors.DARK_GREEN).append(Text.of(TextColors.GREEN, "Settings")).build());
        pages.contents(list);
        pages.sendTo(source);
    } else {
        for (Text text : list) {
            source.sendMessage(text);
        }
    }
    return CommandResult.success();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) ArrayList(java.util.ArrayList) Text(org.spongepowered.api.text.Text) CommandException(org.spongepowered.api.command.CommandException) World(org.spongepowered.api.world.World) WorldGeneratorModifier(org.spongepowered.api.world.gen.WorldGeneratorModifier) PaginationList(org.spongepowered.api.service.pagination.PaginationList) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 19 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project ProjectWorlds by trentech.

the class CommandRegen method getSuggestions.

@Override
public List<String> getSuggestions(CommandSource source, String arguments, Location<World> targetPosition) throws CommandException {
    List<String> list = new ArrayList<>();
    if (arguments.equalsIgnoreCase("regen")) {
        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;
}
Also used : ArrayList(java.util.ArrayList) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 20 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project ProjectWorlds by trentech.

the class CommandRemove method getSuggestions.

@Override
public List<String> getSuggestions(CommandSource source, String arguments, Location<World> targetPosition) throws CommandException {
    List<String> list = new ArrayList<>();
    if (arguments.equalsIgnoreCase("remove")) {
        return list;
    }
    String[] args = arguments.split(" ");
    if (args.length != 1) {
        return list;
    }
    for (WorldProperties world : Sponge.getServer().getAllWorldProperties()) {
        if (world.getWorldName().equalsIgnoreCase(args[args.length - 1])) {
            return list;
        }
        if (world.getWorldName().toLowerCase().startsWith(args[args.length - 1].toLowerCase())) {
            list.add(world.getWorldName());
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Aggregations

WorldProperties (org.spongepowered.api.world.storage.WorldProperties)109 World (org.spongepowered.api.world.World)37 CommandException (org.spongepowered.api.command.CommandException)27 ArrayList (java.util.ArrayList)26 Player (org.spongepowered.api.entity.living.player.Player)19 Text (org.spongepowered.api.text.Text)16 Vector3d (com.flowpowered.math.vector.Vector3d)9 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)9 Listener (org.spongepowered.api.event.Listener)9 WorldGeneratorModifier (org.spongepowered.api.world.gen.WorldGeneratorModifier)9 List (java.util.List)8 Optional (java.util.Optional)8 CommandResult (org.spongepowered.api.command.CommandResult)8 Vector3i (com.flowpowered.math.vector.Vector3i)7 IOException (java.io.IOException)7 Sponge (org.spongepowered.api.Sponge)7 CommandSource (org.spongepowered.api.command.CommandSource)7 IMixinWorldInfo (org.spongepowered.common.interfaces.world.IMixinWorldInfo)7 GenericArguments (org.spongepowered.api.command.args.GenericArguments)6 Location (org.spongepowered.api.world.Location)6