Search in sources :

Example 1 with EnvironmentWorldDataModule

use of io.github.nucleuspowered.nucleus.modules.environment.datamodule.EnvironmentWorldDataModule in project Nucleus by NucleusPowered.

the class LockWeatherCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    Optional<WorldProperties> world = getWorldProperties(src, worldKey, args);
    if (!world.isPresent()) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.specifyworld"));
        return CommandResult.empty();
    }
    WorldProperties wp = world.get();
    Optional<ModularWorldService> ws = loader.getWorld(wp.getUniqueId());
    if (!ws.isPresent()) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.noworld", wp.getWorldName()));
        return CommandResult.empty();
    }
    EnvironmentWorldDataModule environmentWorldDataModule = ws.get().get(EnvironmentWorldDataModule.class);
    boolean toggle = args.<Boolean>getOne(toggleKey).orElse(!environmentWorldDataModule.isLockWeather());
    environmentWorldDataModule.setLockWeather(toggle);
    ws.get().set(environmentWorldDataModule);
    if (toggle) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.lockweather.locked", wp.getWorldName()));
    } else {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.lockweather.unlocked", wp.getWorldName()));
    }
    return CommandResult.success();
}
Also used : EnvironmentWorldDataModule(io.github.nucleuspowered.nucleus.modules.environment.datamodule.EnvironmentWorldDataModule) ModularWorldService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularWorldService) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Aggregations

ModularWorldService (io.github.nucleuspowered.nucleus.dataservices.modular.ModularWorldService)1 EnvironmentWorldDataModule (io.github.nucleuspowered.nucleus.modules.environment.datamodule.EnvironmentWorldDataModule)1 WorldProperties (org.spongepowered.api.world.storage.WorldProperties)1