Search in sources :

Example 91 with WorldProperties

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

the class SpawnListener method onJoin.

@Listener
public void onJoin(ClientConnectionEvent.Login loginEvent) {
    UUID pl = loginEvent.getProfile().getUniqueId();
    boolean first = Nucleus.getNucleus().getUserDataManager().getUnchecked(pl).get(CoreUserDataModule.class).isStartedFirstJoin();
    try {
        if (first) {
            // first spawn.
            Optional<Transform<World>> ofs = Nucleus.getNucleus().getGeneralService().get(SpawnGeneralDataModule.class).getFirstSpawn();
            // setting the location the player safely. If this cannot be done in either case, send them to world spawn.
            if (ofs.isPresent()) {
                NucleusTeleportHandler.StandardTeleportMode mode = spawnConfig.isSafeTeleport() ? NucleusTeleportHandler.StandardTeleportMode.SAFE_TELEPORT : NucleusTeleportHandler.StandardTeleportMode.WALL_CHECK;
                Optional<Location<World>> location = plugin.getTeleportHandler().getSafeLocation(null, ofs.get().getLocation(), mode);
                if (location.isPresent()) {
                    loginEvent.setToTransform(new Transform<>(location.get().getExtent(), process(location.get().getPosition()), ofs.get().getRotation()));
                    return;
                }
                WorldProperties w = Sponge.getServer().getDefaultWorld().get();
                loginEvent.setToTransform(new Transform<>(Sponge.getServer().getWorld(w.getUniqueId()).get(), w.getSpawnPosition().toDouble().add(0.5, 0, 0.5)));
                // We don't want to boot them elsewhere.
                return;
            }
        }
    } catch (Exception e) {
        if (Nucleus.getNucleus().isDebugMode()) {
            e.printStackTrace();
        }
    }
    // Throw them to the default world spawn if the config suggests so.
    User user = Sponge.getServiceManager().provideUnchecked(UserStorageService.class).getOrCreate(loginEvent.getProfile());
    if (spawnConfig.isSpawnOnLogin() && !user.hasPermission(spawnExempt)) {
        GlobalSpawnConfig sc = spawnConfig.getGlobalSpawn();
        World world = loginEvent.getFromTransform().getExtent();
        if (sc.isOnLogin() && sc.getWorld().isPresent()) {
            world = Sponge.getServer().getWorld(sc.getWorld().get().getUniqueId()).orElse(world);
        }
        Location<World> lw = world.getSpawnLocation().add(0.5, 0, 0.5);
        Optional<Location<World>> safe = plugin.getTeleportHandler().getSafeLocation(null, lw, spawnConfig.isSafeTeleport() ? NucleusTeleportHandler.StandardTeleportMode.SAFE_TELEPORT_ASCENDING : NucleusTeleportHandler.StandardTeleportMode.NO_CHECK);
        if (safe.isPresent()) {
            try {
                Optional<Vector3d> ov = Nucleus.getNucleus().getWorldDataManager().getWorld(world.getUniqueId()).get().get(SpawnWorldDataModule.class).getSpawnRotation();
                if (ov.isPresent()) {
                    loginEvent.setToTransform(new Transform<>(safe.get().getExtent(), process(safe.get().getPosition()), ov.get()));
                    return;
                }
            } catch (Exception e) {
            // 
            }
            loginEvent.setToTransform(new Transform<>(process(safe.get())));
        }
    }
}
Also used : GlobalSpawnConfig(io.github.nucleuspowered.nucleus.modules.spawn.config.GlobalSpawnConfig) User(org.spongepowered.api.entity.living.player.User) SpawnWorldDataModule(io.github.nucleuspowered.nucleus.modules.spawn.datamodules.SpawnWorldDataModule) World(org.spongepowered.api.world.World) CoreUserDataModule(io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule) UserStorageService(org.spongepowered.api.service.user.UserStorageService) NucleusTeleportHandler(io.github.nucleuspowered.nucleus.internal.teleport.NucleusTeleportHandler) SpawnGeneralDataModule(io.github.nucleuspowered.nucleus.modules.spawn.datamodules.SpawnGeneralDataModule) Vector3d(com.flowpowered.math.vector.Vector3d) UUID(java.util.UUID) Transform(org.spongepowered.api.entity.Transform) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 92 with WorldProperties

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

the class TeleportPositionCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    Player pl = this.getUserFromArgs(Player.class, src, key, args);
    WorldProperties wp = args.<WorldProperties>getOne(location).orElse(pl.getWorld().getProperties());
    World world = Sponge.getServer().loadWorld(wp.getUniqueId()).get();
    int xx = args.<Integer>getOne(x).get();
    int zz = args.<Integer>getOne(z).get();
    int yy = args.<Integer>getOne(y).get();
    if (yy < 0) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tppos.ysmall"));
        return CommandResult.empty();
    }
    // Chunks are 16 in size, chunk 0 is from 0 - 15, -1 from -1 to -16.
    if (args.hasAny("c")) {
        xx = xx * 16 + 8;
        yy = yy * 16 + 8;
        zz = zz * 16 + 8;
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tppos.fromchunk", String.valueOf(xx), String.valueOf(yy), String.valueOf(zz)));
    }
    Vector3i max = world.getBlockMax();
    Vector3i min = world.getBlockMin();
    if (!(isBetween(xx, max.getX(), min.getX()) && isBetween(yy, max.getY(), min.getY()) && isBetween(zz, max.getZ(), min.getZ()))) {
        throw ReturnMessageException.fromKey("command.tppos.invalid");
    }
    // Create the location
    Location<World> loc = new Location<>(world, xx, yy, zz);
    if (!args.hasAny("b") && !Util.isLocationInWorldBorder(loc)) {
        throw ReturnMessageException.fromKey("command.tppos.worldborder");
    }
    NucleusTeleportHandler teleportHandler = Nucleus.getNucleus().getTeleportHandler();
    Cause cause = CauseStackHelper.createCause(src);
    // Don't bother with the safety if the flag is set.
    if (args.<Boolean>getOne("f").orElse(false)) {
        if (teleportHandler.teleportPlayer(pl, loc, NucleusTeleportHandler.StandardTeleportMode.NO_CHECK, cause).isSuccess()) {
            pl.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tppos.success.self"));
            if (!src.equals(pl)) {
                src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tppos.success.other", pl.getName()));
            }
            return CommandResult.success();
        }
        throw ReturnMessageException.fromKey("command.tppos.cancelledevent");
    }
    // If we have a chunk, scan the whole chunk.
    NucleusTeleportHandler.StandardTeleportMode mode = teleportHandler.getTeleportModeForPlayer(pl);
    if (args.hasAny("c") && mode == NucleusTeleportHandler.StandardTeleportMode.FLYING_THEN_SAFE) {
        mode = NucleusTeleportHandler.StandardTeleportMode.FLYING_THEN_SAFE_CHUNK;
    }
    NucleusTeleportHandler.TeleportResult result = teleportHandler.teleportPlayer(pl, loc, mode, cause, true);
    if (result.isSuccess()) {
        pl.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tppos.success.self"));
        if (!src.equals(pl)) {
            src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tppos.success.other", pl.getName()));
        }
        return CommandResult.success();
    } else if (result == NucleusTeleportHandler.TeleportResult.FAILED_NO_LOCATION) {
        throw ReturnMessageException.fromKey("command.tppos.nosafe");
    }
    throw ReturnMessageException.fromKey("command.tppos.cancelledevent");
}
Also used : NucleusTeleportHandler(io.github.nucleuspowered.nucleus.internal.teleport.NucleusTeleportHandler) Player(org.spongepowered.api.entity.living.player.Player) Cause(org.spongepowered.api.event.cause.Cause) Vector3i(com.flowpowered.math.vector.Vector3i) World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Location(org.spongepowered.api.world.Location)

Example 93 with WorldProperties

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

the class SpawnCommand method executeCommand.

@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
    boolean force = args.hasAny("f");
    GlobalSpawnConfig gsc = sc.getGlobalSpawn();
    WorldProperties wp = args.<WorldProperties>getOne(key).orElseGet(() -> gsc.isOnSpawnCommand() ? gsc.getWorld().orElse(src.getWorld().getProperties()) : src.getWorld().getProperties());
    Optional<World> ow = Sponge.getServer().loadWorld(wp.getUniqueId());
    if (!ow.isPresent()) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawn.noworld"));
    } else if (sc.isPerWorldPerms() && !permissions.testSuffix(src, "worlds." + ow.get().getName().toLowerCase())) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawn.nopermsworld", ow.get().getName()));
    }
    Transform<World> worldTransform = SpawnHelper.getSpawn(wp, plugin, src);
    SendToSpawnEvent event = new SendToSpawnEvent(worldTransform, src, CauseStackHelper.createCause(src));
    if (Sponge.getEventManager().post(event)) {
        if (event.getCancelReason().isPresent()) {
            throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnother.self.failed.reason", event.getCancelReason().get()));
        }
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnother.self.failed.noreason"));
    }
    // If we don't have a rotation, then use the current rotation
    NucleusTeleportHandler.TeleportResult result = this.plugin.getTeleportHandler().teleportPlayer(src, SpawnHelper.getSpawn(ow.get().getProperties(), this.plugin, src), !force && this.sc.isSafeTeleport());
    if (result.isSuccess()) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.spawn.success", wp.getWorldName()));
        return CommandResult.success();
    }
    if (result == NucleusTeleportHandler.TeleportResult.FAILED_NO_LOCATION) {
        throw ReturnMessageException.fromKey("command.spawn.fail", wp.getWorldName());
    }
    throw ReturnMessageException.fromKey("command.spawn.cancelled", wp.getWorldName());
}
Also used : GlobalSpawnConfig(io.github.nucleuspowered.nucleus.modules.spawn.config.GlobalSpawnConfig) NucleusTeleportHandler(io.github.nucleuspowered.nucleus.internal.teleport.NucleusTeleportHandler) SendToSpawnEvent(io.github.nucleuspowered.nucleus.modules.spawn.events.SendToSpawnEvent) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 94 with WorldProperties

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

the class SpawnOtherCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    User target = args.<User>getOne(otherKey).get();
    WorldProperties world = this.getWorldProperties(src, worldKey, args).orElseGet(() -> gsc.isOnSpawnCommand() ? gsc.getWorld().get() : Sponge.getServer().getDefaultWorld().get());
    Transform<World> worldTransform = SpawnHelper.getSpawn(world, plugin, target.getPlayer().orElse(null));
    SendToSpawnEvent event = new SendToSpawnEvent(worldTransform, target, CauseStackHelper.createCause(src));
    if (Sponge.getEventManager().post(event)) {
        if (event.getCancelReason().isPresent()) {
            throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnother.other.failed.reason", target.getName(), event.getCancelReason().get()));
        }
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnother.other.failed.noreason", target.getName()));
    }
    if (!target.isOnline()) {
        return isOffline(src, target, worldTransform);
    }
    // If we don't have a rotation, then use the current rotation
    Player player = target.getPlayer().get();
    NucleusTeleportHandler.TeleportResult result = plugin.getTeleportHandler().teleportPlayer(player, worldTransform, this.safeTeleport);
    if (result.isSuccess()) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnother.success.source", target.getName(), world.getWorldName()));
        player.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnother.success.target", world.getWorldName()));
        return CommandResult.success();
    }
    throw ReturnMessageException.fromKey("command.spawnother.fail", target.getName(), world.getWorldName());
}
Also used : NucleusTeleportHandler(io.github.nucleuspowered.nucleus.internal.teleport.NucleusTeleportHandler) Player(org.spongepowered.api.entity.living.player.Player) User(org.spongepowered.api.entity.living.player.User) SendToSpawnEvent(io.github.nucleuspowered.nucleus.modules.spawn.events.SendToSpawnEvent) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 95 with WorldProperties

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

the class RandomTeleportCommand method executeWithPlayer.

@Override
protected CommandResult executeWithPlayer(CommandSource src, Player player, CommandContext args, boolean self) throws Exception {
    // Get the current world.
    final WorldProperties wp;
    if (this.rc.getDefaultWorld().isPresent()) {
        wp = args.<WorldProperties>getOne(worldKey).orElseGet(() -> this.rc.getDefaultWorld().get());
    } else {
        wp = this.getWorldFromUserOrArgs(src, worldKey, args);
    }
    if (rc.isPerWorldPermissions()) {
        String name = wp.getWorldName();
        permissions.checkSuffix(src, "worlds." + name.toLowerCase(), () -> ReturnMessageException.fromKey("command.rtp.worldnoperm", name));
    }
    World currentWorld = Sponge.getServer().loadWorld(wp.getUniqueId()).orElse(null);
    if (currentWorld == null) {
        currentWorld = Sponge.getServer().loadWorld(wp).orElseThrow(() -> ReturnMessageException.fromKey("command.rtp.worldnoload", wp.getWorldName()));
    }
    // World border
    WorldBorder wb = currentWorld.getWorldBorder();
    int diameter = Math.min(Math.abs(rc.getRadius(currentWorld.getName()) * 2), (int) wb.getDiameter());
    int minDiameter = Math.max(Math.abs(rc.getMinRadius(currentWorld.getName()) * 2), 0);
    Vector3d centre = wb.getCenter();
    src.sendMessage(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("command.rtp.searching"));
    if (self) {
        Sponge.getScheduler().createTaskBuilder().execute(new RTPTask(plugin, centre, minDiameter, diameter, getCost(src, args), player, currentWorld, rc)).submit(plugin);
    } else {
        Sponge.getScheduler().createTaskBuilder().execute(new RTPTask(plugin, centre, minDiameter, diameter, getCost(src, args), player, currentWorld, src, rc)).submit(plugin);
    }
    return CommandResult.success();
}
Also used : Vector3d(com.flowpowered.math.vector.Vector3d) WorldBorder(org.spongepowered.api.world.WorldBorder) World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

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