use of me.lucko.luckperms.common.locale.message.Message in project LuckPerms by lucko.
the class SimpleLocaleManager method loadFromFile.
@Override
@SuppressWarnings("unchecked")
public void loadFromFile(File file) throws Exception {
try (BufferedReader reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) {
ImmutableMap.Builder<Message, String> messages = ImmutableMap.builder();
ImmutableMap.Builder<CommandSpec, CommandSpecData> commands = ImmutableMap.builder();
Map<String, Object> data = (Map<String, Object>) new Yaml().load(reader);
for (Map.Entry<String, Object> entry : data.entrySet()) {
if (entry.getKey() == null || entry.getKey().isEmpty() || entry.getValue() == null) {
continue;
}
// might be a message
if (entry.getValue() instanceof String) {
String key = entry.getKey().toUpperCase().replace('-', '_');
String value = (String) entry.getValue();
try {
messages.put(Message.valueOf(key), value);
} catch (IllegalArgumentException e) {
// ignore
}
}
// might be the entries for command specifications - take care for malformed entries of differing types.
if (entry.getKey().equals("command-specs") && entry.getValue() instanceof Map) {
Map<?, ?> commandKeys = (Map) entry.getValue();
// key is the command id, value is a map of the commands attributes
for (Map.Entry commandKey : commandKeys.entrySet()) {
// just try catch, can't be bothered with safe casting every single value.
try {
String id = (String) commandKey.getKey();
Map<String, Object> attributes = (Map<String, Object>) commandKey.getValue();
CommandSpec spec = CommandSpec.valueOf(id.toUpperCase().replace('-', '_'));
String description = (String) attributes.get("description");
String usage = (String) attributes.get("usage");
Map<String, String> args = (Map<String, String>) attributes.get("args");
if (args != null && args.isEmpty()) {
args = null;
}
CommandSpecData specData = new CommandSpecData(description, usage, args == null ? null : ImmutableMap.copyOf(args));
commands.put(spec, specData);
} catch (IllegalArgumentException e) {
// ignore
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
this.messages = messages.build();
this.commands = commands.build();
}
}
use of me.lucko.luckperms.common.locale.message.Message in project LuckPerms by lucko.
the class VerboseListener method sendNotification.
private void sendNotification(CheckData data) {
String msg = "&a" + data.getCheckTarget() + "&7 - &a" + data.getPermission() + "&7 - " + getTristateColor(data.getResult()) + data.getResult().name().toLowerCase();
if (this.notifiedSender.isConsole()) {
// just send as a raw message
Message.VERBOSE_LOG.send(this.notifiedSender, msg);
return;
}
// form a hoverevent from the check trace
TextComponent textComponent = TextUtils.fromLegacy(Message.VERBOSE_LOG.asString(this.notifiedSender.getPlatform().getLocaleManager(), msg));
// build the text
List<String> hover = new ArrayList<>();
hover.add("&bOrigin: &2" + data.getCheckOrigin().name());
hover.add("&bContext: &r" + MessageUtils.contextSetToString(data.getCheckContext()));
hover.add("&bTrace: &r");
Consumer<StackTraceElement> printer = StackTracePrinter.elementToString(str -> hover.add("&7" + str));
int overflow;
if (data.getCheckOrigin() == CheckOrigin.API || data.getCheckOrigin() == CheckOrigin.INTERNAL) {
overflow = CHAT_UNFILTERED_PRINTER.process(data.getCheckTrace(), printer);
} else {
overflow = CHAT_FILTERED_PRINTER.process(data.getCheckTrace(), printer);
}
if (overflow != 0) {
hover.add("&f... and " + overflow + " more");
}
// send the message
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline(hover.stream()), CommandManager.AMPERSAND_CHAR));
TextComponent text = textComponent.toBuilder().applyDeep(comp -> comp.hoverEvent(hoverEvent)).build();
this.notifiedSender.sendMessage(text);
}
Aggregations