Search in sources :

Example 1 with JailData

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

the class CheckJailCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    User user = args.<User>getOne(playerKey).get();
    Optional<JailData> jail = handler.getPlayerJailDataInternal(user);
    MessageProvider mp = this.plugin.getMessageProvider();
    if (!jail.isPresent()) {
        throw ReturnMessageException.fromKey("command.checkjail.nojail", user.getName());
    }
    JailData md = jail.get();
    String name;
    if (md.getJailerInternal().equals(Util.consoleFakeUUID)) {
        name = Sponge.getServer().getConsole().getName();
    } else {
        name = Sponge.getServiceManager().provideUnchecked(UserStorageService.class).get(md.getJailerInternal()).map(User::getName).orElseGet(() -> mp.getMessageWithFormat("standard.unknown"));
    }
    if (md.getRemainingTime().isPresent()) {
        src.sendMessage(mp.getTextMessageWithFormat("command.checkjail.jailedfor", user.getName(), md.getJailName(), name, Util.getTimeStringFromSeconds(md.getRemainingTime().get().getSeconds())));
    } else {
        src.sendMessage(mp.getTextMessageWithFormat("command.checkjail.jailedperm", user.getName(), md.getJailName(), name));
    }
    if (md.getCreationTime() > 0) {
        src.sendMessage(mp.getTextMessageWithFormat("command.checkjail.created", Util.FULL_TIME_FORMATTER.withLocale(src.getLocale()).format(Instant.ofEpochSecond(md.getCreationTime()))));
    } else {
        src.sendMessage(mp.getTextMessageWithFormat("command.checkjail.created", mp.getMessageWithFormat("standard.unknown")));
    }
    src.sendMessage(mp.getTextMessageWithFormat("standard.reasoncoloured", md.getReason()));
    return CommandResult.success();
}
Also used : User(org.spongepowered.api.entity.living.player.User) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) JailData(io.github.nucleuspowered.nucleus.modules.jail.data.JailData)

Example 2 with JailData

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

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

the class JailHandler method jailPlayer.

@Override
public boolean jailPlayer(User victim, String jail, CommandSource jailer, String reason) throws NoSuchLocationException {
    Preconditions.checkNotNull(victim);
    Preconditions.checkNotNull(jail);
    Preconditions.checkNotNull(jailer);
    Preconditions.checkNotNull(reason);
    NamedLocation location = getJail(jail).orElseThrow(NoSuchLocationException::new);
    return jailPlayer(victim, new JailData(Util.getUUID(jailer), location.getName(), reason, victim.getPlayer().map(Locatable::getLocation).orElse(null)));
}
Also used : NamedLocation(io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation) JailData(io.github.nucleuspowered.nucleus.modules.jail.data.JailData) NoSuchLocationException(io.github.nucleuspowered.nucleus.api.exceptions.NoSuchLocationException)

Example 4 with JailData

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

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

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