Search in sources :

Example 61 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project Skree by Skelril.

the class WorldCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    if (!(src instanceof Player)) {
        src.sendMessage(Text.of("You must be a player to use this command!"));
        return CommandResult.empty();
    }
    WorldService service = Sponge.getServiceManager().provideUnchecked(WorldService.class);
    Optional<WorldProperties> optProperties = args.getOne("world");
    if (!optProperties.isPresent()) {
        src.sendMessage(Text.of(TextColors.YELLOW, "You are in: " + ((Player) src).getWorld().getName() + "."));
        return CommandResult.empty();
    }
    Optional<World> optWorld = Sponge.getServer().getWorld(optProperties.get().getWorldName());
    if (!optWorld.isPresent()) {
        src.sendMessage(Text.of(TextColors.RED, "No loaded world by that name found."));
        return CommandResult.empty();
    }
    World world = optWorld.get();
    if (!WorldEntryPermissionCheck.checkDestination((Player) src, world)) {
        src.sendMessage(Text.of(TextColors.RED, "You do not have permission to access worlds of this type."));
        return CommandResult.empty();
    }
    Location<World> targetLocation;
    if (args.hasAny("s")) {
        targetLocation = world.getSpawnLocation();
    } else {
        targetLocation = service.getWorldEntryPoint((Player) src, world);
    }
    Optional<Location<World>> optLoc = SafeTeleportHelper.teleport((Player) src, targetLocation);
    if (optLoc.isPresent()) {
        src.sendMessage(Text.of(TextColors.YELLOW, "Entered world: " + world.getName() + " successfully!"));
    } else if (args.hasAny("f")) {
        ((Player) src).setLocation(targetLocation);
        src.sendMessage(Text.of(TextColors.YELLOW, "Force entered world: " + world.getName() + " successfully!"));
    } else {
        src.sendMessage(Text.of(TextColors.YELLOW, "Failed to enter " + world.getName() + " please report this!"));
    }
    return CommandResult.success();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) World(org.spongepowered.api.world.World) WorldService(com.skelril.skree.service.WorldService) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Location(org.spongepowered.api.world.Location)

Example 62 with WorldProperties

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

the class CommandCopy method process.

@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
    if (arguments.equalsIgnoreCase("copy")) {
        throw new CommandException(getHelp().getUsageText());
    }
    String[] args = arguments.split(" ");
    if (args[args.length - 1].equalsIgnoreCase("--help")) {
        getHelp().execute(source);
        return CommandResult.success();
    }
    String oldWorldName;
    String newWorldName;
    try {
        oldWorldName = args[0];
    } catch (Exception e) {
        throw new CommandException(getHelp().getUsageText());
    }
    try {
        newWorldName = args[1];
    } catch (Exception e) {
        throw new CommandException(getHelp().getUsageText());
    }
    Optional<WorldProperties> optionalWorld = Sponge.getServer().getWorldProperties(oldWorldName);
    if (!optionalWorld.isPresent()) {
        throw new CommandException(Text.of(TextColors.RED, oldWorldName, " does not exist"), false);
    }
    WorldProperties world = optionalWorld.get();
    if (Sponge.getServer().getWorldProperties(newWorldName).isPresent()) {
        throw new CommandException(Text.of(TextColors.RED, newWorldName, " already exists"), false);
    }
    Optional<WorldProperties> copy = Optional.empty();
    try {
        CompletableFuture<Optional<WorldProperties>> copyFuture = Sponge.getServer().copyWorld(world, newWorldName);
        while (!copyFuture.isDone()) {
        }
        copy = copyFuture.get();
    } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace();
        throw new CommandException(Text.of(TextColors.RED, "Something went wrong. Check server log for details"), false);
    }
    if (!copy.isPresent()) {
        throw new CommandException(Text.of(TextColors.RED, "Could not copy ", world.getWorldName()), false);
    }
    source.sendMessage(Text.of(TextColors.DARK_GREEN, world.getWorldName(), " copied to ", newWorldName));
    return CommandResult.success();
}
Also used : Optional(java.util.Optional) CommandException(org.spongepowered.api.command.CommandException) ExecutionException(java.util.concurrent.ExecutionException) ExecutionException(java.util.concurrent.ExecutionException) CommandException(org.spongepowered.api.command.CommandException) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 63 with WorldProperties

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

the class CommandDifficulty method getSuggestions.

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

Example 64 with WorldProperties

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

the class CommandDifficulty method process.

@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
    if (arguments.equalsIgnoreCase("difficulty")) {
        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 diff;
    try {
        worldName = args[0];
    } catch (Exception e) {
        throw new CommandException(getHelp().getUsageText());
    }
    try {
        diff = 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();
    Optional<Difficulty> optionalDifficulty = Sponge.getRegistry().getType(Difficulty.class, diff);
    if (!optionalDifficulty.isPresent()) {
        source.sendMessage(Text.of(TextColors.YELLOW, diff, " is not a valid Difficulty"));
        throw new CommandException(getHelp().getUsageText());
    }
    Difficulty difficulty = optionalDifficulty.get();
    world.setDifficulty(difficulty);
    Sponge.getServer().saveWorldProperties(world);
    source.sendMessage(Text.of(TextColors.DARK_GREEN, "Set difficulty of ", world.getWorldName(), " to ", TextColors.YELLOW, difficulty.getTranslation().get().toUpperCase()));
    return CommandResult.success();
}
Also used : Difficulty(org.spongepowered.api.world.difficulty.Difficulty) CommandException(org.spongepowered.api.command.CommandException) CommandException(org.spongepowered.api.command.CommandException) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 65 with WorldProperties

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

the class CommandEnable method process.

@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
    if (arguments.equalsIgnoreCase("enable")) {
        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.setEnabled(Boolean.valueOf(bool));
    }
    Sponge.getServer().saveWorldProperties(world);
    source.sendMessage(Text.of(TextColors.DARK_GREEN, "Set enabled 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