Search in sources :

Example 46 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties 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 47 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project Nucleus by NucleusPowered.

the class TimeCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    WorldProperties pr = getWorldPropertiesOrDefault(src, world, args);
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.time", pr.getWorldName(), String.valueOf(Util.getTimeFromTicks(pr.getWorldTime()))));
    return CommandResult.success();
}
Also used : WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 48 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties 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 49 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project Nucleus by NucleusPowered.

the class WorldCorrector method worldCheck.

public static void worldCheck() throws IOException, ObjectMappingException {
    final Map<String, UUID> m = get();
    // Now get the file out.
    Path path = Nucleus.getNucleus().getDataPath().resolve("worlduuids.json");
    ConfigurationLoader<ConfigurationNode> cl = GsonConfigurationLoader.builder().setPath(path).build();
    Map<String, UUID> ms = cl.load().getValue(new TypeToken<Map<String, UUID>>() {
    }, Maps.newHashMap());
    final Map<UUID, UUID> fromToConverter = Maps.newHashMap();
    for (String r : ms.keySet()) {
        UUID oldUuid = ms.get(r);
        @Nullable UUID newUuid = m.get(r);
        if (newUuid != null && !oldUuid.equals(newUuid)) {
            fromToConverter.put(newUuid, oldUuid);
        }
    }
    cl.save(cl.createEmptyNode().setValue(new TypeToken<Map<String, UUID>>() {
    }, m));
    if (fromToConverter.isEmpty()) {
        return;
    }
    MessageProvider mp = Nucleus.getNucleus().getMessageProvider();
    ConsoleSource cs = Sponge.getServer().getConsole();
    List<Text> msg = Lists.newArrayList();
    Nucleus.getNucleus().addX(msg, 0);
    msg.forEach(cs::sendMessage);
    cs.sendMessage(Text.of(TextColors.RED, "--------------------"));
    cs.sendMessage(mp.getTextMessageWithFormat("worldrepair.detected"));
    for (Map.Entry<UUID, UUID> u : fromToConverter.entrySet()) {
        cs.sendMessage(mp.getTextMessageWithFormat("worldrepair.worldlist", Sponge.getServer().getWorldProperties(u.getKey()).get().getWorldName(), u.getValue().toString(), u.getKey().toString()));
    }
    Method method;
    try {
        method = Sponge.getServer().getDefaultWorld().get().getClass().getDeclaredMethod("setUniqueId", UUID.class);
        method.setAccessible(true);
    } catch (NoSuchMethodException e) {
        cs.sendMessage(mp.getTextMessageWithFormat("worldrepair.whitelist.nocmd"));
        return;
    }
    cs.sendMessage(mp.getTextMessageWithFormat("worldrepair.whitelist.cmd"));
    cs.sendMessage(Text.of(TextColors.RED, "--------------------"));
    cs.sendMessage(mp.getTextMessageWithFormat("worldrepair.whitelist.cmd2"));
    Sponge.getServer().setHasWhitelist(true);
    Sponge.getCommandManager().register(Nucleus.getNucleus(), CommandSpec.builder().executor((s, a) -> {
        MessageProvider mpr = Nucleus.getNucleus().getMessageProvider();
        if (s instanceof ConsoleSource) {
            cs.sendMessage(mpr.getTextMessageWithFormat("worldrepair.repair.start"));
            Sponge.getEventManager().registerListener(Nucleus.getNucleus(), GameStoppedServerEvent.class, event -> {
                for (Map.Entry<UUID, UUID> meuu : fromToConverter.entrySet()) {
                    // Magic!
                    WorldProperties wp = Sponge.getServer().getWorldProperties(meuu.getKey()).orElseThrow(() -> new NoSuchElementException(mpr.getMessageWithFormat("worldrepair.repair.nouuid", meuu.getKey().toString())));
                    final String name = wp.getWorldName();
                    try {
                        cs.sendMessage(mpr.getTextMessageWithFormat("worldrepair.repair.try", name));
                        method.invoke(wp, meuu.getValue());
                        Sponge.getServer().saveWorldProperties(wp);
                        cs.sendMessage(mpr.getTextMessageWithFormat("worldrepair.repair.success", name));
                    } catch (Exception e) {
                        cs.sendMessage(mpr.getTextMessageWithFormat("worldrepair.repair.fail", name));
                        e.printStackTrace();
                    }
                }
                try {
                    cl.save(cl.createEmptyNode().setValue(new TypeToken<Map<String, UUID>>() {
                    }, get()));
                } catch (IOException | ObjectMappingException e) {
                    e.printStackTrace();
                }
            });
            Sponge.getServer().shutdown();
            return CommandResult.success();
        } else {
            s.sendMessage(mpr.getTextMessageWithFormat("command.consoleonly"));
            return CommandResult.empty();
        }
    }).build(), "repairuuids");
}
Also used : UUID(java.util.UUID) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException) Path(java.nio.file.Path) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) Text(org.spongepowered.api.text.Text) Method(java.lang.reflect.Method) IOException(java.io.IOException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) TypeToken(com.google.common.reflect.TypeToken) ConsoleSource(org.spongepowered.api.command.source.ConsoleSource) Map(java.util.Map) Nullable(javax.annotation.Nullable) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) NoSuchElementException(java.util.NoSuchElementException)

Example 50 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project Nucleus by NucleusPowered.

the class SpawnListener method onRespawn.

@Listener(order = Order.EARLY)
public void onRespawn(RespawnPlayerEvent event) {
    if (event.isBedSpawn() && !this.spawnConfig.isRedirectBedSpawn()) {
        // Nope, we don't care.
        return;
    }
    GlobalSpawnConfig sc = spawnConfig.getGlobalSpawn();
    World world = event.getToTransform().getExtent();
    // Get the world.
    if (sc.isOnRespawn()) {
        Optional<WorldProperties> oworld = sc.getWorld();
        if (oworld.isPresent()) {
            world = Sponge.getServer().getWorld(oworld.get().getUniqueId()).orElse(world);
        }
    }
    Location<World> spawn = world.getSpawnLocation().add(0.5, 0, 0.5);
    Transform<World> to = new Transform<>(spawn);
    // Compare current transform to spawn - set rotation.
    Nucleus.getNucleus().getWorldDataManager().getWorld(world).ifPresent(x -> x.get(SpawnWorldDataModule.class).getSpawnRotation().ifPresent(y -> event.setToTransform(to.setRotation(y))));
}
Also used : GlobalSpawnConfig(io.github.nucleuspowered.nucleus.modules.spawn.config.GlobalSpawnConfig) CoreUserDataModule(io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule) PermissionInformation(io.github.nucleuspowered.nucleus.internal.permissions.PermissionInformation) Vector3d(com.flowpowered.math.vector.Vector3d) SpawnConfig(io.github.nucleuspowered.nucleus.modules.spawn.config.SpawnConfig) UserStorageService(org.spongepowered.api.service.user.UserStorageService) PermissionRegistry(io.github.nucleuspowered.nucleus.internal.PermissionRegistry) Order(org.spongepowered.api.event.Order) Map(java.util.Map) SuggestedLevel(io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel) NucleusTeleportHandler(io.github.nucleuspowered.nucleus.internal.teleport.NucleusTeleportHandler) ListenerBase(io.github.nucleuspowered.nucleus.internal.ListenerBase) SpawnWorldDataModule(io.github.nucleuspowered.nucleus.modules.spawn.datamodules.SpawnWorldDataModule) SpawnConfigAdapter(io.github.nucleuspowered.nucleus.modules.spawn.config.SpawnConfigAdapter) Location(org.spongepowered.api.world.Location) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) User(org.spongepowered.api.entity.living.player.User) GlobalSpawnConfig(io.github.nucleuspowered.nucleus.modules.spawn.config.GlobalSpawnConfig) Sponge(org.spongepowered.api.Sponge) UUID(java.util.UUID) Maps(com.google.common.collect.Maps) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) Reloadable(io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable) SpawnGeneralDataModule(io.github.nucleuspowered.nucleus.modules.spawn.datamodules.SpawnGeneralDataModule) Transform(org.spongepowered.api.entity.Transform) World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) Listener(org.spongepowered.api.event.Listener) RespawnPlayerEvent(org.spongepowered.api.event.entity.living.humanoid.player.RespawnPlayerEvent) MoveEntityEvent(org.spongepowered.api.event.entity.MoveEntityEvent) SpawnWorldDataModule(io.github.nucleuspowered.nucleus.modules.spawn.datamodules.SpawnWorldDataModule) World(org.spongepowered.api.world.World) Transform(org.spongepowered.api.entity.Transform) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Listener(org.spongepowered.api.event.Listener)

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