Search in sources :

Example 11 with WorldProperties

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;
}
Also used : ArrayList(java.util.ArrayList) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 12 with WorldProperties

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;
}
Also used : ArrayList(java.util.ArrayList) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 13 with WorldProperties

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();
}
Also used : CommandException(org.spongepowered.api.command.CommandException) CommandException(org.spongepowered.api.command.CommandException) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 14 with WorldProperties

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();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) PaginationList(org.spongepowered.api.service.pagination.PaginationList) Builder(org.spongepowered.api.text.Text.Builder) ArrayList(java.util.ArrayList) Text(org.spongepowered.api.text.Text) World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 15 with WorldProperties

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;
}
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