Search in sources :

Example 26 with MessageProvider

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

the class CheckMutedCommand method executeCommand.

@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    // Using the cache, tell us who is jailed.
    MessageProvider provider = plugin.getMessageProvider();
    List<UUID> usersInMute = plugin.getUserCacheService().getMuted();
    if (usersInMute.isEmpty()) {
        src.sendMessage(provider.getTextMessageWithFormat("command.checkmuted.none"));
        return CommandResult.success();
    }
    // Get the users in this jail, or all jails
    Util.getPaginationBuilder(src).title(provider.getTextMessageWithFormat("command.checkmuted.header")).contents(usersInMute.stream().map(x -> {
        Text name = plugin.getNameUtil().getName(x).orElseGet(() -> Text.of("unknown: ", x.toString()));
        return name.toBuilder().onHover(TextActions.showText(provider.getTextMessageWithFormat("command.checkmuted.hover"))).onClick(TextActions.runCommand("/nucleus:checkmute " + 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) RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) CommandSource(org.spongepowered.api.command.CommandSource) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) UUID(java.util.UUID) 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) Util(io.github.nucleuspowered.nucleus.Util) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) Text(org.spongepowered.api.text.Text) UUID(java.util.UUID)

Example 27 with MessageProvider

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

the class MessagesUpdateCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    // First, reload the messages.
    boolean reload = this.plugin.reloadMessages();
    if (!reload) {
        // There was a failure loading a custom file
        throw ReturnMessageException.fromKey("command.nucleus.messageupdate.couldnotload");
    }
    MessageProvider messageProvider = plugin.getMessageProvider();
    if (!(messageProvider instanceof ConfigMessageProvider)) {
        throw new ReturnMessageException(messageProvider.getTextMessageWithFormat("command.nucleus.messageupdate.notfile"));
    }
    ConfigMessageProvider cmp = (ConfigMessageProvider) messageProvider;
    List<String> keys = cmp.checkForMigration();
    src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.messageupdate.reloaded"));
    if (keys.isEmpty()) {
        return CommandResult.success();
    }
    if (args.hasAny("y")) {
        cmp.reset(keys);
        src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.messageupdate.reset"));
    } else {
        src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.messageupdate.sometoupdate", String.valueOf(keys.size())));
        keys.forEach(x -> src.sendMessage(Text.of(TextColors.YELLOW, x)));
        src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.messageupdate.confirm", "/nucleus update-messages -y").toBuilder().onClick(TextActions.runCommand("/nucleus update-messages -y")).build());
    }
    return CommandResult.success();
}
Also used : MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) ConfigMessageProvider(io.github.nucleuspowered.nucleus.internal.messages.ConfigMessageProvider) ConfigMessageProvider(io.github.nucleuspowered.nucleus.internal.messages.ConfigMessageProvider) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)

Example 28 with MessageProvider

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

the class ChatListener method createReplacements.

private static Map<String, Tuple<String[], Function<String, String>>> createReplacements() {
    Map<String, Tuple<String[], Function<String, String>>> t = new HashMap<>();
    MessageProvider mp = Nucleus.getNucleus().getMessageProvider();
    BiFunction<String, String, String> fss = (key, s) -> s.replaceAll("[&]+[" + key.toLowerCase() + key.toUpperCase() + "]", "");
    NameUtil.getColours().forEach((key, value) -> {
        t.put("&" + key, Tuple.of(new String[] { prefix + "colour." + value.getName(), prefix + "color." + value.getName() }, s -> fss.apply(key.toString(), s)));
        permissionToDesc.put(prefix + "colour." + value.getName(), mp.getMessageWithFormat("permission.chat.colourspec", value.getName().toLowerCase(), key.toString()));
        permissionToDesc.put(prefix + "color." + value.getName(), mp.getMessageWithFormat("permission.chat.colorspec", value.getName().toLowerCase(), key.toString()));
    });
    NameUtil.getStyleKeys().entrySet().stream().filter(x -> x.getKey() != 'k').forEach((k) -> {
        t.put("&" + k.getKey(), Tuple.of(new String[] { prefix + "style." + k.getValue().toLowerCase() }, s -> fss.apply(k.getKey().toString(), s)));
        permissionToDesc.put(prefix + "style." + k.getValue().toLowerCase(), mp.getMessageWithFormat("permission.chat.stylespec", k.getValue().toLowerCase(), k.getKey().toString()));
    });
    t.put("&k", Tuple.of(new String[] { prefix + "magic" }, s -> s.replaceAll("[&]+[kK]", "")));
    return t;
}
Also used : Arrays(java.util.Arrays) NameUtil(io.github.nucleuspowered.nucleus.NameUtil) BiFunction(java.util.function.BiFunction) PermissionInformation(io.github.nucleuspowered.nucleus.internal.permissions.PermissionInformation) TextParsingUtils(io.github.nucleuspowered.nucleus.internal.text.TextParsingUtils) HashMap(java.util.HashMap) ChatConfigAdapter(io.github.nucleuspowered.nucleus.modules.chat.config.ChatConfigAdapter) Function(java.util.function.Function) PermissionRegistry(io.github.nucleuspowered.nucleus.internal.PermissionRegistry) ChatTemplateConfig(io.github.nucleuspowered.nucleus.modules.chat.config.ChatTemplateConfig) TemplateUtil(io.github.nucleuspowered.nucleus.modules.chat.util.TemplateUtil) Text(org.spongepowered.api.text.Text) NucleusNoFormatChannel(io.github.nucleuspowered.nucleus.api.chat.NucleusNoFormatChannel) Order(org.spongepowered.api.event.Order) Map(java.util.Map) SuggestedLevel(io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel) ListenerBase(io.github.nucleuspowered.nucleus.internal.ListenerBase) Util(io.github.nucleuspowered.nucleus.Util) NucleusMessageTokenService(io.github.nucleuspowered.nucleus.api.service.NucleusMessageTokenService) Subject(org.spongepowered.api.service.permission.Subject) ChatModule(io.github.nucleuspowered.nucleus.modules.chat.ChatModule) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) EventContexts(io.github.nucleuspowered.nucleus.api.EventContexts) Tuple(org.spongepowered.api.util.Tuple) Maps(com.google.common.collect.Maps) Reloadable(io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable) TextSerializers(org.spongepowered.api.text.serializer.TextSerializers) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) MessageChannelEvent(org.spongepowered.api.event.message.MessageChannelEvent) ChatConfig(io.github.nucleuspowered.nucleus.modules.chat.config.ChatConfig) Player(org.spongepowered.api.entity.living.player.Player) MessageEvent(org.spongepowered.api.event.message.MessageEvent) Pattern(java.util.regex.Pattern) Listener(org.spongepowered.api.event.Listener) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) HashMap(java.util.HashMap) Tuple(org.spongepowered.api.util.Tuple)

Example 29 with MessageProvider

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

the class JailHandler method onJail.

public void onJail(JailData md, Player user) {
    MessageProvider provider = Nucleus.getNucleus().getMessageProvider();
    if (md.getEndTimestamp().isPresent()) {
        user.sendMessage(provider.getTextMessageWithFormat("jail.playernotify.time", Util.getTimeStringFromSeconds(Instant.now().until(md.getEndTimestamp().get(), ChronoUnit.SECONDS))));
    } else {
        user.sendMessage(provider.getTextMessageWithFormat("jail.playernotify.standard"));
    }
    user.sendMessage(provider.getTextMessageWithFormat("standard.reasoncoloured", md.getReason()));
}
Also used : MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider)

Example 30 with MessageProvider

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

the class ListPowertoolCommand method from.

private Text from(final PowertoolUserDataModule inu, Player src, String powertool, List<String> commands) {
    Optional<ItemType> oit = Sponge.getRegistry().getType(ItemType.class, powertool);
    MessageProvider mp = plugin.getMessageProvider();
    // Create the click actions.
    ClickAction viewAction = TextActions.executeCallback(pl -> Util.getPaginationBuilder(src).title(mp.getTextMessageWithFormat("command.powertool.ind.header", powertool)).padding(Text.of(TextColors.GREEN, "-")).contents(commands.stream().map(x -> Text.of(TextColors.YELLOW, x)).collect(Collectors.toList())).sendTo(src));
    ClickAction deleteAction = TextActions.executeCallback(pl -> {
        inu.clearPowertool(powertool);
        pl.sendMessage(mp.getTextMessageWithFormat("command.powertool.removed", powertool));
    });
    TextColor tc = oit.map(itemType -> TextColors.YELLOW).orElse(TextColors.GRAY);
    // id - [View] - [Delete]
    return Text.builder().append(Text.of(tc, powertool)).append(Text.of(" - ")).append(Text.builder(mp.getMessageWithFormat("standard.view")).color(TextColors.YELLOW).onClick(viewAction).build()).append(Text.of(" - ")).append(Text.builder(mp.getMessageWithFormat("standard.delete")).color(TextColors.DARK_RED).onClick(deleteAction).build()).build();
}
Also used : NoModifiers(io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers) CommandResult(org.spongepowered.api.command.CommandResult) ClickAction(org.spongepowered.api.text.action.ClickAction) TextActions(org.spongepowered.api.text.action.TextActions) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) Sponge(org.spongepowered.api.Sponge) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) PowertoolUserDataModule(io.github.nucleuspowered.nucleus.modules.powertool.datamodules.PowertoolUserDataModule) 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) TextColor(org.spongepowered.api.text.format.TextColor) Map(java.util.Map) Optional(java.util.Optional) Util(io.github.nucleuspowered.nucleus.Util) Player(org.spongepowered.api.entity.living.player.Player) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) ItemType(org.spongepowered.api.item.ItemType) TextColors(org.spongepowered.api.text.format.TextColors) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) ClickAction(org.spongepowered.api.text.action.ClickAction) ItemType(org.spongepowered.api.item.ItemType) TextColor(org.spongepowered.api.text.format.TextColor)

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