From e072b4d1abdc55d35ae13707ffc25b078b959ca1 Mon Sep 17 00:00:00 2001 From: ThiagoROX <51332006+SrBedrock@users.noreply.github.com> Date: Sat, 2 Nov 2024 21:45:37 -0300 Subject: [PATCH] Resolvido problema ao recarregar caixas --- gradle.properties | 2 +- .../badbones69/crazycrates/CrazyHandler.java | 9 +- .../crazycrates/api/FileManager.java | 205 +++--------- .../commands/subs/CrateBaseCommand.java | 235 +++++++------- .../tasks/crates/CrateManager.java | 300 +++++++++--------- 5 files changed, 317 insertions(+), 434 deletions(-) diff --git a/gradle.properties b/gradle.properties index a3e29c8ac..adec40b73 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ sources=https://github.com/Crazy-Crew/CrazyCrates issues=https://github.com/Crazy-Crew/CrazyCrates/issues group=com.badbones69.crazycrates description=Add unlimited crates to your server with 10 different crate types to choose from! -version=1.24 +version=1.25.0 apiVersion=1.20 mcVersion=1.20.4 isBeta=false \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/CrazyHandler.java b/paper/src/main/java/com/badbones69/crazycrates/CrazyHandler.java index 5421b1691..bee7df9eb 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/CrazyHandler.java +++ b/paper/src/main/java/com/badbones69/crazycrates/CrazyHandler.java @@ -17,7 +17,7 @@ public class CrazyHandler extends CrazyCratesPlugin { private CrateManager crateManager; private FileManager fileManager; - public CrazyHandler(CrazyCrates plugin) { + public CrazyHandler(@NotNull final CrazyCrates plugin) { super(plugin.getDataFolder()); } @@ -56,7 +56,7 @@ public void load() { this.userManager = new BukkitUserManager(); // Load commands. - CommandManager commandManager = new CommandManager(); + final CommandManager commandManager = new CommandManager(); commandManager.load(); } @@ -69,11 +69,6 @@ public void cleanFiles() { Files.LOCATIONS.getFile().set("Locations.Clear", null); Files.LOCATIONS.saveFile(); } - -// if (!Files.DATA.getFile().contains("Players")) { -// Files.DATA.getFile().set("Players.Clear", null); -// Files.DATA.saveFile(); -// } } @NotNull diff --git a/paper/src/main/java/com/badbones69/crazycrates/api/FileManager.java b/paper/src/main/java/com/badbones69/crazycrates/api/FileManager.java index 5de05daee..ec09013be 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/api/FileManager.java +++ b/paper/src/main/java/com/badbones69/crazycrates/api/FileManager.java @@ -36,7 +36,7 @@ public class FileManager { * Sets up the plugin and loads all necessary files. */ public void setup() { - File dataFolder = this.plugin.getDataFolder(); + final File dataFolder = this.plugin.getDataFolder(); if (!dataFolder.exists()) dataFolder.mkdirs(); @@ -45,18 +45,18 @@ public void setup() { this.configurations.clear(); // Loads all the normal static files. - for (Files file : Files.values()) { - File newFile = new File(dataFolder, file.getFileLocation()); + for (final Files file : Files.values()) { + final File newFile = new File(dataFolder, file.getFileLocation()); this.plugin.debug(() -> "Loading the " + file.getFileName(), Level.INFO); if (!newFile.exists()) { try { - File serverFile = new File(dataFolder, "/" + file.getFileLocation()); - InputStream jarFile = getClass().getResourceAsStream("/" + file.getFileJar()); + final File serverFile = new File(dataFolder, "/" + file.getFileLocation()); + final InputStream jarFile = getClass().getResourceAsStream("/" + file.getFileJar()); copyFile(jarFile, serverFile); - } catch (Exception exception) { + } catch (final Exception exception) { this.logger.log(Level.SEVERE, "Failed to load file: " + file.getFileName(), exception); continue; @@ -78,21 +78,21 @@ public void setup() { if (this.isLogging) this.logger.info("Loading custom files."); for (String homeFolder : this.homeFolders) { - File homeFile = new File(dataFolder, "/" + homeFolder); + final File homeFile = new File(dataFolder, "/" + homeFolder); if (homeFile.exists()) { - File[] filesList = homeFile.listFiles(); + final File[] filesList = homeFile.listFiles(); if (filesList != null) { - for (File directory : filesList) { + for (final File directory : filesList) { if (directory.isDirectory()) { - String[] folder = directory.list(); + final String[] folder = directory.list(); if (folder != null) { - for (String name : folder) { + for (final String name : folder) { if (!name.endsWith(".yml")) continue; - CustomFile file = new CustomFile(name, homeFolder + "/", directory.getName()); + final CustomFile file = new CustomFile(name, homeFolder + "/", directory.getName()); if (file.exists()) { this.customFiles.add(file); @@ -103,11 +103,11 @@ public void setup() { } } } else { - String name = directory.getName(); + final String name = directory.getName(); if (!name.endsWith(".yml")) continue; - CustomFile file = new CustomFile(name, homeFolder); + final CustomFile file = new CustomFile(name, homeFolder); if (file.exists()) { this.customFiles.add(file); @@ -123,12 +123,12 @@ public void setup() { if (this.isLogging) this.logger.info("The folder " + homeFolder + "/ was not found so it was created."); - for (String fileName : this.autoGenerateFiles.keySet()) { + for (final String fileName : this.autoGenerateFiles.keySet()) { if (this.autoGenerateFiles.get(fileName).equalsIgnoreCase(homeFolder)) { homeFolder = this.autoGenerateFiles.get(fileName); - try (InputStream jarFile = getClass().getResourceAsStream((this.jarHomeFolders.getOrDefault(fileName, homeFolder)) + "/" + fileName)) { - File serverFile = new File(dataFolder, homeFolder + "/" + fileName); + try (final InputStream jarFile = getClass().getResourceAsStream((this.jarHomeFolders.getOrDefault(fileName, homeFolder)) + "/" + fileName)) { + final File serverFile = new File(dataFolder, homeFolder + "/" + fileName); copyFile(jarFile, serverFile); @@ -137,7 +137,7 @@ public void setup() { if (this.isLogging) this.logger.info("Created new default file: " + homeFolder + "/" + fileName + "."); - } catch (Exception exception) { + } catch (final Exception exception) { this.logger.log(Level.SEVERE, "Failed to create new default file: " + homeFolder + "/" + fileName + "!", exception); } } @@ -153,35 +153,12 @@ public void setup() { * * @param homeFolder the folder that has custom files in it. */ - public FileManager registerCustomFilesFolder(String homeFolder) { + public FileManager registerCustomFilesFolder(final String homeFolder) { this.homeFolders.add(homeFolder); return this; } - /** - * Unregister a folder that has custom files in it. Make sure to have a "/" in front of the folder name. - * - * @param homeFolder the folder with custom files in it. - */ - public FileManager unregisterCustomFilesFolder(String homeFolder) { - this.homeFolders.remove(homeFolder); - - return this; - } - - /** - * Register a file that needs to be generated when it's home folder doesn't exist. Make sure to have a "/" in front of the home folder's name. - * - * @param fileName the name of the file you want to auto-generate when the folder doesn't exist. - * @param homeFolder the folder that has custom files in it. - */ - public FileManager registerDefaultGenerateFiles(String fileName, String homeFolder) { - this.autoGenerateFiles.put(fileName, homeFolder); - - return this; - } - /** * Register a file that needs to be generated when it's home folder doesn't exist. Make sure to have a "/" in front of the home folder's name. * @@ -189,31 +166,19 @@ public FileManager registerDefaultGenerateFiles(String fileName, String homeFold * @param homeFolder the folder that has custom files in it. * @param jarHomeFolder the folder that the file is found in the jar. */ - public FileManager registerDefaultGenerateFiles(String fileName, String homeFolder, String jarHomeFolder) { + public FileManager registerDefaultGenerateFiles(final String fileName, final String homeFolder, final String jarHomeFolder) { this.autoGenerateFiles.put(fileName, homeFolder); this.jarHomeFolders.put(fileName, jarHomeFolder); return this; } - /** - * Unregister a file that doesn't need to be generated when it's home folder doesn't exist. Make sure to have a "/" in front of the home folder's name. - * - * @param fileName the file that you want to remove from auto-generating. - */ - public FileManager unregisterDefaultGenerateFiles(String fileName) { - this.autoGenerateFiles.remove(fileName); - this.jarHomeFolders.remove(fileName); - - return this; - } - /** * Gets the file from the system. * * @return the file from the system. */ - public FileConfiguration getFile(Files file) { + public FileConfiguration getFile(final Files file) { return this.configurations.get(file); } @@ -224,80 +189,30 @@ public FileConfiguration getFile(Files file) { * @param name name of the crate you want. (Without the .yml) * @return the custom file you wanted otherwise if not found will return null. */ - public CustomFile getFile(String name) { - for (CustomFile file : this.customFiles) { + public CustomFile getFile(final String name) { + for (final CustomFile file : this.customFiles) { if (file.getName().equalsIgnoreCase(name)) return file; } return null; } - /** - * Remove a file by name. - * - * @param name name to use. - */ - public void removeFile(String name) { - this.customFiles.remove(getFile(name)); - } - - /** - * Add a file by name. - * - * @param name name to use. - * @param folder folder to add to. - */ - public void addFile(String name, String folder) { - this.customFiles.add(new CustomFile(name, folder)); - } - /** * Saves the file from the loaded state to the file system. */ - public void saveFile(Files file) { + public void saveFile(final Files file) { try { this.configurations.get(file).save(this.files.get(file)); - } catch (IOException exception) { + } catch (final IOException exception) { this.logger.log(Level.SEVERE, "Could not save " + file.getFileName() + "!", exception); } } - /** - * Save a custom file. - * - * @param name the name of the custom file. - */ - public void saveFile(String name) { - CustomFile file = getFile(name); - - if (file == null) { - if (this.isLogging) this.logger.warning("The file " + name + ".yml could not be found!"); - - return; - } - - try { - file.getFile().save(new File(this.plugin.getDataFolder(), file.getHomeFolder() + "/" + file.getFileName())); - - if (this.isLogging) this.logger.info("Successfully saved the " + file.getFileName() + "."); - } catch (Exception exception) { - this.logger.log(Level.SEVERE, "Could not save " + file.getFileName() + "!", exception); - } - } - - /** - * Save a custom file. - * - * @param file the custom file you are saving. - */ - public void saveFile(CustomFile file) { - file.saveFile(); - } /** * Overrides the loaded state file and loads the file systems file. */ - public void reloadFile(Files file) { + public void reloadFile(final Files file) { if (file.getFileName().endsWith(".yml")) this.configurations.put(file, YamlConfiguration.loadConfiguration(this.files.get(file))); } @@ -305,8 +220,8 @@ public void reloadFile(Files file) { /** * Overrides the loaded state file and loads the file systems file. */ - public void reloadFile(String name) { - CustomFile file = getFile(name); + public void reloadFile(final String name) { + final CustomFile file = getFile(name); if (file != null) { try { @@ -314,7 +229,7 @@ public void reloadFile(String name) { if (this.plugin.isLogging()) this.plugin.getLogger().info("Successfully reloaded the " + file.getFileName() + "."); - } catch (Exception exception) { + } catch (final Exception exception) { this.logger.log(Level.SEVERE, "Could not reload the " + file.getFileName() + "!", exception); } } else { @@ -323,46 +238,26 @@ public void reloadFile(String name) { } } - /** - * Overrides the loaded state file and loads the filesystems file. - */ - public void reloadFile(CustomFile file) { - file.reloadFile(); - } - - /** - * Reloads all files. - */ - public void reloadAllFiles() { - for (Files file : Files.values()) { - file.reloadFile(); - } - - for (CustomFile file : this.customFiles) { - file.reloadFile(); - } - } - /** * @return A list of crate names. */ public List getAllCratesNames() { - List fileList = new ArrayList<>(); + final List fileList = new ArrayList<>(); - File crateDirectory = new File(this.plugin.getDataFolder(), "/crates"); + final File crateDirectory = new File(this.plugin.getDataFolder(), "/crates"); - String[] file = crateDirectory.list(); + final String[] file = crateDirectory.list(); if (file != null) { - File[] filesList = crateDirectory.listFiles(); + final File[] filesList = crateDirectory.listFiles(); if (filesList != null) { - for (File directory : filesList) { + for (final File directory : filesList) { if (directory.isDirectory()) { - String[] folder = directory.list(); + final String[] folder = directory.list(); if (folder != null) { - for (String name : folder) { + for (final String name : folder) { if (!name.endsWith(".yml")) continue; fileList.add(name.replaceAll(".yml", "")); @@ -372,7 +267,7 @@ public List getAllCratesNames() { } } - for (String name : file) { + for (final String name : file) { if (!name.endsWith(".yml")) continue; fileList.add(name.replaceAll(".yml", "")); @@ -385,9 +280,9 @@ public List getAllCratesNames() { /** * Was found here: ... */ - private void copyFile(InputStream in, File out) throws Exception { - try (InputStream fis = in; FileOutputStream fos = new FileOutputStream(out)) { - byte[] buf = new byte[1024]; + private void copyFile(final InputStream in, final File out) throws Exception { + try (final InputStream fis = in; final FileOutputStream fos = new FileOutputStream(out)) { + final byte[] buf = new byte[1024]; int i; while ((i = fis.read(buf)) != -1) { @@ -420,7 +315,7 @@ public enum Files { * @param fileName the file name that will be in the plugin's folder. * @param fileLocation the location the file in the plugin's folder. */ - Files(String fileName, String fileLocation) { + Files(final String fileName, final String fileLocation) { this(fileName, fileLocation, fileLocation); } @@ -431,7 +326,7 @@ public enum Files { * @param fileLocation the location of the file will be in the plugin's folder. * @param fileJar the location of the file in the jar. */ - Files(String fileName, String fileLocation, String fileJar) { + Files(final String fileName, final String fileLocation, final String fileJar) { this.fileName = fileName; this.fileLocation = fileLocation; this.fileJar = fileJar; @@ -505,12 +400,12 @@ public static class CustomFile { * @param name name of the file. * @param homeFolder the home folder of the file. */ - public CustomFile(String name, String homeFolder) { + public CustomFile(final String name, final String homeFolder) { this.name = name.replace(".yml", ""); this.fileName = name; this.homeFolder = homeFolder; - File root = new File(this.plugin.getDataFolder(), "/" + homeFolder); + final File root = new File(this.plugin.getDataFolder(), "/" + homeFolder); if (!root.exists()) { root.mkdirs(); @@ -523,7 +418,7 @@ public CustomFile(String name, String homeFolder) { return; } - File newFile = new File(root, "/" + name); + final File newFile = new File(root, "/" + name); if (newFile.exists()) { this.file = YamlConfiguration.loadConfiguration(newFile); @@ -540,14 +435,14 @@ public CustomFile(String name, String homeFolder) { * @param name name of the file. * @param homeFolder the home folder of the file. */ - public CustomFile(String name, String homeFolder, String subFolder) { + public CustomFile(final String name, final String homeFolder, final String subFolder) { this.name = name.replace(".yml", ""); this.fileName = name; this.homeFolder = homeFolder + "/" + subFolder; - File root = new File(this.plugin.getDataFolder(), "/" + this.homeFolder); + final File root = new File(this.plugin.getDataFolder(), "/" + this.homeFolder); - File newFile = new File(root, "/" + name); + final File newFile = new File(root, "/" + name); if (newFile.exists()) { this.file = YamlConfiguration.loadConfiguration(newFile); @@ -619,7 +514,7 @@ private void saveFile() { if (this.plugin.isLogging()) this.plugin.getLogger().info("Successfully saved the " + this.fileName + "."); - } catch (IOException exception) { + } catch (final IOException exception) { this.plugin.getLogger().log(Level.SEVERE, "Could not save " + this.fileName + "!", exception); } } @@ -640,7 +535,7 @@ public void reloadFile() { if (this.plugin.isLogging()) this.plugin.getLogger().info("Successfully reloaded the " + this.fileName + "."); - } catch (Exception exception) { + } catch (final Exception exception) { this.plugin.getLogger().log(Level.SEVERE, "Could not reload the " + this.fileName + "!", exception); } } diff --git a/paper/src/main/java/com/badbones69/crazycrates/commands/subs/CrateBaseCommand.java b/paper/src/main/java/com/badbones69/crazycrates/commands/subs/CrateBaseCommand.java index ccc19981d..956d86e5b 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/commands/subs/CrateBaseCommand.java +++ b/paper/src/main/java/com/badbones69/crazycrates/commands/subs/CrateBaseCommand.java @@ -16,6 +16,7 @@ import com.badbones69.crazycrates.api.objects.Crate; import com.badbones69.crazycrates.api.objects.Prize; import com.badbones69.crazycrates.api.objects.other.CrateLocation; +import com.badbones69.crazycrates.api.utils.FileUtils; import com.badbones69.crazycrates.api.utils.MiscUtils; import com.badbones69.crazycrates.api.utils.MsgUtils; import com.badbones69.crazycrates.common.config.types.ConfigKeys; @@ -82,9 +83,9 @@ public class CrateBaseCommand extends BaseCommand { @Default @Permission(value = "crazycrates.command.player.menu", def = PermissionDefault.TRUE) - public void onDefaultMenu(Player player) { + public void onDefaultMenu(final Player player) { if (this.config.getProperty(ConfigKeys.enable_crate_menu)) { - CrateMainMenu crateMainMenu = new CrateMainMenu(player, this.config.getProperty(ConfigKeys.inventory_size), this.config.getProperty(ConfigKeys.inventory_name)); + final CrateMainMenu crateMainMenu = new CrateMainMenu(player, this.config.getProperty(ConfigKeys.inventory_size), this.config.getProperty(ConfigKeys.inventory_name)); player.openInventory(crateMainMenu.build().getInventory()); @@ -96,14 +97,14 @@ public void onDefaultMenu(Player player) { @SubCommand("help") @Permission(value = "crazycrates.help", def = PermissionDefault.TRUE) - public void onHelp(CommandSender sender) { - if (sender instanceof ConsoleCommandSender commandSender) { + public void onHelp(final CommandSender sender) { + if (sender instanceof final ConsoleCommandSender commandSender) { commandSender.sendMessage(Messages.admin_help.getMessage()); return; } - if (sender instanceof Player player) { + if (sender instanceof final Player player) { if (player.hasPermission("crazycrates.admin-access")) { player.sendMessage(Messages.admin_help.getMessage(player)); @@ -116,8 +117,8 @@ public void onHelp(CommandSender sender) { @SubCommand("transfer") @Permission(value = "crazycrates.command.player.transfer", def = PermissionDefault.OP) - public void onPlayerTransferKeys(Player sender, @Suggestion("crates") String crateName, @Suggestion("online-players") Player player, @Suggestion("numbers") int amount) { - Crate crate = this.crateManager.getCrateFromName(crateName); + public void onPlayerTransferKeys(final Player sender, @Suggestion("crates") final String crateName, @Suggestion("online-players") final Player player, @Suggestion("numbers") final int amount) { + final Crate crate = this.crateManager.getCrateFromName(crateName); // If the crate is menu or null. we return if (crate == null || crate.getCrateType() == CrateType.menu) { @@ -140,7 +141,7 @@ public void onPlayerTransferKeys(Player sender, @Suggestion("crates") String cra return; } - PlayerReceiveKeyEvent event = new PlayerReceiveKeyEvent(player, crate, PlayerReceiveKeyEvent.KeyReceiveReason.TRANSFER, amount); + final PlayerReceiveKeyEvent event = new PlayerReceiveKeyEvent(player, crate, PlayerReceiveKeyEvent.KeyReceiveReason.TRANSFER, amount); this.plugin.getServer().getPluginManager().callEvent(event); // If the event is cancelled, We return. @@ -149,7 +150,7 @@ public void onPlayerTransferKeys(Player sender, @Suggestion("crates") String cra this.userManager.takeKeys(amount, sender.getUniqueId(), crate.getName(), KeyType.virtual_key, false); this.userManager.addKeys(amount, player.getUniqueId(), crate.getName(), KeyType.virtual_key); - Map placeholders = new HashMap<>(); + final Map placeholders = new HashMap<>(); placeholders.put("%crate%", crate.getName()); placeholders.put("%amount%", String.valueOf(amount)); @@ -166,14 +167,8 @@ public void onPlayerTransferKeys(Player sender, @Suggestion("crates") String cra @SubCommand("reload") @Permission(value = "crazycrates.command.admin.reload", def = PermissionDefault.OP) - public void onReload(CommandSender sender) { + public void onReload(final CommandSender sender) { this.plugin.getConfigManager().reload(); - -// this.fileManager.reloadAllFiles(); -// this.fileManager.setup(); -// -// FileUtils.loadFiles(); - this.crazyHandler.cleanFiles(); // Close previews @@ -189,7 +184,7 @@ public void onReload(CommandSender sender) { this.crateManager.loadCrates(); - if (sender instanceof Player player) { + if (sender instanceof final Player player) { player.sendMessage(Messages.reloaded_plugin.getMessage(player)); return; } @@ -199,8 +194,8 @@ public void onReload(CommandSender sender) { @SubCommand("debug") @Permission(value = "crazycrates.command.admin.debug", def = PermissionDefault.OP) - public void onDebug(Player player, @Suggestion("crates") String crateName) { - Crate crate = this.crateManager.getCrateFromName(crateName); + public void onDebug(final Player player, @Suggestion("crates") final String crateName) { + final Crate crate = this.crateManager.getCrateFromName(crateName); if (crate == null) { player.sendMessage(Messages.not_a_crate.getMessage("%crate%", crateName, player)); @@ -213,7 +208,7 @@ public void onDebug(Player player, @Suggestion("crates") String crateName) { @SubCommand("save") @Permission(value = "crazycrates.save", def = PermissionDefault.OP) - public void onSchematicSave(Player player) { + public void onSchematicSave(final Player player) { player.sendMessage(MsgUtils.color("&cThis feature is not yet developed internally by &eRyder Belserion.")); } @@ -246,21 +241,21 @@ private ItemStack getItem(NamespacedKey key, Material material, String name) { @SubCommand("admin") @Permission(value = "crazycrates.command.admin.access", def = PermissionDefault.OP) - public void onAdminMenu(Player player) { - CrateAdminMenu inventory = new CrateAdminMenu(player, 54, "&c&lAdmin Keys"); + public void onAdminMenu(final Player player) { + final CrateAdminMenu inventory = new CrateAdminMenu(player, 54, "&c&lAdmin Keys"); player.openInventory(inventory.build().getInventory()); } @SubCommand("list") @Permission(value = "crazycrates.command.admin.list", def = PermissionDefault.OP) - public void onAdminList(CommandSender sender) { - StringBuilder crates = new StringBuilder(); - String brokeCrates; + public void onAdminList(final CommandSender sender) { + final StringBuilder crates = new StringBuilder(); + final String brokeCrates; this.crateManager.getUsableCrates().forEach(crate -> crates.append("&a").append(crate.getName()).append("&8, ")); - StringBuilder brokeCratesBuilder = new StringBuilder(); + final StringBuilder brokeCratesBuilder = new StringBuilder(); this.crateManager.getBrokeCrates().forEach(crate -> brokeCratesBuilder.append("&c").append(crate).append(".yml&8,")); @@ -275,13 +270,13 @@ public void onAdminList(CommandSender sender) { sender.sendMessage(MsgUtils.color("&c[ID]&8, &c[Crate]&8, &c[World]&8, &c[X]&8, &c[Y]&8, &c[Z]")); int line = 1; - for (CrateLocation loc : this.crateManager.getCrateLocations()) { - Crate crate = loc.getCrate(); - String world = loc.getLocation().getWorld().getName(); + for (final CrateLocation loc : this.crateManager.getCrateLocations()) { + final Crate crate = loc.getCrate(); + final String world = loc.getLocation().getWorld().getName(); - int x = loc.getLocation().getBlockX(); - int y = loc.getLocation().getBlockY(); - int z = loc.getLocation().getBlockZ(); + final int x = loc.getLocation().getBlockX(); + final int y = loc.getLocation().getBlockY(); + final int z = loc.getLocation().getBlockZ(); sender.sendMessage(MsgUtils.color("&8[&b" + line + "&8]: " + "&c" + loc.getID() + "&8, &c" + crate.getName() + "&8, &c" + world + "&8, &c" + x + "&8, &c" + y + "&8, &c" + z)); line++; @@ -290,22 +285,22 @@ public void onAdminList(CommandSender sender) { @SubCommand("tp") @Permission(value = "crazycrates.command.admin.teleport", def = PermissionDefault.OP) - public void onAdminTeleport(Player player, @Suggestion("locations") String id) { + public void onAdminTeleport(final Player player, @Suggestion("locations") final String id) { if (!this.locations.contains("Locations")) { this.locations.set("Locations.Clear", null); Files.LOCATIONS.saveFile(); } - for (String name : this.locations.getConfigurationSection("Locations").getKeys(false)) { + for (final String name : this.locations.getConfigurationSection("Locations").getKeys(false)) { if (name.equalsIgnoreCase(id)) { - World world = this.plugin.getServer().getWorld(Objects.requireNonNull(this.locations.getString("Locations." + name + ".World"))); + final World world = this.plugin.getServer().getWorld(Objects.requireNonNull(this.locations.getString("Locations." + name + ".World"))); - int x = this.locations.getInt("Locations." + name + ".X"); - int y = this.locations.getInt("Locations." + name + ".Y"); - int z = this.locations.getInt("Locations." + name + ".Z"); + final int x = this.locations.getInt("Locations." + name + ".X"); + final int y = this.locations.getInt("Locations." + name + ".Y"); + final int z = this.locations.getInt("Locations." + name + ".Z"); - Location loc = new Location(world, x, y, z); + final Location loc = new Location(world, x, y, z); player.teleport(loc.add(.5, 0, .5)); @@ -320,8 +315,8 @@ public void onAdminTeleport(Player player, @Suggestion("locations") String id) { @SubCommand("additem") @Permission(value = "crazycrates.command.admin.additem", def = PermissionDefault.OP) - public void onAdminCrateAddItem(Player player, @Suggestion("crates") String crateName, @Suggestion("prizes") String prize, @Suggestion("numbers") int chance, @Optional @Suggestion("tiers") String tier) { - ItemStack item = player.getInventory().getItemInMainHand(); + public void onAdminCrateAddItem(final Player player, @Suggestion("crates") final String crateName, @Suggestion("prizes") final String prize, @Suggestion("numbers") final int chance, @Optional @Suggestion("tiers") final String tier) { + final ItemStack item = player.getInventory().getItemInMainHand(); if (item.getType() == Material.AIR) { player.sendMessage(Messages.no_item_in_hand.getMessage(player)); @@ -329,7 +324,7 @@ public void onAdminCrateAddItem(Player player, @Suggestion("crates") String crat return; } - Crate crate = this.crateManager.getCrateFromName(crateName); + final Crate crate = this.crateManager.getCrateFromName(crateName); if (crate == null) { player.sendMessage(Messages.not_a_crate.getMessage("%crate%", crateName, player)); @@ -343,13 +338,13 @@ public void onAdminCrateAddItem(Player player, @Suggestion("crates") String crat } else { crate.addEditorItem(prize, item, crate.getTier(tier), chance); } - } catch (Exception exception) { + } catch (final Exception exception) { this.plugin.getServer().getLogger().log(Level.WARNING, "Failed to add a new prize to the " + crate.getName() + " crate.", exception); return; } - Map placeholders = new HashMap<>(); + final Map placeholders = new HashMap<>(); placeholders.put("%crate%", crate.getName()); placeholders.put("%prize%", prize); @@ -359,11 +354,11 @@ public void onAdminCrateAddItem(Player player, @Suggestion("crates") String crat @SubCommand("preview") @Permission(value = "crazycrates.command.admin.preview", def = PermissionDefault.OP) - public void onAdminCratePreview(CommandSender sender, @Suggestion("crates") String crateName, @Suggestion("online-players") Player player) { - Crate crate = this.crateManager.getCrateFromName(crateName); + public void onAdminCratePreview(final CommandSender sender, @Suggestion("crates") final String crateName, @Suggestion("online-players") final Player player) { + final Crate crate = this.crateManager.getCrateFromName(crateName); if (crate == null || crate.getCrateType() == CrateType.menu) { - if (sender instanceof Player person) { + if (sender instanceof final Player person) { person.sendMessage(Messages.not_a_crate.getMessage("%crate%", crateName, person)); return; @@ -375,7 +370,7 @@ public void onAdminCratePreview(CommandSender sender, @Suggestion("crates") Stri } if (!crate.isPreviewEnabled()) { - if (sender instanceof Player person) { + if (sender instanceof final Player person) { person.sendMessage(Messages.preview_disabled.getMessage(player)); return; @@ -392,17 +387,17 @@ public void onAdminCratePreview(CommandSender sender, @Suggestion("crates") Stri @SubCommand("open-others") @Permission(value = "crazycrates.command.admin.open.others", def = PermissionDefault.OP) - public void onAdminCrateOpenOthers(CommandSender sender, @Suggestion("crates") String crateName, @Suggestion("online-players") Player player, @Optional @Suggestion("key-types") KeyType keyType) { + public void onAdminCrateOpenOthers(final CommandSender sender, @Suggestion("crates") final String crateName, @Suggestion("online-players") final Player player, @Optional @Suggestion("key-types") final KeyType keyType) { if (sender == player && keyType != KeyType.free_key) { onAdminCrateOpen(player, crateName); return; } - Crate crate = this.crateManager.getCrateFromName(crateName); + final Crate crate = this.crateManager.getCrateFromName(crateName); if (player == null) { - if (sender instanceof Player person) { + if (sender instanceof final Player person) { sender.sendMessage(Messages.not_online.getMessage(person)); return; @@ -414,7 +409,7 @@ public void onAdminCrateOpenOthers(CommandSender sender, @Suggestion("crates") S } if (crate == null || crate.getCrateType() == CrateType.menu) { - if (sender instanceof Player person) { + if (sender instanceof final Player person) { person.sendMessage(Messages.not_a_crate.getMessage("%crate%", crateName, person)); return; @@ -426,7 +421,7 @@ public void onAdminCrateOpenOthers(CommandSender sender, @Suggestion("crates") S } if (crate.getCrateType() == CrateType.crate_on_the_go || crate.getCrateType() == CrateType.quick_crate || crate.getCrateType() == CrateType.fire_cracker || crate.getCrateType() == CrateType.quad_crate) { - if (sender instanceof Player person) { + if (sender instanceof final Player person) { sender.sendMessage(Messages.cant_be_a_virtual_crate.getMessage(person)); return; @@ -438,7 +433,7 @@ public void onAdminCrateOpenOthers(CommandSender sender, @Suggestion("crates") S } if (this.crateManager.isInOpeningList(player)) { - if (sender instanceof Player person) { + if (sender instanceof final Player person) { sender.sendMessage(Messages.already_opening_crate.getMessage(person)); return; @@ -449,10 +444,10 @@ public void onAdminCrateOpenOthers(CommandSender sender, @Suggestion("crates") S return; } - CrateType crateType = crate.getCrateType(); + final CrateType crateType = crate.getCrateType(); if (crateType == null) { - if (sender instanceof Player person) { + if (sender instanceof final Player person) { sender.sendMessage(Messages.internal_error.getMessage(person)); return; @@ -471,7 +466,7 @@ public void onAdminCrateOpenOthers(CommandSender sender, @Suggestion("crates") S if (type == KeyType.free_key) { this.crateManager.openCrate(player, crate, type, player.getLocation(), true, false); - HashMap placeholders = new HashMap<>(); + final HashMap placeholders = new HashMap<>(); placeholders.put("%Crate%", crate.getName()); placeholders.put("%Player%", player.getName()); @@ -483,9 +478,9 @@ public void onAdminCrateOpenOthers(CommandSender sender, @Suggestion("crates") S return; } - boolean hasVirtual = this.userManager.getVirtualKeys(player.getUniqueId(), crate.getName()) >= 1; + final boolean hasVirtual = this.userManager.getVirtualKeys(player.getUniqueId(), crate.getName()) >= 1; - boolean hasPhysical = this.userManager.hasPhysicalKey(player.getUniqueId(), crate.getName(), false); + final boolean hasPhysical = this.userManager.hasPhysicalKey(player.getUniqueId(), crate.getName(), false); if (hasVirtual) { hasKey = true; @@ -503,7 +498,7 @@ public void onAdminCrateOpenOthers(CommandSender sender, @Suggestion("crates") S player.playSound(player.getLocation(), Sound.valueOf(this.config.getProperty(ConfigKeys.need_key_sound)), SoundCategory.PLAYERS, 1f, 1f); } - if (sender instanceof Player person) { + if (sender instanceof final Player person) { sender.sendMessage(Messages.no_virtual_key.getMessage(person)); return; @@ -515,7 +510,7 @@ public void onAdminCrateOpenOthers(CommandSender sender, @Suggestion("crates") S } if (MiscUtils.isInventoryFull(player)) { - if (sender instanceof Player person) { + if (sender instanceof final Player person) { sender.sendMessage(Messages.inventory_not_empty.getMessage(person)); return; @@ -528,7 +523,7 @@ public void onAdminCrateOpenOthers(CommandSender sender, @Suggestion("crates") S this.crateManager.openCrate(player, crate, type, player.getLocation(), true, false); - HashMap placeholders = new HashMap<>(); + final HashMap placeholders = new HashMap<>(); placeholders.put("%Crate%", crate.getName()); placeholders.put("%Player%", player.getName()); @@ -540,8 +535,8 @@ public void onAdminCrateOpenOthers(CommandSender sender, @Suggestion("crates") S @SubCommand("open") @Permission(value = "crazycrates.command.admin.open", def = PermissionDefault.OP) - public void onAdminCrateOpen(Player player, @Suggestion("crates") String crateName) { - Crate crate = this.crateManager.getCrateFromName(crateName); + public void onAdminCrateOpen(final Player player, @Suggestion("crates") final String crateName) { + final Crate crate = this.crateManager.getCrateFromName(crateName); if (crate == null || crate.getCrateType() == CrateType.menu) { player.sendMessage(Messages.not_a_crate.getMessage("%crate%", crateName, player)); @@ -561,7 +556,7 @@ public void onAdminCrateOpen(Player player, @Suggestion("crates") String crateNa return; } - CrateType type = crate.getCrateType(); + final CrateType type = crate.getCrateType(); if (type == null) { player.sendMessage(Messages.internal_error.getMessage(player)); @@ -608,8 +603,8 @@ public void onAdminCrateOpen(Player player, @Suggestion("crates") String crateNa @SubCommand("mass-open") @Permission(value = "crazycrates.command.admin.massopen", def = PermissionDefault.OP) - public void onAdminCrateMassOpen(Player player, @Suggestion("crates") String crateName, @Suggestion("key-types") String keyType, @Suggestion("numbers") int amount) { - KeyType type = KeyType.getFromName(keyType); + public void onAdminCrateMassOpen(final Player player, @Suggestion("crates") final String crateName, @Suggestion("key-types") final String keyType, @Suggestion("numbers") final int amount) { + final KeyType type = KeyType.getFromName(keyType); if (type == null || type == KeyType.free_key) { player.sendMessage(MsgUtils.color(MsgUtils.getPrefix() + "&cPlease use Virtual/V or Physical/P for a Key type.")); @@ -617,7 +612,7 @@ public void onAdminCrateMassOpen(Player player, @Suggestion("crates") String cra return; } - Crate crate = this.crateManager.getCrateFromName(crateName); + final Crate crate = this.crateManager.getCrateFromName(crateName); if (crate == null || crate.getCrateType() == CrateType.menu) { player.sendMessage(Messages.not_a_crate.getMessage("%crate%", crateName, player)); @@ -647,7 +642,7 @@ public void onAdminCrateMassOpen(Player player, @Suggestion("crates") String cra if (keysUsed >= amount) break; if (keysUsed >= crate.getMaxMassOpen()) break; - Prize prize = crate.pickPrize(player); + final Prize prize = crate.pickPrize(player); PrizeManager.givePrize(player, prize, crate); @@ -672,14 +667,14 @@ public void onAdminCrateMassOpen(Player player, @Suggestion("crates") String cra @SubCommand("forceopen") @Permission(value = "crazycrates.command.admin.forceopen", def = PermissionDefault.OP) - public void onAdminForceOpen(CommandSender sender, @Suggestion("crates") String crateName, @Suggestion("online-players") Player player) { + public void onAdminForceOpen(final CommandSender sender, @Suggestion("crates") final String crateName, @Suggestion("online-players") final Player player) { onAdminCrateOpenOthers(sender, crateName, player, KeyType.free_key); } @SubCommand("set") @Permission(value = "crazycrates.command.admin.set", def = PermissionDefault.OP) - public void onAdminCrateSet(Player player, @Suggestion("crates") String crateName) { - Crate crate = this.crateManager.getCrateFromName(crateName); + public void onAdminCrateSet(final Player player, @Suggestion("crates") final String crateName) { + final Crate crate = this.crateManager.getCrateFromName(crateName); if (crate == null) { player.sendMessage(Messages.not_a_crate.getMessage("%crate%", crateName, player)); @@ -687,7 +682,7 @@ public void onAdminCrateSet(Player player, @Suggestion("crates") String crateNam return; } - Block block = player.getTargetBlock(null, 5); + final Block block = player.getTargetBlock(null, 5); if (block.isEmpty()) { player.sendMessage(Messages.must_be_looking_at_block.getMessage(player)); @@ -697,7 +692,7 @@ public void onAdminCrateSet(Player player, @Suggestion("crates") String crateNam this.crateManager.addCrateLocation(block.getLocation(), crate); - Map placeholders = new HashMap<>(); + final Map placeholders = new HashMap<>(); placeholders.put("%crate%", crate.getName()); placeholders.put("%prefix%", MsgUtils.getPrefix()); @@ -707,17 +702,17 @@ public void onAdminCrateSet(Player player, @Suggestion("crates") String crateNam @SubCommand("give-random") @Permission(value = "crazycrates.command.admin.giverandomkey", def = PermissionDefault.OP) - public void onAdminCrateGiveRandom(CommandSender sender, @Suggestion("key-types") String keyType, @Suggestion("numbers") int amount, @Suggestion("online-players") CustomPlayer target) { - Crate crate = this.crateManager.getUsableCrates().get((int) MiscUtils.pickNumber(0, (this.crateManager.getUsableCrates().size() - 2))); + public void onAdminCrateGiveRandom(final CommandSender sender, @Suggestion("key-types") final String keyType, @Suggestion("numbers") final int amount, @Suggestion("online-players") final CustomPlayer target) { + final Crate crate = this.crateManager.getUsableCrates().get((int) MiscUtils.pickNumber(0, (this.crateManager.getUsableCrates().size() - 2))); onAdminCrateGive(sender, keyType, crate.getName(), amount, target); } @SubCommand("give") @Permission(value = "crazycrates.command.admin.givekey", def = PermissionDefault.OP) - public void onAdminCrateGive(CommandSender sender, @Suggestion("key-types") String keyType, @Suggestion("crates") String crateName, @Suggestion("numbers") int amount, @Optional @Suggestion("online-players") CustomPlayer target) { - KeyType type = KeyType.getFromName(keyType); - Crate crate = this.crateManager.getCrateFromName(crateName); + public void onAdminCrateGive(final CommandSender sender, @Suggestion("key-types") final String keyType, @Suggestion("crates") final String crateName, @Suggestion("numbers") final int amount, @Optional @Suggestion("online-players") CustomPlayer target) { + final KeyType type = KeyType.getFromName(keyType); + final Crate crate = this.crateManager.getCrateFromName(crateName); if (type == null || type == KeyType.free_key) { sender.sendMessage(MsgUtils.color(MsgUtils.getPrefix() + "&cPlease use Virtual/V or Physical/P for a Key type.")); @@ -725,7 +720,7 @@ public void onAdminCrateGive(CommandSender sender, @Suggestion("key-types") Stri } if (crate == null || crate.getCrateType() == CrateType.menu) { - if (sender instanceof Player human) { + if (sender instanceof final Player human) { human.sendMessage(Messages.not_a_crate.getMessage("%crate%", crateName, human)); return; @@ -737,7 +732,7 @@ public void onAdminCrateGive(CommandSender sender, @Suggestion("key-types") Stri } if (amount <= 0) { - if (sender instanceof Player human) { + if (sender instanceof final Player human) { human.sendMessage(Messages.not_a_number.getMessage("%number%", String.valueOf(amount), human)); return; @@ -753,20 +748,20 @@ public void onAdminCrateGive(CommandSender sender, @Suggestion("key-types") Stri } if (target.getPlayer() != null) { - Player player = target.getPlayer(); + final Player player = target.getPlayer(); addKey(sender, player, null, crate, type, amount); return; } - OfflinePlayer offlinePlayer = target.getOfflinePlayer(); + final OfflinePlayer offlinePlayer = target.getOfflinePlayer(); addKey(sender, null, offlinePlayer, crate, type, amount); } - private void addKey(CommandSender sender, Player player, OfflinePlayer offlinePlayer, Crate crate, KeyType type, int amount) { - PlayerReceiveKeyEvent event = new PlayerReceiveKeyEvent(player, crate, PlayerReceiveKeyEvent.KeyReceiveReason.GIVE_COMMAND, amount); + private void addKey(final CommandSender sender, final Player player, final OfflinePlayer offlinePlayer, final Crate crate, final KeyType type, final int amount) { + final PlayerReceiveKeyEvent event = new PlayerReceiveKeyEvent(player, crate, PlayerReceiveKeyEvent.KeyReceiveReason.GIVE_COMMAND, amount); this.plugin.getServer().getPluginManager().callEvent(event); @@ -779,16 +774,16 @@ private void addKey(CommandSender sender, Player player, OfflinePlayer offlinePl this.userManager.addKeys(amount, player.getUniqueId(), crate.getName(), type); } - HashMap placeholders = new HashMap<>(); + final HashMap placeholders = new HashMap<>(); placeholders.put("%amount%", String.valueOf(amount)); placeholders.put("%player%", player.getName()); placeholders.put("%key%", crate.getKeyName()); - boolean fullMessage = this.config.getProperty(ConfigKeys.notify_player_when_inventory_full); - boolean inventoryCheck = this.config.getProperty(ConfigKeys.give_virtual_keys_when_inventory_full); + final boolean fullMessage = this.config.getProperty(ConfigKeys.notify_player_when_inventory_full); + final boolean inventoryCheck = this.config.getProperty(ConfigKeys.give_virtual_keys_when_inventory_full); - if (sender instanceof Player person) { + if (sender instanceof final Player person) { person.sendMessage(Messages.gave_a_player_keys.getMessage(placeholders, person)); } else { sender.sendMessage(Messages.gave_a_player_keys.getMessage(placeholders)); @@ -803,18 +798,18 @@ private void addKey(CommandSender sender, Player player, OfflinePlayer offlinePl } if (!this.userManager.addOfflineKeys(offlinePlayer.getUniqueId(), crate.getName(), amount, type)) { - if (sender instanceof Player person) { + if (sender instanceof final Player person) { person.sendMessage(Messages.internal_error.getMessage(person)); } else { sender.sendMessage(Messages.internal_error.getMessage()); } } else { - Map placeholders = new HashMap<>(); + final Map placeholders = new HashMap<>(); placeholders.put("%amount%", String.valueOf(amount)); placeholders.put("%player%", offlinePlayer.getName()); - if (sender instanceof Player person) { + if (sender instanceof final Player person) { person.sendMessage(Messages.given_offline_player_keys.getMessage(placeholders, person)); } else { sender.sendMessage(Messages.given_offline_player_keys.getMessage(placeholders)); @@ -826,10 +821,10 @@ private void addKey(CommandSender sender, Player player, OfflinePlayer offlinePl @SubCommand("take") @Permission(value = "crazycrates.command.admin.takekey", def = PermissionDefault.OP) - public void onAdminCrateTake(CommandSender sender, @Suggestion("key-types") String keyType, @Suggestion("crates") String crateName, @Suggestion("numbers") int amount, @Optional @Suggestion("online-players") CustomPlayer target) { - KeyType type = KeyType.getFromName(keyType); + public void onAdminCrateTake(final CommandSender sender, @Suggestion("key-types") final String keyType, @Suggestion("crates") final String crateName, @Suggestion("numbers") final int amount, @Optional @Suggestion("online-players") CustomPlayer target) { + final KeyType type = KeyType.getFromName(keyType); - Crate crate = this.crateManager.getCrateFromName(crateName); + final Crate crate = this.crateManager.getCrateFromName(crateName); if (type == null || type == KeyType.free_key) { sender.sendMessage(MsgUtils.color(MsgUtils.getPrefix() + "&cPlease use Virtual/V or Physical/P for a Key type.")); @@ -838,7 +833,7 @@ public void onAdminCrateTake(CommandSender sender, @Suggestion("key-types") Stri } if (crate == null || crate.getCrateType() == CrateType.menu) { - if (sender instanceof Player human) { + if (sender instanceof final Player human) { human.sendMessage(Messages.not_a_crate.getMessage("%crate%", crateName, human)); return; @@ -850,7 +845,7 @@ public void onAdminCrateTake(CommandSender sender, @Suggestion("key-types") Stri } if (amount <= 0) { - if (sender instanceof Player human) { + if (sender instanceof final Player human) { human.sendMessage(Messages.not_a_number.getMessage("%number%", String.valueOf(amount), human)); return; @@ -866,7 +861,7 @@ public void onAdminCrateTake(CommandSender sender, @Suggestion("key-types") Stri } if (target.getPlayer() != null) { - Player player = target.getPlayer(); + final Player player = target.getPlayer(); takeKey(sender, player, null, crate, type, amount); @@ -886,8 +881,8 @@ public void onAdminCrateTake(CommandSender sender, @Suggestion("key-types") Stri * @param type the type of key. * @param amount the amount of keys. */ - private void takeKey(CommandSender sender, @Nullable Player player, OfflinePlayer offlinePlayer, Crate crate, KeyType type, int amount) { - Map placeholders = new HashMap<>(); + private void takeKey(final CommandSender sender, @Nullable final Player player, final OfflinePlayer offlinePlayer, final Crate crate, final KeyType type, int amount) { + final Map placeholders = new HashMap<>(); placeholders.put("%crate%", crate.getName()); placeholders.put("%key%", crate.getKeyName()); @@ -895,14 +890,14 @@ private void takeKey(CommandSender sender, @Nullable Player player, OfflinePlaye if (player != null) { placeholders.put("%player%", player.getName()); - int totalKeys = this.userManager.getTotalKeys(player.getUniqueId(), crate.getName()); + final int totalKeys = this.userManager.getTotalKeys(player.getUniqueId(), crate.getName()); if (totalKeys < 1) { this.plugin.debug(() -> "The player " + player.getName() + " does not have enough keys to take.", Level.WARNING); placeholders.put("%amount%", String.valueOf(amount)); - if (sender instanceof Player human) { + if (sender instanceof final Player human) { human.sendMessage(Messages.cannot_take_keys.getMessage(placeholders, human)); return; } @@ -923,7 +918,7 @@ private void takeKey(CommandSender sender, @Nullable Player player, OfflinePlaye placeholders.put("%amount%", String.valueOf(amount)); - if (sender instanceof Player human) { + if (sender instanceof final Player human) { human.sendMessage(Messages.take_player_keys.getMessage(placeholders, human)); } else { sender.sendMessage(Messages.take_player_keys.getMessage(placeholders)); @@ -937,7 +932,7 @@ private void takeKey(CommandSender sender, @Nullable Player player, OfflinePlaye placeholders.put("%player%", offlinePlayer.getName()); placeholders.put("%amount%", String.valueOf(amount)); - if (sender instanceof Player human) { + if (sender instanceof final Player human) { human.sendMessage(Messages.take_offline_player_keys.getMessage(placeholders, human)); } else { sender.sendMessage(Messages.take_offline_player_keys.getMessage(placeholders)); @@ -948,9 +943,9 @@ private void takeKey(CommandSender sender, @Nullable Player player, OfflinePlaye @SubCommand("clear") @Permission(value = "crazycrates.command.admin.clearkey", def = PermissionDefault.OP) - public void onClearKey(CommandSender sender, @Optional @Suggestion("online-players") Player player) { + public void onClearKey(final CommandSender sender, @Optional @Suggestion("online-players") final Player player) { if (player == null) { - if (sender instanceof Player human) { + if (sender instanceof final Player human) { clearKey(sender, human); } else { sender.sendMessage(Messages.must_be_a_player.getMessage()); @@ -962,12 +957,12 @@ public void onClearKey(CommandSender sender, @Optional @Suggestion("online-playe clearKey(sender, player); } - private void clearKey(CommandSender sender, @NotNull Player player) { - Map placeholders = new HashMap<>(); + private void clearKey(final CommandSender sender, @NotNull final Player player) { + final Map placeholders = new HashMap<>(); placeholders.put("%player%", player.getName()); - for (Crate crate : this.crateManager.getUsableCrates()) { - String crateName = crate.getName(); - int amount = this.userManager.getVirtualKeys(player.getUniqueId(), crateName); + for (final Crate crate : this.crateManager.getUsableCrates()) { + final String crateName = crate.getName(); + final int amount = this.userManager.getVirtualKeys(player.getUniqueId(), crateName); if (amount > 0) { this.userManager.takeKeys(amount, player.getUniqueId(), crateName, KeyType.virtual_key, false); placeholders.put("%crate%", crateName); @@ -980,8 +975,8 @@ private void clearKey(CommandSender sender, @NotNull Player player) { @SubCommand("giveall") @Permission(value = "crazycrates.command.admin.giveall", def = PermissionDefault.OP) - public void onAdminCrateGiveAllKeys(CommandSender sender, @Suggestion("key-types") @ArgName("key-type") String keyType, @Suggestion("crates") @ArgName("crate-name") String crateName, @Suggestion("numbers") int amount) { - KeyType type = KeyType.getFromName(keyType); + public void onAdminCrateGiveAllKeys(final CommandSender sender, @Suggestion("key-types") @ArgName("key-type") final String keyType, @Suggestion("crates") @ArgName("crate-name") final String crateName, @Suggestion("numbers") final int amount) { + final KeyType type = KeyType.getFromName(keyType); if (type == null || type == KeyType.free_key) { sender.sendMessage(MsgUtils.color(MsgUtils.getPrefix() + "&cPlease use Virtual/V or Physical/P for a Key type.")); @@ -989,10 +984,10 @@ public void onAdminCrateGiveAllKeys(CommandSender sender, @Suggestion("key-types return; } - Crate crate = this.crateManager.getCrateFromName(crateName); + final Crate crate = this.crateManager.getCrateFromName(crateName); if (crate == null || crate.getCrateType() == CrateType.menu) { - if (sender instanceof Player human) { + if (sender instanceof final Player human) { human.sendMessage(Messages.not_a_crate.getMessage("%crate%", crateName, human)); return; @@ -1003,21 +998,21 @@ public void onAdminCrateGiveAllKeys(CommandSender sender, @Suggestion("key-types return; } - Map placeholders = new HashMap<>(); + final Map placeholders = new HashMap<>(); placeholders.put("%amount%", String.valueOf(amount)); placeholders.put("%key%", crate.getKeyName()); - if (sender instanceof Player human) { + if (sender instanceof final Player human) { human.sendMessage(Messages.given_everyone_keys.getMessage(placeholders, human)); } else { sender.sendMessage(Messages.given_everyone_keys.getMessage(placeholders)); } - for (Player onlinePlayer : this.plugin.getServer().getOnlinePlayers()) { + for (final Player onlinePlayer : this.plugin.getServer().getOnlinePlayers()) { if (Permissions.CRAZYCRATES_PLAYER_EXCLUDE.hasPermission(onlinePlayer)) continue; - PlayerReceiveKeyEvent event = new PlayerReceiveKeyEvent(onlinePlayer, crate, PlayerReceiveKeyEvent.KeyReceiveReason.GIVE_ALL_COMMAND, amount); + final PlayerReceiveKeyEvent event = new PlayerReceiveKeyEvent(onlinePlayer, crate, PlayerReceiveKeyEvent.KeyReceiveReason.GIVE_ALL_COMMAND, amount); onlinePlayer.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) return; @@ -1040,7 +1035,7 @@ public record CustomPlayer(String name) { private static final CrazyCrates plugin = CrazyCrates.getPlugin(CrazyCrates.class); public @NotNull OfflinePlayer getOfflinePlayer() { - CompletableFuture future = CompletableFuture.supplyAsync(() -> plugin.getServer().getOfflinePlayer(name)).thenApply(OfflinePlayer::getUniqueId); + final CompletableFuture future = CompletableFuture.supplyAsync(() -> plugin.getServer().getOfflinePlayer(name)).thenApply(OfflinePlayer::getUniqueId); return plugin.getServer().getOfflinePlayer(future.join()); } diff --git a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java index 5856f58a6..edb300038 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java +++ b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java @@ -103,30 +103,30 @@ public class CrateManager { * * @param crate the crate object. */ - public void reloadCrate(Crate crate) { + public void reloadCrate(final Crate crate) { try { // Close previews this.plugin.getServer().getOnlinePlayers().forEach(player -> this.plugin.getCrazyHandler().getInventoryManager().closeCratePreview(player)); // Grab the new file. - FileConfiguration file = crate.getFile(); + final FileConfiguration file = crate.getFile(); crate.purge(); // Profit? - List prizes = new ArrayList<>(); + final List prizes = new ArrayList<>(); - ConfigurationSection prizesSection = file.getConfigurationSection("Crate.Prizes"); + final ConfigurationSection prizesSection = file.getConfigurationSection("Crate.Prizes"); if (prizesSection != null) { - for (String prize : prizesSection.getKeys(false)) { - ConfigurationSection prizeSection = prizesSection.getConfigurationSection(prize); + for (final String prize : prizesSection.getKeys(false)) { + final ConfigurationSection prizeSection = prizesSection.getConfigurationSection(prize); - List tierPrizes = new ArrayList<>(); + final List tierPrizes = new ArrayList<>(); if (prizeSection != null) { - for (String tier : prizeSection.getStringList("Tiers")) { - for (Tier key : crate.getTiers()) { + for (final String tier : prizeSection.getStringList("Tiers")) { + for (final Tier key : crate.getTiers()) { if (key.getName().equalsIgnoreCase(tier)) { tierPrizes.add(key); } @@ -135,10 +135,10 @@ public void reloadCrate(Crate crate) { Prize alternativePrize = null; - ConfigurationSection alternativeSection = prizeSection.getConfigurationSection("Alternative-Prize"); + final ConfigurationSection alternativeSection = prizeSection.getConfigurationSection("Alternative-Prize"); if (alternativeSection != null) { - boolean isEnabled = alternativeSection.getBoolean("Toggle"); + final boolean isEnabled = alternativeSection.getBoolean("Toggle"); if (isEnabled) { alternativePrize = new Prize(prizeSection.getString("DisplayName", WordUtils.capitalizeFully(prizeSection.getString("DisplayItem", "STONE").replaceAll("_", " "))), prizeSection.getName(), alternativeSection); @@ -158,8 +158,8 @@ public void reloadCrate(Crate crate) { crate.setPrize(prizes); crate.setPreviewItems(crate.getPreviewItems()); - for (UUID uuid : this.plugin.getCrazyHandler().getInventoryManager().getViewers()) { - Player player = this.plugin.getServer().getPlayer(uuid); + for (final UUID uuid : this.plugin.getCrazyHandler().getInventoryManager().getViewers()) { + final Player player = this.plugin.getServer().getPlayer(uuid); if (player != null) { this.plugin.getCrazyHandler().getInventoryManager().openNewCratePreview(player, crate, crate.getCrateType() == CrateType.cosmic || crate.getCrateType() == CrateType.casino); @@ -167,7 +167,7 @@ public void reloadCrate(Crate crate) { } this.plugin.getCrazyHandler().getInventoryManager().purge(); - } catch (Exception exception) { + } catch (final Exception exception) { this.brokeCrates.add(crate.getName()); this.plugin.getLogger().log(Level.WARNING, "There was an error while loading the " + crate.getName() + ".yml file.", exception); } @@ -178,7 +178,6 @@ public void reloadCrate(Crate crate) { */ public void loadCrates() { this.giveNewPlayersKeys = false; - purge(); // Removes all holograms so that they can be replaced. @@ -195,25 +194,18 @@ public void loadCrates() { this.plugin.debug(() -> "Loading all crate information...", Level.INFO); - for (String crateName : this.fileManager.getAllCratesNames()) { + for (final String crateName : this.fileManager.getAllCratesNames()) { try { - FileConfiguration file = this.fileManager.getFile(crateName).getFile(); - CrateType crateType = CrateType.getFromName(file.getString("Crate.CrateType")); - - List prizes = new ArrayList<>(); - List tiers = new ArrayList<>(); - - String previewName = file.contains("Crate.Preview-Name") ? file.getString("Crate.Preview-Name") : file.getString("Crate.Name"); - int maxMassOpen = file.contains("Crate.Max-Mass-Open") ? file.getInt("Crate.Max-Mass-Open") : 10; - int requiredKeys = file.contains("Crate.RequiredKeys") ? file.getInt("Crate.RequiredKeys") : 0; - - ConfigurationSection section = file.getConfigurationSection("Crate.Tiers"); + this.fileManager.reloadFile(crateName); + final FileConfiguration file = this.fileManager.getFile(crateName).getFile(); + final ConfigurationSection section = file.getConfigurationSection("Crate.Tiers"); + final List tiers = new ArrayList<>(); if (file.contains("Crate.Tiers") && section != null) { - for (String tier : section.getKeys(false)) { - String path = "Crate.Tiers." + tier; + for (final String tier : section.getKeys(false)) { + final String path = "Crate.Tiers." + tier; - ConfigurationSection tierSection = file.getConfigurationSection(path); + final ConfigurationSection tierSection = file.getConfigurationSection(path); if (tierSection != null) { tiers.add(new Tier(tier, tierSection)); @@ -221,7 +213,8 @@ public void loadCrates() { } } - boolean isTiersEmpty = crateType == CrateType.cosmic || crateType == CrateType.casino; + final CrateType crateType = CrateType.getFromName(file.getString("Crate.CrateType")); + final boolean isTiersEmpty = crateType == CrateType.cosmic || crateType == CrateType.casino; if (isTiersEmpty && tiers.isEmpty()) { this.brokeCrates.add(crateName); @@ -229,29 +222,30 @@ public void loadCrates() { continue; } - ConfigurationSection prizesSection = file.getConfigurationSection("Crate.Prizes"); + final ConfigurationSection prizesSection = file.getConfigurationSection("Crate.Prizes"); + final List prizes = new ArrayList<>(); if (prizesSection != null) { - for (String prize : prizesSection.getKeys(false)) { - ConfigurationSection prizeSection = prizesSection.getConfigurationSection(prize); + for (final String prize : prizesSection.getKeys(false)) { + final ConfigurationSection prizeSection = prizesSection.getConfigurationSection(prize); - List tierPrizes = new ArrayList<>(); + final List tierPrizes = new ArrayList<>(); Prize alternativePrize = null; if (prizeSection != null) { - for (String tier : prizeSection.getStringList("Tiers")) { - for (Tier key : tiers) { + for (final String tier : prizeSection.getStringList("Tiers")) { + for (final Tier key : tiers) { if (key.getName().equalsIgnoreCase(tier)) { tierPrizes.add(key); } } } - ConfigurationSection alternativeSection = prizeSection.getConfigurationSection("Alternative-Prize"); + final ConfigurationSection alternativeSection = prizeSection.getConfigurationSection("Alternative-Prize"); if (alternativeSection != null) { - boolean isEnabled = alternativeSection.getBoolean("Toggle"); + final boolean isEnabled = alternativeSection.getBoolean("Toggle"); if (isEnabled) { alternativePrize = new Prize(prizeSection.getString("DisplayName", WordUtils.capitalizeFully(prizeSection.getString("DisplayItem", "STONE").replaceAll("_", " "))), prizeSection.getName(), alternativeSection); @@ -263,21 +257,25 @@ public void loadCrates() { } } - int newPlayersKeys = file.getInt("Crate.StartingKeys"); + final int newPlayersKeys = file.getInt("Crate.StartingKeys"); if (!this.giveNewPlayersKeys && (newPlayersKeys > 0)) { this.giveNewPlayersKeys = true; } - List prizeMessage = file.contains("Crate.Prize-Message") ? file.getStringList("Crate.Prize-Message") : List.of(); + final CrateHologram holo = new CrateHologram(file.getBoolean("Crate.Hologram.Toggle"), file.getDouble("Crate.Hologram.Height", 0.0), file.getInt("Crate.Hologram.Range", 8), file.getStringList("Crate.Hologram.Message")); - CrateHologram holo = new CrateHologram(file.getBoolean("Crate.Hologram.Toggle"), file.getDouble("Crate.Hologram.Height", 0.0), file.getInt("Crate.Hologram.Range", 8), file.getStringList("Crate.Hologram.Message")); - addCrate(new Crate(crateName, previewName, crateType, getKey(file), file.getString("Crate.PhysicalKey.Name"), prizes, file, newPlayersKeys, tiers, maxMassOpen, requiredKeys, prizeMessage, holo)); + final List prizeMessage = file.contains("Crate.Prize-Message") ? file.getStringList("Crate.Prize-Message") : List.of(); + final String previewName = file.contains("Crate.Preview-Name") ? file.getString("Crate.Preview-Name") : file.getString("Crate.Name"); + final int maxMassOpen = file.contains("Crate.Max-Mass-Open") ? file.getInt("Crate.Max-Mass-Open") : 10; + final int requiredKeys = file.contains("Crate.RequiredKeys") ? file.getInt("Crate.RequiredKeys") : 0; - Permission doesExist = this.plugin.getServer().getPluginManager().getPermission("crazycrates.open." + crateName); + addCrate(new Crate(crateName, previewName, crateType, getKey(file), file.getString("Crate.PhysicalKey.Name"), prizes, file, newPlayersKeys, tiers, maxMassOpen, requiredKeys, prizeMessage, holo)); + this.plugin.getLogger().info("Loaded " + crateName + ".yml file."); + final Permission doesExist = this.plugin.getServer().getPluginManager().getPermission("crazycrates.open." + crateName); if (doesExist == null) { - Permission permission = new Permission( + final Permission permission = new Permission( "crazycrates.open." + crateName, "Allows you to open " + crateName, PermissionDefault.TRUE @@ -285,7 +283,7 @@ public void loadCrates() { this.plugin.getServer().getPluginManager().addPermission(permission); } - } catch (Exception exception) { + } catch (final Exception exception) { this.brokeCrates.add(crateName); this.plugin.getLogger().log(Level.WARNING, "There was an error while loading the " + crateName + ".yml file.", exception); } @@ -298,16 +296,16 @@ public void loadCrates() { "Loading all the physical crate locations." ).forEach(line -> this.plugin.debug(() -> line, Level.INFO)); - FileConfiguration locations = FileManager.Files.LOCATIONS.getFile(); + final FileConfiguration locations = FileManager.Files.LOCATIONS.getFile(); int loadedAmount = 0; int brokeAmount = 0; - ConfigurationSection section = locations.getConfigurationSection("Locations"); + final ConfigurationSection section = locations.getConfigurationSection("Locations"); if (section != null) { - for (String locationName : section.getKeys(false)) { + for (final String locationName : section.getKeys(false)) { try { - String worldName = locations.getString("Locations." + locationName + ".World"); + final String worldName = locations.getString("Locations." + locationName + ".World"); // If name is null, we return. if (worldName == null) return; @@ -315,12 +313,12 @@ public void loadCrates() { // If name is empty or blank, we return. if (worldName.isEmpty() || worldName.isBlank()) return; - World world = this.plugin.getServer().getWorld(worldName); - int x = locations.getInt("Locations." + locationName + ".X"); - int y = locations.getInt("Locations." + locationName + ".Y"); - int z = locations.getInt("Locations." + locationName + ".Z"); - Location location = new Location(world, x, y, z); - Crate crate = this.plugin.getCrateManager().getCrateFromName(locations.getString("Locations." + locationName + ".Crate")); + final World world = this.plugin.getServer().getWorld(worldName); + final int x = locations.getInt("Locations." + locationName + ".X"); + final int y = locations.getInt("Locations." + locationName + ".Y"); + final int z = locations.getInt("Locations." + locationName + ".Z"); + final Location location = new Location(world, x, y, z); + final Crate crate = this.plugin.getCrateManager().getCrateFromName(locations.getString("Locations." + locationName + ".Crate")); if (world != null && crate != null) { this.crateLocations.add(new CrateLocation(locationName, crate, location)); @@ -335,7 +333,7 @@ public void loadCrates() { brokeAmount++; } - } catch (Exception ignored) { + } catch (final Exception ignored) { } } } @@ -355,10 +353,10 @@ public void loadCrates() { } // Loading schematic files - String[] schems = new File(this.plugin.getDataFolder() + "/schematics/").list(); + final String[] schems = new File(this.plugin.getDataFolder() + "/schematics/").list(); if (schems != null) { - for (String schematicName : schems) { + for (final String schematicName : schems) { if (schematicName.endsWith(".nbt")) { this.crateSchematics.add(new CrateSchematic(schematicName, new File(plugin.getDataFolder() + "/schematics/" + schematicName))); @@ -382,10 +380,10 @@ public void loadCrates() { * @param location the location that may be needed for some crate types. * @param checkHand if it just checks the players hand or if it checks their inventory. */ - public void openCrate(Player player, Crate crate, KeyType keyType, Location location, boolean virtualCrate, boolean checkHand) { + public void openCrate(final Player player, final Crate crate, final KeyType keyType, final Location location, final boolean virtualCrate, final boolean checkHand) { if (crate.getCrateType() == CrateType.menu) { if (this.plugin.getConfigManager().getConfig().getProperty(ConfigKeys.enable_crate_menu)) { - CrateMainMenu crateMainMenu = new CrateMainMenu(player, this.plugin.getConfigManager().getConfig().getProperty(ConfigKeys.inventory_size), this.plugin.getConfigManager().getConfig().getProperty(ConfigKeys.inventory_name)); + final CrateMainMenu crateMainMenu = new CrateMainMenu(player, this.plugin.getConfigManager().getConfig().getProperty(ConfigKeys.inventory_size), this.plugin.getConfigManager().getConfig().getProperty(ConfigKeys.inventory_name)); player.openInventory(crateMainMenu.build().getInventory()); return; @@ -396,7 +394,7 @@ public void openCrate(Player player, Crate crate, KeyType keyType, Location loca return; } - CrateBuilder crateBuilder; + final CrateBuilder crateBuilder; switch (crate.getCrateType()) { case csgo -> crateBuilder = new CsgoCrate(crate, player, 27); @@ -475,7 +473,7 @@ public void openCrate(Player player, Crate crate, KeyType keyType, Location loca * @param player the player opening the crate. * @param location the location the crate is at. */ - public void addCrateInUse(Player player, Location location) { + public void addCrateInUse(final Player player, final Location location) { this.cratesInUse.put(player.getUniqueId(), location); } @@ -483,7 +481,7 @@ public void addCrateInUse(Player player, Location location) { * @param player the player attempting to open a crate. * @return the location of the crate in use. */ - public Location getCrateInUseLocation(Player player) { + public Location getCrateInUseLocation(final Player player) { return this.cratesInUse.get(player.getUniqueId()); } @@ -491,7 +489,7 @@ public Location getCrateInUseLocation(Player player) { * @param player the player attempting to open a crate. * @return true or false. */ - public boolean isCrateInUse(Player player) { + public boolean isCrateInUse(final Player player) { return this.cratesInUse.containsKey(player.getUniqueId()); } @@ -500,7 +498,7 @@ public boolean isCrateInUse(Player player) { * * @param player the player finihsing a crate. */ - public void removeCrateInUse(Player player) { + public void removeCrateInUse(final Player player) { this.cratesInUse.remove(player.getUniqueId()); } @@ -516,7 +514,7 @@ public Map getCratesInUse() { * * @param player the player that the crate is being ended for. */ - public void endCrate(@NotNull Player player) { + public void endCrate(@NotNull final Player player) { if (this.currentTasks.containsKey(player.getUniqueId())) { this.currentTasks.get(player.getUniqueId()).cancel(); } @@ -527,9 +525,9 @@ public void endCrate(@NotNull Player player) { * * @param player the player using the crate. */ - public void endQuadCrate(@NotNull Player player) { + public void endQuadCrate(@NotNull final Player player) { if (this.currentQuadTasks.containsKey(player.getUniqueId())) { - for (BukkitTask task : this.currentQuadTasks.get(player.getUniqueId())) { + for (final BukkitTask task : this.currentQuadTasks.get(player.getUniqueId())) { task.cancel(); } @@ -543,7 +541,7 @@ public void endQuadCrate(@NotNull Player player) { * @param player the player opening the crate. * @param task the task of the quad crate. */ - public void addQuadCrateTask(@NotNull Player player, BukkitTask task) { + public void addQuadCrateTask(@NotNull final Player player, final BukkitTask task) { if (!this.currentQuadTasks.containsKey(player.getUniqueId())) { this.currentQuadTasks.put(player.getUniqueId(), new ArrayList<>()); } @@ -557,7 +555,7 @@ public void addQuadCrateTask(@NotNull Player player, BukkitTask task) { * @param player player that is being checked. * @return true if they do have a task and false if not. */ - public boolean hasQuadCrateTask(@NotNull Player player) { + public boolean hasQuadCrateTask(@NotNull final Player player) { return this.currentQuadTasks.containsKey(player.getUniqueId()); } @@ -567,7 +565,7 @@ public boolean hasQuadCrateTask(@NotNull Player player) { * @param player player opening the crate. * @param task task of the crate. */ - public void addCrateTask(@NotNull Player player, BukkitTask task) { + public void addCrateTask(@NotNull final Player player, final BukkitTask task) { this.currentTasks.put(player.getUniqueId(), task); } @@ -579,7 +577,7 @@ public void addCrateTask(@NotNull Player player, BukkitTask task) { * @param delay delay before running the task. * @param period interval between task runs. */ - public void addRepeatingCrateTask(@NotNull Player player, TimerTask task, Long delay, Long period) { + public void addRepeatingCrateTask(@NotNull final Player player, final TimerTask task, final Long delay, final Long period) { this.timerTasks.put(player.getUniqueId(), task); this.plugin.getTimer().scheduleAtFixedRate(task, delay, period); @@ -590,9 +588,9 @@ public void addRepeatingCrateTask(@NotNull Player player, TimerTask task, Long d * * @param player player that the crate is being ended for. */ - public void removeCrateTask(@NotNull Player player) { + public void removeCrateTask(@NotNull final Player player) { // Get uuid - UUID uuid = player.getUniqueId(); + final UUID uuid = player.getUniqueId(); // Check if contains. if (this.timerTasks.containsKey(uuid)) { @@ -611,7 +609,7 @@ public void removeCrateTask(@NotNull Player player) { * @param task task of the crate. * @param delay delay before running the task. */ - public void addCrateTask(@NotNull Player player, TimerTask task, Long delay) { + public void addCrateTask(@NotNull final Player player, final TimerTask task, final Long delay) { this.timerTasks.put(player.getUniqueId(), task); this.plugin.getTimer().schedule(task, delay); @@ -623,7 +621,7 @@ public void addCrateTask(@NotNull Player player, TimerTask task, Long delay) { * @param player the player opening the crate. * @return the task of the crate. */ - public BukkitTask getCrateTask(@NotNull Player player) { + public BukkitTask getCrateTask(@NotNull final Player player) { return this.currentTasks.get(player.getUniqueId()); } @@ -633,7 +631,7 @@ public BukkitTask getCrateTask(@NotNull Player player) { * @param player the player that is being checked. * @return true if they do have a task and false if not. */ - public boolean hasCrateTask(@NotNull Player player) { + public boolean hasCrateTask(@NotNull final Player player) { return this.currentTasks.containsKey(player.getUniqueId()); } @@ -643,7 +641,7 @@ public boolean hasCrateTask(@NotNull Player player) { * @param player the player that is opening a crate. * @param crate the crate the player is opening. */ - public void addPlayerToOpeningList(@NotNull Player player, Crate crate) { + public void addPlayerToOpeningList(@NotNull final Player player, final Crate crate) { this.playerOpeningCrates.put(player.getUniqueId(), crate); } @@ -652,7 +650,7 @@ public void addPlayerToOpeningList(@NotNull Player player, Crate crate) { * * @param player the player that has finished opening a crate. */ - public void removePlayerFromOpeningList(@NotNull Player player) { + public void removePlayerFromOpeningList(@NotNull final Player player) { this.playerOpeningCrates.remove(player.getUniqueId()); } @@ -662,7 +660,7 @@ public void removePlayerFromOpeningList(@NotNull Player player) { * @param player the player you are checking. * @return true if they are opening a crate and false if they are not. */ - public boolean isInOpeningList(@NotNull Player player) { + public boolean isInOpeningList(@NotNull final Player player) { return this.playerOpeningCrates.containsKey(player.getUniqueId()); } @@ -672,7 +670,7 @@ public boolean isInOpeningList(@NotNull Player player) { * @param player the player you want to check. * @return the Crate of which the player is opening. May return null if no crate found. */ - public Crate getOpeningCrate(@NotNull Player player) { + public Crate getOpeningCrate(@NotNull final Player player) { return this.playerOpeningCrates.get(player.getUniqueId()); } @@ -683,7 +681,7 @@ public Crate getOpeningCrate(@NotNull Player player) { * @param player the player that is opening the crate. * @param keyType the KeyType that they are using. */ - public void addPlayerKeyType(@NotNull Player player, KeyType keyType) { + public void addPlayerKeyType(@NotNull final Player player, final KeyType keyType) { this.playerKeys.put(player.getUniqueId(), keyType); } @@ -693,7 +691,7 @@ public void addPlayerKeyType(@NotNull Player player, KeyType keyType) { * * @param player the player you are removing. */ - public void removePlayerKeyType(@NotNull Player player) { + public void removePlayerKeyType(@NotNull final Player player) { this.playerKeys.remove(player.getUniqueId()); } @@ -703,7 +701,7 @@ public void removePlayerKeyType(@NotNull Player player) { * @param player the player you are checking. * @return true if they are in the list and false if not. */ - public boolean hasPlayerKeyType(@NotNull Player player) { + public boolean hasPlayerKeyType(@NotNull final Player player) { return this.playerKeys.containsKey(player.getUniqueId()); } @@ -713,7 +711,7 @@ public boolean hasPlayerKeyType(@NotNull Player player) { * @param player the player that is using the crate. * @return the key type of the crate the player is using. */ - public KeyType getPlayerKeyType(@NotNull Player player) { + public KeyType getPlayerKeyType(@NotNull final Player player) { return this.playerKeys.get(player.getUniqueId()); } @@ -732,9 +730,9 @@ public void purge() { * * @param player the player that has just joined. */ - public void setNewPlayerKeys(Player player) { + public void setNewPlayerKeys(final Player player) { if (this.giveNewPlayersKeys) { // Checks if any crate gives new players keys and if not then no need to do all this stuff. - String uuid = player.getUniqueId().toString(); + final String uuid = player.getUniqueId().toString(); if (!player.hasPlayedBefore()) { this.plugin.getCrateManager().getCrates().stream() @@ -752,11 +750,11 @@ public void setNewPlayerKeys(Player player) { * * @param crate crate object. */ - public void addCrate(Crate crate) { + public void addCrate(final Crate crate) { this.crates.add(crate); } - public void addLocation(CrateLocation crateLocation) { + public void addLocation(final CrateLocation crateLocation) { this.crateLocations.add(crateLocation); } @@ -765,14 +763,14 @@ public void addLocation(CrateLocation crateLocation) { * * @param crate crate object */ - public void removeCrate(Crate crate) { + public void removeCrate(final Crate crate) { this.crates.remove(crate); } /** * @return true if the arraylist has a crate object otherwise false. */ - public boolean hasCrate(Crate crate) { + public boolean hasCrate(final Crate crate) { return this.crates.contains(crate); } @@ -782,15 +780,15 @@ public boolean hasCrate(Crate crate) { * @param location the location you wish to add. * @param crate the crate which you would like to set it to. */ - public void addCrateLocation(Location location, Crate crate) { - FileConfiguration locations = Files.LOCATIONS.getFile(); + public void addCrateLocation(final Location location, final Crate crate) { + final FileConfiguration locations = Files.LOCATIONS.getFile(); String id = "1"; // Location ID for (int i = 1; locations.contains("Locations." + i); i++) { id = (i + 1) + ""; } - for (CrateLocation crateLocation : getCrateLocations()) { + for (final CrateLocation crateLocation : getCrateLocations()) { if (crateLocation.getLocation().equals(location)) { id = crateLocation.getID(); break; @@ -816,12 +814,12 @@ public void addCrateLocation(Location location, Crate crate) { * * @param id the id of the location. */ - public void removeCrateLocation(String id) { + public void removeCrateLocation(final String id) { Files.LOCATIONS.getFile().set("Locations." + id, null); Files.LOCATIONS.saveFile(); CrateLocation location = null; - for (CrateLocation crateLocation : getCrateLocations()) { + for (final CrateLocation crateLocation : getCrateLocations()) { if (crateLocation.getID().equalsIgnoreCase(id)) { location = crateLocation; break; @@ -839,7 +837,7 @@ public void removeCrateLocation(String id) { * @return an unmodifiable list of crate objects. */ public List getUsableCrates() { - List crateList = new ArrayList<>(this.crates); + final List crateList = new ArrayList<>(this.crates); crateList.removeIf(crate -> crate.getCrateType() == CrateType.menu); return Collections.unmodifiableList(crateList); @@ -858,8 +856,8 @@ public List getCrates() { * @param name name of the crate. * @return the crate object. */ - public Crate getCrateFromName(String name) { - for (Crate crate : this.crates) { + public Crate getCrateFromName(final String name) { + for (final Crate crate : this.crates) { if (crate.getName().equalsIgnoreCase(name)) { return crate; } @@ -874,8 +872,8 @@ public Crate getCrateFromName(String name) { * @param location location you are checking. * @return true if it is a physical crate and false if not. */ - public boolean isCrateLocation(Location location) { - for (CrateLocation crateLocation : getCrateLocations()) { + public boolean isCrateLocation(final Location location) { + for (final CrateLocation crateLocation : getCrateLocations()) { if (crateLocation.getLocation().equals(location)) { return true; } @@ -890,7 +888,7 @@ public boolean isCrateLocation(Location location) { * @param item the item you are checking. * @return true if the item is a key and false if it is not. */ - public boolean isKey(ItemStack item) { + public boolean isKey(final ItemStack item) { return getCrateFromKey(item) != null; } @@ -900,9 +898,9 @@ public boolean isKey(ItemStack item) { * @param item the key ItemStack you are checking. * @return a crate if is a key from a crate otherwise null if it is not. */ - public Crate getCrateFromKey(ItemStack item) { + public Crate getCrateFromKey(final ItemStack item) { if (item != null && item.getType() != Material.AIR) { - for (Crate crate : getCrates()) { + for (final Crate crate : getCrates()) { if (crate.getCrateType() != CrateType.menu && (isKeyFromCrate(item, crate))) { return crate; } @@ -918,8 +916,8 @@ public Crate getCrateFromKey(ItemStack item) { * @param location location you are checking. * @return a crate location if the location is a physical crate otherwise null if not. */ - public CrateLocation getCrateLocation(Location location) { - for (CrateLocation crateLocation : this.crateLocations) { + public CrateLocation getCrateLocation(final Location location) { + for (final CrateLocation crateLocation : this.crateLocations) { if (crateLocation.getLocation().equals(location)) { return crateLocation; } @@ -934,8 +932,8 @@ public CrateLocation getCrateLocation(Location location) { * @param name the name of the schematic. * @return the CrateSchematic otherwise returns null if not found. */ - public CrateSchematic getCrateSchematic(String name) { - for (CrateSchematic schematic : this.crateSchematics) { + public CrateSchematic getCrateSchematic(final String name) { + for (final CrateSchematic schematic : this.crateSchematics) { if (schematic.getSchematicName().equalsIgnoreCase(name)) { return schematic; } @@ -950,17 +948,17 @@ public CrateSchematic getCrateSchematic(String name) { * @param entity entity you wish to check. * @return true if it is a display reward item and false if not. */ - public boolean isDisplayReward(Entity entity) { - if (entity instanceof Item item) { - ItemStack itemStack = item.getItemStack(); + public boolean isDisplayReward(final Entity entity) { + if (entity instanceof final Item item) { + final ItemStack itemStack = item.getItemStack(); if (itemStack.getType() == Material.AIR) return false; - ItemMeta itemMeta = itemStack.getItemMeta(); + final ItemMeta itemMeta = itemStack.getItemMeta(); - PersistentKeys prize = PersistentKeys.crate_prize; + final PersistentKeys prize = PersistentKeys.crate_prize; - PersistentDataContainer container = itemMeta.getPersistentDataContainer(); + final PersistentDataContainer container = itemMeta.getPersistentDataContainer(); return container.has(prize.getNamespacedKey()); } @@ -975,7 +973,7 @@ public boolean isDisplayReward(Entity entity) { * @param crate the Crate you are checking. * @return true if it belongs to that Crate and false if it does not. */ - public boolean isKeyFromCrate(ItemStack item, @NotNull Crate crate) { + public boolean isKeyFromCrate(final ItemStack item, @NotNull final Crate crate) { if (crate.getCrateType() != CrateType.menu && (item != null && item.getType() != Material.AIR)) { return ItemUtils.isSimilar(item, crate); } @@ -1002,7 +1000,7 @@ public List getCrateLocations() { * * @param crateLocation the location to remove. */ - public void removeLocation(CrateLocation crateLocation) { + public void removeLocation(final CrateLocation crateLocation) { this.crateLocations.remove(crateLocation); } @@ -1025,7 +1023,7 @@ public List getBrokeLocations() { * * @param crateLocation list of locations to remove. */ - public void removeBrokeLocation(List crateLocation) { + public void removeBrokeLocation(final List crateLocation) { this.brokeLocations.removeAll(crateLocation); } @@ -1037,11 +1035,11 @@ public List getCrateSchematics() { } // Internal methods. - private ItemStack getKey(@NotNull FileConfiguration file) { - String name = file.getString("Crate.PhysicalKey.Name"); - List lore = file.getStringList("Crate.PhysicalKey.Lore"); - String id = file.getString("Crate.PhysicalKey.Item", "TRIPWIRE_HOOK"); - boolean glowing = file.getBoolean("Crate.PhysicalKey.Glowing", true); + private ItemStack getKey(@NotNull final FileConfiguration file) { + final String name = file.getString("Crate.PhysicalKey.Name"); + final List lore = file.getStringList("Crate.PhysicalKey.Lore"); + final String id = file.getString("Crate.PhysicalKey.Item", "TRIPWIRE_HOOK"); + final boolean glowing = file.getBoolean("Crate.PhysicalKey.Glowing", true); return new ItemBuilder().setMaterial(id).setName(name).setLore(lore).setGlow(glowing).build(); } @@ -1049,7 +1047,7 @@ private ItemStack getKey(@NotNull FileConfiguration file) { // Cleans the data file. private void cleanDataFile() { try { - FileConfiguration data = FileManager.Files.DATA.getFile(); + final FileConfiguration data = FileManager.Files.DATA.getFile(); if (!data.contains("Players")) { return; } @@ -1061,25 +1059,25 @@ private void cleanDataFile() { this.plugin.debug(() -> "Cleaning up the data.yml file.", Level.INFO); - ConfigurationSection playersSection = data.getConfigurationSection("Players"); + final ConfigurationSection playersSection = data.getConfigurationSection("Players"); if (playersSection == null) { this.plugin.debug(() -> "The configuration section Players is null.", Level.INFO); return; } - Set reservedNames = Set.of("Name"); - Set validCrateNames = new HashSet<>(getCrates().stream().map(Crate::getName).toList()); - List removePlayers = new ArrayList<>(); + final Set reservedNames = Set.of("Name"); + final Set validCrateNames = new HashSet<>(getCrates().stream().map(Crate::getName).toList()); + final List removePlayers = new ArrayList<>(); - for (String uuid : playersSection.getKeys(false)) { - ConfigurationSection playerSection = data.getConfigurationSection("Players." + uuid); + for (final String uuid : playersSection.getKeys(false)) { + final ConfigurationSection playerSection = data.getConfigurationSection("Players." + uuid); if (playerSection == null) continue; boolean playerHasValidKeys = false; - List cratesToRemove = new ArrayList<>(); + final List cratesToRemove = new ArrayList<>(); - for (String crateName : playerSection.getKeys(false)) { + for (final String crateName : playerSection.getKeys(false)) { if (reservedNames.contains(crateName)) { continue; } @@ -1092,7 +1090,7 @@ private void cleanDataFile() { continue; } - int keys = data.getInt("Players." + uuid + "." + crateName); + final int keys = data.getInt("Players." + uuid + "." + crateName); if (keys <= 0) { data.set("Players." + uuid + "." + crateName, null); } else { @@ -1119,79 +1117,79 @@ private void cleanDataFile() { FileManager.Files.DATA.saveFile(); this.plugin.debug(() -> "The data.yml file has been cleaned.", Level.INFO); - } catch (Exception e) { + } catch (final Exception e) { this.plugin.debug(() -> "Error cleaning data.yml file: " + e.getMessage(), Level.WARNING); } } private boolean backupDataFile() { try { - File dataFolder = this.plugin.getDataFolder(); - File backupFolder = new File(dataFolder, "backup"); + final File dataFolder = this.plugin.getDataFolder(); + final File backupFolder = new File(dataFolder, "backup"); if (!backupFolder.exists()) { //noinspection ResultOfMethodCallIgnored backupFolder.mkdirs(); } - File dataFile = new File(dataFolder, "data.yml"); - File backupFile = new File(backupFolder, "data_%s.yml".formatted(String.valueOf(System.currentTimeMillis()))); + final File dataFile = new File(dataFolder, "data.yml"); + final File backupFile = new File(backupFolder, "data_%s.yml".formatted(String.valueOf(System.currentTimeMillis()))); com.google.common.io.Files.copy(dataFile, backupFile); this.plugin.getLogger().info("Created a backup of the data.yml file."); return true; - } catch (IOException e) { + } catch (final IOException e) { this.plugin.getLogger().log(Level.WARNING, "Failed to create a backup of the data.yml file.", e); return false; } } - public void addPicker(@NotNull Player player, boolean value) { + public void addPicker(@NotNull final Player player, final boolean value) { this.canPick.put(player.getUniqueId(), value); } - public boolean containsPicker(@NotNull Player player) { + public boolean containsPicker(@NotNull final Player player) { return this.canPick.containsKey(player.getUniqueId()); } - public boolean isPicker(@NotNull Player player) { + public boolean isPicker(@NotNull final Player player) { return this.canPick.get(player.getUniqueId()); } - public void removePicker(@NotNull Player player) { + public void removePicker(@NotNull final Player player) { this.canPick.remove(player.getUniqueId()); } - public void addCloser(@NotNull Player player, boolean value) { + public void addCloser(@NotNull final Player player, final boolean value) { this.canClose.put(player.getUniqueId(), value); } - public boolean containsCloser(@NotNull Player player) { + public boolean containsCloser(@NotNull final Player player) { return this.canClose.containsKey(player.getUniqueId()); } - public void removeCloser(@NotNull Player player) { + public void removeCloser(@NotNull final Player player) { this.canClose.remove(player.getUniqueId()); } - public void addHands(@NotNull Player player, boolean checkHand) { + public void addHands(@NotNull final Player player, final boolean checkHand) { this.checkHands.put(player.getUniqueId(), checkHand); } - public void removeHands(@NotNull Player player) { + public void removeHands(@NotNull final Player player) { this.checkHands.remove(player.getUniqueId()); } - public boolean getHand(@NotNull Player player) { + public boolean getHand(@NotNull final Player player) { return this.checkHands.get(player.getUniqueId()); } - public void addReward(@NotNull Player player, Entity entity) { + public void addReward(@NotNull final Player player, final Entity entity) { this.allRewards.add(entity); this.rewards.put(player.getUniqueId(), entity); } - public void endQuickCrate(Player player, Location location, Crate crate, boolean useQuickCrateAgain) { + public void endQuickCrate(final Player player, final Location location, final Crate crate, final boolean useQuickCrateAgain) { if (hasCrateTask(player)) { getCrateTask(player).cancel(); removeCrateTask(player);