From 7854de8991c109a2ab96ef220a3da9be9594b161 Mon Sep 17 00:00:00 2001 From: MrMicky Date: Sat, 31 Oct 2020 23:25:11 +0100 Subject: [PATCH] Move exception printing to logger (#2695) --- .../luckperms/bukkit/BukkitCommandExecutor.java | 6 ++---- .../me/lucko/luckperms/bukkit/LPBukkitPlugin.java | 12 +++++++----- .../bukkit/inject/server/InjectorDefaultsMap.java | 5 ++--- .../bukkit/inject/server/InjectorPermissionMap.java | 3 +-- .../inject/server/InjectorSubscriptionMap.java | 5 ++--- .../bukkit/listeners/BukkitConnectionListener.java | 9 ++++----- .../bukkit/migration/MigrationPowerfulPerms.java | 2 +- .../bukkit/migration/MigrationZPermissions.java | 2 +- .../luckperms/bukkit/vault/LuckPermsVaultChat.java | 2 +- .../luckperms/bukkit/vault/VaultHookManager.java | 2 +- .../bungee/listeners/BungeeConnectionListener.java | 3 +-- .../listeners/BungeePermissionCheckListener.java | 6 ++---- .../luckperms/common/actionlog/LogDispatcher.java | 2 +- .../me/lucko/luckperms/common/backup/Exporter.java | 4 ++-- .../me/lucko/luckperms/common/backup/Importer.java | 2 +- .../luckperms/common/command/CommandManager.java | 3 +-- .../common/command/tabcomplete/TabCompletions.java | 2 +- .../common/command/utils/StorageAssistant.java | 6 +++--- .../commands/generic/other/HolderShowTracks.java | 2 +- .../luckperms/common/commands/group/CreateGroup.java | 2 +- .../luckperms/common/commands/group/DeleteGroup.java | 2 +- .../luckperms/common/commands/group/GroupRename.java | 4 ++-- .../luckperms/common/commands/group/ListGroups.java | 2 +- .../common/commands/misc/ApplyEditsCommand.java | 2 +- .../common/commands/misc/ExportCommand.java | 2 +- .../common/commands/misc/ImportCommand.java | 4 ++-- .../common/commands/misc/NetworkSyncCommand.java | 2 +- .../common/commands/misc/TranslationsCommand.java | 4 ++-- .../luckperms/common/commands/misc/TreeCommand.java | 2 +- .../common/commands/misc/VerboseCommand.java | 6 +++--- .../luckperms/common/commands/track/CreateTrack.java | 2 +- .../luckperms/common/commands/track/DeleteTrack.java | 2 +- .../luckperms/common/commands/track/ListTracks.java | 2 +- .../luckperms/common/commands/track/TrackRename.java | 4 ++-- .../luckperms/common/context/ContextManager.java | 9 +++------ .../common/dependencies/DependencyManager.java | 5 ++--- .../common/event/LuckPermsEventSubscription.java | 3 +-- .../common/extension/SimpleExtensionManager.java | 6 +++--- .../luckperms/common/locale/TranslationManager.java | 8 +++----- .../luckperms/common/messaging/MessagingFactory.java | 4 ++-- .../common/metastacking/StandardStackElements.java | 2 +- .../common/plugin/AbstractLuckPermsPlugin.java | 3 +-- .../common/plugin/logging/JavaPluginLogger.java | 11 +++++++++++ .../common/plugin/logging/PluginLogger.java | 4 ++++ .../common/plugin/logging/Slf4jPluginLogger.java | 10 ++++++++++ .../me/lucko/luckperms/common/storage/Storage.java | 6 ++---- .../file/AbstractConfigurateStorage.java | 4 +--- .../storage/implementation/split/SplitStorage.java | 2 +- .../common/storage/implementation/sql/SqlNode.java | 4 ++-- .../storage/implementation/sql/SqlStorage.java | 2 +- .../sql/connection/file/H2ConnectionFactory.java | 2 +- .../sql/connection/file/SQLiteConnectionFactory.java | 2 +- .../me/lucko/luckperms/common/treeview/TreeView.java | 2 +- .../me/lucko/luckperms/nukkit/LPNukkitPlugin.java | 8 +++++--- .../lucko/luckperms/nukkit/NukkitPluginLogger.java | 10 ++++++++++ .../nukkit/inject/server/InjectorDefaultsMap.java | 3 +-- .../nukkit/inject/server/InjectorPermissionMap.java | 3 +-- .../inject/server/InjectorSubscriptionMap.java | 3 +-- .../nukkit/listeners/NukkitConnectionListener.java | 9 ++++----- .../me/lucko/luckperms/sponge/LPSpongeBootstrap.java | 2 +- .../luckperms/sponge/SpongeCommandExecutor.java | 3 +-- .../sponge/listeners/SpongeConnectionListener.java | 3 +-- .../sponge/messaging/SpongeMessagingFactory.java | 2 +- .../service/model/persisted/SubjectStorage.java | 2 +- .../listeners/VelocityConnectionListener.java | 3 +-- .../velocity/messaging/VelocityMessagingFactory.java | 2 +- 66 files changed, 136 insertions(+), 126 deletions(-) diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCommandExecutor.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCommandExecutor.java index 3be75bf74..ad98b415f 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCommandExecutor.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCommandExecutor.java @@ -33,7 +33,6 @@ import me.lucko.luckperms.common.sender.Sender; import org.bukkit.Server; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.PluginCommand; @@ -48,7 +47,7 @@ import java.util.List; import java.util.ListIterator; import java.util.stream.Collectors; -public class BukkitCommandExecutor extends CommandManager implements CommandExecutor, TabExecutor, Listener { +public class BukkitCommandExecutor extends CommandManager implements TabExecutor, Listener { private static final boolean SELECT_ENTITIES_SUPPORTED; static { @@ -144,8 +143,7 @@ public class BukkitCommandExecutor extends CommandManager implements CommandExec .map(e -> ((Player) e)) .collect(Collectors.toList()); } catch (IllegalArgumentException e) { - this.plugin.getLogger().warn("Error parsing selector '" + arg + "' for " + sender + " executing " + args); - e.printStackTrace(); + this.plugin.getLogger().warn("Error parsing selector '" + arg + "' for " + sender + " executing " + args, e); continue; } 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 7a69f4eae..ce36b47d6 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java @@ -245,8 +245,7 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin { } } catch (Exception e) { this.vaultHookManager = null; - getLogger().severe("Error occurred whilst hooking into Vault."); - e.printStackTrace(); + getLogger().severe("Error occurred whilst hooking into Vault.", e); } } @@ -305,12 +304,14 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin { LuckPermsPermissible lpPermissible = new LuckPermsPermissible(player, user, this); PermissibleInjector.inject(player, lpPermissible); } catch (Throwable t) { - t.printStackTrace(); + getLogger().severe("Exception thrown when setting up permissions for " + + player.getUniqueId() + " - " + player.getName(), t); } }); } } catch (Exception e) { - e.printStackTrace(); + getLogger().severe("Exception occurred whilst loading data for " + + player.getUniqueId() + " - " + player.getName(), e); } }); } @@ -323,7 +324,8 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin { try { PermissibleInjector.uninject(player, false); } catch (Exception e) { - e.printStackTrace(); + getLogger().severe("Exception thrown when unloading permissions from " + + player.getUniqueId() + " - " + player.getName(), e); } if (getConfiguration().get(ConfigKeys.AUTO_OP)) { diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/server/InjectorDefaultsMap.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/server/InjectorDefaultsMap.java index 810348b35..68b2a9b81 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/server/InjectorDefaultsMap.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/server/InjectorDefaultsMap.java @@ -67,8 +67,7 @@ public class InjectorDefaultsMap { this.plugin.setDefaultPermissionMap(defaultsMap); } } catch (Exception e) { - this.plugin.getLogger().severe("Exception occurred whilst injecting LuckPerms Default Permission map."); - e.printStackTrace(); + this.plugin.getLogger().severe("Exception occurred whilst injecting LuckPerms Default Permission map.", e); } } @@ -111,7 +110,7 @@ public class InjectorDefaultsMap { DEFAULT_PERMISSIONS_FIELD.set(pluginManager, new HashMap<>(lpMap)); } } catch (Exception e) { - e.printStackTrace(); + this.plugin.getLogger().severe("Exception occurred whilst uninjecting LuckPerms Default Permission map.", e); } } } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/server/InjectorPermissionMap.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/server/InjectorPermissionMap.java index 7dedfbd47..bda31d3e8 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/server/InjectorPermissionMap.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/server/InjectorPermissionMap.java @@ -66,8 +66,7 @@ public class InjectorPermissionMap { this.plugin.setPermissionMap(permissionMap); } } catch (Exception e) { - this.plugin.getLogger().severe("Exception occurred whilst injecting LuckPerms Permission map."); - e.printStackTrace(); + this.plugin.getLogger().severe("Exception occurred whilst injecting LuckPerms Permission map.", e); } } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/server/InjectorSubscriptionMap.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/server/InjectorSubscriptionMap.java index 7aafb0bbb..fd65b1fb8 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/server/InjectorSubscriptionMap.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/server/InjectorSubscriptionMap.java @@ -65,8 +65,7 @@ public class InjectorSubscriptionMap { this.plugin.setSubscriptionMap(subscriptionMap); } } catch (Exception e) { - this.plugin.getLogger().severe("Exception occurred whilst injecting LuckPerms Permission Subscription map."); - e.printStackTrace(); + this.plugin.getLogger().severe("Exception occurred whilst injecting LuckPerms Permission Subscription map.", e); } } @@ -113,7 +112,7 @@ public class InjectorSubscriptionMap { PERM_SUBS_FIELD.set(pluginManager, lpMap.detach()); } } catch (Exception e) { - e.printStackTrace(); + this.plugin.getLogger().severe("Exception occurred whilst uninjecting LuckPerms Permission Subscription map.", e); } } 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 22bbe709e..87918aa38 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 @@ -121,8 +121,7 @@ public class BukkitConnectionListener extends AbstractConnectionListener impleme recordConnection(e.getUniqueId()); this.plugin.getEventDispatcher().dispatchPlayerLoginProcess(e.getUniqueId(), e.getName(), user); } catch (Exception ex) { - this.plugin.getLogger().severe("Exception occurred whilst loading data for " + e.getUniqueId() + " - " + e.getName()); - ex.printStackTrace(); + this.plugin.getLogger().severe("Exception occurred whilst loading data for " + e.getUniqueId() + " - " + e.getName(), ex); // deny the connection this.deniedAsyncLogin.add(e.getUniqueId()); @@ -203,8 +202,7 @@ public class BukkitConnectionListener extends AbstractConnectionListener impleme } catch (Throwable t) { this.plugin.getLogger().warn("Exception thrown when setting up permissions for " + - player.getUniqueId() + " - " + player.getName() + " - denying login."); - t.printStackTrace(); + player.getUniqueId() + " - " + player.getName() + " - denying login.", t); Component reason = TranslationManager.render(Message.LOADING_SETUP_ERROR.build(), player.getLocale()); e.disallow(PlayerLoginEvent.Result.KICK_OTHER, LegacyComponentSerializer.legacySection().serialize(reason)); @@ -242,7 +240,8 @@ public class BukkitConnectionListener extends AbstractConnectionListener impleme try { PermissibleInjector.uninject(player, true); } catch (Exception ex) { - ex.printStackTrace(); + this.plugin.getLogger().severe("Exception thrown when unloading permissions from " + + player.getUniqueId() + " - " + player.getName(), ex); } // Handle auto op 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 c17bce1af..a594d448d 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 @@ -131,7 +131,7 @@ public class MigrationPowerfulPerms extends ChildCommand { try (ResultSet rs = ps.executeQuery()) { log.log("Found table: " + dbTable); while (rs.next()) { - log.log("" + rs.getString("COLUMN_NAME") + " - " + rs.getString("COLUMN_TYPE")); + log.log(rs.getString("COLUMN_NAME") + " - " + rs.getString("COLUMN_TYPE")); } } } 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 b5a130cf8..a62957df6 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 @@ -201,7 +201,7 @@ public class MigrationZPermissions extends ChildCommand { for (Entry e : entity.getPermissions()) { if (e.getPermission().isEmpty()) continue; - if (e.getWorld() != null && !e.getWorld().getName().equals("")) { + if (e.getWorld() != null && !e.getWorld().getName().isEmpty()) { holder.setNode(DataType.NORMAL, NodeBuilders.determineMostApplicable(e.getPermission()).value(e.isValue()).withContext(DefaultContextKeys.WORLD_KEY, e.getWorld().getName()).build(), true); } else { holder.setNode(DataType.NORMAL, NodeBuilders.determineMostApplicable(e.getPermission()).value(e.isValue()).build(), true); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/LuckPermsVaultChat.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/LuckPermsVaultChat.java index 9d8ca0531..6519804de 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/LuckPermsVaultChat.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/LuckPermsVaultChat.java @@ -273,7 +273,7 @@ public class LuckPermsVaultChat extends AbstractVaultChat { private QueryOptions createQueryOptionsForWorldSet(String world) { ImmutableContextSet.Builder context = new ImmutableContextSetImpl.BuilderImpl(); - if (world != null && !world.equals("") && !world.equalsIgnoreCase("global")) { + if (world != null && !world.isEmpty() && !world.equalsIgnoreCase("global")) { context.add(DefaultContextKeys.WORLD_KEY, world.toLowerCase()); } context.add(DefaultContextKeys.SERVER_KEY, this.vaultPermission.getVaultServer()); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultHookManager.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultHookManager.java index b45df7968..6b0570df2 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultHookManager.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultHookManager.java @@ -65,7 +65,7 @@ public class VaultHookManager { sm.register(Chat.class, this.chat, this.plugin.getBootstrap(), ServicePriority.High); } catch (Exception e) { - e.printStackTrace(); + this.plugin.getLogger().severe("Error occurred whilst hooking into Vault.", e); } } 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 cb85f5daf..cf581e0d5 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 @@ -93,8 +93,7 @@ public class BungeeConnectionListener extends AbstractConnectionListener impleme recordConnection(c.getUniqueId()); this.plugin.getEventDispatcher().dispatchPlayerLoginProcess(c.getUniqueId(), c.getName(), user); } catch (Exception ex) { - this.plugin.getLogger().severe("Exception occurred whilst loading data for " + c.getUniqueId() + " - " + c.getName()); - ex.printStackTrace(); + this.plugin.getLogger().severe("Exception occurred whilst loading data for " + c.getUniqueId() + " - " + c.getName(), ex); // there was some error loading if (this.plugin.getConfiguration().get(ConfigKeys.CANCEL_FAILED_LOGINS)) { diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeePermissionCheckListener.java b/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeePermissionCheckListener.java index 6c2867ec4..de987ba3f 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeePermissionCheckListener.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeePermissionCheckListener.java @@ -63,8 +63,7 @@ public class BungeePermissionCheckListener implements Listener { User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId()); if (user == null) { this.plugin.getLogger().warn("A permission check was made for player " + player.getName() + " - " + player.getUniqueId() + ", " + - "but LuckPerms does not have any permissions data loaded for them. Perhaps their UUID has been altered since login?"); - new Exception().printStackTrace(); + "but LuckPerms does not have any permissions data loaded for them. Perhaps their UUID has been altered since login?", new Exception()); e.setHasPermission(false); return; @@ -93,8 +92,7 @@ public class BungeePermissionCheckListener implements Listener { User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId()); if (user == null) { this.plugin.getLogger().warn("A permission check was made for player " + player.getName() + " - " + player.getUniqueId() + ", " + - "but LuckPerms does not have any permissions data loaded for them. Perhaps their UUID has been altered since login?"); - new Exception().printStackTrace(); + "but LuckPerms does not have any permissions data loaded for them. Perhaps their UUID has been altered since login?", new Exception()); e.setResult(Tristate.UNDEFINED); return; diff --git a/common/src/main/java/me/lucko/luckperms/common/actionlog/LogDispatcher.java b/common/src/main/java/me/lucko/luckperms/common/actionlog/LogDispatcher.java index 2ef4d526f..a1df1622a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/actionlog/LogDispatcher.java +++ b/common/src/main/java/me/lucko/luckperms/common/actionlog/LogDispatcher.java @@ -100,7 +100,7 @@ public class LogDispatcher { try { this.plugin.getStorage().logAction(entry).get(); } catch (Exception e) { - e.printStackTrace(); + plugin.getLogger().warn("Error whilst storing action", e); } } 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 e3cb5d7e0..197b6b22e 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 @@ -258,7 +258,7 @@ public abstract class Exporter implements Runnable { try (Writer writer = new OutputStreamWriter(new GZIPOutputStream(bytesOut), StandardCharsets.UTF_8)) { GsonProvider.prettyPrinting().toJson(json, writer); } catch (IOException e) { - e.printStackTrace(); + this.plugin.getLogger().severe("Error compressing data", e); } try { @@ -267,7 +267,7 @@ public abstract class Exporter implements Runnable { } catch (UnsuccessfulRequestException e) { this.log.getListeners().forEach(l -> Message.HTTP_REQUEST_FAILURE.send(l, e.getResponse().code(), e.getResponse().message())); } catch (IOException e) { - new RuntimeException("Error uploading data to bytebin", e).printStackTrace(); + this.plugin.getLogger().severe("Error uploading data to bytebin", e); this.log.getListeners().forEach(Message.HTTP_UNKNOWN_FAILURE::send); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/backup/Importer.java b/common/src/main/java/me/lucko/luckperms/common/backup/Importer.java index d80dee173..b86cc98e9 100644 --- a/common/src/main/java/me/lucko/luckperms/common/backup/Importer.java +++ b/common/src/main/java/me/lucko/luckperms/common/backup/Importer.java @@ -134,7 +134,7 @@ public class Importer implements Runnable { @Override public void run() { long startTime = System.currentTimeMillis(); - this.notify.forEach(s -> Message.IMPORT_START.send(s)); + this.notify.forEach(Message.IMPORT_START::send); // start an update task in the background - we'll #join this later CompletableFuture updateTask = CompletableFuture.runAsync(() -> this.plugin.getSyncTaskBuffer().requestDirectly()); diff --git a/common/src/main/java/me/lucko/luckperms/common/command/CommandManager.java b/common/src/main/java/me/lucko/luckperms/common/command/CommandManager.java index 9b4a53e78..5d9493d62 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/CommandManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/CommandManager.java @@ -141,8 +141,7 @@ public class CommandManager { try { return execute(sender, label, args); } catch (Throwable e) { - this.plugin.getLogger().severe("Exception whilst executing command: " + args.toString()); - e.printStackTrace(); + this.plugin.getLogger().severe("Exception whilst executing command: " + args, e); return null; } }, this.executor); diff --git a/common/src/main/java/me/lucko/luckperms/common/command/tabcomplete/TabCompletions.java b/common/src/main/java/me/lucko/luckperms/common/command/tabcomplete/TabCompletions.java index 0500fffc4..f2bbdab6a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/tabcomplete/TabCompletions.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/tabcomplete/TabCompletions.java @@ -104,7 +104,7 @@ public final class TabCompletions { // cursor is specifying the value String key = partial.substring(0, index); - if (key.equals("") || key.trim().isEmpty()) { + if (key.isEmpty() || key.trim().isEmpty()) { return Collections.emptyList(); } diff --git a/common/src/main/java/me/lucko/luckperms/common/command/utils/StorageAssistant.java b/common/src/main/java/me/lucko/luckperms/common/command/utils/StorageAssistant.java index 06627dd6c..f20d4cb21 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/utils/StorageAssistant.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/utils/StorageAssistant.java @@ -77,7 +77,7 @@ public final class StorageAssistant { try { plugin.getStorage().saveUser(user).get(); } catch (Exception e) { - e.printStackTrace(); + plugin.getLogger().warn("Error whilst saving user", e); Message.USER_SAVE_ERROR.send(sender, user); return; } @@ -92,7 +92,7 @@ public final class StorageAssistant { try { plugin.getStorage().saveGroup(group).get(); } catch (Exception e) { - e.printStackTrace(); + plugin.getLogger().warn("Error whilst saving group", e); Message.GROUP_SAVE_ERROR.send(sender, group); return; } @@ -110,7 +110,7 @@ public final class StorageAssistant { try { plugin.getStorage().saveTrack(track).get(); } catch (Exception e) { - e.printStackTrace(); + plugin.getLogger().warn("Error whilst saving track", e); Message.TRACK_SAVE_ERROR.send(sender, track.getName()); return; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderShowTracks.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderShowTracks.java index f6e9c609e..1dc215d6a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderShowTracks.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderShowTracks.java @@ -67,7 +67,7 @@ public class HolderShowTracks extends ChildCommand { try { newGroup = plugin.getStorage().createAndLoadGroup(newGroupName, CreationCause.COMMAND).get(); } catch (Exception e) { - e.printStackTrace(); + plugin.getLogger().warn("Error whilst creating group", e); Message.CREATE_ERROR.send(sender, Component.text(newGroupName)); return CommandResult.FAILURE; } @@ -74,7 +74,7 @@ public class GroupRename extends ChildCommand { try { plugin.getStorage().deleteGroup(target, DeletionCause.COMMAND).get(); } catch (Exception e) { - e.printStackTrace(); + plugin.getLogger().warn("Error whilst deleting group", e); Message.DELETE_ERROR.send(sender, target.getFormattedDisplayName()); return CommandResult.FAILURE; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/ListGroups.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/ListGroups.java index 6bb4805c1..c1e32eb7e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/ListGroups.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/ListGroups.java @@ -49,7 +49,7 @@ public class ListGroups extends SingleCommand { try { plugin.getStorage().loadAllGroups().get(); } catch (Exception e) { - e.printStackTrace(); + plugin.getLogger().warn("Error whilst loading groups", e); Message.GROUPS_LOAD_ERROR.send(sender); return CommandResult.LOADING_ERROR; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/ApplyEditsCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/ApplyEditsCommand.java index 9ab94b6a2..416e9cfb8 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/ApplyEditsCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/ApplyEditsCommand.java @@ -62,7 +62,7 @@ public class ApplyEditsCommand extends SingleCommand { Message.EDITOR_HTTP_REQUEST_FAILURE.send(sender, e.getResponse().code(), e.getResponse().message()); return CommandResult.STATE_ERROR; } catch (IOException e) { - new RuntimeException("Error reading data from bytebin", e).printStackTrace(); + plugin.getLogger().warn("Error reading data from bytebin", e); Message.EDITOR_HTTP_UNKNOWN_FAILURE.send(sender); return CommandResult.STATE_ERROR; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/ExportCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/ExportCommand.java index 3fa042e2f..5906fc11a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/ExportCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/ExportCommand.java @@ -85,7 +85,7 @@ public class ExportCommand extends SingleCommand { Files.createFile(path); } catch (IOException e) { Message.EXPORT_FILE_FAILURE.send(sender); - e.printStackTrace(); + plugin.getLogger().warn("Error whilst writing to the file", e); return CommandResult.FAILURE; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/ImportCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/ImportCommand.java index f8287d86b..47b599b5c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/ImportCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/ImportCommand.java @@ -102,7 +102,7 @@ public class ImportCommand extends SingleCommand { try (BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(Files.newInputStream(path)), StandardCharsets.UTF_8))) { data = GsonProvider.normal().fromJson(reader, JsonObject.class); } catch (IOException e) { - e.printStackTrace(); + plugin.getLogger().warn("Error whilst reading from the import file", e); Message.IMPORT_FILE_READ_FAILURE.send(sender); this.running.set(false); return CommandResult.FAILURE; @@ -121,7 +121,7 @@ public class ImportCommand extends SingleCommand { Message.HTTP_REQUEST_FAILURE.send(sender, e.getResponse().code(), e.getResponse().message()); return CommandResult.STATE_ERROR; } catch (IOException e) { - new RuntimeException("Error reading data to bytebin", e).printStackTrace(); + plugin.getLogger().severe("Error reading data to bytebin", e); Message.HTTP_UNKNOWN_FAILURE.send(sender); return CommandResult.STATE_ERROR; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/NetworkSyncCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/NetworkSyncCommand.java index b5d949a20..7479b6c63 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/NetworkSyncCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/NetworkSyncCommand.java @@ -60,7 +60,7 @@ public class NetworkSyncCommand extends SingleCommand { Message.UPDATE_TASK_PUSH_SUCCESS.send(sender, messagingService.get().getName()); return CommandResult.SUCCESS; } catch (Exception e) { - e.printStackTrace(); + plugin.getLogger().warn("Error whilst pushing changes to other servers", e); Message.UPDATE_TASK_PUSH_FAILURE.send(sender); return CommandResult.FAILURE; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/TranslationsCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/TranslationsCommand.java index 9ea04849e..8a39dd5eb 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/TranslationsCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/TranslationsCommand.java @@ -80,7 +80,7 @@ public class TranslationsCommand extends SingleCommand { availableTranslations = getAvailableTranslations(plugin); } catch (IOException | UnsuccessfulRequestException e) { Message.TRANSLATIONS_SEARCHING_ERROR.send(sender); - e.printStackTrace(); + plugin.getLogger().warn("Unable to obtain a list of available translations", e); return CommandResult.FAILURE; } @@ -134,7 +134,7 @@ public class TranslationsCommand extends SingleCommand { } } catch (UnsuccessfulRequestException | IOException e) { Message.TRANSLATIONS_DOWNLOAD_ERROR.send(sender, language.locale.toString()); - e.printStackTrace(); + plugin.getLogger().warn("Unable to download translations", e); } } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/TreeCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/TreeCommand.java index a45bf334b..eff9f44fe 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/TreeCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/TreeCommand.java @@ -94,7 +94,7 @@ public class TreeCommand extends SingleCommand { Message.GENERIC_HTTP_REQUEST_FAILURE.send(sender, e.getResponse().code(), e.getResponse().message()); return CommandResult.STATE_ERROR; } catch (IOException e) { - new RuntimeException("Error uploading data to bytebin", e).printStackTrace(); + plugin.getLogger().warn("Error uploading data to bytebin", e); Message.GENERIC_HTTP_UNKNOWN_FAILURE.send(sender); return CommandResult.STATE_ERROR; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/VerboseCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/VerboseCommand.java index 1d124255e..df6759a0d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/VerboseCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/VerboseCommand.java @@ -128,13 +128,13 @@ public class VerboseCommand extends SingleCommand { verboseHandler.registerListener(sender, compiledFilter, notify); if (notify) { - if (!filter.equals("")) { + if (!filter.isEmpty()) { Message.VERBOSE_ON_QUERY.send(sender, filter); } else { Message.VERBOSE_ON.send(sender); } } else { - if (!filter.equals("")) { + if (!filter.isEmpty()) { Message.VERBOSE_RECORDING_ON_QUERY.send(sender, filter); } else { Message.VERBOSE_RECORDING_ON.send(sender); @@ -160,7 +160,7 @@ public class VerboseCommand extends SingleCommand { Message.GENERIC_HTTP_REQUEST_FAILURE.send(sender, e.getResponse().code(), e.getResponse().message()); return CommandResult.STATE_ERROR; } catch (IOException e) { - new RuntimeException("Error uploading data to bytebin", e).printStackTrace(); + plugin.getLogger().warn("Error uploading data to bytebin", e); Message.GENERIC_HTTP_UNKNOWN_FAILURE.send(sender); return CommandResult.STATE_ERROR; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/CreateTrack.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/CreateTrack.java index 451a2ff05..7cbc3a68b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/CreateTrack.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/CreateTrack.java @@ -67,7 +67,7 @@ public class CreateTrack extends SingleCommand { try { plugin.getStorage().createAndLoadTrack(trackName, CreationCause.COMMAND).get(); } catch (Exception e) { - e.printStackTrace(); + plugin.getLogger().warn("Error whilst creating track", e); Message.CREATE_ERROR.send(sender, Component.text(trackName)); return CommandResult.FAILURE; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/DeleteTrack.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/DeleteTrack.java index fcb33563f..8a0f7a116 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/DeleteTrack.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/DeleteTrack.java @@ -67,7 +67,7 @@ public class DeleteTrack extends SingleCommand { try { plugin.getStorage().deleteTrack(track, DeletionCause.COMMAND).get(); } catch (Exception e) { - e.printStackTrace(); + plugin.getLogger().warn("Error whilst deleting track", e); Message.DELETE_ERROR.send(sender, Component.text(track.getName())); return CommandResult.FAILURE; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/ListTracks.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/ListTracks.java index 7f3be513b..87c1c8cf6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/ListTracks.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/ListTracks.java @@ -47,7 +47,7 @@ public class ListTracks extends SingleCommand { try { plugin.getStorage().loadAllTracks().get(); } catch (Exception e) { - e.printStackTrace(); + plugin.getLogger().warn("Error whilst loading tracks", e); Message.TRACKS_LOAD_ERROR.send(sender); return CommandResult.LOADING_ERROR; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackRename.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackRename.java index 675c15e08..8533d8733 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackRename.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackRename.java @@ -65,7 +65,7 @@ public class TrackRename extends ChildCommand { try { newTrack = plugin.getStorage().createAndLoadTrack(newTrackName, CreationCause.COMMAND).get(); } catch (Exception e) { - e.printStackTrace(); + plugin.getLogger().warn("Error whilst creating track", e); Message.CREATE_ERROR.send(sender, Component.text(newTrackName)); return CommandResult.FAILURE; } @@ -73,7 +73,7 @@ public class TrackRename extends ChildCommand { try { plugin.getStorage().deleteTrack(target, DeletionCause.COMMAND).get(); } catch (Exception e) { - e.printStackTrace(); + plugin.getLogger().warn("Error whilst deleting track", e); Message.DELETE_ERROR.send(sender, Component.text(target.getName())); return CommandResult.FAILURE; } diff --git a/common/src/main/java/me/lucko/luckperms/common/context/ContextManager.java b/common/src/main/java/me/lucko/luckperms/common/context/ContextManager.java index dd806c8c9..731cb37f6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/context/ContextManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/context/ContextManager.java @@ -137,8 +137,7 @@ public abstract class ContextManager { try { calculator.calculate(subject, accumulator::add); } catch (Throwable e) { - this.plugin.getLogger().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst calculating the context of subject " + subject); - e.printStackTrace(); + this.plugin.getLogger().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst calculating the context of subject " + subject, e); } } return formQueryOptions(subject, accumulator.build()); @@ -150,8 +149,7 @@ public abstract class ContextManager { try { calculator.calculate(accumulator::add); } catch (Throwable e) { - this.plugin.getLogger().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst calculating static contexts"); - e.printStackTrace(); + this.plugin.getLogger().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst calculating static contexts", e); } } return formQueryOptions(accumulator.build()); @@ -164,8 +162,7 @@ public abstract class ContextManager { try { potentialContexts = calculator.estimatePotentialContexts(); } catch (Throwable e) { - this.plugin.getLogger().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst estimating potential contexts"); - e.printStackTrace(); + this.plugin.getLogger().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst estimating potential contexts", e); continue; } builder.addAll(potentialContexts); diff --git a/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyManager.java b/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyManager.java index 221b77f7a..22899d219 100644 --- a/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyManager.java @@ -126,8 +126,7 @@ public class DependencyManager { try { loadDependency(dependency); } catch (Throwable e) { - this.plugin.getLogger().severe("Unable to load dependency " + dependency.name() + "."); - e.printStackTrace(); + this.plugin.getLogger().severe("Unable to load dependency " + dependency.name() + ".", e); } finally { latch.countDown(); } @@ -210,7 +209,7 @@ public class DependencyManager { try { MoreFiles.deleteDirectory(oldCacheDirectory); } catch (IOException e) { - e.printStackTrace(); + plugin.getLogger().warn("Unable to delete lib directory", e); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/event/LuckPermsEventSubscription.java b/common/src/main/java/me/lucko/luckperms/common/event/LuckPermsEventSubscription.java index 32bc33df1..2df785fc5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/event/LuckPermsEventSubscription.java +++ b/common/src/main/java/me/lucko/luckperms/common/event/LuckPermsEventSubscription.java @@ -94,8 +94,7 @@ public class LuckPermsEventSubscription implements Eve try { this.consumer.accept(event); } catch (Throwable t) { - this.eventBus.getPlugin().getLogger().warn("Unable to pass event " + event.getEventType().getSimpleName() + " to handler " + this.consumer.getClass().getName()); - t.printStackTrace(); + this.eventBus.getPlugin().getLogger().warn("Unable to pass event " + event.getEventType().getSimpleName() + " to handler " + this.consumer.getClass().getName(), t); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/extension/SimpleExtensionManager.java b/common/src/main/java/me/lucko/luckperms/common/extension/SimpleExtensionManager.java index bd9cb150e..bad891dda 100644 --- a/common/src/main/java/me/lucko/luckperms/common/extension/SimpleExtensionManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/extension/SimpleExtensionManager.java @@ -68,7 +68,7 @@ public class SimpleExtensionManager implements ExtensionManager, AutoCloseable { try { extension.instance.unload(); } catch (Exception e) { - e.printStackTrace(); + this.plugin.getLogger().warn("Exception unloading extension", e); } } this.extensions.clear(); @@ -96,12 +96,12 @@ public class SimpleExtensionManager implements ExtensionManager, AutoCloseable { try { loadExtension(path); } catch (IOException e) { - new RuntimeException("Exception loading extension from " + path, e).printStackTrace(); + this.plugin.getLogger().warn("Exception loading extension from " + path, e); } } }); } catch (IOException e) { - e.printStackTrace(); + this.plugin.getLogger().warn("Exception loading extensions from " + directory, e); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/locale/TranslationManager.java b/common/src/main/java/me/lucko/luckperms/common/locale/TranslationManager.java index 3ee92e6db..96b3f4721 100644 --- a/common/src/main/java/me/lucko/luckperms/common/locale/TranslationManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/locale/TranslationManager.java @@ -104,7 +104,7 @@ public class TranslationManager { try { this.registry.registerAll(DEFAULT_LOCALE, bundle, false); } catch (IllegalArgumentException e) { - e.printStackTrace(); + this.plugin.getLogger().warn("Error loading default locale file", e); } } @@ -127,8 +127,7 @@ public class TranslationManager { loaded.put(result.getKey(), result.getValue()); } } catch (Exception e) { - this.plugin.getLogger().warn("Error loading locale file: " + translationFile.getFileName().toString()); - e.printStackTrace(); + this.plugin.getLogger().warn("Error loading locale file: " + translationFile.getFileName(), e); } } @@ -155,8 +154,7 @@ public class TranslationManager { try (BufferedReader reader = Files.newBufferedReader(translationFile, StandardCharsets.UTF_8)) { bundle = new PropertyResourceBundle(reader); } catch(IOException e) { - this.plugin.getLogger().warn("Error loading locale file: " + localeString); - e.printStackTrace(); + this.plugin.getLogger().warn("Error loading locale file: " + localeString, e); return null; } diff --git a/common/src/main/java/me/lucko/luckperms/common/messaging/MessagingFactory.java b/common/src/main/java/me/lucko/luckperms/common/messaging/MessagingFactory.java index 4c55d138d..1902acbc6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/messaging/MessagingFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/messaging/MessagingFactory.java @@ -96,7 +96,7 @@ public class MessagingFactory

{ try { return new LuckPermsMessagingService(this.plugin, new RedisMessengerProvider()); } catch (Exception e) { - e.printStackTrace(); + getPlugin().getLogger().severe("Exception occurred whilst enabling Redis messaging service", e); } } else { this.plugin.getLogger().warn("Messaging Service was set to redis, but redis is not enabled!"); @@ -105,7 +105,7 @@ public class MessagingFactory

{ try { return new LuckPermsMessagingService(this.plugin, new SqlMessengerProvider()); } catch (Exception e) { - e.printStackTrace(); + getPlugin().getLogger().severe("Exception occurred whilst enabling SQL messaging service", e); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/metastacking/StandardStackElements.java b/common/src/main/java/me/lucko/luckperms/common/metastacking/StandardStackElements.java index 6023c3b01..0c94af9cd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/metastacking/StandardStackElements.java +++ b/common/src/main/java/me/lucko/luckperms/common/metastacking/StandardStackElements.java @@ -84,7 +84,7 @@ public final class StandardStackElements { .map(s -> { MetaStackElement parsed = parseFromString(plugin, s); if (parsed == null) { - new IllegalArgumentException("Unable to parse from: " + s).printStackTrace(); + plugin.getLogger().warn("Unable to parse from: " + s, new IllegalArgumentException()); } return parsed; }) 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 ebeb15e72..236382881 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 @@ -140,8 +140,7 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin { } catch (Throwable e) { // catch throwable here, seems some JVMs throw UnsatisfiedLinkError when trying // to create a watch service. see: https://github.com/lucko/LuckPerms/issues/2066 - getLogger().warn("Error occurred whilst trying to create a file watcher:"); - e.printStackTrace(); + getLogger().warn("Error occurred whilst trying to create a file watcher:", e); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/plugin/logging/JavaPluginLogger.java b/common/src/main/java/me/lucko/luckperms/common/plugin/logging/JavaPluginLogger.java index fd986ba31..ff771aba9 100644 --- a/common/src/main/java/me/lucko/luckperms/common/plugin/logging/JavaPluginLogger.java +++ b/common/src/main/java/me/lucko/luckperms/common/plugin/logging/JavaPluginLogger.java @@ -25,6 +25,7 @@ package me.lucko.luckperms.common.plugin.logging; +import java.util.logging.Level; import java.util.logging.Logger; public class JavaPluginLogger implements PluginLogger { @@ -44,8 +45,18 @@ public class JavaPluginLogger implements PluginLogger { this.logger.warning(s); } + @Override + public void warn(String s, Throwable t) { + this.logger.log(Level.WARNING, s, t); + } + @Override public void severe(String s) { this.logger.severe(s); } + + @Override + public void severe(String s, Throwable t) { + this.logger.log(Level.SEVERE, s, t); + } } diff --git a/common/src/main/java/me/lucko/luckperms/common/plugin/logging/PluginLogger.java b/common/src/main/java/me/lucko/luckperms/common/plugin/logging/PluginLogger.java index 4a4e2373c..7a0de4e57 100644 --- a/common/src/main/java/me/lucko/luckperms/common/plugin/logging/PluginLogger.java +++ b/common/src/main/java/me/lucko/luckperms/common/plugin/logging/PluginLogger.java @@ -37,6 +37,10 @@ public interface PluginLogger { void warn(String s); + void warn(String s, Throwable t); + void severe(String s); + void severe(String s, Throwable t); + } diff --git a/common/src/main/java/me/lucko/luckperms/common/plugin/logging/Slf4jPluginLogger.java b/common/src/main/java/me/lucko/luckperms/common/plugin/logging/Slf4jPluginLogger.java index 7408f8d4f..557230000 100644 --- a/common/src/main/java/me/lucko/luckperms/common/plugin/logging/Slf4jPluginLogger.java +++ b/common/src/main/java/me/lucko/luckperms/common/plugin/logging/Slf4jPluginLogger.java @@ -44,8 +44,18 @@ public class Slf4jPluginLogger implements PluginLogger { this.logger.warn(s); } + @Override + public void warn(String s, Throwable t) { + this.logger.warn(s, t); + } + @Override public void severe(String s) { this.logger.error(s); } + + @Override + public void severe(String s, Throwable t) { + this.logger.error(s, t); + } } 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 425baec9e..c3b3a1c92 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 @@ -115,8 +115,7 @@ public class Storage { try { this.implementation.init(); } catch (Exception e) { - this.plugin.getLogger().severe("Failed to init storage implementation"); - e.printStackTrace(); + this.plugin.getLogger().severe("Failed to init storage implementation", e); } } @@ -124,8 +123,7 @@ public class Storage { try { this.implementation.shutdown(); } catch (Exception e) { - this.plugin.getLogger().severe("Failed to shutdown storage implementation"); - e.printStackTrace(); + this.plugin.getLogger().severe("Failed to shutdown storage implementation", e); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/file/AbstractConfigurateStorage.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/file/AbstractConfigurateStorage.java index 35ecdbdea..51479498f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/file/AbstractConfigurateStorage.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/file/AbstractConfigurateStorage.java @@ -36,7 +36,6 @@ import me.lucko.luckperms.common.context.ContextSetConfigurateSerializer; import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl; import me.lucko.luckperms.common.model.Group; import me.lucko.luckperms.common.model.HolderType; -import me.lucko.luckperms.common.model.PermissionHolderIdentifier; import me.lucko.luckperms.common.model.Track; import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.model.manager.group.GroupManager; @@ -150,8 +149,7 @@ public abstract class AbstractConfigurateStorage implements StorageImplementatio // used to report i/o exceptions which took place in a specific file protected RuntimeException reportException(String file, Exception ex) throws RuntimeException { - this.plugin.getLogger().warn("Exception thrown whilst performing i/o: " + file); - ex.printStackTrace(); + this.plugin.getLogger().warn("Exception thrown whilst performing i/o: " + file, ex); Throwables.throwIfUnchecked(ex); throw new RuntimeException(ex); } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/split/SplitStorage.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/split/SplitStorage.java index 365f099a1..06aa16294 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/split/SplitStorage.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/split/SplitStorage.java @@ -103,7 +103,7 @@ public class SplitStorage implements StorageImplementation { try { ds.shutdown(); } catch (Exception e) { - e.printStackTrace(); + this.plugin.getLogger().severe("Exception whilst disabling " + ds + " storage", e); } } } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SqlNode.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SqlNode.java index c4720df44..484a9611f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SqlNode.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SqlNode.java @@ -86,10 +86,10 @@ public final class SqlNode { } public static SqlNode fromSqlFields(long sqlId, String permission, boolean value, String server, String world, long expiry, String contexts) { - if (Strings.emptyToNull(server) == null) { + if (Strings.isNullOrEmpty(server)) { server = "global"; } - if (Strings.emptyToNull(world) == null) { + if (Strings.isNullOrEmpty(world)) { world = "global"; } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SqlStorage.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SqlStorage.java index a8a075e93..bf49f450e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SqlStorage.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SqlStorage.java @@ -215,7 +215,7 @@ public class SqlStorage implements StorageImplementation { try { this.connectionFactory.shutdown(); } catch (Exception e) { - e.printStackTrace(); + this.plugin.getLogger().severe("Exception whilst disabling SQLite storage", e); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/file/H2ConnectionFactory.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/file/H2ConnectionFactory.java index 31b3b05ce..c4c63ff94 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/file/H2ConnectionFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/file/H2ConnectionFactory.java @@ -57,7 +57,7 @@ public class H2ConnectionFactory extends FlatfileConnectionFactory { try { Files.move(data, getWriteFile()); } catch (IOException e) { - e.printStackTrace(); + plugin.getLogger().warn("Unable to move old database", e); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/file/SQLiteConnectionFactory.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/file/SQLiteConnectionFactory.java index f1735320d..4b05571e1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/file/SQLiteConnectionFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/file/SQLiteConnectionFactory.java @@ -56,7 +56,7 @@ public class SQLiteConnectionFactory extends FlatfileConnectionFactory { try { Files.move(data, file); } catch (IOException e) { - e.printStackTrace(); + plugin.getLogger().warn("Unable to move old database", e); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/treeview/TreeView.java b/common/src/main/java/me/lucko/luckperms/common/treeview/TreeView.java index 331b8ac0a..6391aa3aa 100644 --- a/common/src/main/java/me/lucko/luckperms/common/treeview/TreeView.java +++ b/common/src/main/java/me/lucko/luckperms/common/treeview/TreeView.java @@ -63,7 +63,7 @@ public class TreeView { private final ImmutableTreeNode view; public TreeView(PermissionRegistry source, String rootPosition) { - if (rootPosition.equals("") || rootPosition.equals("*")) { + if (rootPosition.isEmpty() || rootPosition.equals("*")) { rootPosition = "."; } else if (!rootPosition.equals(".") && rootPosition.endsWith(".")) { rootPosition = rootPosition.substring(0, rootPosition.length() - 1); 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 eade58ed1..77155f325 100644 --- a/nukkit/src/main/java/me/lucko/luckperms/nukkit/LPNukkitPlugin.java +++ b/nukkit/src/main/java/me/lucko/luckperms/nukkit/LPNukkitPlugin.java @@ -221,12 +221,13 @@ public class LPNukkitPlugin extends AbstractLuckPermsPlugin { LuckPermsPermissible lpPermissible = new LuckPermsPermissible(player, user, this); PermissibleInjector.inject(player, lpPermissible); } catch (Throwable t) { - t.printStackTrace(); + getLogger().severe("Exception thrown when setting up permissions for " + + player.getUniqueId() + " - " + player.getName(), t); } }); } } catch (Exception e) { - e.printStackTrace(); + getLogger().severe("Exception occurred whilst loading data for " + player.getUniqueId() + " - " + player.getName(), e); } }); } @@ -239,7 +240,8 @@ public class LPNukkitPlugin extends AbstractLuckPermsPlugin { try { PermissibleInjector.uninject(player, false); } catch (Exception e) { - e.printStackTrace(); + getLogger().severe("Exception thrown when unloading permissions from " + + player.getUniqueId() + " - " + player.getName(), e); } if (getConfiguration().get(ConfigKeys.AUTO_OP)) { diff --git a/nukkit/src/main/java/me/lucko/luckperms/nukkit/NukkitPluginLogger.java b/nukkit/src/main/java/me/lucko/luckperms/nukkit/NukkitPluginLogger.java index b58547fab..454814532 100644 --- a/nukkit/src/main/java/me/lucko/luckperms/nukkit/NukkitPluginLogger.java +++ b/nukkit/src/main/java/me/lucko/luckperms/nukkit/NukkitPluginLogger.java @@ -46,8 +46,18 @@ public class NukkitPluginLogger implements PluginLogger { this.logger.warning(s); } + @Override + public void warn(String s, Throwable t) { + this.logger.warning(s, t); + } + @Override public void severe(String s) { this.logger.error(s); } + + @Override + public void severe(String s, Throwable t) { + this.logger.error(s, t); + } } diff --git a/nukkit/src/main/java/me/lucko/luckperms/nukkit/inject/server/InjectorDefaultsMap.java b/nukkit/src/main/java/me/lucko/luckperms/nukkit/inject/server/InjectorDefaultsMap.java index 3bec897ab..a53e9063b 100644 --- a/nukkit/src/main/java/me/lucko/luckperms/nukkit/inject/server/InjectorDefaultsMap.java +++ b/nukkit/src/main/java/me/lucko/luckperms/nukkit/inject/server/InjectorDefaultsMap.java @@ -79,8 +79,7 @@ public class InjectorDefaultsMap implements Runnable { this.plugin.setDefaultPermissionMap(defaultsMap); } } catch (Exception e) { - this.plugin.getLogger().severe("Exception occurred whilst injecting LuckPerms Default Permission map."); - e.printStackTrace(); + this.plugin.getLogger().severe("Exception occurred whilst injecting LuckPerms Default Permission map.", e); } } diff --git a/nukkit/src/main/java/me/lucko/luckperms/nukkit/inject/server/InjectorPermissionMap.java b/nukkit/src/main/java/me/lucko/luckperms/nukkit/inject/server/InjectorPermissionMap.java index 400859474..23c47914f 100644 --- a/nukkit/src/main/java/me/lucko/luckperms/nukkit/inject/server/InjectorPermissionMap.java +++ b/nukkit/src/main/java/me/lucko/luckperms/nukkit/inject/server/InjectorPermissionMap.java @@ -67,8 +67,7 @@ public class InjectorPermissionMap implements Runnable { this.plugin.setPermissionMap(permissionMap); } } catch (Exception e) { - this.plugin.getLogger().severe("Exception occurred whilst injecting LuckPerms Permission map."); - e.printStackTrace(); + this.plugin.getLogger().severe("Exception occurred whilst injecting LuckPerms Permission map.", e); } } diff --git a/nukkit/src/main/java/me/lucko/luckperms/nukkit/inject/server/InjectorSubscriptionMap.java b/nukkit/src/main/java/me/lucko/luckperms/nukkit/inject/server/InjectorSubscriptionMap.java index 1b3a8278c..691020dcb 100644 --- a/nukkit/src/main/java/me/lucko/luckperms/nukkit/inject/server/InjectorSubscriptionMap.java +++ b/nukkit/src/main/java/me/lucko/luckperms/nukkit/inject/server/InjectorSubscriptionMap.java @@ -67,8 +67,7 @@ public class InjectorSubscriptionMap implements Runnable { this.plugin.setSubscriptionMap(subscriptionMap); } } catch (Exception e) { - this.plugin.getLogger().severe("Exception occurred whilst injecting LuckPerms Permission Subscription map."); - e.printStackTrace(); + this.plugin.getLogger().severe("Exception occurred whilst injecting LuckPerms Permission Subscription map.", e); } } 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 66ef0a48c..2539c4da6 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 @@ -92,8 +92,7 @@ public class NukkitConnectionListener extends AbstractConnectionListener impleme recordConnection(e.getUuid()); this.plugin.getEventDispatcher().dispatchPlayerLoginProcess(e.getUuid(), e.getName(), user); } catch (Exception ex) { - this.plugin.getLogger().severe("Exception occurred whilst loading data for " + e.getUuid() + " - " + e.getName()); - ex.printStackTrace(); + this.plugin.getLogger().severe("Exception occurred whilst loading data for " + e.getUuid() + " - " + e.getName(), ex); // deny the connection this.deniedAsyncLogin.add(e.getUuid()); @@ -165,8 +164,7 @@ public class NukkitConnectionListener extends AbstractConnectionListener impleme } catch (Throwable t) { this.plugin.getLogger().warn("Exception thrown when setting up permissions for " + - player.getUniqueId() + " - " + player.getName() + " - denying login."); - t.printStackTrace(); + player.getUniqueId() + " - " + player.getName() + " - denying login.", t); e.setCancelled(); Component reason = TranslationManager.render(Message.LOADING_SETUP_ERROR.build()); @@ -211,7 +209,8 @@ public class NukkitConnectionListener extends AbstractConnectionListener impleme try { PermissibleInjector.uninject(player, true); } catch (Exception ex) { - ex.printStackTrace(); + this.plugin.getLogger().severe("Exception thrown when unloading permissions from " + + player.getUniqueId() + " - " + player.getName(), ex); } // Handle auto op diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongeBootstrap.java b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongeBootstrap.java index 095c035a2..736ec78ac 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongeBootstrap.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongeBootstrap.java @@ -256,7 +256,7 @@ public class LPSpongeBootstrap implements LuckPermsBootstrap { try { MoreFiles.createDirectoriesIfNotExists(dataDirectory); } catch (IOException e) { - e.printStackTrace(); + this.logger.warn("Unable to create LuckPerms directory", e); } return dataDirectory; } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommandExecutor.java b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommandExecutor.java index bbb6ca50a..30a50ace4 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommandExecutor.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommandExecutor.java @@ -107,8 +107,7 @@ public class SpongeCommandExecutor extends CommandManager implements CommandCall .map(e -> ((Player) e)) .collect(Collectors.toList()); } catch (IllegalArgumentException e) { - this.plugin.getLogger().warn("Error parsing selector '" + arg + "' for " + source + " executing " + args); - e.printStackTrace(); + this.plugin.getLogger().warn("Error parsing selector '" + arg + "' for " + source + " executing " + args, e); continue; } 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 b52d9050b..d13abf390 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 @@ -93,8 +93,7 @@ public class SpongeConnectionListener extends AbstractConnectionListener { recordConnection(profile.getUniqueId()); this.plugin.getEventDispatcher().dispatchPlayerLoginProcess(profile.getUniqueId(), username, user); } catch (Exception ex) { - this.plugin.getLogger().severe("Exception occurred whilst loading data for " + profile.getUniqueId() + " - " + profile.getName()); - ex.printStackTrace(); + this.plugin.getLogger().severe("Exception occurred whilst loading data for " + profile.getUniqueId() + " - " + profile.getName(), ex); this.deniedAsyncLogin.add(profile.getUniqueId()); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/messaging/SpongeMessagingFactory.java b/sponge/src/main/java/me/lucko/luckperms/sponge/messaging/SpongeMessagingFactory.java index a920a5d03..88b84d0a1 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/messaging/SpongeMessagingFactory.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/messaging/SpongeMessagingFactory.java @@ -47,7 +47,7 @@ public class SpongeMessagingFactory extends MessagingFactory { try { return new LuckPermsMessagingService(getPlugin(), new PluginMessageMessengerProvider()); } catch (Exception e) { - e.printStackTrace(); + getPlugin().getLogger().severe("Exception occurred whilst enabling messaging", e); } } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/persisted/SubjectStorage.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/persisted/SubjectStorage.java index a16f4513a..6eb811c37 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/persisted/SubjectStorage.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/persisted/SubjectStorage.java @@ -76,7 +76,7 @@ public class SubjectStorage { } try (Stream s = Files.list(this.container)) { - return s.filter(p -> Files.isDirectory(p)) + return s.filter(Files::isDirectory) .map(p -> p.getFileName().toString()) .collect(ImmutableCollectors.toSet()); } catch (IOException e) { diff --git a/velocity/src/main/java/me/lucko/luckperms/velocity/listeners/VelocityConnectionListener.java b/velocity/src/main/java/me/lucko/luckperms/velocity/listeners/VelocityConnectionListener.java index 74bc89359..eed927954 100644 --- a/velocity/src/main/java/me/lucko/luckperms/velocity/listeners/VelocityConnectionListener.java +++ b/velocity/src/main/java/me/lucko/luckperms/velocity/listeners/VelocityConnectionListener.java @@ -91,8 +91,7 @@ public class VelocityConnectionListener extends AbstractConnectionListener { e.setProvider(new PlayerPermissionProvider(p, user, this.plugin.getContextManager().getCacheFor(p))); this.plugin.getEventDispatcher().dispatchPlayerLoginProcess(p.getUniqueId(), p.getUsername(), user); } catch (Exception ex) { - this.plugin.getLogger().severe("Exception occurred whilst loading data for " + p.getUniqueId() + " - " + p.getUsername()); - ex.printStackTrace(); + this.plugin.getLogger().severe("Exception occurred whilst loading data for " + p.getUniqueId() + " - " + p.getUsername(), ex); // there was some error loading if (this.plugin.getConfiguration().get(ConfigKeys.CANCEL_FAILED_LOGINS)) { diff --git a/velocity/src/main/java/me/lucko/luckperms/velocity/messaging/VelocityMessagingFactory.java b/velocity/src/main/java/me/lucko/luckperms/velocity/messaging/VelocityMessagingFactory.java index a4ca081a0..33c6b21d8 100644 --- a/velocity/src/main/java/me/lucko/luckperms/velocity/messaging/VelocityMessagingFactory.java +++ b/velocity/src/main/java/me/lucko/luckperms/velocity/messaging/VelocityMessagingFactory.java @@ -47,7 +47,7 @@ public class VelocityMessagingFactory extends MessagingFactory try { return new LuckPermsMessagingService(getPlugin(), new PluginMessageMessengerProvider()); } catch (Exception e) { - e.printStackTrace(); + getPlugin().getLogger().severe("Exception occurred whilst enabling messaging", e); } }