use of me.lucko.luckperms.common.locale.message.Message in project LuckPerms by lucko.
the class DebugCommand method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
Message.DEBUG_START.send(sender);
StringBuilder sb = new StringBuilder();
sb.append("LuckPerms Debug Output\n\n\n");
BiConsumer<String, JObject> builder = (name, content) -> {
sb.append("-- ").append(name).append(" --\n");
sb.append(GSON.toJson(content.toJson()));
sb.append("\n\n");
};
builder.accept("platform.json", getPlatformData(plugin));
builder.accept("storage.json", getStorageData(plugin));
builder.accept("context.json", getContextData(plugin));
builder.accept("players.json", getPlayersData(plugin));
Pastebin.Paste paste = StandardPastebin.HASTEBIN.postPlain(sb.toString());
Message.DEBUG_URL.send(sender);
Component message = TextComponent.builder(paste.url()).color(TextColor.AQUA).clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, String.valueOf(paste.url()))).hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the debugging data.").color(TextColor.GRAY))).build();
sender.sendMessage(message);
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.common.locale.message.Message in project LuckPerms by lucko.
the class GroupListMembers method sendResult.
private static <T> void sendResult(Sender sender, List<HeldPermission<T>> results, Function<T, String> lookupFunction, Message headerMessage, HolderType holderType, String label, int page) {
results = new ArrayList<>(results);
// we need a deterministic sort order
// even though we're comparing uuids here in some cases - it doesn't matter
// the import thing is that the order is the same each time the command is executed
results.sort((o1, o2) -> {
Comparable h1 = (Comparable) o1.getHolder();
Comparable h2 = (Comparable) o2.getHolder();
// noinspection unchecked
return h1.compareTo(h2);
});
int pageIndex = page - 1;
List<List<HeldPermission<T>>> pages = Iterators.divideIterable(results, 15);
if (pageIndex < 0 || pageIndex >= pages.size()) {
page = 1;
pageIndex = 0;
}
List<HeldPermission<T>> content = pages.get(pageIndex);
List<Map.Entry<String, HeldPermission<T>>> mappedContent = content.stream().map(hp -> Maps.immutableEntry(lookupFunction.apply(hp.getHolder()), hp)).collect(Collectors.toList());
// send header
headerMessage.send(sender, page, pages.size(), results.size());
for (Map.Entry<String, HeldPermission<T>> ent : mappedContent) {
String s = "&3> &b" + ent.getKey() + " " + getNodeExpiryString(ent.getValue().asNode()) + MessageUtils.getAppendableNodeContextString(ent.getValue().asNode());
TextComponent message = TextUtils.fromLegacy(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue())).build();
sender.sendMessage(message);
}
}
use of me.lucko.luckperms.common.locale.message.Message in project LuckPerms by lucko.
the class EditorCommand method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
Type type = Type.ALL;
// parse type
String typeString = ArgumentParser.parseStringOrElse(0, args, null);
if (typeString != null) {
try {
type = Type.valueOf(typeString.toUpperCase());
} catch (IllegalArgumentException e) {
// ignored
}
}
// collect holders
List<PermissionHolder> holders = new ArrayList<>();
if (type.includingGroups) {
plugin.getGroupManager().getAll().values().stream().sorted((o1, o2) -> {
int i = Integer.compare(o2.getWeight().orElse(0), o1.getWeight().orElse(0));
return i != 0 ? i : o1.getName().compareToIgnoreCase(o2.getName());
}).forEach(holders::add);
}
if (type.includingUsers) {
plugin.getUserManager().getAll().values().stream().sorted((o1, o2) -> o1.getFriendlyName().compareToIgnoreCase(o2.getFriendlyName())).forEach(holders::add);
}
// remove holders which the sender doesn't have perms to view
holders.removeIf(holder -> ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), holder));
// they don't have perms to view any of them
if (holders.isEmpty()) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
Message.EDITOR_START.send(sender);
// form the payload data
JsonObject payload = WebEditor.formPayload(holders, sender, label, plugin);
// upload the payload data to gist
String pasteId = StandardPastebin.BYTEBIN.postJson(payload, true).id();
if (pasteId == null) {
Message.EDITOR_UPLOAD_FAILURE.send(sender);
return CommandResult.STATE_ERROR;
}
// form a url for the editor
String url = plugin.getConfiguration().get(ConfigKeys.WEB_EDITOR_URL_PATTERN) + "?" + pasteId;
Message.EDITOR_URL.send(sender);
Component message = TextComponent.builder(url).color(TextColor.AQUA).clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url)).hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the editor.").color(TextColor.GRAY))).build();
sender.sendMessage(message);
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.common.locale.message.Message in project LuckPerms by lucko.
the class SearchCommand method sendResult.
private static <T> void sendResult(Sender sender, List<HeldPermission<T>> results, Function<T, String> lookupFunction, Message headerMessage, HolderType holderType, String label, int page) {
results = new ArrayList<>(results);
// we need a deterministic sort order
// even though we're comparing uuids here in some cases - it doesn't matter
// the import thing is that the order is the same each time the command is executed
results.sort((o1, o2) -> {
Comparable h1 = (Comparable) o1.getHolder();
Comparable h2 = (Comparable) o2.getHolder();
// noinspection unchecked
return h1.compareTo(h2);
});
int pageIndex = page - 1;
List<List<HeldPermission<T>>> pages = Iterators.divideIterable(results, 15);
if (pageIndex < 0 || pageIndex >= pages.size()) {
page = 1;
pageIndex = 0;
}
List<HeldPermission<T>> content = pages.get(pageIndex);
List<Map.Entry<String, HeldPermission<T>>> mappedContent = content.stream().map(hp -> Maps.immutableEntry(lookupFunction.apply(hp.getHolder()), hp)).collect(Collectors.toList());
// send header
headerMessage.send(sender, page, pages.size(), results.size());
for (Map.Entry<String, HeldPermission<T>> ent : mappedContent) {
String s = "&3> &b" + ent.getKey() + " &7- " + (ent.getValue().getValue() ? "&a" : "&c") + ent.getValue().getValue() + getNodeExpiryString(ent.getValue().asNode()) + MessageUtils.getAppendableNodeContextString(ent.getValue().asNode());
TextComponent message = TextUtils.fromLegacy(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue())).build();
sender.sendMessage(message);
}
}
use of me.lucko.luckperms.common.locale.message.Message in project LuckPerms by lucko.
the class UserInfo method execute.
@SuppressWarnings("unchecked")
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), user)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
Message status = plugin.getBootstrap().isPlayerOnline(user.getUuid()) ? Message.PLAYER_ONLINE : Message.PLAYER_OFFLINE;
Message.USER_INFO_GENERAL.send(sender, user.getName().orElse("Unknown"), user.getUuid(), user.getUuid().version() == 4 ? "&2mojang" : "&8offline", status.asString(plugin.getLocaleManager()), user.getPrimaryGroup().getValue());
Set<Node> parents = user.getEnduringData().asSet().stream().filter(Node::isGroupNode).filter(Node::isPermanent).collect(Collectors.toSet());
Set<Node> tempParents = user.getEnduringData().asSet().stream().filter(Node::isGroupNode).filter(Node::isTemporary).collect(Collectors.toSet());
if (!parents.isEmpty()) {
Message.INFO_PARENT_HEADER.send(sender);
for (Node node : parents) {
Message.EMPTY.send(sender, "&f- &3> &f" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(node));
}
}
if (!tempParents.isEmpty()) {
Message.INFO_TEMP_PARENT_HEADER.send(sender);
for (Node node : tempParents) {
Message.EMPTY.send(sender, "&f- &3> &f" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(node));
Message.EMPTY.send(sender, "&f- &2- expires in " + DateUtil.formatDateDiff(node.getExpiryUnixTime()));
}
}
String context = "&bNone";
String prefix = "&bNone";
String suffix = "&bNone";
String meta = "&bNone";
Contexts contexts = plugin.getContextForUser(user).orElse(null);
if (contexts != null) {
ContextSet contextSet = contexts.getContexts();
if (!contextSet.isEmpty()) {
context = contextSet.toSet().stream().map(e -> MessageUtils.contextToString(e.getKey(), e.getValue())).collect(Collectors.joining(" "));
}
MetaData data = user.getCachedData().getMetaData(contexts);
if (data.getPrefix() != null) {
prefix = "&f\"" + data.getPrefix() + "&f\"";
}
if (data.getSuffix() != null) {
suffix = "&f\"" + data.getSuffix() + "&f\"";
}
ListMultimap<String, String> metaMap = data.getMetaMultimap();
if (!metaMap.isEmpty()) {
meta = metaMap.entries().stream().map(e -> MessageUtils.contextToString(e.getKey(), e.getValue())).collect(Collectors.joining(" "));
}
}
Message.USER_INFO_DATA.send(sender, MessageUtils.formatBoolean(contexts != null), context, prefix, suffix, meta);
return CommandResult.SUCCESS;
}
Aggregations