Search in sources :

Example 1 with DropClearService

use of com.skelril.skree.service.DropClearService in project Skree by Skelril.

the class DropClearCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    Optional<DropClearService> optService = Sponge.getServiceManager().provide(DropClearService.class);
    if (!optService.isPresent()) {
        src.sendMessage(Text.of(TextColors.DARK_RED, "The drop clear service is not currently running."));
        return CommandResult.empty();
    }
    DropClearService service = optService.get();
    // World resolution
    Optional<WorldProperties> optWorldProps = args.getOne("world");
    Optional<World> optWorld;
    if (!optWorldProps.isPresent()) {
        if (!(src instanceof Player)) {
            src.sendMessage(Text.of(TextColors.RED, "You are not a player and need to specify a world!"));
            return CommandResult.empty();
        }
        optWorld = Optional.of(((Player) src).getWorld());
    } else {
        optWorld = Sponge.getServer().getWorld(optWorldProps.get().getUniqueId());
    }
    // Handled by command spec, so always provided
    int seconds = args.<Integer>getOne("seconds").get();
    World world = optWorld.get();
    if (!world.isLoaded()) {
        src.sendMessage(Text.of(TextColors.RED, "The specified world was not loaded!"));
        return CommandResult.empty();
    }
    service.cleanup(world, Math.max(0, Math.min(seconds, maxDelay)));
    return CommandResult.success();
}
Also used : DropClearService(com.skelril.skree.service.DropClearService) Player(org.spongepowered.api.entity.living.player.Player) World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Aggregations

DropClearService (com.skelril.skree.service.DropClearService)1 Player (org.spongepowered.api.entity.living.player.Player)1 World (org.spongepowered.api.world.World)1 WorldProperties (org.spongepowered.api.world.storage.WorldProperties)1