Search in sources :

Example 1 with NamedLocation

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

the class CheckJailedCommand method executeCommand.

@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    // Using the cache, tell us who is jailed.
    MessageProvider provider = plugin.getMessageProvider();
    Optional<NamedLocation> jail = args.getOne(jailNameKey);
    List<UUID> usersInJail = jail.map(x -> plugin.getUserCacheService().getJailedIn(x.getName())).orElseGet(() -> plugin.getUserCacheService().getJailed());
    String jailName = jail.map(NamedLocation::getName).orElseGet(() -> provider.getMessageWithFormat("standard.alljails"));
    if (usersInJail.isEmpty()) {
        src.sendMessage(provider.getTextMessageWithFormat("command.checkjailed.none", jailName));
        return CommandResult.success();
    }
    // Get the users in this jail, or all jails
    Util.getPaginationBuilder(src).title(provider.getTextMessageWithFormat("command.checkjailed.header", jailName)).contents(usersInJail.stream().map(x -> {
        Text name = plugin.getNameUtil().getName(x).orElseGet(() -> Text.of("unknown: ", x.toString()));
        return name.toBuilder().onHover(TextActions.showText(provider.getTextMessageWithFormat("command.checkjailed.hover"))).onClick(TextActions.runCommand("/nucleus:checkjail " + x.toString())).build();
    }).collect(Collectors.toList())).sendTo(src);
    return CommandResult.success();
}
Also used : NoModifiers(io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers) CommandResult(org.spongepowered.api.command.CommandResult) TextActions(org.spongepowered.api.text.action.TextActions) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) CommandSource(org.spongepowered.api.command.CommandSource) NamedLocation(io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) UUID(java.util.UUID) CommandElement(org.spongepowered.api.command.args.CommandElement) GenericArguments(org.spongepowered.api.command.args.GenericArguments) Collectors(java.util.stream.Collectors) RunAsync(io.github.nucleuspowered.nucleus.internal.annotations.RunAsync) List(java.util.List) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) JailArgument(io.github.nucleuspowered.nucleus.argumentparsers.JailArgument) Optional(java.util.Optional) Util(io.github.nucleuspowered.nucleus.Util) JailHandler(io.github.nucleuspowered.nucleus.modules.jail.handlers.JailHandler) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) NamedLocation(io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation) Text(org.spongepowered.api.text.Text) UUID(java.util.UUID)

Example 2 with NamedLocation

use of io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation 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 3 with NamedLocation

use of io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation 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 4 with NamedLocation

use of io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation 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 5 with NamedLocation

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

the class ListHomeCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    // args.getOne(subject);
    User user = this.getUserFromArgs(User.class, src, player, args);
    Text header;
    boolean other = src instanceof User && !((User) src).getUniqueId().equals(user.getUniqueId());
    if (other && user.hasPermission(this.exempt)) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.listhome.exempt"));
    }
    List<Home> msw = homeHandler.getHomes(user);
    if (msw.isEmpty()) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.home.nohomes"));
        return CommandResult.empty();
    }
    if (other) {
        header = plugin.getMessageProvider().getTextMessageWithFormat("home.title.name", user.getName());
    } else {
        header = plugin.getMessageProvider().getTextMessageWithFormat("home.title.normal");
    }
    List<Text> lt = msw.stream().sorted(Comparator.comparing(NamedLocation::getName)).map(x -> {
        Optional<Location<World>> olw = x.getLocation();
        if (!olw.isPresent()) {
            return Text.builder().append(Text.builder(x.getName()).color(TextColors.RED).onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithFormat("home.warphoverinvalid", x.getName()))).build()).build();
        } else {
            final Location<World> lw = olw.get();
            return Text.builder().append(Text.builder(x.getName()).color(TextColors.GREEN).style(TextStyles.UNDERLINE).onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithFormat("home.warphover", x.getName()))).onClick(TextActions.runCommand(other ? "/homeother " + user.getName() + " " + x.getName() : "/home " + x.getName())).build()).append(plugin.getMessageProvider().getTextMessageWithFormat("home.location", lw.getExtent().getName(), String.valueOf(lw.getBlockX()), String.valueOf(lw.getBlockY()), String.valueOf(lw.getBlockZ()))).build();
        }
    }).collect(Collectors.toList());
    PaginationList.Builder pb = Util.getPaginationBuilder(src).title(Text.of(TextColors.YELLOW, header)).padding(Text.of(TextColors.GREEN, "-")).contents(lt);
    pb.sendTo(src);
    return CommandResult.success();
}
Also used : RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) PermissionInformation(io.github.nucleuspowered.nucleus.internal.permissions.PermissionInformation) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) HashMap(java.util.HashMap) GenericArguments(org.spongepowered.api.command.args.GenericArguments) RunAsync(io.github.nucleuspowered.nucleus.internal.annotations.RunAsync) PaginationList(org.spongepowered.api.service.pagination.PaginationList) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) Home(io.github.nucleuspowered.nucleus.api.nucleusdata.Home) SelectorWrapperArgument(io.github.nucleuspowered.nucleus.argumentparsers.SelectorWrapperArgument) Map(java.util.Map) SuggestedLevel(io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel) Util(io.github.nucleuspowered.nucleus.Util) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) TextColors(org.spongepowered.api.text.format.TextColors) NoModifiers(io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers) CommandResult(org.spongepowered.api.command.CommandResult) TextActions(org.spongepowered.api.text.action.TextActions) Location(org.spongepowered.api.world.Location) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) User(org.spongepowered.api.entity.living.player.User) CommandSource(org.spongepowered.api.command.CommandSource) TextStyles(org.spongepowered.api.text.format.TextStyles) NicknameArgument(io.github.nucleuspowered.nucleus.argumentparsers.NicknameArgument) NamedLocation(io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) CommandElement(org.spongepowered.api.command.args.CommandElement) Collectors(java.util.stream.Collectors) HomeHandler(io.github.nucleuspowered.nucleus.modules.home.handlers.HomeHandler) List(java.util.List) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) World(org.spongepowered.api.world.World) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) Comparator(java.util.Comparator) User(org.spongepowered.api.entity.living.player.User) Optional(java.util.Optional) Text(org.spongepowered.api.text.Text) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) World(org.spongepowered.api.world.World) PaginationList(org.spongepowered.api.service.pagination.PaginationList) Home(io.github.nucleuspowered.nucleus.api.nucleusdata.Home) Location(org.spongepowered.api.world.Location) NamedLocation(io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation)

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