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();
}
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;
}
}
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());
});
}
}
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()));
}
}
}
Aggregations