Search in sources :

Example 1 with JailUserDataModule

use of io.github.nucleuspowered.nucleus.modules.jail.datamodules.JailUserDataModule in project Nucleus by NucleusPowered.

the class JailHandler method unjailPlayer.

public boolean unjailPlayer(User user, Cause cause) {
    final ModularUserService modularUserService = plugin.getUserDataManager().getUnchecked(user);
    final JailUserDataModule jailUserDataModule = modularUserService.get(JailUserDataModule.class);
    Optional<JailData> ojd = jailUserDataModule.getJailData();
    if (!ojd.isPresent()) {
        return false;
    }
    Optional<Location<World>> ow = ojd.get().getPreviousLocation();
    jailDataCache.put(user.getUniqueId(), null);
    if (user.isOnline()) {
        Player player = user.getPlayer().get();
        Sponge.getScheduler().createSyncExecutor(plugin).execute(() -> {
            NucleusTeleportHandler.setLocation(player, ow.orElseGet(() -> player.getWorld().getSpawnLocation()));
            player.sendMessage(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("jail.elapsed"));
            // Remove after the teleport for the back data.
            jailUserDataModule.removeJailData();
        });
    } else {
        modularUserService.get(CoreUserDataModule.class).sendToLocationOnLogin(ow.orElseGet(() -> new Location<>(Sponge.getServer().getWorld(Sponge.getServer().getDefaultWorld().get().getUniqueId()).get(), Sponge.getServer().getDefaultWorld().get().getSpawnPosition())));
        jailUserDataModule.removeJailData();
    }
    Sponge.getEventManager().post(new JailEvent.Unjailed(user, cause));
    return true;
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) JailData(io.github.nucleuspowered.nucleus.modules.jail.data.JailData) 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) CoreUserDataModule(io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule) Location(org.spongepowered.api.world.Location) NamedLocation(io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation)

Example 2 with JailUserDataModule

use of io.github.nucleuspowered.nucleus.modules.jail.datamodules.JailUserDataModule in project Nucleus by NucleusPowered.

the class JailListener method onPlayerLogin.

@Listener
public void onPlayerLogin(final NucleusOnLoginEvent event, @Getter("getTargetUser") User user, @Getter("getUserService") ModularUserService qs) {
    JailUserDataModule userDataModule = qs.get(JailUserDataModule.class);
    // Jailing the subject if we need to.
    if (userDataModule.jailOnNextLogin() && userDataModule.getJailData().isPresent()) {
        Optional<NamedLocation> owl = handler.getWarpLocation(user);
        if (!owl.isPresent()) {
            new PermissionMessageChannel(notify).send(Text.of(TextColors.RED, "WARNING: No jail is defined. Jailed players are going free!"));
            handler.unjailPlayer(user);
            return;
        }
        JailData jd = userDataModule.getJailData().get();
        jd.setPreviousLocation(event.getFrom().getLocation());
        userDataModule.setJailData(jd);
        event.setTo(owl.get().getTransform().get());
    }
}
Also used : PermissionMessageChannel(io.github.nucleuspowered.nucleus.util.PermissionMessageChannel) NamedLocation(io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation) JailData(io.github.nucleuspowered.nucleus.modules.jail.data.JailData) JailUserDataModule(io.github.nucleuspowered.nucleus.modules.jail.datamodules.JailUserDataModule) Listener(org.spongepowered.api.event.Listener)

Example 3 with JailUserDataModule

use of io.github.nucleuspowered.nucleus.modules.jail.datamodules.JailUserDataModule in project Nucleus by NucleusPowered.

the class JailListener method onPlayerJoin.

/**
 * At the time the subject joins, check to see if the subject is muted.
 *
 * @param event The event.
 */
@Listener(order = Order.LATE)
public void onPlayerJoin(final ClientConnectionEvent.Join event) {
    final Player user = event.getTargetEntity();
    Optional<ModularUserService> oqs = Nucleus.getNucleus().getUserDataManager().get(user);
    if (!oqs.isPresent()) {
        return;
    }
    JailUserDataModule qs = oqs.get().get(JailUserDataModule.class);
    // Jailing the subject if we need to.
    Optional<JailData> data = handler.getPlayerJailDataInternal(user);
    if (qs.jailOnNextLogin() && data.isPresent()) {
        // It exists.
        NamedLocation owl = handler.getWarpLocation(user).get();
        JailData jd = data.get();
        Optional<Duration> timeLeft = jd.getRemainingTime();
        Text message;
        message = timeLeft.map(duration -> plugin.getMessageProvider().getTextMessageWithFormat("command.jail.jailed", owl.getName(), plugin.getNameUtil().getNameFromUUID(jd.getJailerInternal()), plugin.getMessageProvider().getMessageWithFormat("standard.for"), Util.getTimeStringFromSeconds(duration.getSeconds()))).orElseGet(() -> plugin.getMessageProvider().getTextMessageWithFormat("command.jail.jailed", owl.getName(), plugin.getNameUtil().getNameFromUUID(jd.getJailerInternal()), "", ""));
        oqs.get().get(FlyUserDataModule.class).setFlying(false);
        user.sendMessage(message);
        user.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("standard.reasoncoloured", jd.getReason()));
    }
    qs.setJailOnNextLogin(false);
    // Kick off a scheduled task.
    Sponge.getScheduler().createTaskBuilder().async().delay(500, TimeUnit.MILLISECONDS).execute(() -> {
        Optional<JailData> omd = qs.getJailData();
        if (omd.isPresent()) {
            JailData md = omd.get();
            md.nextLoginToTimestamp();
            omd = Util.testForEndTimestamp(qs.getJailData(), () -> handler.unjailPlayer(user));
            if (omd.isPresent()) {
                md = omd.get();
                handler.onJail(md, event.getTargetEntity());
            }
        }
    }).submit(plugin);
}
Also used : FlyUserDataModule(io.github.nucleuspowered.nucleus.modules.fly.datamodules.FlyUserDataModule) Player(org.spongepowered.api.entity.living.player.Player) NamedLocation(io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation) Optional(java.util.Optional) JailData(io.github.nucleuspowered.nucleus.modules.jail.data.JailData) Duration(java.time.Duration) Text(org.spongepowered.api.text.Text) ModularUserService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService) JailUserDataModule(io.github.nucleuspowered.nucleus.modules.jail.datamodules.JailUserDataModule) Listener(org.spongepowered.api.event.Listener)

Example 4 with JailUserDataModule

use of io.github.nucleuspowered.nucleus.modules.jail.datamodules.JailUserDataModule 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)4 JailData (io.github.nucleuspowered.nucleus.modules.jail.data.JailData)4 JailUserDataModule (io.github.nucleuspowered.nucleus.modules.jail.datamodules.JailUserDataModule)4 ModularUserService (io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService)3 Player (org.spongepowered.api.entity.living.player.Player)3 CoreUserDataModule (io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule)2 FlyUserDataModule (io.github.nucleuspowered.nucleus.modules.fly.datamodules.FlyUserDataModule)2 JailEvent (io.github.nucleuspowered.nucleus.modules.jail.events.JailEvent)2 Optional (java.util.Optional)2 Listener (org.spongepowered.api.event.Listener)2 Location (org.spongepowered.api.world.Location)2 Vector3d (com.flowpowered.math.vector.Vector3d)1 Preconditions (com.google.common.base.Preconditions)1 Maps (com.google.common.collect.Maps)1 Nucleus (io.github.nucleuspowered.nucleus.Nucleus)1 NucleusPlugin (io.github.nucleuspowered.nucleus.NucleusPlugin)1 Util (io.github.nucleuspowered.nucleus.Util)1 NoSuchLocationException (io.github.nucleuspowered.nucleus.api.exceptions.NoSuchLocationException)1 Inmate (io.github.nucleuspowered.nucleus.api.nucleusdata.Inmate)1 NucleusJailService (io.github.nucleuspowered.nucleus.api.service.NucleusJailService)1