Search in sources :

Example 1 with ModularWorldService

use of io.github.nucleuspowered.nucleus.dataservices.modular.ModularWorldService 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)

Example 2 with ModularWorldService

use of io.github.nucleuspowered.nucleus.dataservices.modular.ModularWorldService in project Nucleus by NucleusPowered.

the class WeatherCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    // We can predict the weather on multiple worlds now!
    WorldProperties wp = this.getWorldFromUserOrArgs(src, world, args);
    World w = Sponge.getServer().getWorld(wp.getUniqueId()).orElseThrow(() -> ReturnMessageException.fromKey("args.worldproperties.notloaded", wp.getWorldName()));
    // Get whether we locked the weather.
    ModularWorldService ew = Nucleus.getNucleus().getWorldDataManager().getWorld(w).get();
    if (ew.get(EnvironmentWorldDataModule.class).isLockWeather()) {
        // Tell the user to unlock first.
        throw ReturnMessageException.fromKey("command.weather.locked", w.getName());
    }
    // Houston, we have a world! Now, what was the forecast?
    Weather we = args.<Weather>getOne(weather).get();
    // Have we gotten an accurate forecast? Do we know how long this weather spell will go on for?
    Optional<Long> oi = args.getOne(duration);
    // Even weather masters have their limits. Sometimes.
    if (max > 0 && oi.orElse(Long.MAX_VALUE) > max && !permissions.testSuffix(src, "exempt.length")) {
        throw ReturnMessageException.fromKey("command.weather.toolong", Util.getTimeStringFromSeconds(max));
    }
    if (oi.isPresent()) {
        // YES! I should get a job at the weather service and show them how it's done!
        w.setWeather(we, oi.get());
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.weather.time", we.getName(), w.getName(), Util.getTimeStringFromSeconds(oi.get())));
    } else {
        // No, probably because I've already gotten a job at the weather service...
        w.setWeather(we);
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.weather.set", we.getName(), w.getName()));
    }
    // The weather control device has been activated!
    return CommandResult.success();
}
Also used : Weather(org.spongepowered.api.world.weather.Weather) EnvironmentWorldDataModule(io.github.nucleuspowered.nucleus.modules.environment.datamodule.EnvironmentWorldDataModule) ModularWorldService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularWorldService) World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 3 with ModularWorldService

use of io.github.nucleuspowered.nucleus.dataservices.modular.ModularWorldService in project Nucleus by NucleusPowered.

the class WorldDataManager method getNew.

@Override
public Optional<ModularWorldService> getNew(UUID data, DataProvider<ConfigurationNode> dataProvider) throws Exception {
    ModularWorldService m = new ModularWorldService(dataProvider, Sponge.getServer().getWorldProperties(data).orElseThrow(() -> new IllegalStateException("world")).getUniqueId());
    m.loadInternal();
    return Optional.of(m);
}
Also used : ModularWorldService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularWorldService)

Example 4 with ModularWorldService

use of io.github.nucleuspowered.nucleus.dataservices.modular.ModularWorldService in project Nucleus by NucleusPowered.

the class SetSpawnCommand method executeCommand.

@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
    // Minecraft does not set the rotation of the player at the spawn point, so we'll do it for them!
    ModularWorldService worldService = Nucleus.getNucleus().getWorldDataManager().getWorld(src.getWorld().getUniqueId()).get();
    SpawnWorldDataModule m = worldService.get(SpawnWorldDataModule.class);
    m.setSpawnRotation(src.getRotation());
    worldService.set(m);
    src.getWorld().getProperties().setSpawnPosition(src.getLocation().getBlockPosition());
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.setspawn.success", src.getWorld().getName()));
    return CommandResult.success();
}
Also used : SpawnWorldDataModule(io.github.nucleuspowered.nucleus.modules.spawn.datamodules.SpawnWorldDataModule) ModularWorldService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularWorldService)

Aggregations

ModularWorldService (io.github.nucleuspowered.nucleus.dataservices.modular.ModularWorldService)4 EnvironmentWorldDataModule (io.github.nucleuspowered.nucleus.modules.environment.datamodule.EnvironmentWorldDataModule)2 WorldProperties (org.spongepowered.api.world.storage.WorldProperties)2 SpawnWorldDataModule (io.github.nucleuspowered.nucleus.modules.spawn.datamodules.SpawnWorldDataModule)1 World (org.spongepowered.api.world.World)1 Weather (org.spongepowered.api.world.weather.Weather)1