Search in sources :

Example 21 with MessageProvider

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

the class NucleusArgumentParseException method getUsage.

@Nullable
public Text getUsage() {
    Text.Builder builder = Text.builder();
    MessageProvider mp = Nucleus.getNucleus().getMessageProvider();
    if (usage != null) {
        builder.append(Text.NEW_LINE).append(mp.getTextMessageWithTextFormat("command.exception.usage", this.usage));
    }
    if (subcommands != null) {
        builder.append(Text.NEW_LINE).append(mp.getTextMessageWithTextFormat("command.exception.subcommands", this.subcommands));
    }
    return builder.build();
}
Also used : MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) Text(org.spongepowered.api.text.Text) Nullable(javax.annotation.Nullable)

Example 22 with MessageProvider

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

the class NucleusCommandException method print.

private Text print(List<Tuple<String, CommandException>> lce) {
    MessageProvider mp = Nucleus.getNucleus().getMessageProvider();
    Text sept = mp.getTextMessageWithFormat("command.exception.separator");
    Text.Builder builder = mp.getTextMessageWithFormat("command.exception.multiple").toBuilder();
    lce.forEach(x -> builder.append(Text.NEW_LINE).append(sept).append(Text.NEW_LINE).append(mp.getTextMessageWithFormat("command.exception.fromcommand", x.getFirst())).append(Text.NEW_LINE).append(x.getSecond().getText()));
    builder.append(Text.NEW_LINE).append(sept);
    return builder.toText();
}
Also used : MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) Text(org.spongepowered.api.text.Text)

Example 23 with MessageProvider

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

the class CoreListener method onPlayerJoinLast.

@Listener
public void onPlayerJoinLast(final ClientConnectionEvent.Join event, @Getter("getTargetEntity") final Player player) {
    if (Nucleus.getNucleus().getUserDataManager().get(player).map(x -> x.get(CoreUserDataModule.class).isFirstPlay()).orElse(true)) {
        NucleusFirstJoinEvent firstJoinEvent = new OnFirstLoginEvent(event.getCause(), player, event.getOriginalChannel(), event.getChannel().orElse(null), event.getOriginalMessage(), event.isMessageCancelled(), event.getFormatter());
        Sponge.getEventManager().post(firstJoinEvent);
        event.setChannel(firstJoinEvent.getChannel().get());
        event.setMessageCancelled(firstJoinEvent.isMessageCancelled());
        Nucleus.getNucleus().getUserDataManager().getUnchecked(player).get(CoreUserDataModule.class).setStartedFirstJoin(false);
    }
    // Warn about wildcard.
    if (!ServiceChangeListener.isOpOnly() && player.hasPermission("nucleus")) {
        MessageProvider provider = this.plugin.getMessageProvider();
        Nucleus.getNucleus().getLogger().warn("The player " + player.getName() + " has got either the nucleus wildcard or the * wildcard " + "permission. This may cause unintended side effects.");
        if (this.warnOnWildcard) {
            // warn
            List<Text> text = Lists.newArrayList();
            text.add(provider.getTextMessageWithFormat("core.permission.wildcard2"));
            text.add(provider.getTextMessageWithFormat("core.permission.wildcard3"));
            if (this.url != null) {
                text.add(provider.getTextMessageWithFormat("core.permission.wildcard4").toBuilder().onClick(TextActions.openUrl(this.url)).build());
            }
            text.add(provider.getTextMessageWithFormat("core.permission.wildcard5"));
            Sponge.getServiceManager().provideUnchecked(PaginationService.class).builder().title(provider.getTextMessageWithFormat("core.permission.wildcard")).contents(text).padding(Text.of(TextColors.GOLD, "-")).sendTo(player);
        }
    }
}
Also used : Getter(org.spongepowered.api.event.filter.Getter) CoreUserDataModule(io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule) URL(java.net.URL) GameStoppingServerEvent(org.spongepowered.api.event.game.state.GameStoppingServerEvent) CoreConfigAdapter(io.github.nucleuspowered.nucleus.modules.core.config.CoreConfigAdapter) InetAddress(java.net.InetAddress) Lists(com.google.common.collect.Lists) Text(org.spongepowered.api.text.Text) Order(org.spongepowered.api.event.Order) NucleusTextTemplate(io.github.nucleuspowered.nucleus.api.text.NucleusTextTemplate) IsCancelled(org.spongepowered.api.event.filter.IsCancelled) Task(org.spongepowered.api.scheduler.Task) ListenerBase(io.github.nucleuspowered.nucleus.internal.ListenerBase) CoreConfig(io.github.nucleuspowered.nucleus.modules.core.config.CoreConfig) GameProfile(org.spongepowered.api.profile.GameProfile) Util(io.github.nucleuspowered.nucleus.Util) ServiceChangeListener(io.github.nucleuspowered.nucleus.internal.permissions.ServiceChangeListener) NucleusOnLoginEvent(io.github.nucleuspowered.nucleus.modules.core.events.NucleusOnLoginEvent) TextColors(org.spongepowered.api.text.format.TextColors) Nullable(javax.annotation.Nullable) 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) GameReloadEvent(org.spongepowered.api.event.game.GameReloadEvent) Iterator(java.util.Iterator) CommandSource(org.spongepowered.api.command.CommandSource) MalformedURLException(java.net.MalformedURLException) UniqueUserCountTransientModule(io.github.nucleuspowered.nucleus.modules.core.datamodules.UniqueUserCountTransientModule) CauseStackHelper(io.github.nucleuspowered.nucleus.util.CauseStackHelper) Sponge(org.spongepowered.api.Sponge) ModularUserService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService) PaginationService(org.spongepowered.api.service.pagination.PaginationService) Instant(java.time.Instant) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) Tristate(org.spongepowered.api.util.Tristate) Reloadable(io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable) List(java.util.List) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) NucleusFirstJoinEvent(io.github.nucleuspowered.nucleus.api.events.NucleusFirstJoinEvent) World(org.spongepowered.api.world.World) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) OnFirstLoginEvent(io.github.nucleuspowered.nucleus.modules.core.events.OnFirstLoginEvent) Listener(org.spongepowered.api.event.Listener) OnFirstLoginEvent(io.github.nucleuspowered.nucleus.modules.core.events.OnFirstLoginEvent) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) NucleusFirstJoinEvent(io.github.nucleuspowered.nucleus.api.events.NucleusFirstJoinEvent) Text(org.spongepowered.api.text.Text) PaginationService(org.spongepowered.api.service.pagination.PaginationService) CoreUserDataModule(io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule) ServiceChangeListener(io.github.nucleuspowered.nucleus.internal.permissions.ServiceChangeListener) Listener(org.spongepowered.api.event.Listener)

Example 24 with MessageProvider

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

the class NicknameCommand method afterPostInit.

@Override
protected void afterPostInit() {
    super.afterPostInit();
    MessageProvider mp = Nucleus.getNucleus().getMessageProvider();
    String colPerm = permissions.getPermissionWithSuffix("colour.");
    String colPerm2 = permissions.getPermissionWithSuffix("color.");
    NameUtil.getColours().forEach((key, value) -> {
        permissionToDesc.put(colPerm + value.getName(), mp.getMessageWithFormat("permission.nick.colourspec", value.getName().toLowerCase(), key.toString()));
        permissionToDesc.put(colPerm2 + value.getName(), mp.getMessageWithFormat("permission.nick.colorspec", value.getName().toLowerCase(), key.toString()));
    });
    String stylePerm = permissions.getPermissionWithSuffix("style.");
    NameUtil.getStyleKeys().entrySet().stream().filter(x -> x.getKey() != 'k').forEach((k) -> permissionToDesc.put(stylePerm + k.getValue().toLowerCase(), mp.getMessageWithFormat("permission.nick.stylespec", k.getValue().toLowerCase(), k.getKey().toString())));
}
Also used : NameUtil(io.github.nucleuspowered.nucleus.NameUtil) 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) NicknameService(io.github.nucleuspowered.nucleus.modules.nickname.services.NicknameService) NicknameException(io.github.nucleuspowered.nucleus.api.exceptions.NicknameException) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) Map(java.util.Map) SuggestedLevel(io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) TextColors(org.spongepowered.api.text.format.TextColors) CommandResult(org.spongepowered.api.command.CommandResult) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) User(org.spongepowered.api.entity.living.player.User) CommandSource(org.spongepowered.api.command.CommandSource) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) Maps(com.google.common.collect.Maps) CommandElement(org.spongepowered.api.command.args.CommandElement) Collectors(java.util.stream.Collectors) TextSerializers(org.spongepowered.api.text.serializer.TextSerializers) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) EssentialsEquivalent(io.github.nucleuspowered.nucleus.internal.docgen.annotations.EssentialsEquivalent) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider)

Example 25 with MessageProvider

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

the class NicknameService method register.

public void register() {
    if (this.registered) {
        return;
    }
    MessageProvider mp = Nucleus.getNucleus().getMessageProvider();
    CommandPermissionHandler permissions = Nucleus.getNucleus().getPermissionRegistry().getPermissionsForNucleusCommand(NicknameCommand.class);
    String colPerm = permissions.getPermissionWithSuffix("colour.");
    String colPerm2 = permissions.getPermissionWithSuffix("color.");
    NameUtil.getColours().forEach((key, value) -> replacements.put(new String[] { colPerm + value.getName(), colPerm2 + value.getName() }, Tuple.of(Pattern.compile("[&]+" + key.toString().toLowerCase(), Pattern.CASE_INSENSITIVE).matcher(""), mp.getTextMessageWithFormat("command.nick.colour.nopermswith", value.getName()))));
    String stylePerm = permissions.getPermissionWithSuffix("style.");
    NameUtil.getStyleKeys().entrySet().stream().filter(x -> x.getKey() != 'k').forEach((k) -> replacements.put(new String[] { stylePerm + k.getValue().toLowerCase() }, Tuple.of(Pattern.compile("[&]+" + k.getKey().toString().toLowerCase(), Pattern.CASE_INSENSITIVE).matcher(""), mp.getTextMessageWithFormat("command.nick.style.nopermswith", k.getValue().toLowerCase()))));
    this.replacements.put(new String[] { permissions.getPermissionWithSuffix("magic") }, Tuple.of(Pattern.compile("[&]+k", Pattern.CASE_INSENSITIVE).matcher(""), mp.getTextMessageWithFormat("command.nick.style.nopermswith", "magic")));
    this.registered = true;
}
Also used : Arrays(java.util.Arrays) NameUtil(io.github.nucleuspowered.nucleus.NameUtil) NucleusNicknameService(io.github.nucleuspowered.nucleus.api.service.NucleusNicknameService) NicknameConfigAdapter(io.github.nucleuspowered.nucleus.modules.nickname.config.NicknameConfigAdapter) NicknameException(io.github.nucleuspowered.nucleus.api.exceptions.NicknameException) UserStorageService(org.spongepowered.api.service.user.UserStorageService) Matcher(java.util.regex.Matcher) Text(org.spongepowered.api.text.Text) Map(java.util.Map) NicknameCommand(io.github.nucleuspowered.nucleus.modules.nickname.commands.NicknameCommand) NicknameModule(io.github.nucleuspowered.nucleus.modules.nickname.NicknameModule) Subject(org.spongepowered.api.service.permission.Subject) TextColors(org.spongepowered.api.text.format.TextColors) Nullable(javax.annotation.Nullable) NicknameUserDataModule(io.github.nucleuspowered.nucleus.modules.nickname.datamodules.NicknameUserDataModule) CommandPermissionHandler(io.github.nucleuspowered.nucleus.internal.CommandPermissionHandler) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) User(org.spongepowered.api.entity.living.player.User) NicknameConfig(io.github.nucleuspowered.nucleus.modules.nickname.config.NicknameConfig) CommandSource(org.spongepowered.api.command.CommandSource) CauseStackHelper(io.github.nucleuspowered.nucleus.util.CauseStackHelper) Sponge(org.spongepowered.api.Sponge) ModularUserService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService) 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) Cause(org.spongepowered.api.event.cause.Cause) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) ChangeNicknameEvent(io.github.nucleuspowered.nucleus.modules.nickname.events.ChangeNicknameEvent) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) CommandPermissionHandler(io.github.nucleuspowered.nucleus.internal.CommandPermissionHandler)

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