use of io.github.nucleuspowered.nucleus.modules.serverlist.datamodules.ServerListGeneralDataModule in project Nucleus by NucleusPowered.
the class ServerListCommand method executeCommand.
@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
// Display current information
if (args.hasAny("m")) {
onMessage(src, slc.getMessages(), "command.serverlist.head.messages");
return CommandResult.success();
} else if (args.hasAny("w")) {
onMessage(src, slc.getWhitelist(), "command.serverlist.head.whitelist");
return CommandResult.success();
}
MessageProvider messageProvider = plugin.getMessageProvider();
if (slc.isModifyServerList()) {
src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.modify.true"));
if (!slc.getMessages().isEmpty()) {
src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.messages.click").toBuilder().onClick(TextActions.runCommand("/nucleus:serverlist -m")).toText());
}
if (!slc.getWhitelist().isEmpty()) {
src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.whitelistmessages.click").toBuilder().onClick(TextActions.runCommand("/nucleus:serverlist -w")).toText());
}
} else if (slc.getModifyServerList() == ServerListConfig.ServerListSelection.WHITELIST) {
src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.modify.whitelist"));
if (!slc.getWhitelist().isEmpty()) {
src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.whitelistmessages.click").toBuilder().onClick(TextActions.runCommand("/nucleus:serverlist -w")).toText());
}
} else {
src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.modify.false"));
}
ServerListGeneralDataModule ss = plugin.getGeneralService().get(ServerListGeneralDataModule.class);
ss.getMessage().ifPresent(t -> {
src.sendMessage(Util.SPACE);
src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.tempheader"));
src.sendMessage(t);
src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.message.expiry", Util.getTimeToNow(ss.getExpiry().get())));
});
if (slc.isHidePlayerCount()) {
src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.hideplayers"));
} else if (slc.isHideVanishedPlayers()) {
src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.hidevanished"));
}
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.modules.serverlist.datamodules.ServerListGeneralDataModule in project Nucleus by NucleusPowered.
the class TemporaryMessageCommand method executeCommand.
@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
// Get the temporary message item.
ServerListGeneralDataModule mod = plugin.getGeneralService().get(ServerListGeneralDataModule.class);
if (args.hasAny("r")) {
if (mod.getMessage().isPresent()) {
// Remove
mod.remove();
// Send message.
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.serverlist.message.removed"));
return CommandResult.success();
}
throw ReturnMessageException.fromKey("command.serverlist.message.noremoved");
}
// Which line?
boolean linetwo = args.<Integer>getOne(line).map(x -> x == 2).orElse(false);
Optional<String> onMessage = args.getOne(this.message);
if (!onMessage.isPresent()) {
boolean isValid = mod.getExpiry().map(x -> x.isAfter(Instant.now())).orElse(false);
if (!isValid) {
throw ReturnMessageException.fromKey("command.serverlist.message.isempty");
}
if (linetwo) {
mod.setLineTwo(null);
} else {
mod.setLineOne(null);
}
Optional<Text> newMessage = mod.getMessage();
if (newMessage.isPresent()) {
// Send message
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.serverlist.message.set"));
src.sendMessage(newMessage.get());
} else {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.serverlist.message.empty"));
}
return CommandResult.success();
}
String nMessage = onMessage.get();
// If the expiry is null or before now, and there is no timespan, then it's an hour.
Instant endTime = args.<Long>getOne(timespan).map(x -> Instant.now().plus(x, ChronoUnit.SECONDS)).orElseGet(() -> mod.getExpiry().map(x -> x.isBefore(Instant.now()) ? x.plusSeconds(3600) : x).orElseGet(() -> Instant.now().plusSeconds(3600)));
// Set the expiry.
mod.setExpiry(endTime);
if (linetwo) {
mod.setLineTwo(nMessage);
} else {
mod.setLineOne(nMessage);
}
Optional<Text> newMessage = mod.getMessage();
if (newMessage.isPresent()) {
// Send message
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.serverlist.message.set"));
src.sendMessage(newMessage.get());
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.serverlist.message.expiry", Util.getTimeToNow(endTime)));
return CommandResult.success();
}
throw ReturnMessageException.fromKey("command.serverlist.message.notset");
}
Aggregations