diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCalculatorFactory.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCalculatorFactory.java index d1f4415d..fb732ec5 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCalculatorFactory.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCalculatorFactory.java @@ -44,6 +44,7 @@ import me.lucko.luckperms.common.calculators.processors.WildcardProcessor; import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.core.model.User; +import java.util.List; import java.util.UUID; @AllArgsConstructor @@ -82,4 +83,16 @@ public class BukkitCalculatorFactory extends AbstractCalculatorFactory { return registerCalculator(new PermissionCalculator(plugin, user.getFriendlyName(), processors.build())); } + + @Override + public List getActiveProcessors() { + ImmutableList.Builder ret = ImmutableList.builder(); + ret.add("Map"); + if (plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_CHILD_PERMISSIONS)) ret.add("Child"); + if (plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_ATTACHMENT_PERMISSIONS)) ret.add("Attachment"); + if (plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) ret.add("Regex"); + if (plugin.getConfiguration().get(ConfigKeys.APPLYING_WILDCARDS)) ret.add("Wildcard"); + if (plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS)) ret.add("Defaults"); + return ret.build(); + } } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java index 76568c34..b80e537e 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java @@ -86,6 +86,8 @@ public class BukkitListener implements Listener { return; } + plugin.getUniqueConnections().add(e.getUniqueId()); + /* Actually process the login for the connection. We do this here to delay the login until the data is ready. If the login gets cancelled later on, then this will be cleaned up. diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java index d79c3f52..eddda439 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java @@ -107,6 +107,8 @@ import java.util.stream.Collectors; @Getter public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { private Set ignoringLogs; + private Set uniqueConnections; + private long startTime; private LPBukkitScheduler scheduler; private BukkitCommand commandManager; private VaultHook vaultHook = null; @@ -159,9 +161,11 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { } private void enable() { + startTime = System.currentTimeMillis(); LuckPermsPlugin.sendStartupBanner(getConsoleSender(), this); ignoringLogs = ConcurrentHashMap.newKeySet(); + uniqueConnections = ConcurrentHashMap.newKeySet(); verboseHandler = new VerboseHandler(scheduler.getAsyncBukkitExecutor(), getVersion()); permissionVault = new PermissionVault(scheduler.getAsyncBukkitExecutor()); @@ -349,7 +353,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { }); } - getLog().info("Successfully enabled."); + getLog().info("Successfully enabled. (took " + (System.currentTimeMillis() - startTime) + "ms)"); } @Override @@ -642,16 +646,8 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { public LinkedHashMap getExtraInfo() { LinkedHashMap map = new LinkedHashMap<>(); map.put("Vault Enabled", vaultHook != null); - map.put("Vault Server", configuration.get(ConfigKeys.VAULT_SERVER)); map.put("Bukkit Defaults count", defaultsProvider.size()); map.put("Bukkit Child Permissions count", childPermissionProvider.getPermissions().size()); - map.put("Vault Including Global", configuration.get(ConfigKeys.VAULT_INCLUDING_GLOBAL)); - map.put("Vault Ignoring World", configuration.get(ConfigKeys.VAULT_IGNORE_WORLD)); - map.put("Vault Primary Group Overrides", configuration.get(ConfigKeys.VAULT_PRIMARY_GROUP_OVERRIDES)); - map.put("Vault Debug", configuration.get(ConfigKeys.VAULT_DEBUG)); - map.put("OPs Enabled", configuration.get(ConfigKeys.OPS_ENABLED)); - map.put("Auto OP", configuration.get(ConfigKeys.AUTO_OP)); - map.put("Commands Allow OPs", configuration.get(ConfigKeys.COMMANDS_ALLOW_OP)); return map; } diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCalculatorFactory.java b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCalculatorFactory.java index 20d46708..8612e10c 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCalculatorFactory.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCalculatorFactory.java @@ -39,6 +39,8 @@ import me.lucko.luckperms.common.calculators.processors.WildcardProcessor; import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.core.model.User; +import java.util.List; + @AllArgsConstructor public class BungeeCalculatorFactory extends AbstractCalculatorFactory { private final LPBungeePlugin plugin; @@ -59,4 +61,13 @@ public class BungeeCalculatorFactory extends AbstractCalculatorFactory { return registerCalculator(new PermissionCalculator(plugin, user.getFriendlyName(), processors.build())); } + + @Override + public List getActiveProcessors() { + ImmutableList.Builder ret = ImmutableList.builder(); + ret.add("Map"); + if (plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) ret.add("Regex"); + if (plugin.getConfiguration().get(ConfigKeys.APPLYING_WILDCARDS)) ret.add("Wildcards"); + return ret.build(); + } } diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java index d601567b..ac793458 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java @@ -84,6 +84,8 @@ public class BungeeListener implements Listener { plugin.doAsync(() -> { + plugin.getUniqueConnections().add(c.getUniqueId()); + /* Actually process the login for the connection. We do this here to delay the login until the data is ready. If the login gets cancelled later on, then this will be cleaned up. diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java index f96d8a24..0dbda54d 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java @@ -91,6 +91,8 @@ import java.util.stream.Collectors; @Getter public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { private final Set ignoringLogs = ConcurrentHashMap.newKeySet(); + private Set uniqueConnections = ConcurrentHashMap.newKeySet(); + private long startTime; private LuckPermsScheduler scheduler; private CommandManager commandManager; private LuckPermsConfiguration configuration; @@ -125,6 +127,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { @Override public void onEnable() { + startTime = System.currentTimeMillis(); LuckPermsPlugin.sendStartupBanner(getConsoleSender(), this); verboseHandler = new VerboseHandler(scheduler.async(), getVersion()); permissionVault = new PermissionVault(scheduler.async()); @@ -256,7 +259,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { scheduler.asyncRepeating(new ExpireTemporaryTask(this), 60L); scheduler.asyncRepeating(new CacheHousekeepingTask(this), 2400L); - getLog().info("Successfully enabled."); + getLog().info("Successfully enabled. (took " + (System.currentTimeMillis() - startTime) + "ms)"); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/calculators/CalculatorFactory.java b/common/src/main/java/me/lucko/luckperms/common/calculators/CalculatorFactory.java index 56b0cb6e..cc89d78e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/calculators/CalculatorFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/calculators/CalculatorFactory.java @@ -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 getActiveProcessors(); + /** * Invalidates all calculators build by this factory */ diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/InfoCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/InfoCommand.java index c0537b97..76ddd983 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/InfoCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/InfoCommand.java @@ -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 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 storageInfo = plugin.getStorage().getMeta(); + + Message.EMPTY.send(sender, "&f- &bStorage:"); + Message.EMPTY.send(sender, "&f- &3Type: &f" + plugin.getStorage().getName()); + for (Map.Entry 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 platformInfo = plugin.getExtraInfo(); diff --git a/common/src/main/java/me/lucko/luckperms/common/locale/Message.java b/common/src/main/java/me/lucko/luckperms/common/locale/Message.java index 80575129..c185d38b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/locale/Message.java +++ b/common/src/main/java/me/lucko/luckperms/common/locale/Message.java @@ -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), diff --git a/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java b/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java index 3e76de15..5e41cedd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java +++ b/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java @@ -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 getUniqueConnections(); + /** * Gets a set of Contexts that should be pre-processed in advance * diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/AbstractStorage.java b/common/src/main/java/me/lucko/luckperms/common/storage/AbstractStorage.java index eba9b739..5c071a8f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/AbstractStorage.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/AbstractStorage.java @@ -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 getMeta(); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/SplitBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/SplitBacking.java index d4ef0d53..dda5d580 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/SplitBacking.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/SplitBacking.java @@ -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 getMeta() { + Map 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); diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/Storage.java b/common/src/main/java/me/lucko/luckperms/common/storage/Storage.java index 88c2509c..0b0e48a5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/Storage.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/Storage.java @@ -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 getMeta(); + CompletableFuture logAction(LogEntry entry); CompletableFuture getLog(); diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/AbstractBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/AbstractBacking.java index fb8e389f..a2cb83b1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/AbstractBacking.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/AbstractBacking.java @@ -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 getMeta() { + return Collections.emptyMap(); + } + public abstract boolean logAction(LogEntry entry); public abstract Log getLog(); diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/MongoDBBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/MongoDBBacking.java index eb8b7cbb..3ef880f0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/MongoDBBacking.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/MongoDBBacking.java @@ -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 getMeta() { + Map 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(() -> { diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/SQLBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/SQLBacking.java index 0bf382f0..2f6dde88 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/SQLBacking.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/SQLBacking.java @@ -208,6 +208,11 @@ public class SQLBacking extends AbstractBacking { } } + @Override + public Map getMeta() { + return provider.getMeta(); + } + @Override public boolean logAction(LogEntry entry) { try (Connection c = provider.getConnection()) { diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/FlatfileProvider.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/FlatfileProvider.java index f6014e79..b42c4fcd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/FlatfileProvider.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/FlatfileProvider.java @@ -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; diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/H2Provider.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/H2Provider.java index 8dbd1d70..0e2ccc62 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/H2Provider.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/H2Provider.java @@ -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 getMeta() { + Map 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"; diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/MySQLProvider.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/MySQLProvider.java index 80f128b4..a0d1e516 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/MySQLProvider.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/MySQLProvider.java @@ -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 getMeta() { + Map 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(); diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/PostgreSQLProvider.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/PostgreSQLProvider.java index 7cf38435..58b5cb64 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/PostgreSQLProvider.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/PostgreSQLProvider.java @@ -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 getMeta() { + Map 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(); diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/SQLProvider.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/SQLProvider.java index 2150929f..3b6b3198 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/SQLProvider.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/SQLProvider.java @@ -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 getMeta() { + return Collections.emptyMap(); + } + public abstract WrappedConnection getConnection() throws SQLException; } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/SQLiteProvider.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/SQLiteProvider.java index d3ea5632..837834be 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/SQLiteProvider.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/SQLiteProvider.java @@ -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 getMeta() { + Map 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"; diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/wrappings/PhasedStorage.java b/common/src/main/java/me/lucko/luckperms/common/storage/wrappings/PhasedStorage.java index dc008f72..a99cf688 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/wrappings/PhasedStorage.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/wrappings/PhasedStorage.java @@ -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 getMeta(); } } diff --git a/sponge/sponge-service-api7/pom.xml b/sponge/sponge-service-api7/pom.xml index a7b8d6d5..56965e76 100644 --- a/sponge/sponge-service-api7/pom.xml +++ b/sponge/sponge-service-api7/pom.xml @@ -54,7 +54,7 @@ org.spongepowered spongeapi - 7.0.0-SNAPSHOT + 7.0.0-20170716.103113-1 provided diff --git a/sponge/sponge-service/pom.xml b/sponge/sponge-service/pom.xml index aecdd2b5..ae8f3772 100644 --- a/sponge/sponge-service/pom.xml +++ b/sponge/sponge-service/pom.xml @@ -33,7 +33,7 @@ org.spongepowered spongeapi - 7.0.0-SNAPSHOT + 7.0.0-20170716.103113-1 provided true diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java index da1b62a7..1c2be11e 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java @@ -124,6 +124,7 @@ import java.util.stream.Collectors; public class LPSpongePlugin implements LuckPermsPlugin { private final Set ignoringLogs = ConcurrentHashMap.newKeySet(); + private Set uniqueConnections = ConcurrentHashMap.newKeySet(); @Inject private Logger logger; @@ -147,6 +148,7 @@ public class LPSpongePlugin implements LuckPermsPlugin { private LPTimings timings; private boolean lateLoad = false; + private long startTime; private LuckPermsScheduler scheduler; private SpongeCommand commandManager; @@ -172,6 +174,7 @@ public class LPSpongePlugin implements LuckPermsPlugin { @Listener(order = Order.FIRST) public void onEnable(GamePreInitializationEvent event) { + startTime = System.currentTimeMillis(); scheduler = new LPSpongeScheduler(this); localeManager = new NoopLocaleManager(); senderFactory = new SpongeSenderFactory(this); @@ -315,7 +318,7 @@ public class LPSpongePlugin implements LuckPermsPlugin { scheduler.asyncRepeating(new ServiceCacheHousekeepingTask(service), 2400L); // scheduler.asyncRepeating(() -> userManager.performCleanup(), 2400L); - getLog().info("Successfully enabled."); + getLog().info("Successfully enabled. (took " + (System.currentTimeMillis() - startTime) + "ms)"); } @Listener(order = Order.LATE) diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCalculatorFactory.java b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCalculatorFactory.java index d6a8f06b..3220d9f1 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCalculatorFactory.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCalculatorFactory.java @@ -41,6 +41,8 @@ import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.sponge.calculators.DefaultsProcessor; import me.lucko.luckperms.sponge.calculators.SpongeWildcardProcessor; +import java.util.List; + @AllArgsConstructor public class SpongeCalculatorFactory extends AbstractCalculatorFactory { private final LPSpongePlugin plugin; @@ -69,4 +71,15 @@ public class SpongeCalculatorFactory extends AbstractCalculatorFactory { return registerCalculator(new PermissionCalculator(plugin, user.getFriendlyName(), processors.build())); } + + @Override + public List getActiveProcessors() { + ImmutableList.Builder ret = ImmutableList.builder(); + ret.add("Map"); + if (plugin.getConfiguration().get(ConfigKeys.APPLY_SPONGE_IMPLICIT_WILDCARDS)) ret.add("SpongeWildcard"); + if (plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) ret.add("Regex"); + if (plugin.getConfiguration().get(ConfigKeys.APPLYING_WILDCARDS)) ret.add("Wildcards"); + if (plugin.getConfiguration().get(ConfigKeys.APPLY_SPONGE_DEFAULT_SUBJECTS)) ret.add("Defaults"); + return ret.build(); + } } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeListener.java b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeListener.java index ea614699..15e3cbe5 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeListener.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeListener.java @@ -90,6 +90,8 @@ public class SpongeListener { return; } + plugin.getUniqueConnections().add(p.getUniqueId()); + /* Actually process the login for the connection. We do this here to delay the login until the data is ready. If the login gets cancelled later on, then this will be cleaned up.