Search in sources :

Example 6 with JailData

use of io.github.nucleuspowered.nucleus.modules.jail.data.JailData in project Nucleus by NucleusPowered.

the class JailModule method performEnableTasks.

@Override
public void performEnableTasks() {
    createSeenModule(CheckJailCommand.class, (c, u) -> {
        // If we have a ban service, then check for a ban.
        JailHandler jh = Nucleus.getNucleus().getInternalServiceManager().getService(JailHandler.class).get();
        if (jh.isPlayerJailed(u)) {
            JailData jd = jh.getPlayerJailDataInternal(u).get();
            Text.Builder m;
            if (jd.getRemainingTime().isPresent()) {
                m = NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("seen.isjailed.temp", Util.getTimeToNow(jd.getEndTimestamp().get())).toBuilder();
            } else {
                m = NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("seen.isjailed.perm").toBuilder();
            }
            return Lists.newArrayList(m.onClick(TextActions.runCommand("/checkjail " + u.getName())).onHover(TextActions.showText(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("standard.clicktoseemore"))).build(), NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("standard.reason", jd.getReason()));
        }
        return Lists.newArrayList(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("seen.notjailed"));
    });
}
Also used : JailHandler(io.github.nucleuspowered.nucleus.modules.jail.handlers.JailHandler) JailData(io.github.nucleuspowered.nucleus.modules.jail.data.JailData) Text(org.spongepowered.api.text.Text)

Example 7 with JailData

use of io.github.nucleuspowered.nucleus.modules.jail.data.JailData in project Nucleus by NucleusPowered.

the class JailCommand method onJail.

private CommandResult onJail(CommandSource src, CommandContext args, User user) throws ReturnMessageException {
    Optional<LocationData> owl = args.getOne(jailKey);
    if (!owl.isPresent()) {
        throw ReturnMessageException.fromKey("command.jail.jail.nojail");
    }
    // This might not be there.
    Optional<Long> duration = args.getOne(durationKey);
    String reason = args.<String>getOne(reasonKey).orElse(plugin.getMessageProvider().getMessageWithFormat("command.jail.reason"));
    JailData jd;
    Text message;
    Text messageTo;
    if (duration.isPresent()) {
        if (user.isOnline()) {
            jd = new JailData(Util.getUUID(src), owl.get().getName(), reason, user.getPlayer().get().getLocation(), Instant.now().plusSeconds(duration.get()));
        } else {
            jd = new JailData(Util.getUUID(src), owl.get().getName(), reason, null, Duration.of(duration.get(), ChronoUnit.SECONDS));
        }
        message = plugin.getMessageProvider().getTextMessageWithFormat("command.checkjail.jailedfor", user.getName(), jd.getJailName(), src.getName(), Util.getTimeStringFromSeconds(duration.get()));
        messageTo = plugin.getMessageProvider().getTextMessageWithFormat("command.jail.jailedfor", owl.get().getName(), src.getName(), Util.getTimeStringFromSeconds(duration.get()));
    } else {
        jd = new JailData(Util.getUUID(src), owl.get().getName(), reason, user.getPlayer().map(Locatable::getLocation).orElse(null));
        message = plugin.getMessageProvider().getTextMessageWithFormat("command.checkjail.jailedperm", user.getName(), owl.get().getName(), src.getName());
        messageTo = plugin.getMessageProvider().getTextMessageWithFormat("command.jail.jailedperm", owl.get().getName(), src.getName());
    }
    if (handler.jailPlayer(user, jd)) {
        MutableMessageChannel mc = new PermissionMessageChannel(permissions.getPermissionWithSuffix("notify")).asMutable();
        mc.addMember(src);
        mc.send(message);
        mc.send(plugin.getMessageProvider().getTextMessageWithFormat("standard.reasoncoloured", reason));
        user.getPlayer().ifPresent(x -> {
            x.sendMessage(messageTo);
            x.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("standard.reasoncoloured", reason));
        });
        return CommandResult.success();
    }
    throw ReturnMessageException.fromKey("command.jail.error");
}
Also used : PermissionMessageChannel(io.github.nucleuspowered.nucleus.util.PermissionMessageChannel) LocationData(io.github.nucleuspowered.nucleus.internal.LocationData) JailData(io.github.nucleuspowered.nucleus.modules.jail.data.JailData) Text(org.spongepowered.api.text.Text) MutableMessageChannel(org.spongepowered.api.text.channel.MutableMessageChannel)

Example 8 with JailData

use of io.github.nucleuspowered.nucleus.modules.jail.data.JailData 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

JailData (io.github.nucleuspowered.nucleus.modules.jail.data.JailData)8 NamedLocation (io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation)5 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 Text (org.spongepowered.api.text.Text)3 NoSuchLocationException (io.github.nucleuspowered.nucleus.api.exceptions.NoSuchLocationException)2 MessageProvider (io.github.nucleuspowered.nucleus.internal.messages.MessageProvider)2 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 PermissionMessageChannel (io.github.nucleuspowered.nucleus.util.PermissionMessageChannel)2 Optional (java.util.Optional)2 User (org.spongepowered.api.entity.living.player.User)2 Listener (org.spongepowered.api.event.Listener)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