Search in sources :

Example 1 with NameUtil

use of io.github.nucleuspowered.nucleus.NameUtil in project Nucleus by NucleusPowered.

the class ChatListener method useMessage.

private Text useMessage(Player player, Text rawMessage, ChatTemplateConfig chatTemplateConfig) {
    String m = stripPermissionless(player, TextSerializers.FORMATTING_CODE.serialize(rawMessage));
    if (chatConfig.isRemoveBlueUnderline()) {
        m = m.replaceAll("&9&n([A-Za-z0-9-.]+)", "$1");
    }
    Text result;
    if (player.hasPermission(prefix + "url")) {
        result = TextParsingUtils.addUrls(m);
    } else {
        result = TextSerializers.FORMATTING_CODE.deserialize(m);
    }
    String chatcol = Util.getOptionFromSubject(player, "chatcolour", "chatcolor").orElseGet(chatTemplateConfig::getChatcolour);
    String chatstyle = Util.getOptionFromSubject(player, "chatstyle").orElseGet(chatTemplateConfig::getChatstyle);
    NameUtil nu = plugin.getNameUtil();
    return Text.of(nu.getColourFromString(chatcol), nu.getTextStyleFromString(chatstyle), result);
}
Also used : Text(org.spongepowered.api.text.Text) NameUtil(io.github.nucleuspowered.nucleus.NameUtil)

Example 2 with NameUtil

use of io.github.nucleuspowered.nucleus.NameUtil in project Nucleus by NucleusPowered.

the class GetFromIpCommand method executeCommand.

@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    String ip = args.<String>getOne(ipKey).get();
    if (Arrays.stream(ip.split("\\.")).anyMatch(x -> Integer.parseInt(x) > 255)) {
        throw ReturnMessageException.fromKey("command.getfromip.notvalid");
    }
    UserStorageService uss = Sponge.getServiceManager().provideUnchecked(UserStorageService.class);
    List<User> users = plugin.getUserCacheService().getForIp(ip).stream().map(uss::get).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
    if (users.isEmpty()) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.getfromip.nousers"));
        return CommandResult.success();
    }
    NameUtil name = plugin.getNameUtil();
    Util.getPaginationBuilder(src).title(plugin.getMessageProvider().getTextMessageWithFormat("command.getfromip.title", ip)).contents(users.stream().map(y -> {
        Text n = name.getName(y);
        return n.toBuilder().onClick(TextActions.runCommand("/nucleus:seen " + y.getName())).onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithTextFormat("command.getfromip.hover", n))).build();
    }).collect(Collectors.toList())).sendTo(src);
    return CommandResult.success();
}
Also used : UserStorageService(org.spongepowered.api.service.user.UserStorageService) CommandResult(org.spongepowered.api.command.CommandResult) TextActions(org.spongepowered.api.text.action.TextActions) Arrays(java.util.Arrays) NameUtil(io.github.nucleuspowered.nucleus.NameUtil) RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) User(org.spongepowered.api.entity.living.player.User) CommandSource(org.spongepowered.api.command.CommandSource) Sponge(org.spongepowered.api.Sponge) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) CommandElement(org.spongepowered.api.command.args.CommandElement) Collectors(java.util.stream.Collectors) UserStorageService(org.spongepowered.api.service.user.UserStorageService) RegexArgument(io.github.nucleuspowered.nucleus.argumentparsers.RegexArgument) List(java.util.List) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) Optional(java.util.Optional) Util(io.github.nucleuspowered.nucleus.Util) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) User(org.spongepowered.api.entity.living.player.User) Optional(java.util.Optional) Text(org.spongepowered.api.text.Text) NameUtil(io.github.nucleuspowered.nucleus.NameUtil)

Aggregations

NameUtil (io.github.nucleuspowered.nucleus.NameUtil)2 Text (org.spongepowered.api.text.Text)2 Util (io.github.nucleuspowered.nucleus.Util)1 RegexArgument (io.github.nucleuspowered.nucleus.argumentparsers.RegexArgument)1 Permissions (io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions)1 RegisterCommand (io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand)1 AbstractCommand (io.github.nucleuspowered.nucleus.internal.command.AbstractCommand)1 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Sponge (org.spongepowered.api.Sponge)1 CommandResult (org.spongepowered.api.command.CommandResult)1 CommandSource (org.spongepowered.api.command.CommandSource)1 CommandContext (org.spongepowered.api.command.args.CommandContext)1 CommandElement (org.spongepowered.api.command.args.CommandElement)1 User (org.spongepowered.api.entity.living.player.User)1 UserStorageService (org.spongepowered.api.service.user.UserStorageService)1 TextActions (org.spongepowered.api.text.action.TextActions)1