From e4acc133a943f51ddf5c1166bce40dace6fc5989 Mon Sep 17 00:00:00 2001 From: Luck Date: Tue, 12 Jun 2018 18:18:38 +0100 Subject: [PATCH] remove some unnecessary interfaces --- .../luckperms/bukkit/LPBukkitPlugin.java | 4 +- .../bukkit/contexts/BukkitContextManager.java | 4 +- .../listeners/BukkitConnectionListener.java | 2 +- .../bukkit/migration/BukkitUuids.java | 2 +- .../migration/MigrationBPermissions.java | 2 +- .../migration/MigrationGroupManager.java | 2 +- .../migration/MigrationPermissionsBukkit.java | 2 +- .../migration/MigrationPermissionsEx.java | 2 +- .../migration/MigrationPowerfulPerms.java | 2 +- .../migration/MigrationZPermissions.java | 2 +- .../bungee/BungeeSchedulerAdapter.java | 2 +- .../luckperms/bungee/LPBungeePlugin.java | 4 +- .../bungee/contexts/BungeeContextManager.java | 4 +- .../listeners/BungeeConnectionListener.java | 2 +- .../migration/MigrationBungeePerms.java | 2 +- .../luckperms/common/backup/Exporter.java | 2 +- .../common/buffers/BufferedRequest.java | 2 +- .../contexts/AbstractContextManager.java | 238 ------------------ .../common/contexts/ContextManager.java | 225 ++++++++++++++--- .../common/contexts/ContextsCache.java | 6 +- ...r.java => LPStaticContextsCalculator.java} | 4 +- .../common/listener/ConnectionListener.java | 43 ---- .../common/locale/LocaleManager.java | 102 +++++++- .../common/locale/SimpleLocaleManager.java | 137 ---------- .../common/locale/command/CommandSpec.java | 78 +----- .../locale/command/LocalizedCommandSpec.java | 63 ++++- .../luckperms/common/logging/Logger.java | 42 ---- .../common/messaging/sql/SqlMessenger.java | 2 +- .../comparator/HeldPermissionComparator.java | 5 +- .../plugin/AbstractLuckPermsPlugin.java | 16 +- .../common/plugin/LuckPermsPlugin.java | 8 +- .../scheduler/AbstractJavaScheduler.java | 2 - .../plugin/scheduler/SchedulerAdapter.java | 2 - .../plugin/{ => scheduler}/SchedulerTask.java | 2 +- .../util}/AbstractConnectionListener.java | 10 +- .../util/PluginLogger.java} | 15 +- .../{logging => utils}/ProgressLogger.java | 2 +- .../luckperms/common/utils/RepeatingTask.java | 2 +- .../luckperms/nukkit/LPNukkitPlugin.java | 4 +- .../nukkit/contexts/NukkitContextManager.java | 4 +- .../listeners/NukkitConnectionListener.java | 2 +- .../sponge/SpongeSchedulerAdapter.java | 2 +- .../sponge/contexts/SpongeContextManager.java | 4 +- .../listeners/SpongeConnectionListener.java | 2 +- 44 files changed, 414 insertions(+), 650 deletions(-) delete mode 100644 common/src/main/java/me/lucko/luckperms/common/contexts/AbstractContextManager.java rename common/src/main/java/me/lucko/luckperms/common/contexts/{LuckPermsCalculator.java => LPStaticContextsCalculator.java} (93%) delete mode 100644 common/src/main/java/me/lucko/luckperms/common/listener/ConnectionListener.java delete mode 100644 common/src/main/java/me/lucko/luckperms/common/locale/SimpleLocaleManager.java delete mode 100644 common/src/main/java/me/lucko/luckperms/common/logging/Logger.java rename common/src/main/java/me/lucko/luckperms/common/plugin/{ => scheduler}/SchedulerTask.java (96%) rename common/src/main/java/me/lucko/luckperms/common/{listener => plugin/util}/AbstractConnectionListener.java (95%) rename common/src/main/java/me/lucko/luckperms/common/{logging/SenderLogger.java => plugin/util/PluginLogger.java} (85%) rename common/src/main/java/me/lucko/luckperms/common/{logging => utils}/ProgressLogger.java (98%) 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 c4f1b294..a91ec29c 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java @@ -53,13 +53,13 @@ import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter; import me.lucko.luckperms.common.contexts.ContextManager; import me.lucko.luckperms.common.dependencies.Dependency; import me.lucko.luckperms.common.event.AbstractEventBus; -import me.lucko.luckperms.common.listener.ConnectionListener; import me.lucko.luckperms.common.managers.group.StandardGroupManager; import me.lucko.luckperms.common.managers.track.StandardTrackManager; import me.lucko.luckperms.common.managers.user.StandardUserManager; import me.lucko.luckperms.common.messaging.MessagingFactory; import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.plugin.AbstractLuckPermsPlugin; +import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.tasks.CacheHousekeepingTask; import me.lucko.luckperms.common.tasks.ExpireTemporaryTask; @@ -350,7 +350,7 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin { } @Override - public ConnectionListener getConnectionListener() { + public AbstractConnectionListener getConnectionListener() { return this.connectionListener; } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/contexts/BukkitContextManager.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/contexts/BukkitContextManager.java index 4da776c6..92045825 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/contexts/BukkitContextManager.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/contexts/BukkitContextManager.java @@ -30,13 +30,13 @@ import me.lucko.luckperms.api.LookupSetting; import me.lucko.luckperms.api.context.ImmutableContextSet; import me.lucko.luckperms.bukkit.LPBukkitPlugin; import me.lucko.luckperms.common.config.ConfigKeys; -import me.lucko.luckperms.common.contexts.AbstractContextManager; +import me.lucko.luckperms.common.contexts.ContextManager; import org.bukkit.entity.Player; import java.util.EnumSet; -public class BukkitContextManager extends AbstractContextManager { +public class BukkitContextManager extends ContextManager { public BukkitContextManager(LPBukkitPlugin plugin) { super(plugin, Player.class); } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/listeners/BukkitConnectionListener.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/listeners/BukkitConnectionListener.java index 8fae5b91..d9174b11 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/listeners/BukkitConnectionListener.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/listeners/BukkitConnectionListener.java @@ -29,9 +29,9 @@ import me.lucko.luckperms.bukkit.LPBukkitPlugin; import me.lucko.luckperms.bukkit.model.permissible.LPPermissible; import me.lucko.luckperms.bukkit.model.permissible.PermissibleInjector; import me.lucko.luckperms.common.config.ConfigKeys; -import me.lucko.luckperms.common.listener.AbstractConnectionListener; import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.model.User; +import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/BukkitUuids.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/BukkitUuids.java index d242eed9..75c374b4 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/BukkitUuids.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/BukkitUuids.java @@ -25,7 +25,7 @@ package me.lucko.luckperms.bukkit.migration; -import me.lucko.luckperms.common.logging.ProgressLogger; +import me.lucko.luckperms.common.utils.ProgressLogger; import me.lucko.luckperms.common.utils.Uuids; import org.bukkit.Bukkit; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java index a0e09b49..861a53b8 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java @@ -38,7 +38,6 @@ import me.lucko.luckperms.common.command.abstraction.SubCommand; import me.lucko.luckperms.common.commands.migration.MigrationUtils; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; -import me.lucko.luckperms.common.logging.ProgressLogger; import me.lucko.luckperms.common.model.Group; import me.lucko.luckperms.common.model.PermissionHolder; import me.lucko.luckperms.common.model.User; @@ -48,6 +47,7 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.utils.Iterators; import me.lucko.luckperms.common.utils.Predicates; +import me.lucko.luckperms.common.utils.ProgressLogger; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java index 67ef7276..e4ac517a 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java @@ -34,7 +34,6 @@ import me.lucko.luckperms.common.command.access.CommandPermission; import me.lucko.luckperms.common.commands.migration.MigrationUtils; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; -import me.lucko.luckperms.common.logging.ProgressLogger; import me.lucko.luckperms.common.model.Group; import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.model.UserIdentifier; @@ -44,6 +43,7 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.utils.Iterators; import me.lucko.luckperms.common.utils.Predicates; +import me.lucko.luckperms.common.utils.ProgressLogger; import me.lucko.luckperms.common.utils.Uuids; import org.anjocaido.groupmanager.GlobalGroups; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsBukkit.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsBukkit.java index 306639cc..74825ac6 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsBukkit.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsBukkit.java @@ -34,7 +34,6 @@ import me.lucko.luckperms.common.command.access.CommandPermission; import me.lucko.luckperms.common.commands.migration.MigrationUtils; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; -import me.lucko.luckperms.common.logging.ProgressLogger; import me.lucko.luckperms.common.model.Group; import me.lucko.luckperms.common.model.PermissionHolder; import me.lucko.luckperms.common.model.User; @@ -43,6 +42,7 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.utils.Iterators; import me.lucko.luckperms.common.utils.Predicates; +import me.lucko.luckperms.common.utils.ProgressLogger; import org.bukkit.Bukkit; import org.bukkit.configuration.ConfigurationSection; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java index af9d26f8..47d303e1 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java @@ -34,7 +34,6 @@ import me.lucko.luckperms.common.command.access.CommandPermission; import me.lucko.luckperms.common.commands.migration.MigrationUtils; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; -import me.lucko.luckperms.common.logging.ProgressLogger; import me.lucko.luckperms.common.model.Group; import me.lucko.luckperms.common.model.PermissionHolder; import me.lucko.luckperms.common.model.Track; @@ -45,6 +44,7 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.utils.Iterators; import me.lucko.luckperms.common.utils.Predicates; +import me.lucko.luckperms.common.utils.ProgressLogger; import org.bukkit.Bukkit; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java index 3b9d3467..32ad60f0 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java @@ -41,7 +41,6 @@ import me.lucko.luckperms.common.commands.migration.MigrationUtils; import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; -import me.lucko.luckperms.common.logging.ProgressLogger; import me.lucko.luckperms.common.model.PermissionHolder; import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.node.factory.NodeFactory; @@ -50,6 +49,7 @@ import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.storage.StorageType; import me.lucko.luckperms.common.utils.Iterators; import me.lucko.luckperms.common.utils.Predicates; +import me.lucko.luckperms.common.utils.ProgressLogger; import org.bukkit.Bukkit; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java index 13e886c7..63e4d5c6 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java @@ -34,7 +34,6 @@ import me.lucko.luckperms.common.command.access.CommandPermission; import me.lucko.luckperms.common.commands.migration.MigrationUtils; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; -import me.lucko.luckperms.common.logging.ProgressLogger; import me.lucko.luckperms.common.model.Group; import me.lucko.luckperms.common.model.PermissionHolder; import me.lucko.luckperms.common.model.Track; @@ -45,6 +44,7 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.utils.Iterators; import me.lucko.luckperms.common.utils.Predicates; +import me.lucko.luckperms.common.utils.ProgressLogger; import org.bukkit.Bukkit; import org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService; diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeSchedulerAdapter.java b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeSchedulerAdapter.java index 0289ea78..bc792d6a 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeSchedulerAdapter.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeSchedulerAdapter.java @@ -25,8 +25,8 @@ package me.lucko.luckperms.bungee; -import me.lucko.luckperms.common.plugin.SchedulerTask; import me.lucko.luckperms.common.plugin.scheduler.SchedulerAdapter; +import me.lucko.luckperms.common.plugin.scheduler.SchedulerTask; import me.lucko.luckperms.common.utils.Iterators; import net.md_5.bungee.api.scheduler.ScheduledTask; 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 a710aa20..e2ed44a1 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java @@ -41,13 +41,13 @@ import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter; import me.lucko.luckperms.common.contexts.ContextManager; import me.lucko.luckperms.common.dependencies.Dependency; import me.lucko.luckperms.common.event.AbstractEventBus; -import me.lucko.luckperms.common.listener.ConnectionListener; import me.lucko.luckperms.common.managers.group.StandardGroupManager; import me.lucko.luckperms.common.managers.track.StandardTrackManager; import me.lucko.luckperms.common.managers.user.StandardUserManager; import me.lucko.luckperms.common.messaging.MessagingFactory; import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.plugin.AbstractLuckPermsPlugin; +import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.tasks.CacheHousekeepingTask; import me.lucko.luckperms.common.tasks.ExpireTemporaryTask; @@ -209,7 +209,7 @@ public class LPBungeePlugin extends AbstractLuckPermsPlugin { } @Override - public ConnectionListener getConnectionListener() { + public AbstractConnectionListener getConnectionListener() { return this.connectionListener; } diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/contexts/BungeeContextManager.java b/bungee/src/main/java/me/lucko/luckperms/bungee/contexts/BungeeContextManager.java index 3086e203..ade800eb 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/contexts/BungeeContextManager.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/contexts/BungeeContextManager.java @@ -28,11 +28,11 @@ package me.lucko.luckperms.bungee.contexts; import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.context.ImmutableContextSet; import me.lucko.luckperms.bungee.LPBungeePlugin; -import me.lucko.luckperms.common.contexts.AbstractContextManager; +import me.lucko.luckperms.common.contexts.ContextManager; import net.md_5.bungee.api.connection.ProxiedPlayer; -public class BungeeContextManager extends AbstractContextManager { +public class BungeeContextManager extends ContextManager { public BungeeContextManager(LPBungeePlugin plugin) { super(plugin, ProxiedPlayer.class); } diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeeConnectionListener.java b/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeeConnectionListener.java index 1e6e8582..7d3b261f 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeeConnectionListener.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeeConnectionListener.java @@ -27,9 +27,9 @@ package me.lucko.luckperms.bungee.listeners; import me.lucko.luckperms.bungee.LPBungeePlugin; import me.lucko.luckperms.common.config.ConfigKeys; -import me.lucko.luckperms.common.listener.AbstractConnectionListener; import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.model.User; +import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.PendingConnection; diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java b/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java index 91a4e404..8913b27d 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java @@ -32,13 +32,13 @@ import me.lucko.luckperms.common.command.access.CommandPermission; import me.lucko.luckperms.common.commands.migration.MigrationUtils; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; -import me.lucko.luckperms.common.logging.ProgressLogger; import me.lucko.luckperms.common.model.PermissionHolder; import me.lucko.luckperms.common.node.factory.NodeFactory; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.utils.Iterators; import me.lucko.luckperms.common.utils.Predicates; +import me.lucko.luckperms.common.utils.ProgressLogger; import net.alpenblock.bungeeperms.BungeePerms; import net.alpenblock.bungeeperms.Group; diff --git a/common/src/main/java/me/lucko/luckperms/common/backup/Exporter.java b/common/src/main/java/me/lucko/luckperms/common/backup/Exporter.java index bf04db0c..92ef2c5d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/backup/Exporter.java +++ b/common/src/main/java/me/lucko/luckperms/common/backup/Exporter.java @@ -27,7 +27,6 @@ package me.lucko.luckperms.common.backup; import me.lucko.luckperms.api.Node; import me.lucko.luckperms.common.locale.message.Message; -import me.lucko.luckperms.common.logging.ProgressLogger; import me.lucko.luckperms.common.model.Group; import me.lucko.luckperms.common.model.HolderType; import me.lucko.luckperms.common.model.Track; @@ -36,6 +35,7 @@ import me.lucko.luckperms.common.node.factory.NodeFactory; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.storage.Storage; +import me.lucko.luckperms.common.utils.ProgressLogger; import java.io.BufferedWriter; import java.io.IOException; diff --git a/common/src/main/java/me/lucko/luckperms/common/buffers/BufferedRequest.java b/common/src/main/java/me/lucko/luckperms/common/buffers/BufferedRequest.java index 1dc4a5f9..abe30cbe 100644 --- a/common/src/main/java/me/lucko/luckperms/common/buffers/BufferedRequest.java +++ b/common/src/main/java/me/lucko/luckperms/common/buffers/BufferedRequest.java @@ -25,8 +25,8 @@ package me.lucko.luckperms.common.buffers; -import me.lucko.luckperms.common.plugin.SchedulerTask; import me.lucko.luckperms.common.plugin.scheduler.SchedulerAdapter; +import me.lucko.luckperms.common.plugin.scheduler.SchedulerTask; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; diff --git a/common/src/main/java/me/lucko/luckperms/common/contexts/AbstractContextManager.java b/common/src/main/java/me/lucko/luckperms/common/contexts/AbstractContextManager.java deleted file mode 100644 index 61dcdba4..00000000 --- a/common/src/main/java/me/lucko/luckperms/common/contexts/AbstractContextManager.java +++ /dev/null @@ -1,238 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.lucko.luckperms.common.contexts; - -import com.github.benmanes.caffeine.cache.Caffeine; -import com.github.benmanes.caffeine.cache.LoadingCache; -import com.google.common.collect.ImmutableList; - -import me.lucko.luckperms.api.Contexts; -import me.lucko.luckperms.api.caching.MetaContexts; -import me.lucko.luckperms.api.context.ContextCalculator; -import me.lucko.luckperms.api.context.ImmutableContextSet; -import me.lucko.luckperms.api.context.MutableContextSet; -import me.lucko.luckperms.api.context.StaticContextCalculator; -import me.lucko.luckperms.common.buffers.ExpiringCache; -import me.lucko.luckperms.common.config.ConfigKeys; -import me.lucko.luckperms.common.plugin.LuckPermsPlugin; - -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; - -import javax.annotation.Nonnull; - -/** - * An abstract implementation of {@link ContextManager} which caches content lookups. - * - * @param the calculator type - */ -public abstract class AbstractContextManager implements ContextManager { - - protected final LuckPermsPlugin plugin; - private final Class subjectClass; - - private final List> calculators = new CopyOnWriteArrayList<>(); - private final List staticCalculators = new CopyOnWriteArrayList<>(); - - // caches the creation of cache instances. cache-ception. - // we want to encourage re-use of these instances, it's faster that way - private final LoadingCache> subjectCaches = Caffeine.newBuilder() - .weakKeys() - .build(key -> new ContextsCache<>(key, this)); - - // caches static context lookups - private final StaticLookupCache staticLookupCache = new StaticLookupCache(); - - protected AbstractContextManager(LuckPermsPlugin plugin, Class subjectClass) { - this.plugin = plugin; - this.subjectClass = subjectClass; - } - - @Override - public List> getCalculators() { - return ImmutableList.copyOf(this.calculators); - } - - @Override - public List getStaticCalculators() { - return ImmutableList.copyOf(this.staticCalculators); - } - - @Override - public Class getSubjectClass() { - return this.subjectClass; - } - - @Override - public ImmutableContextSet getApplicableContext(T subject) { - return getCacheFor(subject).getContextSet(); - } - - @Override - public Contexts getApplicableContexts(T subject) { - return getCacheFor(subject).getContexts(); - } - - @Override - public ContextsCache getCacheFor(T subject) { - if (subject == null) { - throw new NullPointerException("subject"); - } - return this.subjectCaches.get(subject); - } - - @Override - public ImmutableContextSet getStaticContext() { - // this is actually already immutable, but the Contexts method signature returns the interface. - // using the makeImmutable method is faster than casting - return getStaticContexts().getContexts().makeImmutable(); - } - - @Override - public Contexts getStaticContexts() { - return this.staticLookupCache.get(); - } - - @Override - public Optional getStaticContextString() { - Set> entries = getStaticContext().toSet(); - if (entries.isEmpty()) { - return Optional.empty(); - } - - // effectively: if entries contains any non-server keys - if (entries.stream().anyMatch(pair -> !pair.getKey().equals(Contexts.SERVER_KEY))) { - // return all entries in 'key=value' form - return Optional.of(entries.stream().map(pair -> pair.getKey() + "=" + pair.getValue()).collect(Collectors.joining(";"))); - } else { - // just return the server ids, without the 'server=' - return Optional.of(entries.stream().map(Map.Entry::getValue).collect(Collectors.joining(";"))); - } - } - - @Override - public Contexts formContexts(ImmutableContextSet contextSet) { - return Contexts.of(contextSet, this.plugin.getConfiguration().get(ConfigKeys.LOOKUP_SETTINGS)); - } - - @Override - public MetaContexts formMetaContexts(Contexts contexts) { - return new MetaContexts( - contexts, - this.plugin.getConfiguration().get(ConfigKeys.PREFIX_FORMATTING_OPTIONS), - this.plugin.getConfiguration().get(ConfigKeys.SUFFIX_FORMATTING_OPTIONS) - ); - } - - @Override - public void registerCalculator(ContextCalculator calculator) { - // calculators registered first should have priority (and be checked last.) - this.calculators.add(0, calculator); - } - - @Override - public void registerStaticCalculator(StaticContextCalculator calculator) { - registerCalculator(calculator); - this.staticCalculators.add(0, calculator); - } - - @Override - public void invalidateCache(T subject) { - if (subject == null) { - throw new NullPointerException("subject"); - } - - this.subjectCaches.invalidate(subject); - } - - Contexts calculate(T subject) { - MutableContextSet accumulator = MutableContextSet.create(); - - for (ContextCalculator calculator : AbstractContextManager.this.calculators) { - try { - MutableContextSet ret = calculator.giveApplicableContext(subject, accumulator); - //noinspection ConstantConditions - if (ret == null) { - throw new IllegalStateException(calculator.getClass() + " returned a null context set"); - } - accumulator = ret; - } catch (Exception e) { - AbstractContextManager.this.plugin.getLogger().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst calculating the context of subject " + subject); - e.printStackTrace(); - } - } - - return formContexts(subject, accumulator.makeImmutable()); - } - - private Contexts calculateStatic() { - MutableContextSet accumulator = MutableContextSet.create(); - - for (StaticContextCalculator calculator : this.staticCalculators) { - try { - MutableContextSet ret = calculator.giveApplicableContext(accumulator); - //noinspection ConstantConditions - if (ret == null) { - throw new IllegalStateException(calculator.getClass() + " returned a null context set"); - } - accumulator = ret; - } catch (Exception e) { - this.plugin.getLogger().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst calculating static contexts"); - e.printStackTrace(); - } - } - - return formContexts(accumulator.makeImmutable()); - } - - private final class StaticLookupCache extends ExpiringCache { - StaticLookupCache() { - super(50L, TimeUnit.MILLISECONDS); - } - - @Nonnull - @Override - public Contexts supply() { - return calculateStatic(); - } - } - - private static String getCalculatorClass(ContextCalculator calculator) { - Class calculatorClass; - if (calculator instanceof ProxiedContextCalculator) { - calculatorClass = ((ProxiedContextCalculator) calculator).getDelegate().getClass(); - } else { - calculatorClass = calculator.getClass(); - } - return calculatorClass.getName(); - } - -} diff --git a/common/src/main/java/me/lucko/luckperms/common/contexts/ContextManager.java b/common/src/main/java/me/lucko/luckperms/common/contexts/ContextManager.java index 80e039df..d0d3dc7e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/contexts/ContextManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/contexts/ContextManager.java @@ -25,29 +25,83 @@ package me.lucko.luckperms.common.contexts; +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.LoadingCache; +import com.google.common.collect.ImmutableList; + import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.caching.MetaContexts; import me.lucko.luckperms.api.context.ContextCalculator; import me.lucko.luckperms.api.context.ImmutableContextSet; +import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.api.context.StaticContextCalculator; +import me.lucko.luckperms.common.buffers.ExpiringCache; +import me.lucko.luckperms.common.config.ConfigKeys; +import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import java.util.List; +import java.util.Map; import java.util.Optional; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +import javax.annotation.Nonnull; /** - * Manages {@link ContextCalculator}s, and calculates applicable contexts for a - * given type. + * Base implementation of {@link ContextManager} which caches content lookups. * * @param the calculator type */ -public interface ContextManager { +public abstract class ContextManager { + + protected final LuckPermsPlugin plugin; + private final Class subjectClass; + + private final List> calculators = new CopyOnWriteArrayList<>(); + private final List staticCalculators = new CopyOnWriteArrayList<>(); + + // caches the creation of cache instances. cache-ception. + // we want to encourage re-use of these instances, it's faster that way + private final LoadingCache> subjectCaches = Caffeine.newBuilder() + .weakKeys() + .build(key -> new ContextsCache<>(key, this)); + + // caches static context lookups + private final StaticLookupCache staticLookupCache = new StaticLookupCache(); + + protected ContextManager(LuckPermsPlugin plugin, Class subjectClass) { + this.plugin = plugin; + this.subjectClass = subjectClass; + } + + /** + * Gets the calculators registered on the platform + * + * @return the registered calculators + */ + public List> getCalculators() { + return ImmutableList.copyOf(this.calculators); + } + + /** + * Gets the static calculators registered on the platform + * + * @return the registered static calculators + */ + public List getStaticCalculators() { + return ImmutableList.copyOf(this.staticCalculators); + } /** * Gets the class of the subject handled by this instance * * @return the subject class */ - Class getSubjectClass(); + public Class getSubjectClass() { + return this.subjectClass; + } /** * Queries the ContextManager for current context values for the subject. @@ -55,15 +109,19 @@ public interface ContextManager { * @param subject the subject * @return the applicable context for the subject */ - ImmutableContextSet getApplicableContext(T subject); + public ImmutableContextSet getApplicableContext(T subject) { + return getCacheFor(subject).getContextSet(); + } /** - * Queries the ContextManager for current context values for the subject. - * - * @param subject the subject - * @return the applicable context for the subject - */ - Contexts getApplicableContexts(T subject); + * Queries the ContextManager for current context values for the subject. + * + * @param subject the subject + * @return the applicable context for the subject + */ + public Contexts getApplicableContexts(T subject) { + return getCacheFor(subject).getContexts(); + } /** * Gets the cache instance for the given subject. @@ -71,21 +129,32 @@ public interface ContextManager { * @param subject the subject * @return the cache */ - ContextsCache getCacheFor(T subject); + public ContextsCache getCacheFor(T subject) { + if (subject == null) { + throw new NullPointerException("subject"); + } + return this.subjectCaches.get(subject); + } /** * Gets the contexts from the static calculators in this manager. * * @return the current active static contexts */ - ImmutableContextSet getStaticContext(); + public ImmutableContextSet getStaticContext() { + // this is actually already immutable, but the Contexts method signature returns the interface. + // using the makeImmutable method is faster than casting + return getStaticContexts().getContexts().makeImmutable(); + } /** * Gets the contexts from the static calculators in this manager. * * @return the current active static contexts */ - Contexts getStaticContexts(); + public Contexts getStaticContexts() { + return this.staticLookupCache.get(); + } /** * Returns a string form of the managers static context @@ -94,16 +163,21 @@ public interface ContextManager { * * @return a string representation of {@link #getStaticContext()} */ - Optional getStaticContextString(); + public Optional getStaticContextString() { + Set> entries = getStaticContext().toSet(); + if (entries.isEmpty()) { + return Optional.empty(); + } - /** - * Forms a {@link Contexts} instance from an {@link ImmutableContextSet}. - * - * @param subject the subject - * @param contextSet the context set - * @return a contexts instance - */ - Contexts formContexts(T subject, ImmutableContextSet contextSet); + // effectively: if entries contains any non-server keys + if (entries.stream().anyMatch(pair -> !pair.getKey().equals(Contexts.SERVER_KEY))) { + // return all entries in 'key=value' form + return Optional.of(entries.stream().map(pair -> pair.getKey() + "=" + pair.getValue()).collect(Collectors.joining(";"))); + } else { + // just return the server ids, without the 'server=' + return Optional.of(entries.stream().map(Map.Entry::getValue).collect(Collectors.joining(";"))); + } + } /** * Forms a {@link Contexts} instance from an {@link ImmutableContextSet}. @@ -111,7 +185,9 @@ public interface ContextManager { * @param contextSet the context set * @return a contexts instance */ - Contexts formContexts(ImmutableContextSet contextSet); + public Contexts formContexts(ImmutableContextSet contextSet) { + return Contexts.of(contextSet, this.plugin.getConfiguration().get(ConfigKeys.LOOKUP_SETTINGS)); + } /** * Forms a "default" {@link MetaContexts} instance from {@link Contexts}. @@ -119,41 +195,116 @@ public interface ContextManager { * @param contexts the contexts * @return a contexts instance */ - MetaContexts formMetaContexts(Contexts contexts); + public MetaContexts formMetaContexts(Contexts contexts) { + return new MetaContexts( + contexts, + this.plugin.getConfiguration().get(ConfigKeys.PREFIX_FORMATTING_OPTIONS), + this.plugin.getConfiguration().get(ConfigKeys.SUFFIX_FORMATTING_OPTIONS) + ); + } /** * Registers a context calculator with the manager. * * @param calculator the calculator */ - void registerCalculator(ContextCalculator calculator); + public void registerCalculator(ContextCalculator calculator) { + // calculators registered first should have priority (and be checked last.) + this.calculators.add(0, calculator); + } /** * Registers a static context calculator with the manager. * * @param calculator the calculator */ - void registerStaticCalculator(StaticContextCalculator calculator); + public void registerStaticCalculator(StaticContextCalculator calculator) { + registerCalculator(calculator); + this.staticCalculators.add(0, calculator); + } /** * Invalidates the lookup cache for a given subject * * @param subject the subject */ - void invalidateCache(T subject); + public void invalidateCache(T subject) { + if (subject == null) { + throw new NullPointerException("subject"); + } + + this.subjectCaches.invalidate(subject); + } + + Contexts calculate(T subject) { + MutableContextSet accumulator = MutableContextSet.create(); + + for (ContextCalculator calculator : ContextManager.this.calculators) { + try { + MutableContextSet ret = calculator.giveApplicableContext(subject, accumulator); + //noinspection ConstantConditions + if (ret == null) { + throw new IllegalStateException(calculator.getClass() + " returned a null context set"); + } + accumulator = ret; + } catch (Exception e) { + ContextManager.this.plugin.getLogger().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst calculating the context of subject " + subject); + e.printStackTrace(); + } + } + + return formContexts(subject, accumulator.makeImmutable()); + } + + private Contexts calculateStatic() { + MutableContextSet accumulator = MutableContextSet.create(); + + for (StaticContextCalculator calculator : this.staticCalculators) { + try { + MutableContextSet ret = calculator.giveApplicableContext(accumulator); + //noinspection ConstantConditions + if (ret == null) { + throw new IllegalStateException(calculator.getClass() + " returned a null context set"); + } + accumulator = ret; + } catch (Exception e) { + this.plugin.getLogger().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst calculating static contexts"); + e.printStackTrace(); + } + } + + return formContexts(accumulator.makeImmutable()); + } /** - * Gets the calculators registered on the platform + * Forms a {@link Contexts} instance from an {@link ImmutableContextSet}. * - * @return the registered calculators + * @param subject the subject + * @param contextSet the context set + * @return a contexts instance */ - List> getCalculators(); + public abstract Contexts formContexts(T subject, ImmutableContextSet contextSet); - /** - * Gets the static calculators registered on the platform - * - * @return the registered static calculators - */ - List getStaticCalculators(); + private final class StaticLookupCache extends ExpiringCache { + StaticLookupCache() { + super(50L, TimeUnit.MILLISECONDS); + } + + @Nonnull + @Override + public Contexts supply() { + return calculateStatic(); + } + } + + private static String getCalculatorClass(ContextCalculator calculator) { + Class calculatorClass; + if (calculator instanceof ProxiedContextCalculator) { + calculatorClass = ((ProxiedContextCalculator) calculator).getDelegate().getClass(); + } else { + calculatorClass = calculator.getClass(); + } + return calculatorClass.getName(); + } } diff --git a/common/src/main/java/me/lucko/luckperms/common/contexts/ContextsCache.java b/common/src/main/java/me/lucko/luckperms/common/contexts/ContextsCache.java index 99225eb1..cdc5c24e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/contexts/ContextsCache.java +++ b/common/src/main/java/me/lucko/luckperms/common/contexts/ContextsCache.java @@ -34,16 +34,16 @@ import java.util.concurrent.TimeUnit; import javax.annotation.Nonnull; /** - * Extension of {@link AbstractContextManager} that implements an expiring lookup cache + * Extension of {@link ContextManager} that implements an expiring lookup cache * per player. * * @param the player type */ public final class ContextsCache extends ExpiringCache { private final T subject; - private final AbstractContextManager contextManager; + private final ContextManager contextManager; - public ContextsCache(T subject, AbstractContextManager contextManager) { + public ContextsCache(T subject, ContextManager contextManager) { super(50L, TimeUnit.MILLISECONDS); // expire roughly every tick this.subject = subject; this.contextManager = contextManager; diff --git a/common/src/main/java/me/lucko/luckperms/common/contexts/LuckPermsCalculator.java b/common/src/main/java/me/lucko/luckperms/common/contexts/LPStaticContextsCalculator.java similarity index 93% rename from common/src/main/java/me/lucko/luckperms/common/contexts/LuckPermsCalculator.java rename to common/src/main/java/me/lucko/luckperms/common/contexts/LPStaticContextsCalculator.java index 9d990c14..614545ab 100644 --- a/common/src/main/java/me/lucko/luckperms/common/contexts/LuckPermsCalculator.java +++ b/common/src/main/java/me/lucko/luckperms/common/contexts/LPStaticContextsCalculator.java @@ -33,10 +33,10 @@ import me.lucko.luckperms.common.config.LuckPermsConfiguration; import javax.annotation.Nonnull; -public class LuckPermsCalculator implements StaticContextCalculator { +public class LPStaticContextsCalculator implements StaticContextCalculator { private final LuckPermsConfiguration config; - public LuckPermsCalculator(LuckPermsConfiguration config) { + public LPStaticContextsCalculator(LuckPermsConfiguration config) { this.config = config; } diff --git a/common/src/main/java/me/lucko/luckperms/common/listener/ConnectionListener.java b/common/src/main/java/me/lucko/luckperms/common/listener/ConnectionListener.java deleted file mode 100644 index f4aab58d..00000000 --- a/common/src/main/java/me/lucko/luckperms/common/listener/ConnectionListener.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.lucko.luckperms.common.listener; - -import java.util.Set; -import java.util.UUID; - -/** - * Handles incoming connections on the platform - */ -public interface ConnectionListener { - - /** - * Gets the unique players which have connected to the server since it started. - * - * @return the unique connections - */ - Set getUniqueConnections(); - -} diff --git a/common/src/main/java/me/lucko/luckperms/common/locale/LocaleManager.java b/common/src/main/java/me/lucko/luckperms/common/locale/LocaleManager.java index de56cde7..7bd15765 100644 --- a/common/src/main/java/me/lucko/luckperms/common/locale/LocaleManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/locale/LocaleManager.java @@ -25,17 +25,25 @@ package me.lucko.luckperms.common.locale; +import com.google.common.collect.ImmutableMap; + import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.command.CommandSpecData; import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; -import java.nio.file.Path; +import org.yaml.snakeyaml.Yaml; -/** - * Manages translations - */ -public interface LocaleManager { +import java.io.BufferedReader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Map; + +public class LocaleManager { + + private Map messages = ImmutableMap.of(); + private Map commands = ImmutableMap.of(); /** * Tries to load from a locale file, and logs via the plugin if successful. @@ -43,7 +51,16 @@ public interface LocaleManager { * @param plugin the plugin to log to * @param file the file to load from */ - void tryLoad(LuckPermsPlugin plugin, Path file); + public void tryLoad(LuckPermsPlugin plugin, Path file) { + if (Files.exists(file)) { + plugin.getLogger().info("Found lang.yml - loading messages..."); + try { + loadFromFile(file); + } catch (Exception e) { + e.printStackTrace(); + } + } + } /** * Loads a locale file @@ -51,14 +68,75 @@ public interface LocaleManager { * @param file the file to load from * @throws Exception if the process fails */ - void loadFromFile(Path file) throws Exception; + @SuppressWarnings("unchecked") + public void loadFromFile(Path file) throws Exception { + try (BufferedReader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) { + ImmutableMap.Builder messages = ImmutableMap.builder(); + ImmutableMap.Builder commands = ImmutableMap.builder(); + + Map data = (Map) new Yaml().load(reader); + for (Map.Entry 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 attributes = (Map) commandKey.getValue(); + CommandSpec spec = CommandSpec.valueOf(id.toUpperCase().replace('-', '_')); + + String description = (String) attributes.get("description"); + String usage = (String) attributes.get("usage"); + Map args = (Map) 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(); + } + } /** * Gets the size of loaded translations * * @return the size of the loaded translations */ - int getSize(); + public int getSize() { + return this.messages.size() + this.commands.size(); + } /** * Gets a translation for a given message key @@ -66,7 +144,9 @@ public interface LocaleManager { * @param key the key * @return the translation, or null if there isn't any translation available. */ - String getTranslation(Message key); + public String getTranslation(Message key) { + return this.messages.get(key); + } /** * Gets a translation for a given command spec key @@ -74,6 +154,8 @@ public interface LocaleManager { * @param key the key * @return the translation data, or null if there isn't any translation available. */ - CommandSpecData getTranslation(CommandSpec key); + public CommandSpecData getTranslation(CommandSpec key) { + return this.commands.get(key); + } } diff --git a/common/src/main/java/me/lucko/luckperms/common/locale/SimpleLocaleManager.java b/common/src/main/java/me/lucko/luckperms/common/locale/SimpleLocaleManager.java deleted file mode 100644 index abe69ceb..00000000 --- a/common/src/main/java/me/lucko/luckperms/common/locale/SimpleLocaleManager.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.lucko.luckperms.common.locale; - -import com.google.common.collect.ImmutableMap; - -import me.lucko.luckperms.common.locale.command.CommandSpec; -import me.lucko.luckperms.common.locale.command.CommandSpecData; -import me.lucko.luckperms.common.locale.message.Message; -import me.lucko.luckperms.common.plugin.LuckPermsPlugin; - -import org.yaml.snakeyaml.Yaml; - -import java.io.BufferedReader; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Map; - -public class SimpleLocaleManager implements LocaleManager { - - private Map messages = ImmutableMap.of(); - private Map commands = ImmutableMap.of(); - - @Override - public void tryLoad(LuckPermsPlugin plugin, Path file) { - if (Files.exists(file)) { - plugin.getLogger().info("Found lang.yml - loading messages..."); - try { - loadFromFile(file); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - @Override - @SuppressWarnings("unchecked") - public void loadFromFile(Path file) throws Exception { - try (BufferedReader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) { - ImmutableMap.Builder messages = ImmutableMap.builder(); - ImmutableMap.Builder commands = ImmutableMap.builder(); - - Map data = (Map) new Yaml().load(reader); - for (Map.Entry 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 attributes = (Map) commandKey.getValue(); - CommandSpec spec = CommandSpec.valueOf(id.toUpperCase().replace('-', '_')); - - String description = (String) attributes.get("description"); - String usage = (String) attributes.get("usage"); - Map args = (Map) 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(); - } - } - - @Override - public int getSize() { - return this.messages.size() + this.commands.size(); - } - - @Override - public String getTranslation(Message key) { - return this.messages.get(key); - } - - @Override - public CommandSpecData getTranslation(CommandSpec key) { - return this.commands.get(key); - } - -} diff --git a/common/src/main/java/me/lucko/luckperms/common/locale/command/CommandSpec.java b/common/src/main/java/me/lucko/luckperms/common/locale/command/CommandSpec.java index fde271f5..543afc5e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/locale/command/CommandSpec.java +++ b/common/src/main/java/me/lucko/luckperms/common/locale/command/CommandSpec.java @@ -25,13 +25,9 @@ package me.lucko.luckperms.common.locale.command; -import com.google.common.collect.ImmutableList; - import me.lucko.luckperms.common.locale.LocaleManager; -import java.util.ArrayList; import java.util.List; -import java.util.ListIterator; /** * An enumeration of the command defintion/usage messages used in the plugin. @@ -570,6 +566,18 @@ public enum CommandSpec { this(description, null, args); } + public String getDescription() { + return this.description; + } + + public String getUsage() { + return this.usage; + } + + public List getArgs() { + return this.args; + } + /** * Creates a {@link LocalizedCommandSpec} for the spec using the platforms locale manager. * @@ -577,67 +585,7 @@ public enum CommandSpec { * @return a localized spec instance */ public LocalizedCommandSpec localize(LocaleManager localeManager) { - return new Localized(this, localeManager); - } - - private static final class Localized implements LocalizedCommandSpec { - private final LocaleManager localeManager; - private final CommandSpec spec; - - private Localized(CommandSpec spec, LocaleManager localeManager) { - this.localeManager = localeManager; - this.spec = spec; - } - - @Override - public String description() { - CommandSpecData translation = this.localeManager.getTranslation(this.spec); - if (translation != null && translation.getDescription() != null) { - return translation.getDescription(); - } - - // fallback - return this.spec.description; - } - - @Override - public String usage() { - CommandSpecData translation = this.localeManager.getTranslation(this.spec); - if (translation != null && translation.getUsage() != null) { - return translation.getUsage(); - } - - // fallback - return this.spec.usage; - } - - @Override - public List args() { - CommandSpecData translation = this.localeManager.getTranslation(this.spec); - if (translation == null || translation.getArgs() == null) { - // fallback - return this.spec.args; - } - - List args = new ArrayList<>(this.spec.args); - ListIterator it = args.listIterator(); - while (it.hasNext()) { - Argument next = it.next(); - String s = translation.getArgs().get(next.getName()); - - // if a translation for the given arg key is present, apply the new description. - if (s != null) { - it.set(Argument.create(next.getName(), next.isRequired(), s)); - } - } - - return ImmutableList.copyOf(args); - } - - @Override - public LocaleManager getLocaleManager() { - return this.localeManager; - } + return new LocalizedCommandSpec(this, localeManager); } /** diff --git a/common/src/main/java/me/lucko/luckperms/common/locale/command/LocalizedCommandSpec.java b/common/src/main/java/me/lucko/luckperms/common/locale/command/LocalizedCommandSpec.java index 440ac040..097473f2 100644 --- a/common/src/main/java/me/lucko/luckperms/common/locale/command/LocalizedCommandSpec.java +++ b/common/src/main/java/me/lucko/luckperms/common/locale/command/LocalizedCommandSpec.java @@ -25,26 +25,69 @@ package me.lucko.luckperms.common.locale.command; +import com.google.common.collect.ImmutableList; + import me.lucko.luckperms.common.locale.LocaleManager; +import java.util.ArrayList; import java.util.List; +import java.util.ListIterator; /** * Represents a localized instance of a {@link CommandSpec}. */ -public interface LocalizedCommandSpec { +public class LocalizedCommandSpec { + private final LocaleManager localeManager; + private final CommandSpec spec; - /** - * Gets the locale manager used to translate the {@link CommandSpec}. - * - * @return the locale manager - */ - LocaleManager getLocaleManager(); + public LocalizedCommandSpec(CommandSpec spec, LocaleManager localeManager) { + this.localeManager = localeManager; + this.spec = spec; + } - String description(); + public String description() { + CommandSpecData translation = this.localeManager.getTranslation(this.spec); + if (translation != null && translation.getDescription() != null) { + return translation.getDescription(); + } - String usage(); + // fallback + return this.spec.getDescription(); + } - List args(); + public String usage() { + CommandSpecData translation = this.localeManager.getTranslation(this.spec); + if (translation != null && translation.getUsage() != null) { + return translation.getUsage(); + } + // fallback + return this.spec.getUsage(); + } + + public List args() { + CommandSpecData translation = this.localeManager.getTranslation(this.spec); + if (translation == null || translation.getArgs() == null) { + // fallback + return this.spec.getArgs(); + } + + List args = new ArrayList<>(this.spec.getArgs()); + ListIterator it = args.listIterator(); + while (it.hasNext()) { + Argument next = it.next(); + String s = translation.getArgs().get(next.getName()); + + // if a translation for the given arg key is present, apply the new description. + if (s != null) { + it.set(Argument.create(next.getName(), next.isRequired(), s)); + } + } + + return ImmutableList.copyOf(args); + } + + public LocaleManager getLocaleManager() { + return this.localeManager; + } } diff --git a/common/src/main/java/me/lucko/luckperms/common/logging/Logger.java b/common/src/main/java/me/lucko/luckperms/common/logging/Logger.java deleted file mode 100644 index 3fcbd130..00000000 --- a/common/src/main/java/me/lucko/luckperms/common/logging/Logger.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.lucko.luckperms.common.logging; - -/** - * Represents the logger instance being used by LuckPerms on the platform. - * - *

Messages sent using the logger are sent prefixed with the LuckPerms tag, and on some implementations will be colored - * depending on the message type.

- */ -public interface Logger { - - void info(String s); - - void warn(String s); - - void severe(String s); - -} diff --git a/common/src/main/java/me/lucko/luckperms/common/messaging/sql/SqlMessenger.java b/common/src/main/java/me/lucko/luckperms/common/messaging/sql/SqlMessenger.java index c8bea759..af3fb32f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/messaging/sql/SqlMessenger.java +++ b/common/src/main/java/me/lucko/luckperms/common/messaging/sql/SqlMessenger.java @@ -27,8 +27,8 @@ package me.lucko.luckperms.common.messaging.sql; import me.lucko.luckperms.api.messenger.IncomingMessageConsumer; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; -import me.lucko.luckperms.common.plugin.SchedulerTask; import me.lucko.luckperms.common.plugin.scheduler.SchedulerAdapter; +import me.lucko.luckperms.common.plugin.scheduler.SchedulerTask; import me.lucko.luckperms.common.storage.dao.sql.SqlDao; import java.sql.Connection; diff --git a/common/src/main/java/me/lucko/luckperms/common/node/comparator/HeldPermissionComparator.java b/common/src/main/java/me/lucko/luckperms/common/node/comparator/HeldPermissionComparator.java index 409fa249..0b5cb5cd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/node/comparator/HeldPermissionComparator.java +++ b/common/src/main/java/me/lucko/luckperms/common/node/comparator/HeldPermissionComparator.java @@ -41,11 +41,10 @@ public class HeldPermissionComparator> implements Compar @Override public int compare(HeldPermission o1, HeldPermission o2) { - int i = o1.getHolder().compareTo(o2.getHolder()); + int i = NodeWithContextComparator.normal().compare(o1.asNode(), o2.asNode()); if (i != 0) { return i; } - - return NodeWithContextComparator.normal().compare(o1.asNode(), o2.asNode()); + return o1.getHolder().compareTo(o2.getHolder()); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/plugin/AbstractLuckPermsPlugin.java b/common/src/main/java/me/lucko/luckperms/common/plugin/AbstractLuckPermsPlugin.java index abd15855..902dc815 100644 --- a/common/src/main/java/me/lucko/luckperms/common/plugin/AbstractLuckPermsPlugin.java +++ b/common/src/main/java/me/lucko/luckperms/common/plugin/AbstractLuckPermsPlugin.java @@ -37,18 +37,16 @@ import me.lucko.luckperms.common.config.AbstractConfiguration; import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.config.LuckPermsConfiguration; import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter; -import me.lucko.luckperms.common.contexts.LuckPermsCalculator; +import me.lucko.luckperms.common.contexts.LPStaticContextsCalculator; import me.lucko.luckperms.common.dependencies.Dependency; import me.lucko.luckperms.common.dependencies.DependencyManager; import me.lucko.luckperms.common.event.AbstractEventBus; import me.lucko.luckperms.common.event.EventFactory; import me.lucko.luckperms.common.inheritance.InheritanceHandler; import me.lucko.luckperms.common.locale.LocaleManager; -import me.lucko.luckperms.common.locale.SimpleLocaleManager; -import me.lucko.luckperms.common.logging.Logger; -import me.lucko.luckperms.common.logging.SenderLogger; import me.lucko.luckperms.common.messaging.InternalMessagingService; import me.lucko.luckperms.common.messaging.MessagingFactory; +import me.lucko.luckperms.common.plugin.util.PluginLogger; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.storage.Storage; import me.lucko.luckperms.common.storage.StorageFactory; @@ -66,7 +64,7 @@ import java.util.concurrent.TimeUnit; public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin { // init during load - private Logger logger; + private PluginLogger logger; private DependencyManager dependencyManager; // init during enable @@ -90,7 +88,7 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin { public final void load() { // load the sender factory instance and create a new logger for the plugin setupSenderFactory(); - this.logger = new SenderLogger(this, getConsoleSender()); + this.logger = new PluginLogger(this, getConsoleSender()); // load dependencies this.dependencyManager = new DependencyManager(this); @@ -111,7 +109,7 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin { this.configuration = new AbstractConfiguration(this, provideConfigurationAdapter()); // load locale - this.localeManager = new SimpleLocaleManager(); + this.localeManager = new LocaleManager(); this.localeManager.tryLoad(this, getBootstrap().getConfigDirectory().resolve("lang.yml")); // now the configuration is loaded, we can create a storage factory and load initial dependencies @@ -154,7 +152,7 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin { // setup contextmanager & register common calculators setupContextManager(); - getContextManager().registerStaticCalculator(new LuckPermsCalculator(getConfiguration())); + getContextManager().registerStaticCalculator(new LPStaticContextsCalculator(getConfiguration())); // setup platform hooks setupPlatformHooks(); @@ -247,7 +245,7 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin { } @Override - public Logger getLogger() { + public PluginLogger getLogger() { return this.logger; } 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 13fdc87d..635f24b3 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 @@ -37,15 +37,15 @@ import me.lucko.luckperms.common.contexts.ContextManager; import me.lucko.luckperms.common.dependencies.DependencyManager; import me.lucko.luckperms.common.event.EventFactory; import me.lucko.luckperms.common.inheritance.InheritanceHandler; -import me.lucko.luckperms.common.listener.ConnectionListener; import me.lucko.luckperms.common.locale.LocaleManager; -import me.lucko.luckperms.common.logging.Logger; import me.lucko.luckperms.common.managers.group.GroupManager; import me.lucko.luckperms.common.managers.track.TrackManager; import me.lucko.luckperms.common.managers.user.UserManager; import me.lucko.luckperms.common.messaging.InternalMessagingService; import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.plugin.bootstrap.LuckPermsBootstrap; +import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener; +import me.lucko.luckperms.common.plugin.util.PluginLogger; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.storage.Storage; import me.lucko.luckperms.common.storage.dao.file.FileWatcher; @@ -126,7 +126,7 @@ public interface LuckPermsPlugin { * * @return the plugin's logger */ - Logger getLogger(); + PluginLogger getLogger(); /** * Gets the event factory @@ -154,7 +154,7 @@ public interface LuckPermsPlugin { * * @return the connection listener */ - ConnectionListener getConnectionListener(); + AbstractConnectionListener getConnectionListener(); /** * Gets the instance providing locale translations for the plugin diff --git a/common/src/main/java/me/lucko/luckperms/common/plugin/scheduler/AbstractJavaScheduler.java b/common/src/main/java/me/lucko/luckperms/common/plugin/scheduler/AbstractJavaScheduler.java index 817ae850..3119890b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/plugin/scheduler/AbstractJavaScheduler.java +++ b/common/src/main/java/me/lucko/luckperms/common/plugin/scheduler/AbstractJavaScheduler.java @@ -27,8 +27,6 @@ package me.lucko.luckperms.common.plugin.scheduler; import com.google.common.util.concurrent.ThreadFactoryBuilder; -import me.lucko.luckperms.common.plugin.SchedulerTask; - import java.util.concurrent.Executor; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; diff --git a/common/src/main/java/me/lucko/luckperms/common/plugin/scheduler/SchedulerAdapter.java b/common/src/main/java/me/lucko/luckperms/common/plugin/scheduler/SchedulerAdapter.java index be47bea9..93e02038 100644 --- a/common/src/main/java/me/lucko/luckperms/common/plugin/scheduler/SchedulerAdapter.java +++ b/common/src/main/java/me/lucko/luckperms/common/plugin/scheduler/SchedulerAdapter.java @@ -25,8 +25,6 @@ package me.lucko.luckperms.common.plugin.scheduler; -import me.lucko.luckperms.common.plugin.SchedulerTask; - import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; diff --git a/common/src/main/java/me/lucko/luckperms/common/plugin/SchedulerTask.java b/common/src/main/java/me/lucko/luckperms/common/plugin/scheduler/SchedulerTask.java similarity index 96% rename from common/src/main/java/me/lucko/luckperms/common/plugin/SchedulerTask.java rename to common/src/main/java/me/lucko/luckperms/common/plugin/scheduler/SchedulerTask.java index 2180b2c1..e9766c5f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/plugin/SchedulerTask.java +++ b/common/src/main/java/me/lucko/luckperms/common/plugin/scheduler/SchedulerTask.java @@ -23,7 +23,7 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.plugin; +package me.lucko.luckperms.common.plugin.scheduler; /** * Represents a scheduled task diff --git a/common/src/main/java/me/lucko/luckperms/common/listener/AbstractConnectionListener.java b/common/src/main/java/me/lucko/luckperms/common/plugin/util/AbstractConnectionListener.java similarity index 95% rename from common/src/main/java/me/lucko/luckperms/common/listener/AbstractConnectionListener.java rename to common/src/main/java/me/lucko/luckperms/common/plugin/util/AbstractConnectionListener.java index d2befa27..4bca9849 100644 --- a/common/src/main/java/me/lucko/luckperms/common/listener/AbstractConnectionListener.java +++ b/common/src/main/java/me/lucko/luckperms/common/plugin/util/AbstractConnectionListener.java @@ -23,7 +23,7 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.listener; +package me.lucko.luckperms.common.plugin.util; import me.lucko.luckperms.api.PlayerSaveResult; import me.lucko.luckperms.api.platform.PlatformType; @@ -40,7 +40,7 @@ import java.util.concurrent.ConcurrentHashMap; /** * Abstract listener utility for handling new player connections */ -public abstract class AbstractConnectionListener implements ConnectionListener { +public abstract class AbstractConnectionListener { private final LuckPermsPlugin plugin; private final Set uniqueConnections = ConcurrentHashMap.newKeySet(); @@ -48,7 +48,11 @@ public abstract class AbstractConnectionListener implements ConnectionListener { this.plugin = plugin; } - @Override + /** + * Gets the unique players which have connected to the server since it started. + * + * @return the unique connections + */ public Set getUniqueConnections() { return this.uniqueConnections; } diff --git a/common/src/main/java/me/lucko/luckperms/common/logging/SenderLogger.java b/common/src/main/java/me/lucko/luckperms/common/plugin/util/PluginLogger.java similarity index 85% rename from common/src/main/java/me/lucko/luckperms/common/logging/SenderLogger.java rename to common/src/main/java/me/lucko/luckperms/common/plugin/util/PluginLogger.java index 1f75194f..b4cfd4cd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/logging/SenderLogger.java +++ b/common/src/main/java/me/lucko/luckperms/common/plugin/util/PluginLogger.java @@ -23,7 +23,7 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.logging; +package me.lucko.luckperms.common.plugin.util; import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.config.ConfigKeys; @@ -33,26 +33,29 @@ import me.lucko.luckperms.common.sender.Sender; import java.util.Objects; -public class SenderLogger implements Logger { +/** + * Represents the logger instance being used by LuckPerms on the platform. + * + *

Messages sent using the logger are sent prefixed with the LuckPerms tag, + * and on some implementations will be colored depending on the message type.

+ */ +public class PluginLogger { private final LuckPermsPlugin plugin; private final Sender console; - public SenderLogger(LuckPermsPlugin plugin, Sender console) { + public PluginLogger(LuckPermsPlugin plugin, Sender console) { this.plugin = plugin; this.console = console; } - @Override public void info(String s) { msg(Message.LOG_INFO, Objects.requireNonNull(s)); } - @Override public void warn(String s) { msg(Message.LOG_WARN, Objects.requireNonNull(s)); } - @Override public void severe(String s) { msg(Message.LOG_ERROR, Objects.requireNonNull(s)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/logging/ProgressLogger.java b/common/src/main/java/me/lucko/luckperms/common/utils/ProgressLogger.java similarity index 98% rename from common/src/main/java/me/lucko/luckperms/common/logging/ProgressLogger.java rename to common/src/main/java/me/lucko/luckperms/common/utils/ProgressLogger.java index d31f229c..6e3da22a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/logging/ProgressLogger.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/ProgressLogger.java @@ -23,7 +23,7 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.logging; +package me.lucko.luckperms.common.utils; import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.sender.Sender; diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/RepeatingTask.java b/common/src/main/java/me/lucko/luckperms/common/utils/RepeatingTask.java index a77ed3f6..e6154b8c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/RepeatingTask.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/RepeatingTask.java @@ -25,8 +25,8 @@ package me.lucko.luckperms.common.utils; -import me.lucko.luckperms.common.plugin.SchedulerTask; import me.lucko.luckperms.common.plugin.scheduler.SchedulerAdapter; +import me.lucko.luckperms.common.plugin.scheduler.SchedulerTask; import java.util.concurrent.TimeUnit; diff --git a/nukkit/src/main/java/me/lucko/luckperms/nukkit/LPNukkitPlugin.java b/nukkit/src/main/java/me/lucko/luckperms/nukkit/LPNukkitPlugin.java index 32053e51..cb904906 100644 --- a/nukkit/src/main/java/me/lucko/luckperms/nukkit/LPNukkitPlugin.java +++ b/nukkit/src/main/java/me/lucko/luckperms/nukkit/LPNukkitPlugin.java @@ -37,13 +37,13 @@ import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter; import me.lucko.luckperms.common.contexts.ContextManager; import me.lucko.luckperms.common.dependencies.Dependency; import me.lucko.luckperms.common.event.AbstractEventBus; -import me.lucko.luckperms.common.listener.ConnectionListener; import me.lucko.luckperms.common.managers.group.StandardGroupManager; import me.lucko.luckperms.common.managers.track.StandardTrackManager; import me.lucko.luckperms.common.managers.user.StandardUserManager; import me.lucko.luckperms.common.messaging.MessagingFactory; import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.plugin.AbstractLuckPermsPlugin; +import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.tasks.CacheHousekeepingTask; import me.lucko.luckperms.common.tasks.ExpireTemporaryTask; @@ -314,7 +314,7 @@ public class LPNukkitPlugin extends AbstractLuckPermsPlugin { } @Override - public ConnectionListener getConnectionListener() { + public AbstractConnectionListener getConnectionListener() { return this.connectionListener; } diff --git a/nukkit/src/main/java/me/lucko/luckperms/nukkit/contexts/NukkitContextManager.java b/nukkit/src/main/java/me/lucko/luckperms/nukkit/contexts/NukkitContextManager.java index ccc605f8..0eba4c29 100644 --- a/nukkit/src/main/java/me/lucko/luckperms/nukkit/contexts/NukkitContextManager.java +++ b/nukkit/src/main/java/me/lucko/luckperms/nukkit/contexts/NukkitContextManager.java @@ -29,14 +29,14 @@ import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.LookupSetting; import me.lucko.luckperms.api.context.ImmutableContextSet; import me.lucko.luckperms.common.config.ConfigKeys; -import me.lucko.luckperms.common.contexts.AbstractContextManager; +import me.lucko.luckperms.common.contexts.ContextManager; import me.lucko.luckperms.nukkit.LPNukkitPlugin; import cn.nukkit.Player; import java.util.EnumSet; -public class NukkitContextManager extends AbstractContextManager { +public class NukkitContextManager extends ContextManager { public NukkitContextManager(LPNukkitPlugin plugin) { super(plugin, Player.class); } diff --git a/nukkit/src/main/java/me/lucko/luckperms/nukkit/listeners/NukkitConnectionListener.java b/nukkit/src/main/java/me/lucko/luckperms/nukkit/listeners/NukkitConnectionListener.java index 235d09a1..6c7d43c5 100644 --- a/nukkit/src/main/java/me/lucko/luckperms/nukkit/listeners/NukkitConnectionListener.java +++ b/nukkit/src/main/java/me/lucko/luckperms/nukkit/listeners/NukkitConnectionListener.java @@ -26,9 +26,9 @@ package me.lucko.luckperms.nukkit.listeners; import me.lucko.luckperms.common.config.ConfigKeys; -import me.lucko.luckperms.common.listener.AbstractConnectionListener; import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.model.User; +import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener; import me.lucko.luckperms.nukkit.LPNukkitPlugin; import me.lucko.luckperms.nukkit.model.permissible.LPPermissible; import me.lucko.luckperms.nukkit.model.permissible.PermissibleInjector; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeSchedulerAdapter.java b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeSchedulerAdapter.java index 4d608f50..51db536c 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeSchedulerAdapter.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeSchedulerAdapter.java @@ -25,8 +25,8 @@ package me.lucko.luckperms.sponge; -import me.lucko.luckperms.common.plugin.SchedulerTask; import me.lucko.luckperms.common.plugin.scheduler.SchedulerAdapter; +import me.lucko.luckperms.common.plugin.scheduler.SchedulerTask; import me.lucko.luckperms.common.utils.Iterators; import org.spongepowered.api.scheduler.Scheduler; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/contexts/SpongeContextManager.java b/sponge/src/main/java/me/lucko/luckperms/sponge/contexts/SpongeContextManager.java index fefad79b..5ff5c59d 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/contexts/SpongeContextManager.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/contexts/SpongeContextManager.java @@ -27,12 +27,12 @@ package me.lucko.luckperms.sponge.contexts; import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.context.ImmutableContextSet; -import me.lucko.luckperms.common.contexts.AbstractContextManager; +import me.lucko.luckperms.common.contexts.ContextManager; import me.lucko.luckperms.sponge.LPSpongePlugin; import org.spongepowered.api.service.permission.Subject; -public class SpongeContextManager extends AbstractContextManager { +public class SpongeContextManager extends ContextManager { public SpongeContextManager(LPSpongePlugin plugin) { super(plugin, Subject.class); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/listeners/SpongeConnectionListener.java b/sponge/src/main/java/me/lucko/luckperms/sponge/listeners/SpongeConnectionListener.java index 5d4d7684..86b1062d 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/listeners/SpongeConnectionListener.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/listeners/SpongeConnectionListener.java @@ -26,9 +26,9 @@ package me.lucko.luckperms.sponge.listeners; import me.lucko.luckperms.common.config.ConfigKeys; -import me.lucko.luckperms.common.listener.AbstractConnectionListener; import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.model.User; +import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener; import me.lucko.luckperms.sponge.LPSpongePlugin; import org.spongepowered.api.entity.living.player.Player;