Search in sources :

Example 11 with MessageProvider

use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider in project Nucleus by NucleusPowered.

the class KitInfoCommand method executeCommand.

@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    Kit kit = args.<Kit>getOne(KIT_PARAMETER).get();
    MessageProvider mp = this.plugin.getMessageProvider();
    Util.getPaginationBuilder(src).title(mp.getTextMessageWithFormat("command.kit.info.title", kit.getName())).contents(addViewHover(mp, kit), addCommandHover(mp, kit), mp.getTextMessageWithFormat("command.kit.info.sep"), mp.getTextMessageWithFormat("command.kit.info.firstjoin", yesno(mp, kit.isFirstJoinKit())), mp.getTextMessageWithFormat("command.kit.info.cost", String.valueOf(kit.getCost())), mp.getTextMessageWithFormat("command.kit.info.cooldown", kit.getCooldown().map(x -> Util.getTimeStringFromSeconds(x.getSeconds())).orElse(mp.getMessageWithFormat("standard.none"))), mp.getTextMessageWithFormat("command.kit.info.onetime", yesno(mp, kit.isOneTime())), mp.getTextMessageWithFormat("command.kit.info.autoredeem", yesno(mp, kit.isAutoRedeem())), mp.getTextMessageWithFormat("command.kit.info.hidden", yesno(mp, kit.isHiddenFromList())), mp.getTextMessageWithFormat("command.kit.info.displayredeem", yesno(mp, kit.isAutoRedeem())), mp.getTextMessageWithFormat("command.kit.info.ignoresperm", yesno(mp, kit.ignoresPermission()))).sendTo(src);
    return CommandResult.success();
}
Also used : MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) Kit(io.github.nucleuspowered.nucleus.api.nucleusdata.Kit)

Example 12 with MessageProvider

use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider 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 13 with MessageProvider

use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider 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 14 with MessageProvider

use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider in project Nucleus by NucleusPowered.

the class ItemNameSetCommand method executeCommand.

@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
    MessageProvider provider = Nucleus.getNucleus().getMessageProvider();
    if (!src.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
        throw ReturnMessageException.fromKey("command.itemname.set.noitem");
    }
    ItemStack stack = src.getItemInHand(HandTypes.MAIN_HAND).get();
    Text name = TextSerializers.FORMATTING_CODE.deserialize(args.<String>getOne(nameKey).get());
    if (stack.offer(Keys.DISPLAY_NAME, name).isSuccessful()) {
        src.setItemInHand(HandTypes.MAIN_HAND, stack);
        src.sendMessage(provider.getTextMessageWithFormat("command.itemname.set.success"));
        return CommandResult.success();
    }
    throw ReturnMessageException.fromKey("command.itemname.set.fail");
}
Also used : MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) Text(org.spongepowered.api.text.Text) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Example 15 with MessageProvider

use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider in project Nucleus by NucleusPowered.

the class Util method getTimeStringFromSeconds.

public static String getTimeStringFromSeconds(long time) {
    time = Math.abs(time);
    long sec = time % 60;
    long min = (time / 60) % 60;
    long hour = (time / 3600) % 24;
    long day = time / 86400;
    MessageProvider messageProvider = Nucleus.getNucleus().getMessageProvider();
    if (time == 0) {
        return messageProvider.getMessageWithFormat("standard.inamoment");
    }
    StringBuilder sb = new StringBuilder();
    if (day > 0) {
        sb.append(day).append(" ");
        if (day > 1) {
            sb.append(messageProvider.getMessageWithFormat("standard.days"));
        } else {
            sb.append(messageProvider.getMessageWithFormat("standard.day"));
        }
    }
    if (hour > 0) {
        appendComma(sb);
        sb.append(hour).append(" ");
        if (hour > 1) {
            sb.append(messageProvider.getMessageWithFormat("standard.hours"));
        } else {
            sb.append(messageProvider.getMessageWithFormat("standard.hour"));
        }
    }
    if (min > 0) {
        appendComma(sb);
        sb.append(min).append(" ");
        if (min > 1) {
            sb.append(messageProvider.getMessageWithFormat("standard.minutes"));
        } else {
            sb.append(messageProvider.getMessageWithFormat("standard.minute"));
        }
    }
    if (sec > 0) {
        appendComma(sb);
        sb.append(sec).append(" ");
        if (sec > 1) {
            sb.append(Nucleus.getNucleus().getMessageProvider().getMessageWithFormat("standard.seconds"));
        } else {
            sb.append(Nucleus.getNucleus().getMessageProvider().getMessageWithFormat("standard.second"));
        }
    }
    if (sb.length() > 0) {
        return sb.toString();
    } else {
        return messageProvider.getMessageWithFormat("standard.unknown");
    }
}
Also used : MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider)

Aggregations

MessageProvider (io.github.nucleuspowered.nucleus.internal.messages.MessageProvider)33 Text (org.spongepowered.api.text.Text)18 Nucleus (io.github.nucleuspowered.nucleus.Nucleus)10 List (java.util.List)10 Util (io.github.nucleuspowered.nucleus.Util)8 Collectors (java.util.stream.Collectors)8 CommandSource (org.spongepowered.api.command.CommandSource)8 AbstractCommand (io.github.nucleuspowered.nucleus.internal.command.AbstractCommand)7 Nullable (javax.annotation.Nullable)7 CommandResult (org.spongepowered.api.command.CommandResult)7 CommandContext (org.spongepowered.api.command.args.CommandContext)7 NonnullByDefault (org.spongepowered.api.util.annotation.NonnullByDefault)7 Permissions (io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions)6 RegisterCommand (io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand)6 Optional (java.util.Optional)6 Sponge (org.spongepowered.api.Sponge)6 User (org.spongepowered.api.entity.living.player.User)6 TextActions (org.spongepowered.api.text.action.TextActions)6 RunAsync (io.github.nucleuspowered.nucleus.internal.annotations.RunAsync)5 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)5