use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.
the class GetFromIpCommand method executeCommand.
@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
String ip = args.<String>getOne(ipKey).get();
if (Arrays.stream(ip.split("\\.")).anyMatch(x -> Integer.parseInt(x) > 255)) {
throw ReturnMessageException.fromKey("command.getfromip.notvalid");
}
UserStorageService uss = Sponge.getServiceManager().provideUnchecked(UserStorageService.class);
List<User> users = plugin.getUserCacheService().getForIp(ip).stream().map(uss::get).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
if (users.isEmpty()) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.getfromip.nousers"));
return CommandResult.success();
}
NameUtil name = plugin.getNameUtil();
Util.getPaginationBuilder(src).title(plugin.getMessageProvider().getTextMessageWithFormat("command.getfromip.title", ip)).contents(users.stream().map(y -> {
Text n = name.getName(y);
return n.toBuilder().onClick(TextActions.runCommand("/nucleus:seen " + y.getName())).onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithTextFormat("command.getfromip.hover", n))).build();
}).collect(Collectors.toList())).sendTo(src);
return CommandResult.success();
}
use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.
the class ListPlayerCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
boolean showVanished = this.permissions.testSuffix(src, "seevanished");
Collection<Player> players = Sponge.getServer().getOnlinePlayers();
long playerCount = players.size();
long hiddenCount = players.stream().filter(x -> x.get(Keys.VANISH).orElse(false)).count();
Text header;
if (showVanished && hiddenCount > 0) {
header = plugin.getMessageProvider().getTextMessageWithFormat("command.list.playercount.hidden", String.valueOf(playerCount), String.valueOf(Sponge.getServer().getMaxPlayers()), String.valueOf(hiddenCount));
} else {
header = plugin.getMessageProvider().getTextMessageWithFormat("command.list.playercount.base", String.valueOf(playerCount - hiddenCount), String.valueOf(Sponge.getServer().getMaxPlayers()));
}
src.sendMessage(header);
Optional<PermissionService> optPermissionService = Sponge.getServiceManager().provide(PermissionService.class);
if (this.listConfig.isGroupByPermissionGroup() && optPermissionService.isPresent()) {
listByPermissionGroup(optPermissionService.get(), players, src, showVanished);
} else {
// If we have players, send them on.
getPlayerList(players, showVanished).ifPresent(src::sendMessage);
}
return CommandResult.success();
}
use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.
the class MailReadBase method executeCommand.
public CommandResult executeCommand(CommandSource src, final User target, Collection<NucleusMailService.MailFilter> lmf) {
List<MailData> lmd;
if (!lmf.isEmpty()) {
lmd = handler.getMailInternal(target, lmf.toArray(new NucleusMailService.MailFilter[lmf.size()]));
} else {
lmd = handler.getMailInternal(target);
}
if (lmd.isEmpty()) {
if (src instanceof Player && target.getUniqueId().equals(((Player) src).getUniqueId())) {
src.sendMessage(Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat(!lmf.isEmpty() ? "command.mail.none.filter" : "command.mail.none.normal.self"));
} else {
src.sendMessage(Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat(!lmf.isEmpty() ? "command.mail.none.filter" : "command.mail.none.normal.other", target.getName()));
}
return CommandResult.success();
}
List<Text> mails = lmd.stream().sorted(Comparator.comparing(MailMessage::getDate)).map(x -> createMessage(x, target)).collect(Collectors.toList());
// Paginate the mail.
PaginationService ps = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
PaginationList.Builder b = ps.builder().padding(Text.of(TextColors.GREEN, "-")).title(getHeader(src, target, !lmf.isEmpty())).contents(mails);
if (!(src instanceof Player)) {
b.linesPerPage(-1);
} else {
b.header(Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("mail.header"));
}
b.sendTo(src);
return CommandResult.success();
}
use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.
the class CheckNotesCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
User user = args.<User>getOne(playerKey).get();
List<NoteData> notes = handler.getNotesInternal(user);
if (notes.isEmpty()) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.checknotes.none", user.getName()));
return CommandResult.success();
}
List<Text> messages = notes.stream().sorted(Comparator.comparing(NoteData::getDate)).map(x -> createMessage(x, user)).collect(Collectors.toList());
messages.add(0, plugin.getMessageProvider().getTextMessageWithFormat("command.checknotes.info"));
PaginationService paginationService = Sponge.getGame().getServiceManager().provideUnchecked(PaginationService.class);
paginationService.builder().title(Text.builder().color(TextColors.GOLD).append(Text.of(plugin.getMessageProvider().getMessageWithFormat("command.checknotes.header", user.getName()))).build()).padding(Text.builder().color(TextColors.YELLOW).append(Text.of("=")).build()).contents(messages).sendTo(src);
return CommandResult.success();
}
use of org.spongepowered.api.command.CommandSource 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();
}
Aggregations