From 3c0b79ba069ee8159f59f7ef0ef1d50b105cbceb Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Thu, 17 Mar 2022 17:16:17 -0500 Subject: [PATCH] Start getting rid of legacy strings --- src/main/java/dev/plex/Plex.java | 68 +++++++++++++------ src/main/java/dev/plex/admin/AdminList.java | 1 - .../java/dev/plex/command/PlexCommand.java | 46 ++++++------- .../java/dev/plex/command/impl/LockupCMD.java | 7 +- .../dev/plex/command/impl/NameHistoryCMD.java | 1 - .../java/dev/plex/command/impl/PlexCMD.java | 34 ++++++---- src/main/java/dev/plex/config/Config.java | 47 ++++++++----- .../java/dev/plex/module/ModuleManager.java | 67 +++++++++++------- src/main/java/dev/plex/module/PlexModule.java | 25 ++++--- .../java/dev/plex/punishment/Punishment.java | 1 + .../plex/punishment/PunishmentManager.java | 22 +++--- .../services/impl/UpdateCheckerService.java | 4 +- .../dev/plex/storage/MongoConnection.java | 1 - .../dev/plex/storage/RedisConnection.java | 3 +- 14 files changed, 198 insertions(+), 129 deletions(-) diff --git a/src/main/java/dev/plex/Plex.java b/src/main/java/dev/plex/Plex.java index 0a50900..9361d44 100644 --- a/src/main/java/dev/plex/Plex.java +++ b/src/main/java/dev/plex/Plex.java @@ -23,18 +23,18 @@ import dev.plex.util.PlexLog; import dev.plex.util.PlexUtils; import dev.plex.util.UpdateChecker; import dev.plex.world.CustomWorld; +import java.io.File; +import java.util.UUID; import lombok.Getter; import lombok.Setter; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; -import java.io.File; -import java.util.UUID; - @Getter @Setter -public class Plex extends JavaPlugin { +public class Plex extends JavaPlugin +{ private static Plex plugin; public Config config; public Config messages; @@ -63,19 +63,24 @@ public class Plex extends JavaPlugin { private String system; - public static Plex get() { + public static Plex get() + { return plugin; } @Override - public void onLoad() { + public void onLoad() + { plugin = this; config = new Config(this, "config.yml"); messages = new Config(this, "messages.yml"); indefBans = new Config(this, "indefbans.yml"); modulesFolder = new File(this.getDataFolder() + File.separator + "modules"); - if (!modulesFolder.exists()) modulesFolder.mkdir(); + if (!modulesFolder.exists()) + { + modulesFolder.mkdir(); + } sqlConnection = new SQLConnection(); mongoConnection = new MongoConnection(); @@ -87,19 +92,24 @@ public class Plex extends JavaPlugin { } @Override - public void onEnable() { + public void onEnable() + { config.load(); messages.load(); + // Don't add default entries to indefinite ban file indefBans.load(false); moduleManager.enableModules(); system = config.getString("commands.permissions"); - try { + try + { PlexUtils.testConnections(); PlexLog.log("Connected to " + storageType.name().toUpperCase()); - } catch (Exception e) { + } + catch (Exception e) + { PlexLog.error("Failed to connect to " + storageType.name().toUpperCase()); e.printStackTrace(); } @@ -111,16 +121,22 @@ public class Plex extends JavaPlugin { Metrics metrics = new Metrics(this, 14143); PlexLog.log("Enabled Metrics"); - if (redisConnection.isEnabled()) { + if (redisConnection.isEnabled()) + { redisConnection.getJedis(); PlexLog.log("Connected to Redis!"); - } else { + } + else + { PlexLog.log("Redis is disabled in the configuration file, not connecting."); } - if (storageType == StorageType.MONGODB) { + if (storageType == StorageType.MONGODB) + { mongoPlayerData = new MongoPlayerData(); - } else { + } + else + { sqlPlayerData = new SQLPlayerData(); } @@ -148,24 +164,28 @@ public class Plex extends JavaPlugin { } @Override - public void onDisable() { + public void onDisable() + { Bukkit.getOnlinePlayers().forEach(player -> { PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId()); //get the player because it's literally impossible for them to not have an object - if (plugin.getRankManager().isAdmin(plexPlayer)) { + if (plugin.getRankManager().isAdmin(plexPlayer)) + { plugin.getAdminList().removeFromCache(UUID.fromString(plexPlayer.getUuid())); } if (mongoPlayerData != null) //back to mongo checking { mongoPlayerData.update(plexPlayer); //update the player's document - } else if (sqlPlayerData != null) //sql checking + } + else if (sqlPlayerData != null) //sql checking { sqlPlayerData.update(plexPlayer); } }); - if (redisConnection.isEnabled() && redisConnection.getJedis().isConnected()) { + if (redisConnection.isEnabled() && redisConnection.getJedis().isConnected()) + { PlexLog.log("Disabling Redis/Jedis. No memory leaks in this Anarchy server!"); redisConnection.getJedis().close(); } @@ -173,21 +193,25 @@ public class Plex extends JavaPlugin { moduleManager.disableModules(); } - private void generateWorlds() { + private void generateWorlds() + { PlexLog.log("Generating any worlds if needed..."); - for (String key : config.getConfigurationSection("worlds").getKeys(false)) { + for (String key : config.getConfigurationSection("worlds").getKeys(false)) + { CustomWorld.generateConfigFlatWorld(key); } PlexLog.log("Finished with world generation!"); } - private void reloadPlayers() { + private void reloadPlayers() + { Bukkit.getOnlinePlayers().forEach(player -> { PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId()); PlayerCache.getPlexPlayerMap().put(player.getUniqueId(), plexPlayer); //put them into the cache PlayerCache.getPunishedPlayerMap().put(player.getUniqueId(), new PunishedPlayer(player.getUniqueId())); - if (plugin.getRankManager().isAdmin(plexPlayer)) { + if (plugin.getRankManager().isAdmin(plexPlayer)) + { Admin admin = new Admin(UUID.fromString(plexPlayer.getUuid())); admin.setRank(plexPlayer.getRankFromString()); diff --git a/src/main/java/dev/plex/admin/AdminList.java b/src/main/java/dev/plex/admin/AdminList.java index 1224ca3..e6db31c 100644 --- a/src/main/java/dev/plex/admin/AdminList.java +++ b/src/main/java/dev/plex/admin/AdminList.java @@ -4,7 +4,6 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import dev.morphia.Datastore; import dev.morphia.query.Query; -import dev.plex.Plex; import dev.plex.PlexBase; import dev.plex.player.PlexPlayer; import dev.plex.rank.enums.Rank; diff --git a/src/main/java/dev/plex/command/PlexCommand.java b/src/main/java/dev/plex/command/PlexCommand.java index 93d92ba..fa870b0 100644 --- a/src/main/java/dev/plex/command/PlexCommand.java +++ b/src/main/java/dev/plex/command/PlexCommand.java @@ -19,6 +19,7 @@ import java.util.Arrays; import java.util.UUID; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.Bukkit; @@ -90,9 +91,8 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC * Executes the command * * @param sender The sender of the command - * @param playerSender The player who executed the command (null if command source is console or if command source is any but console executed) + * @param playerSender The player who executed the command (null if CommandSource is console or if CommandSource is any but console executed) * @param args A Kyori Component to send to the sender (can be null) - * @return */ protected abstract Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args); @@ -165,9 +165,9 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC } /** - * Checks if the string given is a command string + * Checks if the String given is a matching command * - * @param label The string to check + * @param label The String to check * @return true if the string is a command name or alias */ private boolean matches(String label) @@ -202,9 +202,9 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC } /** - * Sends a message to an audience + * Sends a message to an Audience * - * @param audience The audience to send the message to + * @param audience The Audience to send the message to * @param s The message to send */ protected void send(Audience audience, String s) @@ -213,10 +213,10 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC } /** - * Sends a message to an audience + * Sends a message to an Audience * - * @param audience The audience to send the message to - * @param component The component to send + * @param audience The Audience to send the message to + * @param component The Component to send */ protected void send(Audience audience, Component component) { @@ -226,7 +226,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC /** * Checks whether a sender has enough permissions or is high enough a rank * - * @param sender A command sender + * @param sender A CommandSender * @param rank The rank to check (if the server is using ranks) * @param permission The permission to check (if the server is using permissions) * @return true if the sender has enough permissions @@ -415,7 +415,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC * * @param s The message entry * @param objects Any objects to replace in order - * @return A Kyori component + * @return A Kyori Component */ protected Component messageComponent(String s, Object... objects) { @@ -435,25 +435,25 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC } /** - * Converts usage to a component + * Converts usage to a Component * - * @return A Kyori component stating the usage + * @return A Kyori Component stating the usage */ protected Component usage() { - return componentFromString(ChatColor.YELLOW + "Correct Usage: " + ChatColor.GRAY + this.getUsage()); + return Component.text("Correct Usage: ").color(NamedTextColor.YELLOW).append(componentFromString(this.getUsage()).color(NamedTextColor.GRAY)); } /** - * Converts usage to a component + * Converts usage to a Component *

* s The usage to convert * - * @return A Kyori component stating the usage + * @return A Kyori Component stating the usage */ protected Component usage(String s) { - return componentFromString(ChatColor.YELLOW + "Correct Usage: " + ChatColor.GRAY + s); + return Component.text("Correct Usage: ").color(NamedTextColor.YELLOW).append(componentFromString(s).color(NamedTextColor.GRAY)); } protected Player getNonNullPlayer(String name) @@ -498,21 +498,21 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC } /** - * Converts a string to a legacy Kyori component + * Converts a String to a legacy Kyori Component * - * @param s The string to convert + * @param s The String to convert * @return A Kyori component */ protected Component componentFromString(String s) { - return LegacyComponentSerializer.legacyAmpersand().deserialize(s); + return LegacyComponentSerializer.legacyAmpersand().deserialize(s).colorIfAbsent(NamedTextColor.GRAY); } /** - * Converts a string to a mini message kyori component + * Converts a String to a MiniMessage Component * - * @param s The string to convert - * @return A Kyori component + * @param s The String to convert + * @return A Kyori Component */ protected Component mmString(String s) { diff --git a/src/main/java/dev/plex/command/impl/LockupCMD.java b/src/main/java/dev/plex/command/impl/LockupCMD.java index 5778778..a70b449 100644 --- a/src/main/java/dev/plex/command/impl/LockupCMD.java +++ b/src/main/java/dev/plex/command/impl/LockupCMD.java @@ -7,20 +7,15 @@ import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.player.PlexPlayer; import dev.plex.player.PunishedPlayer; -import dev.plex.punishment.Punishment; -import dev.plex.punishment.PunishmentType; import dev.plex.rank.enums.Rank; import dev.plex.util.PlexUtils; +import java.util.List; import net.kyori.adventure.text.Component; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.time.LocalDateTime; -import java.util.List; -import java.util.UUID; - @CommandParameters(name = "lockup", description = "Lockup a player on the server", usage = "/ ") @CommandPermissions(level = Rank.ADMIN, permission = "plex.lockup") public class LockupCMD extends PlexCommand diff --git a/src/main/java/dev/plex/command/impl/NameHistoryCMD.java b/src/main/java/dev/plex/command/impl/NameHistoryCMD.java index adee199..8b02301 100644 --- a/src/main/java/dev/plex/command/impl/NameHistoryCMD.java +++ b/src/main/java/dev/plex/command/impl/NameHistoryCMD.java @@ -15,7 +15,6 @@ import java.util.Arrays; import java.util.List; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.format.TextDecoration; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/dev/plex/command/impl/PlexCMD.java b/src/main/java/dev/plex/command/impl/PlexCMD.java index 9cbcfb2..bff92ae 100644 --- a/src/main/java/dev/plex/command/impl/PlexCMD.java +++ b/src/main/java/dev/plex/command/impl/PlexCMD.java @@ -9,18 +9,16 @@ import dev.plex.command.source.RequiredCommandSource; import dev.plex.module.PlexModule; import dev.plex.module.PlexModuleFile; import dev.plex.rank.enums.Rank; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.minimessage.MiniMessage; import org.apache.commons.lang.StringUtils; -import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.List; -import java.util.stream.Collectors; - @CommandPermissions(level = Rank.OP, permission = "plex.plex", source = RequiredCommandSource.ANY) @CommandParameters(name = "plex", usage = "/ [reload | redis | modules [reload]]", description = "Show information about Plex or reload it") public class PlexCMD extends PlexCommand @@ -31,10 +29,11 @@ public class PlexCMD extends PlexCommand { if (args.length == 0) { - send(sender, ChatColor.LIGHT_PURPLE + "Plex - A new freedom plugin."); - send(sender, ChatColor.LIGHT_PURPLE + "Plugin version: " + plugin.getDescription().getVersion()); - send(sender, ChatColor.LIGHT_PURPLE + "Authors: " + ChatColor.GOLD + "Telesphoreo, Taahh"); - return componentFromString(ChatColor.LIGHT_PURPLE + "Run " + ChatColor.GOLD + "/plex modules" + ChatColor.LIGHT_PURPLE + " to see a list of modules."); + send(sender, mmString("Plex - A new freedom plugin.")); + send(sender, mmString("Plugin version: " + plugin.getDescription().getVersion())); + send(sender, mmString("Authors: Telesphoreo, Taahh")); + send(sender, mmString("Run /plex modules to see a list of modules.")); + return null; } if (args[0].equalsIgnoreCase("reload")) { @@ -49,6 +48,7 @@ public class PlexCMD extends PlexCommand plugin.getRankManager().importDefaultRanks(); send(sender, "Imported ranks"); send(sender, "Plex successfully reloaded."); + return null; } else if (args[0].equalsIgnoreCase("redis")) { @@ -61,12 +61,13 @@ public class PlexCMD extends PlexCommand send(sender, "Set test to 123. Now outputting key test..."); send(sender, plugin.getRedisConnection().getJedis().get("test")); plugin.getRedisConnection().getJedis().close(); + return null; } - if (args[0].equalsIgnoreCase("modules")) + else if (args[0].equalsIgnoreCase("modules")) { if (args.length == 1) { - return MiniMessage.miniMessage().deserialize("Modules (" + plugin.getModuleManager().getModules().size() + "): " + StringUtils.join(plugin.getModuleManager().getModules().stream().map(PlexModule::getPlexModuleFile).map(PlexModuleFile::getName).collect(Collectors.toList()), ", ")); + return mmString("Modules (" + plugin.getModuleManager().getModules().size() + "): " + StringUtils.join(plugin.getModuleManager().getModules().stream().map(PlexModule::getPlexModuleFile).map(PlexModuleFile::getName).collect(Collectors.toList()), ", ")); } if (args[1].equalsIgnoreCase("reload")) { @@ -74,6 +75,7 @@ public class PlexCMD extends PlexCommand plugin.getModuleManager().loadAllModules(); plugin.getModuleManager().loadModules(); plugin.getModuleManager().enableModules(); + return null; } } else @@ -86,6 +88,14 @@ public class PlexCMD extends PlexCommand @Override public @NotNull List tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException { - return ImmutableList.of("reload", "redis"); + if (args.length == 0) + { + return ImmutableList.of("reload", "redis", "modules"); + } + if (args[0].equalsIgnoreCase("modules")) + { + return ImmutableList.of("reload"); + } + return Collections.emptyList(); } } \ No newline at end of file diff --git a/src/main/java/dev/plex/config/Config.java b/src/main/java/dev/plex/config/Config.java index 29bb4a8..e374fde 100644 --- a/src/main/java/dev/plex/config/Config.java +++ b/src/main/java/dev/plex/config/Config.java @@ -2,16 +2,16 @@ package dev.plex.config; import dev.plex.Plex; import dev.plex.util.PlexLog; -import org.bukkit.configuration.file.YamlConfiguration; - import java.io.File; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; +import org.bukkit.configuration.file.YamlConfiguration; /** * Creates a custom Config object */ -public class Config extends YamlConfiguration { +public class Config extends YamlConfiguration +{ /** * The plugin instance */ @@ -38,12 +38,14 @@ public class Config extends YamlConfiguration { * @param plugin The plugin instance * @param name The file name */ - public Config(Plex plugin, String name) { + public Config(Plex plugin, String name) + { this.plugin = plugin; this.file = new File(plugin.getDataFolder(), name); this.name = name; - if (!file.exists()) { + if (!file.exists()) + { saveDefault(); } } @@ -56,17 +58,22 @@ public class Config extends YamlConfiguration { /** * Loads the configuration file */ - public void load(boolean loadFromFile) { - try { - if (loadFromFile) { + public void load(boolean loadFromFile) + { + try + { + if (loadFromFile) + { YamlConfiguration externalYamlConfig = YamlConfiguration.loadConfiguration(file); InputStreamReader internalConfigFileStream = new InputStreamReader(Plex.get().getResource(name), StandardCharsets.UTF_8); YamlConfiguration internalYamlConfig = YamlConfiguration.loadConfiguration(internalConfigFileStream); // Gets all the keys inside the internal file and iterates through all of it's key pairs - for (String string : internalYamlConfig.getKeys(true)) { + for (String string : internalYamlConfig.getKeys(true)) + { // Checks if the external file contains the key already. - if (!externalYamlConfig.contains(string)) { + if (!externalYamlConfig.contains(string)) + { // If it doesn't contain the key, we set the key based off what was found inside the plugin jar externalYamlConfig.setComments(string, internalYamlConfig.getComments(string)); externalYamlConfig.set(string, internalYamlConfig.get(string)); @@ -74,14 +81,17 @@ public class Config extends YamlConfiguration { added = true; } } - if (added) { + if (added) + { externalYamlConfig.save(file); PlexLog.log("Saving new file..."); added = false; } } super.load(file); - } catch (Exception ex) { + } + catch (Exception ex) + { ex.printStackTrace(); } } @@ -89,10 +99,14 @@ public class Config extends YamlConfiguration { /** * Saves the configuration file */ - public void save() { - try { + public void save() + { + try + { super.save(file); - } catch (Exception ex) { + } + catch (Exception ex) + { ex.printStackTrace(); } } @@ -100,7 +114,8 @@ public class Config extends YamlConfiguration { /** * Moves the configuration file from the plugin's resources folder to the data folder (plugins/Plex/) */ - private void saveDefault() { + private void saveDefault() + { plugin.saveResource(name, false); } } \ No newline at end of file diff --git a/src/main/java/dev/plex/module/ModuleManager.java b/src/main/java/dev/plex/module/ModuleManager.java index 5f94648..4140d04 100644 --- a/src/main/java/dev/plex/module/ModuleManager.java +++ b/src/main/java/dev/plex/module/ModuleManager.java @@ -4,10 +4,6 @@ import com.google.common.collect.Lists; import dev.plex.Plex; import dev.plex.module.exception.ModuleLoadException; import dev.plex.util.PlexLog; -import lombok.Getter; -import org.apache.logging.log4j.LogManager; -import org.bukkit.configuration.file.YamlConfiguration; - import java.io.File; import java.io.IOException; import java.io.InputStreamReader; @@ -18,18 +14,26 @@ import java.net.URLClassLoader; import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; +import lombok.Getter; +import org.apache.logging.log4j.LogManager; +import org.bukkit.configuration.file.YamlConfiguration; @Getter -public class ModuleManager { +public class ModuleManager +{ private final List modules = Lists.newArrayList(); - public void loadAllModules() { + public void loadAllModules() + { this.modules.clear(); PlexLog.debug(String.valueOf(Plex.get().getModulesFolder().listFiles().length)); - Arrays.stream(Plex.get().getModulesFolder().listFiles()).forEach(file -> { - if (file.getName().endsWith(".jar")) { - try { + Arrays.stream(Plex.get().getModulesFolder().listFiles()).forEach(file -> + { + if (file.getName().endsWith(".jar")) + { + try + { URLClassLoader loader = new URLClassLoader( new URL[]{file.toURI().toURL()}, Plex.class.getClassLoader() @@ -54,42 +58,54 @@ public class ModuleManager { String version = internalModuleConfig.getString("version", "1.0"); PlexModuleFile plexModuleFile = new PlexModuleFile(name, main, description, version); - Class module = (Class) Class.forName(main, true, loader); + Class module = (Class)Class.forName(main, true, loader); PlexModule plexModule = module.getConstructor().newInstance(); plexModule.setPlex(Plex.get()); plexModule.setPlexModuleFile(plexModuleFile); plexModule.setDataFolder(new File(Plex.get().getModulesFolder() + File.separator + plexModuleFile.getName())); - if (!plexModule.getDataFolder().exists()) plexModule.getDataFolder().mkdir(); + if (!plexModule.getDataFolder().exists()) + { + plexModule.getDataFolder().mkdir(); + } plexModule.setLogger(LogManager.getLogger(plexModuleFile.getName())); modules.add(plexModule); - } catch (MalformedURLException | ClassNotFoundException | InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) { + } + catch (MalformedURLException | ClassNotFoundException | InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) + { e.printStackTrace(); } } }); } - public void loadModules() { - this.modules.forEach(module -> { + public void loadModules() + { + this.modules.forEach(module -> + { PlexLog.log("Loading module " + module.getPlexModuleFile().getName() + " with version " + module.getPlexModuleFile().getVersion()); module.load(); }); } - public void enableModules() { - this.modules.forEach(module -> { + public void enableModules() + { + this.modules.forEach(module -> + { PlexLog.log("Enabling module " + module.getPlexModuleFile().getName() + " with version " + module.getPlexModuleFile().getVersion()); module.enable(); }); } - public void disableModules() { - this.modules.forEach(module -> { + public void disableModules() + { + this.modules.forEach(module -> + { PlexLog.log("Disabling module " + module.getPlexModuleFile().getName() + " with version " + module.getPlexModuleFile().getVersion()); - module.getCommands().stream().toList().forEach(plexCommand -> { + module.getCommands().stream().toList().forEach(plexCommand -> + { module.unregisterCommand(plexCommand); Plex.get().getServer().getCommandMap().getKnownCommands().remove(plexCommand.getName()); plexCommand.getAliases().forEach(alias -> Plex.get().getServer().getCommandMap().getKnownCommands().remove(alias)); @@ -99,12 +115,17 @@ public class ModuleManager { }); } - public void unloadModules() { + public void unloadModules() + { this.disableModules(); - this.modules.forEach(module -> { - try { + this.modules.forEach(module -> + { + try + { ((URLClassLoader)module.getClass().getClassLoader()).close(); - } catch (IOException e) { + } + catch (IOException e) + { e.printStackTrace(); } }); diff --git a/src/main/java/dev/plex/module/PlexModule.java b/src/main/java/dev/plex/module/PlexModule.java index 4edff06..61c4d78 100644 --- a/src/main/java/dev/plex/module/PlexModule.java +++ b/src/main/java/dev/plex/module/PlexModule.java @@ -4,17 +4,14 @@ import com.google.common.collect.Lists; import dev.plex.Plex; import dev.plex.command.PlexCommand; import dev.plex.listener.PlexListener; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.Setter; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.bukkit.event.HandlerList; - import java.io.File; import java.util.List; import java.util.Locale; -import java.util.stream.Collectors; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; +import org.apache.logging.log4j.Logger; +import org.bukkit.event.HandlerList; @Getter @Setter(AccessLevel.MODULE) @@ -31,11 +28,17 @@ public abstract class PlexModule private File dataFolder; private Logger logger; - public void load() {} + public void load() + { + } - public void enable() {} + public void enable() + { + } - public void disable() {} + public void disable() + { + } public void registerListener(PlexListener listener) { diff --git a/src/main/java/dev/plex/punishment/Punishment.java b/src/main/java/dev/plex/punishment/Punishment.java index eb31025..58634c2 100644 --- a/src/main/java/dev/plex/punishment/Punishment.java +++ b/src/main/java/dev/plex/punishment/Punishment.java @@ -30,6 +30,7 @@ public class Punishment private boolean customTime; private boolean active; // Field is only for bans private LocalDateTime endDate; + public Punishment(UUID punished, UUID punisher) { this.punished = punished; diff --git a/src/main/java/dev/plex/punishment/PunishmentManager.java b/src/main/java/dev/plex/punishment/PunishmentManager.java index d165725..bb1e00d 100644 --- a/src/main/java/dev/plex/punishment/PunishmentManager.java +++ b/src/main/java/dev/plex/punishment/PunishmentManager.java @@ -7,7 +7,6 @@ import com.google.gson.Gson; import dev.plex.Plex; import dev.plex.PlexBase; import dev.plex.cache.PlayerCache; -import dev.plex.player.PlexPlayer; import dev.plex.player.PunishedPlayer; import dev.plex.util.PlexLog; import dev.plex.util.PlexUtils; @@ -15,7 +14,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; -import java.lang.reflect.Type; import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; @@ -24,11 +22,9 @@ import java.util.List; import java.util.Map; import java.util.UUID; import java.util.stream.Collectors; - import lombok.Data; import org.apache.commons.io.FileUtils; import org.bukkit.Bukkit; -import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import org.json.JSONObject; import org.json.JSONTokener; @@ -41,7 +37,8 @@ public class PunishmentManager extends PlexBase public void mergeIndefiniteBans() { this.indefiniteBans.clear(); - Plex.get().indefBans.getKeys(false).forEach(key -> { + Plex.get().indefBans.getKeys(false).forEach(key -> + { IndefiniteBan ban = new IndefiniteBan(); ban.ips.addAll(Plex.get().getIndefBans().getStringList(key + ".ips")); ban.usernames.addAll(Plex.get().getIndefBans().getStringList(key + ".users")); @@ -54,7 +51,8 @@ public class PunishmentManager extends PlexBase if (Plex.get().getRedisConnection().isEnabled()) { PlexLog.log("Asynchronously uploading all indefinite bans to Redis"); - Plex.get().getRedisConnection().runAsync(jedis -> { + Plex.get().getRedisConnection().runAsync(jedis -> + { jedis.set("indefbans", new Gson().toJson(indefiniteBans)); }); } @@ -65,7 +63,9 @@ public class PunishmentManager extends PlexBase if (Plex.get().getRedisConnection().isEnabled()) { PlexLog.debug("Checking if UUID is banned in Redis"); - List bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken>(){}.getType()); + List bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken>() + { + }.getType()); return bans.stream().anyMatch(indefiniteBan -> indefiniteBan.getUuids().contains(uuid)); } return this.indefiniteBans.stream().anyMatch(indefiniteBan -> indefiniteBan.getUuids().contains(uuid)); @@ -76,7 +76,9 @@ public class PunishmentManager extends PlexBase if (Plex.get().getRedisConnection().isEnabled()) { PlexLog.debug("Checking if IP is banned in Redis"); - List bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken>(){}.getType()); + List bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken>() + { + }.getType()); return bans.stream().anyMatch(indefiniteBan -> indefiniteBan.getIps().contains(ip)); } return this.indefiniteBans.stream().anyMatch(indefiniteBan -> indefiniteBan.getIps().contains(ip)); @@ -87,7 +89,9 @@ public class PunishmentManager extends PlexBase if (Plex.get().getRedisConnection().isEnabled()) { PlexLog.debug("Checking if username is banned in Redis"); - List bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken>(){}.getType()); + List bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken>() + { + }.getType()); return bans.stream().anyMatch(indefiniteBan -> indefiniteBan.getUsernames().contains(username)); } return this.indefiniteBans.stream().anyMatch(indefiniteBan -> indefiniteBan.getUsernames().contains(username)); diff --git a/src/main/java/dev/plex/services/impl/UpdateCheckerService.java b/src/main/java/dev/plex/services/impl/UpdateCheckerService.java index 31f7abe..15548bd 100644 --- a/src/main/java/dev/plex/services/impl/UpdateCheckerService.java +++ b/src/main/java/dev/plex/services/impl/UpdateCheckerService.java @@ -4,13 +4,13 @@ import dev.plex.services.AbstractService; public class UpdateCheckerService extends AbstractService { + private boolean newVersion = false; + public UpdateCheckerService() { super(true, true); } - private boolean newVersion = false; - @Override public void run() { diff --git a/src/main/java/dev/plex/storage/MongoConnection.java b/src/main/java/dev/plex/storage/MongoConnection.java index 699856c..62bb5ba 100644 --- a/src/main/java/dev/plex/storage/MongoConnection.java +++ b/src/main/java/dev/plex/storage/MongoConnection.java @@ -5,7 +5,6 @@ import com.mongodb.client.MongoClients; import dev.morphia.Datastore; import dev.morphia.Morphia; import dev.morphia.mapping.MapperOptions; -import dev.plex.Plex; import dev.plex.PlexBase; import dev.plex.player.PlexPlayer; diff --git a/src/main/java/dev/plex/storage/RedisConnection.java b/src/main/java/dev/plex/storage/RedisConnection.java index 06f2545..2433d93 100644 --- a/src/main/java/dev/plex/storage/RedisConnection.java +++ b/src/main/java/dev/plex/storage/RedisConnection.java @@ -2,9 +2,8 @@ package dev.plex.storage; import dev.plex.PlexBase; import dev.plex.util.PlexLog; -import redis.clients.jedis.Jedis; - import java.util.function.Consumer; +import redis.clients.jedis.Jedis; public class RedisConnection extends PlexBase {