use of org.spongepowered.api.command.CommandResult in project Nucleus by NucleusPowered.
the class PrintPermsCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
Map<String, PermissionInformation> l = plugin.getPermissionRegistry().getPermissions();
List<String> notsuggested = l.entrySet().stream().filter(x -> x.getValue().level == SuggestedLevel.NONE).map(Map.Entry::getKey).collect(Collectors.toList());
List<String> owner = l.entrySet().stream().filter(x -> x.getValue().level == SuggestedLevel.NONE).map(Map.Entry::getKey).collect(Collectors.toList());
List<String> admin = l.entrySet().stream().filter(x -> x.getValue().level == SuggestedLevel.ADMIN).map(Map.Entry::getKey).collect(Collectors.toList());
List<String> mod = l.entrySet().stream().filter(x -> x.getValue().level == SuggestedLevel.MOD).map(Map.Entry::getKey).collect(Collectors.toList());
List<String> user = l.entrySet().stream().filter(x -> x.getValue().level == SuggestedLevel.USER).map(Map.Entry::getKey).collect(Collectors.toList());
String file = "plugin-perms.txt";
BufferedWriter f = new BufferedWriter(new FileWriter(file));
Consumer<String> permWriter = x -> {
try {
f.write(x);
f.newLine();
} catch (IOException e) {
e.printStackTrace();
}
};
f.write("Not Suggested");
f.write("-----");
f.newLine();
notsuggested.stream().sorted().forEach(permWriter);
f.newLine();
f.write("Owner");
f.write("-----");
f.newLine();
owner.stream().sorted().forEach(permWriter);
f.newLine();
f.write("Admin");
f.write("-----");
f.newLine();
admin.stream().sorted().forEach(permWriter);
f.newLine();
f.write("Mod");
f.write("-----");
f.newLine();
mod.stream().sorted().forEach(permWriter);
f.newLine();
f.write("User");
f.write("-----");
f.newLine();
user.stream().sorted().forEach(permWriter);
f.flush();
f.close();
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.printperms", file));
return CommandResult.success();
}
use of org.spongepowered.api.command.CommandResult in project Nucleus by NucleusPowered.
the class KitListCommand method executeCommand.
@Override
public CommandResult executeCommand(final CommandSource src, CommandContext args) throws Exception {
Set<String> kits = KIT_HANDLER.getKitNames();
if (kits.isEmpty()) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.list.empty"));
return CommandResult.empty();
}
PaginationService paginationService = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
ArrayList<Text> kitText = Lists.newArrayList();
final KitUserDataModule user = src instanceof Player ? Nucleus.getNucleus().getUserDataManager().getUnchecked(((Player) src).getUniqueId()).get(KitUserDataModule.class) : null;
final boolean showHidden = kitPermissionHandler.testSuffix(src, "showhidden");
Stream<String> kitStream = KIT_HANDLER.getKitNames(showHidden).stream();
if (this.isSeparatePermissions) {
kitStream = kitStream.filter(kit -> src.hasPermission(KitHandler.getPermissionForKit(kit.toLowerCase())));
}
kitStream.forEach(kit -> kitText.add(createKit(src, user, kit, KIT_HANDLER.getKit(kit).get())));
PaginationList.Builder paginationBuilder = paginationService.builder().contents(kitText).title(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.list.kits")).padding(Text.of(TextColors.GREEN, "-"));
paginationBuilder.sendTo(src);
return CommandResult.success();
}
use of org.spongepowered.api.command.CommandResult in project Nucleus by NucleusPowered.
the class KitViewCommand method executeCommand.
@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
final Kit kitInfo = args.<Kit>getOne(KIT_PARAMETER).get();
Inventory inventory = Util.getKitInventoryBuilder().property(InventoryTitle.PROPERTY_NAME, InventoryTitle.of(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.view.title", kitInfo.getName()))).build(this.plugin);
List<ItemStack> lis = kitInfo.getStacks().stream().filter(x -> !x.getType().equals(ItemTypes.NONE)).map(ItemStackSnapshot::createStack).collect(Collectors.toList());
if (this.processTokens) {
KIT_HANDLER.processTokensInItemStacks(src, lis);
}
lis.forEach(inventory::offer);
return src.openInventory(inventory).map(x -> {
KIT_HANDLER.addViewer(x);
return CommandResult.success();
}).orElseThrow(() -> ReturnMessageException.fromKey("command.kit.view.cantopen", kitInfo.getName()));
}
use of org.spongepowered.api.command.CommandResult in project Nucleus by NucleusPowered.
the class StaffChatCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
Optional<String> toSend = args.getOne(message);
if (toSend.isPresent()) {
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
frame.addContext(EventContexts.SHOULD_FORMAT_CHANNEL, StaffChatMessageChannel.getInstance().formatMessages());
if (src instanceof Player) {
Player pl = (Player) src;
frame.pushCause(pl);
frame.addContext(EventContextKeys.PLAYER_SIMULATED, pl.getProfile());
MessageChannel mc = pl.getMessageChannel();
pl.setMessageChannel(StaffChatMessageChannel.getInstance());
pl.simulateChat(TextParsingUtils.addUrls(toSend.get()), Sponge.getCauseStackManager().getCurrentCause());
pl.setMessageChannel(mc);
} else {
StaffChatMessageChannel.getInstance().send(src, TextParsingUtils.addUrls(toSend.get()), ChatTypes.CHAT);
}
return CommandResult.success();
}
}
if (!(src instanceof Player)) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.staffchat.consoletoggle"));
}
Player player = (Player) src;
StaffChatTransientModule s = plugin.getUserDataManager().get(player).map(y -> y.getTransient(StaffChatTransientModule.class)).orElseGet(StaffChatTransientModule::new);
boolean result = !(src.getMessageChannel() instanceof StaffChatMessageChannel);
if (result) {
s.setPreviousMessageChannel(player.getMessageChannel());
src.setMessageChannel(StaffChatMessageChannel.getInstance());
} else {
src.setMessageChannel(s.getPreviousMessageChannel().orElse(MessageChannel.TO_ALL));
}
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.staffchat." + (result ? "on" : "off")));
return CommandResult.success();
}
use of org.spongepowered.api.command.CommandResult 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