Search in sources :

Example 71 with WorldProperties

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

Example 72 with WorldProperties

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();
}
Also used : CommandResult(org.spongepowered.api.command.CommandResult) TextActions(org.spongepowered.api.text.action.TextActions) Location(org.spongepowered.api.world.Location) Utils(com.gmail.trentech.pjw.utils.Utils) CommandSource(org.spongepowered.api.command.CommandSource) WorldData(com.gmail.trentech.pjw.io.WorldData) CommandCallable(org.spongepowered.api.command.CommandCallable) Sponge(org.spongepowered.api.Sponge) ArrayList(java.util.ArrayList) CommandException(org.spongepowered.api.command.CommandException) Direction(org.spongepowered.api.util.Direction) List(java.util.List) Text(org.spongepowered.api.text.Text) Main(com.gmail.trentech.pjw.Main) World(org.spongepowered.api.world.World) Task(org.spongepowered.api.scheduler.Task) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Help(com.gmail.trentech.pjc.help.Help) Optional(java.util.Optional) SpongeData(com.gmail.trentech.pjw.io.SpongeData) TextColors(org.spongepowered.api.text.format.TextColors) Optional(java.util.Optional) SpongeData(com.gmail.trentech.pjw.io.SpongeData) CommandException(org.spongepowered.api.command.CommandException) WorldData(com.gmail.trentech.pjw.io.WorldData) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 73 with WorldProperties

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

Example 74 with WorldProperties

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

Example 75 with WorldProperties

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