use of org.spongepowered.api.world.weather.Weather in project Skree by Skelril.
the class WeatherCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
// 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
Weather weather = args.<Weather>getOne("type").get();
Optional<Integer> duration = args.getOne("duration");
if (!duration.isPresent()) {
// Between 5 and 15 minutes
duration = Optional.of(Probability.getRangedRandom(5 * 60, 15 * 60));
}
if (duration.get() < 1) {
src.sendMessage(Text.of(TextColors.RED, "Weather duration must be at least 1 second!"));
return CommandResult.empty();
}
World world = optWorld.get();
if (!world.isLoaded()) {
src.sendMessage(Text.of(TextColors.RED, "The specified world was not loaded!"));
return CommandResult.empty();
}
world.setWeather(weather, duration.get() * 20);
src.sendMessage(Text.of(TextColors.YELLOW, "Changed weather state in " + world.getName() + " to: " + weather.getName() + '.'));
return CommandResult.success();
}
Aggregations