Update /lp info output

This commit is contained in:
Luck
2017-07-19 22:15:12 +01:00
Unverified
parent 400f3a9156
commit 3c44388883
28 changed files with 268 additions and 58 deletions
@@ -28,6 +28,8 @@ package me.lucko.luckperms.common.calculators;
import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.common.core.model.User;
import java.util.List;
/**
* Creates a calculator instance given a set of contexts
*/
@@ -42,6 +44,13 @@ public interface CalculatorFactory {
*/
PermissionCalculator build(Contexts contexts, User user);
/**
* Gets the processors which are currently being added to built calculators
*
* @return a list of processors
*/
List<String> getActiveProcessors();
/**
* Invalidates all calculators build by this factory
*/
@@ -37,13 +37,13 @@ import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.messaging.NoopMessagingService;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.DateUtil;
import me.lucko.luckperms.common.utils.Predicates;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import static me.lucko.luckperms.common.commands.utils.Util.formatBoolean;
import java.util.stream.Collectors;
public class InfoCommand extends SingleCommand {
public InfoCommand(LocaleManager locale) {
@@ -53,31 +53,34 @@ public class InfoCommand extends SingleCommand {
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
final LuckPermsConfiguration c = plugin.getConfiguration();
Message.INFO.send(sender,
Message.INFO_TOP.send(sender,
plugin.getVersion(),
plugin.getServerType().getFriendlyName(),
plugin.getStorage().getName(),
c.get(ConfigKeys.SERVER),
c.get(ConfigKeys.SYNC_TIME),
plugin.getServerName(),
plugin.getServerVersion()
);
Map<String, String> storageInfo = plugin.getStorage().getMeta();
Message.EMPTY.send(sender, "&f- &bStorage:");
Message.EMPTY.send(sender, "&f- &3Type: &f" + plugin.getStorage().getName());
for (Map.Entry<String, String> e : storageInfo.entrySet()) {
Message.EMPTY.send(sender, "&f- &3" + e.getKey() + ": " + formatValue(e.getValue()));
}
Message.INFO_MIDDLE.send(sender,
plugin.getMessagingService() instanceof NoopMessagingService ? "None" : plugin.getMessagingService().getName(),
c.get(ConfigKeys.SERVER),
plugin.getPlayerCount(),
plugin.getUniqueConnections().size(),
DateUtil.formatTime((System.currentTimeMillis() - plugin.getStartTime()) / 1000L),
plugin.getUserManager().getAll().size(),
plugin.getGroupManager().getAll().size(),
plugin.getTrackManager().getAll().size(),
plugin.getStorage().getLog().join().getContent().size(),
plugin.getUuidCache().getSize(),
plugin.getLocaleManager().getSize(),
plugin.getPreProcessContexts(false).size(),
plugin.getContextManager().getCalculatorsSize(),
plugin.getPermissionVault().getSize(),
formatBoolean(c.get(ConfigKeys.USE_SERVER_UUIDS)),
formatBoolean(c.get(ConfigKeys.INCLUDING_GLOBAL_PERMS)),
formatBoolean(c.get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS)),
formatBoolean(c.get(ConfigKeys.APPLYING_GLOBAL_GROUPS)),
formatBoolean(c.get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS)),
formatBoolean(c.get(ConfigKeys.APPLYING_WILDCARDS)),
formatBoolean(c.get(ConfigKeys.APPLYING_REGEX)),
formatBoolean(c.get(ConfigKeys.APPLYING_SHORTHAND))
plugin.getCalculatorFactory().getActiveProcessors().stream().collect(Collectors.joining(", "))
);
LinkedHashMap<String, Object> platformInfo = plugin.getExtraInfo();
@@ -172,34 +172,24 @@ public enum Message {
UPDATE_TASK_PUSH_FAILURE("&cError whilst pushing changes to other servers.", true),
UPDATE_TASK_PUSH_FAILURE_NOT_SETUP("&cError whilst pushing changes to other servers. A messaging service has not been configured.", true),
RELOAD_CONFIG_SUCCESS("&aThe configuration file was reloaded. &7(some options will only apply after the server has restarted.)", true),
INFO(
INFO_TOP(
"{PREFIX}&2Running &bLuckPerms v{0}&2 by &bLuck&2." + "\n" +
"{PREFIX}&f- &3Platform: &f{1}" + "\n" +
"{PREFIX}&f- &3Storage Method: &f{2}" + "\n" +
"{PREFIX}&f- &3Server Name: &f{3}" + "\n" +
"{PREFIX}&f- &3Sync Interval: &a{4} &fminutes" + "\n" +
"{PREFIX}&f- &3Messaging Service: &f{5}" + "\n" +
"{PREFIX}&f- &bCounts:" + "\n" +
"{PREFIX}&f- &3Online Players: &a{6}" + "\n" +
"{PREFIX}&f- &3Loaded Users: &a{7}" + "\n" +
"{PREFIX}&f- &3Loaded Groups: &a{8}" + "\n" +
"{PREFIX}&f- &3Loaded Tracks: &a{9}" + "\n" +
"{PREFIX}&f- &3Log size: &a{10}" + "\n" +
"{PREFIX}&f- &3UUID Cache size: &a{11}" + "\n" +
"{PREFIX}&f- &3Translations loaded: &a{12}" + "\n" +
"{PREFIX}&f- &3Pre-process contexts: &a{13}" + "\n" +
"{PREFIX}&f- &3Context Calculators: &a{14}" + "\n" +
"{PREFIX}&f- &3Unique permissions: &a{15}" + "\n" +
"{PREFIX}&f- &bConfiguration:" + "\n" +
"{PREFIX}&f- &3Use Server UUIDs: {16}" + "\n" +
"{PREFIX}&f- &bPermission Calculation:" + "\n" +
"{PREFIX}&f- &3Including Global: {17}" + "\n" +
"{PREFIX}&f- &3Including Global World: {18}" + "\n" +
"{PREFIX}&f- &3Applying Global Groups: {19}" + "\n" +
"{PREFIX}&f- &3Applying Global World Groups: {20}" + "\n" +
"{PREFIX}&f- &3Applying Wildcards: {21}" + "\n" +
"{PREFIX}&f- &3Applying Regex: {22}" + "\n" +
"{PREFIX}&f- &3Applying Shorthand: {23}",
"{PREFIX}&f- &3Server Brand: &f{2}" + "\n" +
"{PREFIX}&f- &3Server Version: &f{3}",
false
),
INFO_MIDDLE(
"{PREFIX}&f- &bMessaging Type: &f{0}" + "\n" +
"{PREFIX}&f- &bInstance:" + "\n" +
"{PREFIX}&f- &3Server Name: &f{1}" + "\n" +
"{PREFIX}&f- &3Online Players: &a{2}" + "\n" +
"{PREFIX}&f- &3Unique Connections: &a{3}" + "\n" +
"{PREFIX}&f- &3Uptime: &7{4}" + "\n" +
"{PREFIX}&f- &3Local Data: &a{5} &7users, &a{6} &7groups, &a{7} &7tracks" + "\n" +
"{PREFIX}&f- &3Context Calculators: &a{8}" + "\n" +
"{PREFIX}&f- &3Known permissions: &a{9}" + "\n" +
"{PREFIX}&f- &3Active processors: &7{10}",
false
),
CREATE_GROUP_ERROR("There was an error whilst creating the group.", true),
@@ -222,6 +222,13 @@ public interface LuckPermsPlugin {
*/
String getServerVersion();
/**
* Gets the time when the plugin first started in millis.
*
* @return the enable time
*/
long getStartTime();
/**
* Gets the file watcher running on the platform, or null if it's not enabled.
*
@@ -345,6 +352,13 @@ public interface LuckPermsPlugin {
*/
Sender getConsoleSender();
/**
* Gets the unique players which have connected to the server since it started.
*
* @return the unique connections
*/
Set<UUID> getUniqueConnections();
/**
* Gets a set of Contexts that should be pre-processed in advance
*
@@ -46,6 +46,7 @@ import me.lucko.luckperms.common.storage.wrappings.BufferedOutputStorage;
import me.lucko.luckperms.common.storage.wrappings.PhasedStorage;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@@ -258,5 +259,6 @@ public class AbstractStorage implements Storage {
void setAcceptingLogins(boolean b);
void init();
void shutdown();
Map<String, String> getMeta();
}
}
@@ -37,6 +37,7 @@ import me.lucko.luckperms.common.data.Log;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.storage.backing.AbstractBacking;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -70,6 +71,16 @@ public class SplitBacking extends AbstractBacking {
backing.values().forEach(AbstractBacking::shutdown);
}
@Override
public Map<String, String> getMeta() {
Map<String, String> ret = new LinkedHashMap<>();
ret.put("Types", types.toString());
for (AbstractBacking backing : backing.values()) {
ret.putAll(backing.getMeta());
}
return ret;
}
@Override
public boolean logAction(LogEntry entry) {
return backing.get(types.get("log")).logAction(entry);
@@ -37,6 +37,7 @@ import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.data.Log;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@@ -60,6 +61,8 @@ public interface Storage {
void shutdown();
Map<String, String> getMeta();
CompletableFuture<Boolean> logAction(LogEntry entry);
CompletableFuture<Log> getLog();
@@ -39,7 +39,9 @@ import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.data.Log;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
@@ -60,6 +62,10 @@ public abstract class AbstractBacking {
public abstract void shutdown();
public Map<String, String> getMeta() {
return Collections.emptyMap();
}
public abstract boolean logAction(LogEntry entry);
public abstract Log getLog();
@@ -60,6 +60,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -182,6 +183,29 @@ public class MongoDBBacking extends AbstractBacking {
}
}
@Override
public Map<String, String> getMeta() {
Map<String, String> ret = new LinkedHashMap<>();
boolean success = true;
long start = System.currentTimeMillis();
try {
database.runCommand(new Document("ping", 1));
} catch (Exception e) {
success = false;
}
long duration = System.currentTimeMillis() - start;
if (success) {
ret.put("Ping", "&a" + duration + "ms");
ret.put("Connected", "true");
} else {
ret.put("Connected", "false");
}
return ret;
}
@Override
public boolean logAction(LogEntry entry) {
return call(() -> {
@@ -208,6 +208,11 @@ public class SQLBacking extends AbstractBacking {
}
}
@Override
public Map<String, String> getMeta() {
return provider.getMeta();
}
@Override
public boolean logAction(LogEntry entry) {
try (Connection c = provider.getConnection()) {
@@ -29,11 +29,13 @@ import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.concurrent.locks.ReentrantLock;
abstract class FlatfileProvider extends SQLProvider {
protected static final DecimalFormat DF = new DecimalFormat("#.00");
private final File file;
protected final File file;
private final ReentrantLock lock = new ReentrantLock();
private WrappedConnection connection;
@@ -26,6 +26,8 @@
package me.lucko.luckperms.common.storage.backing.sqlprovider;
import java.io.File;
import java.util.LinkedHashMap;
import java.util.Map;
public class H2Provider extends FlatfileProvider {
public H2Provider(File file) {
@@ -38,6 +40,20 @@ public class H2Provider extends FlatfileProvider {
}
}
@Override
public Map<String, String> getMeta() {
Map<String, String> ret = new LinkedHashMap<>();
File databaseFile = new File(super.file.getParent(), "luckperms-h2.mv.db");
if (databaseFile.exists()) {
ret.put("File Size", DF.format(databaseFile.length() / 1048576) + "MB");
} else {
ret.put("File Size", "0MB");
}
return ret;
}
@Override
protected String getDriverClass() {
return "org.h2.Driver";
@@ -32,6 +32,9 @@ import me.lucko.luckperms.common.storage.DatastoreConfiguration;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
public class MySQLProvider extends SQLProvider {
@@ -113,6 +116,31 @@ public class MySQLProvider extends SQLProvider {
}
}
@Override
public Map<String, String> getMeta() {
Map<String, String> ret = new LinkedHashMap<>();
boolean success = true;
long start = System.currentTimeMillis();
try (Connection c = hikari.getConnection()) {
try (Statement s = c.createStatement()) {
s.execute("/* ping */ SELECT 1");
}
} catch (SQLException e) {
success = false;
}
long duration = System.currentTimeMillis() - start;
if (success) {
ret.put("Ping", "&a" + duration + "ms");
ret.put("Connected", "true");
} else {
ret.put("Connected", "false");
}
return ret;
}
@Override
public WrappedConnection getConnection() throws SQLException {
Connection connection = hikari.getConnection();
@@ -32,6 +32,9 @@ import me.lucko.luckperms.common.storage.DatastoreConfiguration;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
public class PostgreSQLProvider extends SQLProvider {
@@ -87,6 +90,31 @@ public class PostgreSQLProvider extends SQLProvider {
}
}
@Override
public Map<String, String> getMeta() {
Map<String, String> ret = new LinkedHashMap<>();
boolean success = true;
long start = System.currentTimeMillis();
try (Connection c = hikari.getConnection()) {
try (Statement s = c.createStatement()) {
s.execute("/* ping */ SELECT 1");
}
} catch (SQLException e) {
success = false;
}
long duration = System.currentTimeMillis() - start;
if (success) {
ret.put("Ping", "&a" + duration + "ms");
ret.put("Connected", "true");
} else {
ret.put("Connected", "false");
}
return ret;
}
@Override
public WrappedConnection getConnection() throws SQLException {
Connection connection = hikari.getConnection();
@@ -29,6 +29,8 @@ import lombok.Getter;
import lombok.RequiredArgsConstructor;
import java.sql.SQLException;
import java.util.Collections;
import java.util.Map;
@RequiredArgsConstructor
public abstract class SQLProvider {
@@ -40,6 +42,10 @@ public abstract class SQLProvider {
public abstract void shutdown() throws Exception;
public Map<String, String> getMeta() {
return Collections.emptyMap();
}
public abstract WrappedConnection getConnection() throws SQLException;
}
@@ -26,6 +26,8 @@
package me.lucko.luckperms.common.storage.backing.sqlprovider;
import java.io.File;
import java.util.LinkedHashMap;
import java.util.Map;
public class SQLiteProvider extends FlatfileProvider {
public SQLiteProvider(File file) {
@@ -38,6 +40,20 @@ public class SQLiteProvider extends FlatfileProvider {
}
}
@Override
public Map<String, String> getMeta() {
Map<String, String> ret = new LinkedHashMap<>();
File databaseFile = new File(super.file.getParent(), "luckperms-sqlite.db");
if (databaseFile.exists()) {
ret.put("File Size", DF.format(databaseFile.length() / 1048576) + "MB");
} else {
ret.put("File Size", "0MB");
}
return ret;
}
@Override
protected String getDriverClass() {
return "org.sqlite.JDBC";
@@ -42,6 +42,7 @@ import me.lucko.luckperms.common.data.Log;
import me.lucko.luckperms.common.storage.Storage;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@@ -306,5 +307,6 @@ public class PhasedStorage implements Storage {
boolean isAcceptingLogins();
void setAcceptingLogins(boolean b);
void init();
Map<String, String> getMeta();
}
}