Make storage meta keys translatable

This commit is contained in:
Luck 2020-10-28 10:42:47 +00:00
parent ad174742e9
commit 15d3000fc1
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
11 changed files with 71 additions and 47 deletions

View File

@ -35,6 +35,8 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.Predicates;
import net.kyori.adventure.text.Component;
import java.util.Map;
public class InfoCommand extends SingleCommand {
@ -44,7 +46,7 @@ public class InfoCommand extends SingleCommand {
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
Map<String, String> storageMeta = plugin.getStorage().getMeta();
Map<Component, Component> storageMeta = plugin.getStorage().getMeta();
Message.INFO.send(sender, plugin, storageMeta);
return CommandResult.SUCCESS;
}

View File

@ -71,7 +71,6 @@ import static net.kyori.adventure.text.Component.space;
import static net.kyori.adventure.text.Component.text;
import static net.kyori.adventure.text.Component.translatable;
import static net.kyori.adventure.text.format.NamedTextColor.AQUA;
import static net.kyori.adventure.text.format.NamedTextColor.BLUE;
import static net.kyori.adventure.text.format.NamedTextColor.DARK_AQUA;
import static net.kyori.adventure.text.format.NamedTextColor.DARK_GRAY;
import static net.kyori.adventure.text.format.NamedTextColor.DARK_GREEN;
@ -322,7 +321,7 @@ public interface Message {
.append(space())
.append(text(target, GREEN))
.append(text(" - ", GRAY))
.append(text("meta: ", BLUE))
.append(text("meta: ", AQUA))
.append(text(metaKey, GREEN))
.append(text(" - ", GRAY))
.append(text(result, GRAY))
@ -1319,7 +1318,7 @@ public interface Message {
)
);
Args2<LuckPermsPlugin, Map<String, String>> INFO = (plugin, storageMeta) -> join(newline(),
Args2<LuckPermsPlugin, Map<Component, Component>> INFO = (plugin, storageMeta) -> join(newline(),
// "&2Running &bLuckPerms v{}&2 by &bLuck&2."
// "&f- &3Platform: &f{}"
// "&f- &3Server Brand: &f{}"
@ -1382,28 +1381,14 @@ public interface Message {
.append(text(plugin.getStorage().getName(), WHITE))
);
for (Map.Entry<String, String> metaEntry : storageMeta.entrySet()) {
for (Map.Entry<Component, Component> metaEntry : storageMeta.entrySet()) {
builder.append(newline());
String value = metaEntry.getValue();
Component valueComponent;
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
valueComponent = formatBoolean(Boolean.parseBoolean(value));
} else {
try {
int i = Integer.parseInt(value);
valueComponent = text(i, GREEN);
} catch (NumberFormatException e) {
valueComponent = text(value, WHITE);
}
}
builder.append(prefixed(text()
.color(DARK_AQUA)
.append(text(" "))
.append(text(metaEntry.getKey()))
.append(metaEntry.getKey())
.append(text(": "))
.append(valueComponent)
.append(metaEntry.getValue())
));
}
})),

View File

@ -39,6 +39,7 @@ import me.lucko.luckperms.common.storage.implementation.split.SplitStorage;
import me.lucko.luckperms.common.storage.misc.NodeEntry;
import me.lucko.luckperms.common.util.Throwing;
import net.kyori.adventure.text.Component;
import net.luckperms.api.actionlog.Action;
import net.luckperms.api.event.cause.CreationCause;
import net.luckperms.api.event.cause.DeletionCause;
@ -128,7 +129,7 @@ public class Storage {
}
}
public Map<String, String> getMeta() {
public Map<Component, Component> getMeta() {
return this.implementation.getMeta();
}

View File

@ -34,6 +34,7 @@ import me.lucko.luckperms.common.node.matcher.ConstraintNodeMatcher;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.storage.misc.NodeEntry;
import net.kyori.adventure.text.Component;
import net.luckperms.api.actionlog.Action;
import net.luckperms.api.model.PlayerSaveResult;
import net.luckperms.api.node.Node;
@ -56,7 +57,7 @@ public interface StorageImplementation {
void shutdown();
default Map<String, String> getMeta() {
default Map<Component, Component> getMeta() {
return Collections.emptyMap();
}

View File

@ -42,6 +42,7 @@ import me.lucko.luckperms.common.actionlog.LoggedAction;
import me.lucko.luckperms.common.bulkupdate.BulkUpdate;
import me.lucko.luckperms.common.bulkupdate.BulkUpdateStatistics;
import me.lucko.luckperms.common.context.contextset.MutableContextSetImpl;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.Track;
import me.lucko.luckperms.common.model.User;
@ -55,6 +56,8 @@ import me.lucko.luckperms.common.storage.misc.PlayerSaveResultImpl;
import me.lucko.luckperms.common.storage.misc.StorageCredentials;
import me.lucko.luckperms.common.util.Iterators;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.luckperms.api.actionlog.Action;
import net.luckperms.api.context.Context;
import net.luckperms.api.context.ContextSet;
@ -142,8 +145,8 @@ public class MongoStorage implements StorageImplementation {
}
@Override
public Map<String, String> getMeta() {
Map<String, String> meta = new LinkedHashMap<>();
public Map<Component, Component> getMeta() {
Map<Component, Component> meta = new LinkedHashMap<>();
boolean success = true;
long start = System.currentTimeMillis();
@ -155,11 +158,15 @@ public class MongoStorage implements StorageImplementation {
long duration = System.currentTimeMillis() - start;
if (success) {
meta.put("Ping", duration + "ms");
meta.put("Connected", "true");
} else {
meta.put("Connected", "false");
meta.put(
Component.translatable("luckperms.command.info.storage.meta.ping-key"),
Component.text(duration + "ms", NamedTextColor.GREEN)
);
}
meta.put(
Component.translatable("luckperms.command.info.storage.meta.connected-key"),
Message.formatBoolean(success)
);
return meta;
}

View File

@ -29,6 +29,7 @@ import com.google.common.collect.ImmutableMap;
import me.lucko.luckperms.common.actionlog.Log;
import me.lucko.luckperms.common.bulkupdate.BulkUpdate;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.Track;
import me.lucko.luckperms.common.model.User;
@ -38,6 +39,7 @@ import me.lucko.luckperms.common.storage.StorageType;
import me.lucko.luckperms.common.storage.implementation.StorageImplementation;
import me.lucko.luckperms.common.storage.misc.NodeEntry;
import net.kyori.adventure.text.Component;
import net.luckperms.api.actionlog.Action;
import net.luckperms.api.model.PlayerSaveResult;
import net.luckperms.api.node.Node;
@ -48,6 +50,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
public class SplitStorage implements StorageImplementation {
private final LuckPermsPlugin plugin;
@ -106,9 +109,14 @@ public class SplitStorage implements StorageImplementation {
}
@Override
public Map<String, String> getMeta() {
Map<String, String> meta = new LinkedHashMap<>();
meta.put("Types", this.types.toString());
public Map<Component, Component> getMeta() {
Map<Component, Component> meta = new LinkedHashMap<>();
meta.put(
Component.translatable("luckperms.command.info.storage.meta.split-types-key"),
Message.formatStringList(this.types.entrySet().stream()
.map(e -> e.getKey().toString().toLowerCase() + "->" + e.getValue().getName().toLowerCase())
.collect(Collectors.toList()))
);
for (StorageImplementation backing : this.implementations.values()) {
meta.putAll(backing.getMeta());
}

View File

@ -47,6 +47,7 @@ import me.lucko.luckperms.common.storage.misc.PlayerSaveResultImpl;
import me.lucko.luckperms.common.util.Uuids;
import me.lucko.luckperms.common.util.gson.GsonProvider;
import net.kyori.adventure.text.Component;
import net.luckperms.api.actionlog.Action;
import net.luckperms.api.model.PlayerSaveResult;
import net.luckperms.api.model.data.DataType;
@ -219,7 +220,7 @@ public class SqlStorage implements StorageImplementation {
}
@Override
public Map<String, String> getMeta() {
public Map<Component, Component> getMeta() {
return this.connectionFactory.getMeta();
}

View File

@ -27,6 +27,8 @@ package me.lucko.luckperms.common.storage.implementation.sql.connection;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import net.kyori.adventure.text.Component;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collections;
@ -41,7 +43,7 @@ public interface ConnectionFactory {
void shutdown() throws Exception;
default Map<String, String> getMeta() {
default Map<Component, Component> getMeta() {
return Collections.emptyMap();
}

View File

@ -28,11 +28,14 @@ package me.lucko.luckperms.common.storage.implementation.sql.connection.file;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.storage.implementation.sql.connection.ConnectionFactory;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.DecimalFormat;
import java.util.LinkedHashMap;
import java.util.Collections;
import java.util.Map;
abstract class FlatfileConnectionFactory implements ConnectionFactory {
@ -54,9 +57,8 @@ abstract class FlatfileConnectionFactory implements ConnectionFactory {
}
@Override
public Map<String, String> getMeta() {
Map<String, String> meta = new LinkedHashMap<>();
public Map<Component, Component> getMeta() {
String fileSize;
Path databaseFile = getWriteFile();
if (Files.exists(databaseFile)) {
long length;
@ -67,11 +69,14 @@ abstract class FlatfileConnectionFactory implements ConnectionFactory {
}
double size = length / 1048576D;
meta.put("File Size", DF.format(size) + "MB");
fileSize = DF.format(size) + "MB";
} else {
meta.put("File Size", "0MB");
fileSize = "0MB";
}
return meta;
return Collections.singletonMap(
Component.translatable("luckperms.command.info.storage.meta.file-size-key"),
Component.text(fileSize, NamedTextColor.GREEN)
);
}
}

View File

@ -29,11 +29,15 @@ import com.google.common.collect.ImmutableList;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.plugin.logging.PluginLogger;
import me.lucko.luckperms.common.storage.implementation.sql.connection.ConnectionFactory;
import me.lucko.luckperms.common.storage.misc.StorageCredentials;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
@ -119,8 +123,8 @@ public abstract class HikariConnectionFactory implements ConnectionFactory {
}
@Override
public Map<String, String> getMeta() {
Map<String, String> meta = new LinkedHashMap<>();
public Map<Component, Component> getMeta() {
Map<Component, Component> meta = new LinkedHashMap<>();
boolean success = true;
long start = System.currentTimeMillis();
@ -134,11 +138,15 @@ public abstract class HikariConnectionFactory implements ConnectionFactory {
long duration = System.currentTimeMillis() - start;
if (success) {
meta.put("Ping", duration + "ms");
meta.put("Connected", "true");
} else {
meta.put("Connected", "false");
meta.put(
Component.translatable("luckperms.command.info.storage.meta.ping-key"),
Component.text(duration + "ms", NamedTextColor.GREEN)
);
}
meta.put(
Component.translatable("luckperms.command.info.storage.meta.connected-key"),
Message.formatBoolean(success)
);
return meta;
}

View File

@ -119,6 +119,10 @@ luckperms.command.info.server-brand-key=Server Brand
luckperms.command.info.server-version-key=Server Version
luckperms.command.info.storage-key=Storage
luckperms.command.info.storage-type-key=Type
luckperms.command.info.storage.meta.split-types-key=Types
luckperms.command.info.storage.meta.ping-key=Ping
luckperms.command.info.storage.meta.connected-key=Connected
luckperms.command.info.storage.meta.file-size-key=File Size
luckperms.command.info.extensions-key=Extensions
luckperms.command.info.messaging-key=Messaging
luckperms.command.info.instance-key=Instance