Search in sources :

Example 1 with NucleusTextTemplate

use of io.github.nucleuspowered.nucleus.api.text.NucleusTextTemplate in project Nucleus by NucleusPowered.

the class BroadcastCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    String m = args.<String>getOne(message).get();
    NucleusTextTemplate textTemplate = NucleusTextTemplateFactory.createFromAmpersandString(m);
    Text p = bc.getPrefix().getForCommandSource(src);
    Text s = bc.getSuffix().getForCommandSource(src);
    new NucleusTextTemplateMessageSender(textTemplate, src, t -> TextParsingUtils.joinTextsWithColoursFlowing(p, t, s)).send();
    return CommandResult.success();
}
Also used : NoModifiers(io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers) NucleusTextTemplateFactory(io.github.nucleuspowered.nucleus.internal.text.NucleusTextTemplateFactory) CommandResult(org.spongepowered.api.command.CommandResult) RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) RemainingStringsArgument(io.github.nucleuspowered.nucleus.argumentparsers.RemainingStringsArgument) AdminConfig(io.github.nucleuspowered.nucleus.modules.admin.config.AdminConfig) CommandSource(org.spongepowered.api.command.CommandSource) AdminConfigAdapter(io.github.nucleuspowered.nucleus.modules.admin.config.AdminConfigAdapter) TextParsingUtils(io.github.nucleuspowered.nucleus.internal.text.TextParsingUtils) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) AdminModule(io.github.nucleuspowered.nucleus.modules.admin.AdminModule) CommandElement(org.spongepowered.api.command.args.CommandElement) GenericArguments(org.spongepowered.api.command.args.GenericArguments) RunAsync(io.github.nucleuspowered.nucleus.internal.annotations.RunAsync) Reloadable(io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) NucleusTextTemplate(io.github.nucleuspowered.nucleus.api.text.NucleusTextTemplate) NucleusTextTemplateMessageSender(io.github.nucleuspowered.nucleus.internal.text.NucleusTextTemplateMessageSender) BroadcastConfig(io.github.nucleuspowered.nucleus.modules.admin.config.BroadcastConfig) EssentialsEquivalent(io.github.nucleuspowered.nucleus.internal.docgen.annotations.EssentialsEquivalent) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) NucleusTextTemplateMessageSender(io.github.nucleuspowered.nucleus.internal.text.NucleusTextTemplateMessageSender) NucleusTextTemplate(io.github.nucleuspowered.nucleus.api.text.NucleusTextTemplate) Text(org.spongepowered.api.text.Text)

Example 2 with NucleusTextTemplate

use of io.github.nucleuspowered.nucleus.api.text.NucleusTextTemplate in project Nucleus by NucleusPowered.

the class AFKCommandInterceptor method onReload.

@Override
public void onReload() throws Exception {
    AFKConfig config = Nucleus.getNucleus().getInternalServiceManager().getServiceUnchecked(AFKConfigAdapter.class).getNodeOrDefault();
    if (config.isAlertSenderOnAfk()) {
        NucleusTextTemplate textTemplate = config.getMessages().getOnCommand();
        if (textTemplate == null || textTemplate.isEmpty()) {
            // NPE has occurred here in the past due to an empty message.
            this.message = null;
        } else {
            this.message = textTemplate;
        }
        this.send = true;
    } else {
        this.message = null;
        this.send = false;
    }
}
Also used : AFKConfig(io.github.nucleuspowered.nucleus.modules.afk.config.AFKConfig) NucleusTextTemplate(io.github.nucleuspowered.nucleus.api.text.NucleusTextTemplate) AFKConfigAdapter(io.github.nucleuspowered.nucleus.modules.afk.config.AFKConfigAdapter)

Example 3 with NucleusTextTemplate

use of io.github.nucleuspowered.nucleus.api.text.NucleusTextTemplate in project Nucleus by NucleusPowered.

the class ServerListListener method onServerListPing.

@Listener
public void onServerListPing(ClientPingServerEvent event, @Getter("getResponse") ClientPingServerEvent.Response response) {
    if (this.config == null) {
        try {
            onReload();
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
    }
    if (this.config.isModifyServerList()) {
        List<NucleusTextTemplateImpl> list = null;
        Optional<Text> ott = plugin.getGeneralService().get(ServerListGeneralDataModule.class).getMessage();
        if (ott.isPresent()) {
            response.setDescription(ott.get());
        } else {
            if (Sponge.getServer().hasWhitelist() && !this.config.getWhitelist().isEmpty()) {
                list = this.config.getWhitelist();
            } else if (!this.config.getMessages().isEmpty()) {
                list = this.config.getMessages();
            }
            if (list != null) {
                NucleusTextTemplate template = list.get(this.random.nextInt(list.size()));
                response.setDescription(template.getForCommandSource(Sponge.getServer().getConsole()));
            }
        }
    }
    if (this.config.isHidePlayerCount()) {
        response.setHidePlayers(true);
    } else if (this.config.isHideVanishedPlayers()) {
        Collection<GameProfile> players = Sponge.getServer().getOnlinePlayers().stream().filter(x -> !x.get(Keys.VANISH).orElse(false)).map(User::getProfile).collect(Collectors.toList());
        response.getPlayers().ifPresent(y -> {
            y.getProfiles().clear();
            y.getProfiles().addAll(players);
            y.setOnline(players.size());
        });
    }
}
Also used : Getter(org.spongepowered.api.event.filter.Getter) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) Keys(org.spongepowered.api.data.key.Keys) User(org.spongepowered.api.entity.living.player.User) ServerListGeneralDataModule(io.github.nucleuspowered.nucleus.modules.serverlist.datamodules.ServerListGeneralDataModule) Collection(java.util.Collection) ServerListModule(io.github.nucleuspowered.nucleus.modules.serverlist.ServerListModule) Sponge(org.spongepowered.api.Sponge) Random(java.util.Random) ClientPingServerEvent(org.spongepowered.api.event.server.ClientPingServerEvent) ServerListConfigAdapter(io.github.nucleuspowered.nucleus.modules.serverlist.config.ServerListConfigAdapter) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Reloadable(io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable) ServerListConfig(io.github.nucleuspowered.nucleus.modules.serverlist.config.ServerListConfig) List(java.util.List) Text(org.spongepowered.api.text.Text) NucleusTextTemplate(io.github.nucleuspowered.nucleus.api.text.NucleusTextTemplate) Optional(java.util.Optional) ListenerBase(io.github.nucleuspowered.nucleus.internal.ListenerBase) GameProfile(org.spongepowered.api.profile.GameProfile) NucleusTextTemplateImpl(io.github.nucleuspowered.nucleus.internal.text.NucleusTextTemplateImpl) Listener(org.spongepowered.api.event.Listener) NucleusTextTemplateImpl(io.github.nucleuspowered.nucleus.internal.text.NucleusTextTemplateImpl) User(org.spongepowered.api.entity.living.player.User) NucleusTextTemplate(io.github.nucleuspowered.nucleus.api.text.NucleusTextTemplate) Collection(java.util.Collection) Text(org.spongepowered.api.text.Text) ServerListGeneralDataModule(io.github.nucleuspowered.nucleus.modules.serverlist.datamodules.ServerListGeneralDataModule) Listener(org.spongepowered.api.event.Listener)

Example 4 with NucleusTextTemplate

use of io.github.nucleuspowered.nucleus.api.text.NucleusTextTemplate in project Nucleus by NucleusPowered.

the class WhitelistServerListListener method onServerListPing.

@Listener(order = Order.LATE)
public void onServerListPing(ClientPingServerEvent event, @Getter("getResponse") ClientPingServerEvent.Response response) {
    if (!Sponge.getServer().hasWhitelist()) {
        return;
    }
    Optional<Text> ott = plugin.getGeneralService().get(ServerListGeneralDataModule.class).getMessage();
    if (!ott.isPresent() && !this.config.getWhitelist().isEmpty()) {
        List<NucleusTextTemplateImpl> list = this.config.getWhitelist();
        if (list != null) {
            NucleusTextTemplate template = list.get(this.random.nextInt(list.size()));
            response.setDescription(template.getForCommandSource(Sponge.getServer().getConsole()));
        }
    }
}
Also used : NucleusTextTemplateImpl(io.github.nucleuspowered.nucleus.internal.text.NucleusTextTemplateImpl) NucleusTextTemplate(io.github.nucleuspowered.nucleus.api.text.NucleusTextTemplate) Text(org.spongepowered.api.text.Text) ServerListGeneralDataModule(io.github.nucleuspowered.nucleus.modules.serverlist.datamodules.ServerListGeneralDataModule) Listener(org.spongepowered.api.event.Listener)

Aggregations

NucleusTextTemplate (io.github.nucleuspowered.nucleus.api.text.NucleusTextTemplate)4 Text (org.spongepowered.api.text.Text)3 Reloadable (io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable)2 NucleusTextTemplateImpl (io.github.nucleuspowered.nucleus.internal.text.NucleusTextTemplateImpl)2 ServerListGeneralDataModule (io.github.nucleuspowered.nucleus.modules.serverlist.datamodules.ServerListGeneralDataModule)2 Listener (org.spongepowered.api.event.Listener)2 Nucleus (io.github.nucleuspowered.nucleus.Nucleus)1 RemainingStringsArgument (io.github.nucleuspowered.nucleus.argumentparsers.RemainingStringsArgument)1 ListenerBase (io.github.nucleuspowered.nucleus.internal.ListenerBase)1 RunAsync (io.github.nucleuspowered.nucleus.internal.annotations.RunAsync)1 NoModifiers (io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers)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 EssentialsEquivalent (io.github.nucleuspowered.nucleus.internal.docgen.annotations.EssentialsEquivalent)1 NucleusTextTemplateFactory (io.github.nucleuspowered.nucleus.internal.text.NucleusTextTemplateFactory)1 NucleusTextTemplateMessageSender (io.github.nucleuspowered.nucleus.internal.text.NucleusTextTemplateMessageSender)1 TextParsingUtils (io.github.nucleuspowered.nucleus.internal.text.TextParsingUtils)1 AdminModule (io.github.nucleuspowered.nucleus.modules.admin.AdminModule)1 AdminConfig (io.github.nucleuspowered.nucleus.modules.admin.config.AdminConfig)1