Search in sources :

Example 6 with NamedLocation

use of io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation in project Nucleus by NucleusPowered.

the class JailTeleportCommand method executeCommand.

@Override
protected CommandResult executeCommand(Player src, CommandContext args) throws Exception {
    NamedLocation location = args.<NamedLocation>getOne(jailKey).get();
    Transform<World> location1 = location.getTransform().orElseThrow(() -> new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.jails.tp.noworld", location.getName())));
    src.setTransform(location1);
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.jails.tp.success", location.getName()));
    return CommandResult.success();
}
Also used : NamedLocation(io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) World(org.spongepowered.api.world.World)

Example 7 with NamedLocation

use of io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation in project Nucleus by NucleusPowered.

the class JailHandler method jailPlayer.

public boolean jailPlayer(User user, JailData data) {
    ModularUserService modularUserService = plugin.getUserDataManager().getUnchecked(user);
    JailUserDataModule jailUserDataModule = modularUserService.get(JailUserDataModule.class);
    if (jailUserDataModule.getJailData().isPresent()) {
        return false;
    }
    // Get the jail.
    Optional<NamedLocation> owl = getJail(data.getJailName());
    NamedLocation wl = owl.filter(x -> x.getLocation().isPresent()).orElseGet(() -> {
        if (!getJails().isEmpty()) {
            return null;
        }
        return getJails().entrySet().stream().findFirst().get().getValue();
    });
    if (wl == null) {
        return false;
    }
    jailUserDataModule.setJailData(data);
    if (user.isOnline()) {
        Sponge.getScheduler().createSyncExecutor(plugin).execute(() -> {
            Player player = user.getPlayer().get();
            plugin.getTeleportHandler().teleportPlayer(player, owl.get().getLocation().get(), owl.get().getRotation(), NucleusTeleportHandler.StandardTeleportMode.NO_CHECK, Sponge.getCauseStackManager().getCurrentCause());
            modularUserService.get(FlyUserDataModule.class).setFlying(false);
        });
    } else {
        jailUserDataModule.setJailOnNextLogin(true);
    }
    this.jailDataCache.put(user.getUniqueId(), new Context(NucleusJailService.JAIL_CONTEXT, data.getJailName()));
    Sponge.getEventManager().post(new JailEvent.Jailed(user, CauseStackHelper.createCause(Util.getObjectFromUUID(data.getJailerInternal())), data.getJailName(), TextSerializers.FORMATTING_CODE.deserialize(data.getReason()), data.getRemainingTime().orElse(null)));
    return true;
}
Also used : JailGeneralDataModule(io.github.nucleuspowered.nucleus.modules.jail.datamodules.JailGeneralDataModule) CoreUserDataModule(io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule) NucleusPlugin(io.github.nucleuspowered.nucleus.NucleusPlugin) NoSuchLocationException(io.github.nucleuspowered.nucleus.api.exceptions.NoSuchLocationException) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) Vector3d(com.flowpowered.math.vector.Vector3d) Locatable(org.spongepowered.api.world.Locatable) JailData(io.github.nucleuspowered.nucleus.modules.jail.data.JailData) Map(java.util.Map) FlyUserDataModule(io.github.nucleuspowered.nucleus.modules.fly.datamodules.FlyUserDataModule) NucleusJailService(io.github.nucleuspowered.nucleus.api.service.NucleusJailService) NucleusTeleportHandler(io.github.nucleuspowered.nucleus.internal.teleport.NucleusTeleportHandler) Util(io.github.nucleuspowered.nucleus.Util) Subject(org.spongepowered.api.service.permission.Subject) Location(org.spongepowered.api.world.Location) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) JailUserDataModule(io.github.nucleuspowered.nucleus.modules.jail.datamodules.JailUserDataModule) User(org.spongepowered.api.entity.living.player.User) CommandSource(org.spongepowered.api.command.CommandSource) Context(org.spongepowered.api.service.context.Context) Collection(java.util.Collection) CauseStackHelper(io.github.nucleuspowered.nucleus.util.CauseStackHelper) NamedLocation(io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation) Sponge(org.spongepowered.api.Sponge) Set(java.util.Set) ModularUserService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService) UUID(java.util.UUID) Instant(java.time.Instant) Maps(com.google.common.collect.Maps) JailEvent(io.github.nucleuspowered.nucleus.modules.jail.events.JailEvent) TextSerializers(org.spongepowered.api.text.serializer.TextSerializers) Cause(org.spongepowered.api.event.cause.Cause) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) ContextCalculator(org.spongepowered.api.service.context.ContextCalculator) ChronoUnit(java.time.temporal.ChronoUnit) World(org.spongepowered.api.world.World) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Inmate(io.github.nucleuspowered.nucleus.api.nucleusdata.Inmate) Player(org.spongepowered.api.entity.living.player.Player) ModularGeneralService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularGeneralService) FlyUserDataModule(io.github.nucleuspowered.nucleus.modules.fly.datamodules.FlyUserDataModule) Context(org.spongepowered.api.service.context.Context) Player(org.spongepowered.api.entity.living.player.Player) NamedLocation(io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation) JailEvent(io.github.nucleuspowered.nucleus.modules.jail.events.JailEvent) ModularUserService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService) JailUserDataModule(io.github.nucleuspowered.nucleus.modules.jail.datamodules.JailUserDataModule)

Aggregations

NamedLocation (io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation)7 JailData (io.github.nucleuspowered.nucleus.modules.jail.data.JailData)4 Optional (java.util.Optional)4 Nucleus (io.github.nucleuspowered.nucleus.Nucleus)3 Util (io.github.nucleuspowered.nucleus.Util)3 JailUserDataModule (io.github.nucleuspowered.nucleus.modules.jail.datamodules.JailUserDataModule)3 CommandSource (org.spongepowered.api.command.CommandSource)3 Player (org.spongepowered.api.entity.living.player.Player)3 NonnullByDefault (org.spongepowered.api.util.annotation.NonnullByDefault)3 World (org.spongepowered.api.world.World)3 NoSuchLocationException (io.github.nucleuspowered.nucleus.api.exceptions.NoSuchLocationException)2 ModularUserService (io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService)2 RunAsync (io.github.nucleuspowered.nucleus.internal.annotations.RunAsync)2 NoModifiers (io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers)2 Permissions (io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions)2 RegisterCommand (io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand)2 AbstractCommand (io.github.nucleuspowered.nucleus.internal.command.AbstractCommand)2 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)2 MessageProvider (io.github.nucleuspowered.nucleus.internal.messages.MessageProvider)2 FlyUserDataModule (io.github.nucleuspowered.nucleus.modules.fly.datamodules.FlyUserDataModule)2