diff --git a/ChestsPlusPlus_Main/dependency-reduced-pom.xml b/ChestsPlusPlus_Main/dependency-reduced-pom.xml index a060ed2..34698ee 100644 --- a/ChestsPlusPlus_Main/dependency-reduced-pom.xml +++ b/ChestsPlusPlus_Main/dependency-reduced-pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.jamesdpeters.minecraft.chests ChestsPlusPlus-Master - 2.5-Beta + 2.5-Release scm:git:git@github.com:JamesPeters98/ChestsPlusPlus.git scm:git:git@github.com:JamesPeters98/ChestsPlusPlus.git @@ -132,7 +132,7 @@ org.apache.commons commons-lang3 - 3.4 + 3.12.0 compile @@ -144,13 +144,13 @@ org.jetbrains annotations - 18.0.0 + 22.0.0 compile org.projectlombok lombok - 1.18.20 + 1.18.22 provided diff --git a/ChestsPlusPlus_Main/pom.xml b/ChestsPlusPlus_Main/pom.xml index 4d377ed..b3b2072 100644 --- a/ChestsPlusPlus_Main/pom.xml +++ b/ChestsPlusPlus_Main/pom.xml @@ -6,7 +6,7 @@ com.jamesdpeters.minecraft.chests ChestsPlusPlus-Master - 2.5-Beta + 2.5-Release 16 @@ -71,7 +71,7 @@ org.apache.commons commons-lang3 - 3.4 + 3.12.0 @@ -96,7 +96,7 @@ org.bstats bstats-bukkit - 1.7 + 2.2.1 @@ -157,7 +157,7 @@ org.jetbrains annotations - 18.0.0 + 22.0.0 compile @@ -165,7 +165,7 @@ org.projectlombok lombok - 1.18.20 + 1.18.22 provided diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/ChestsPlusPlus.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/ChestsPlusPlus.java index 7f3f6fb..0ef5a49 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/ChestsPlusPlus.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/ChestsPlusPlus.java @@ -114,20 +114,18 @@ public class ChestsPlusPlus extends JavaPlugin { if (PluginConfig.IS_UPDATE_CHECKER_ENABLED.get()) { String BUKKIT_URL = "https://dev.bukkit.org/projects/chests-plus-plus/files"; UpdateChecker.init(this, 71355, UpdateChecker.VERSION_SCHEME_DECIMAL); - Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> { - UpdateChecker.get().requestUpdateCheck().whenCompleteAsync((updateResult, throwable) -> { - switch (updateResult.getReason()) { - case NEW_UPDATE: - Bukkit.broadcastMessage(ChatColor.RED + "[Chests++] New version of the plugin was found: " + updateResult.getNewestVersion()); - Bukkit.broadcastMessage(ChatColor.RED + "[Chests++] Download at: " + ChatColor.WHITE + BUKKIT_URL); - break; - case UP_TO_DATE: - if (!boot) getLogger().info("Plugin is up to date! Thank you for supporting Chests++!"); - break; - } - boot = true; - }); - }, 0, PluginConfig.UPDATE_CHECKER_PERIOD.get() * 20); + Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> UpdateChecker.get().requestUpdateCheck().whenCompleteAsync((updateResult, throwable) -> { + switch (updateResult.getReason()) { + case NEW_UPDATE: + Bukkit.broadcastMessage(ChatColor.RED + "[Chests++] New version of the plugin was found: " + updateResult.getNewestVersion()); + Bukkit.broadcastMessage(ChatColor.RED + "[Chests++] Download at: " + ChatColor.WHITE + BUKKIT_URL); + break; + case UP_TO_DATE: + if (!boot) getLogger().info("Plugin is up to date! Thank you for supporting Chests++!"); + break; + } + boot = true; + }), 0, PluginConfig.UPDATE_CHECKER_PERIOD.get() * 20); } // Remove armour stands if disabled diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/commands/AutoCraftCommand.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/commands/AutoCraftCommand.java index b9cf5db..9d3e480 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/commands/AutoCraftCommand.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/commands/AutoCraftCommand.java @@ -60,12 +60,11 @@ public class AutoCraftCommand extends ServerCommand { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { sender.sendMessage("Only a player can use this command"); return false; } - Player player = (Player) sender; if (args != null && args.length > 0) { try { switch (OPTIONS.valueOf(args[0].toUpperCase())) { @@ -184,8 +183,7 @@ public class AutoCraftCommand extends ServerCommand { @Override public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { - if ((sender instanceof Player)) { - Player player = (Player) sender; + if ((sender instanceof Player player)) { if (args.length == 1) { return OPTIONS.valuesList; @@ -208,11 +206,12 @@ public class AutoCraftCommand extends ServerCommand { if (args.length == 3) { try { switch (OPTIONS.valueOf(args[0].toUpperCase())) { - case MEMBER: + case MEMBER -> { if (args[1].equals("add-to-all")) return Utils.filterList(Utils.getAllPlayers(), args[2]); if (args[1].equals("remove-from-all")) return Utils.filterList(Utils.getAllPlayers(), args[2]); return Config.getAutoCraft().getStorageList(player, args[2]); + } } } catch (IllegalArgumentException ignored) { } diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/commands/ChestLinkCommand.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/commands/ChestLinkCommand.java index 1c4372d..a1078df 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/commands/ChestLinkCommand.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/commands/ChestLinkCommand.java @@ -64,12 +64,11 @@ public class ChestLinkCommand extends ServerCommand { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { sender.sendMessage("Only a player can use this command"); return false; } - Player player = (Player) sender; if (args != null && args.length > 0) { try { switch (OPTIONS.valueOf(args[0].toUpperCase())) { @@ -206,8 +205,7 @@ public class ChestLinkCommand extends ServerCommand { @Override public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { - if ((sender instanceof Player)) { - Player player = (Player) sender; + if ((sender instanceof Player player)) { if (args.length == 1) { return OPTIONS.valuesList; diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/commands/ChestsPlusPlusCommand.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/commands/ChestsPlusPlusCommand.java index ff10f66..60b6d41 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/commands/ChestsPlusPlusCommand.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/commands/ChestsPlusPlusCommand.java @@ -49,11 +49,10 @@ public class ChestsPlusPlusCommand extends ServerCommand { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { sender.sendMessage("Only a player can use this command"); return false; } - Player player = (Player) sender; if (args != null && args.length > 0) { switch (OPTIONS.valueOf(args[0].toUpperCase())) { case VERSION: @@ -84,8 +83,7 @@ public class ChestsPlusPlusCommand extends ServerCommand { @Override public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { - if ((sender instanceof Player)) { - Player player = (Player) sender; + if ((sender instanceof Player player)) { if (args.length == 1) { return OPTIONS.valuesList; } @@ -101,7 +99,7 @@ public class ChestsPlusPlusCommand extends ServerCommand { if (args.length == 3) { try { switch (OPTIONS.valueOf(args[0].toUpperCase())) { - case PARTY: { + case PARTY -> { String arg = args[1]; if (arg.equals("delete") || arg.equals("invite") || arg.equals("remove-member")) { List strings = PartyUtils.getPlayerPartyStorage(player).getOwnedPartiesAsStrings(); @@ -115,7 +113,7 @@ public class ChestsPlusPlusCommand extends ServerCommand { if (args.length == 4) { try { switch (OPTIONS.valueOf(args[0].toUpperCase())) { - case PARTY: { + case PARTY -> { String arg = args[2]; if (arg.equals("invite") || arg.equals("remove-member")) { return Utils.filterList(Utils.getAllPlayers(), args[3]); diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/crafting/UserShapedRecipe.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/crafting/UserShapedRecipe.java index e77a9ee..26c3e52 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/crafting/UserShapedRecipe.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/crafting/UserShapedRecipe.java @@ -98,13 +98,12 @@ public class UserShapedRecipe { private Map flipShape(String[] shape) { Map map = new HashMap<>(); - for (int i = 0; i < shape.length; i++) { + for (String s : shape) { StringBuilder input = new StringBuilder(); - String row = shape[i]; - String reverse = input.append(row).reverse().toString(); - char[] originalChars = row.toCharArray(); + String reverse = input.append(s).reverse().toString(); + char[] originalChars = s.toCharArray(); char[] reverseChars = reverse.toCharArray(); - for (int c = 0; c < row.length(); c++) { + for (int c = 0; c < s.length(); c++) { map.put(originalChars[c], reverseChars[c]); } } diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/filters/HopperFilter.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/filters/HopperFilter.java index f14f49a..99dad90 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/filters/HopperFilter.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/filters/HopperFilter.java @@ -27,8 +27,7 @@ public class HopperFilter { Collection ent = block.getWorld().getNearbyEntities(block.getLocation(), 1.01, 1.01, 1.01); List filters = new ArrayList<>(ent.size()); for (Entity entity : ent) { - if (entity instanceof ItemFrame) { - ItemFrame frame = (ItemFrame) entity; + if (entity instanceof ItemFrame frame) { if (frame.getItem().getType().equals(Material.AIR)) continue; Block attachedBlock = frame.getLocation().getBlock().getRelative(frame.getAttachedFace()); if (block.equals(attachedBlock)) { diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/interfaces/VirtualCraftingHolder.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/interfaces/VirtualCraftingHolder.java index 9ab8250..da74d8c 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/interfaces/VirtualCraftingHolder.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/interfaces/VirtualCraftingHolder.java @@ -74,8 +74,7 @@ public class VirtualCraftingHolder implements InventoryHolder { List choiceList = shapelessRecipe.getChoiceList(); for (int i = 0; i < choiceList.size(); i++) { RecipeChoice recipeChoice = choiceList.get(i); - if (recipeChoice instanceof RecipeChoice.MaterialChoice) { - RecipeChoice.MaterialChoice materialChoice = (RecipeChoice.MaterialChoice) recipeChoice; + if (recipeChoice instanceof RecipeChoice.MaterialChoice materialChoice) { ItemStack[] choices = materialChoice.getChoices().stream().map(ItemStack::new).toArray(ItemStack[]::new); recipeChoices[i] = choices; } @@ -90,8 +89,7 @@ public class VirtualCraftingHolder implements InventoryHolder { int col = 0; for (char c : r.toCharArray()) { RecipeChoice recipeChoice = recipe.getChoiceMap().get(c); - if (recipeChoice instanceof RecipeChoice.MaterialChoice) { - RecipeChoice.MaterialChoice materialChoice = (RecipeChoice.MaterialChoice) recipeChoice; + if (recipeChoice instanceof RecipeChoice.MaterialChoice materialChoice) { ItemStack[] choices = materialChoice.getChoices().stream().map(ItemStack::new).toArray(ItemStack[]::new); int i = (row * 3) + col; recipeChoices[i] = choices; @@ -242,8 +240,7 @@ public class VirtualCraftingHolder implements InventoryHolder { Inventory output; - if (blockBelow.getState() instanceof Hopper) { - Hopper hopper = (Hopper) blockBelow.getState(); + if (blockBelow.getState() instanceof Hopper hopper) { if (blockBelow.isBlockPowered() || blockBelow.isBlockIndirectlyPowered()) { continue; //If hopper is powered no crafting should happen. } diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/lang/LanguageFile.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/lang/LanguageFile.java index beb42cd..a3ff105 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/lang/LanguageFile.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/lang/LanguageFile.java @@ -43,11 +43,13 @@ public class LanguageFile extends Properties { if (generated) { writeComments(bw, " Chests++ Language File (Version " + BuildConstants.VERSION + ")"); writeComments(bw, - " NOTE: This file gets replaced when the plugin launches! If you want to make modifications create a copy first!\n" + - " To create a new language file simply create a copy of this file and rename it to your desired choice for example 'en_US.properties'\n" + - " It should be located in the 'lang' folder\n" + - " Then in config.yml 'language-file: default' would be renamed to 'language-file: en_US'\n" + - " To help contribute to the plugin and provide new language files you can create a pull-request at https://github.com/JamesPeters98/ChestsPlusPlus or join our Discord https://discord.gg/YRs3mP5"); + """ + NOTE: This file gets replaced when the plugin launches! If you want to make modifications create a copy first! + To create a new language file simply create a copy of this file and rename it to your desired choice for example 'en_US.properties' + It should be located in the 'lang' folder + Then in config.yml 'language-file: default' would be renamed to 'language-file: en_US' + To help contribute to the plugin and provide new language files you can create a pull-request at https://github.com/JamesPeters98/ChestsPlusPlus or join our Discord https://discord.gg/YRs3mP5 + """.indent(1)); for (String additionalComment : additionalComments) { writeComments(bw, additionalComment); diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/listeners/InventoryListener.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/listeners/InventoryListener.java index 65ef983..5e15593 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/listeners/InventoryListener.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/listeners/InventoryListener.java @@ -48,8 +48,7 @@ public class InventoryListener implements Listener { public void inventoryUpdate(InventoryInteractEvent event) { InventoryHolder holder = event.getInventory().getHolder(); - if (holder instanceof VirtualInventoryHolder) { - VirtualInventoryHolder vHolder = (VirtualInventoryHolder) holder; + if (holder instanceof VirtualInventoryHolder vHolder) { Bukkit.getScheduler().scheduleSyncDelayedTask(ChestsPlusPlus.PLUGIN, () -> { vHolder.getStorage().sort(); vHolder.getStorage().onItemDisplayUpdate(InventorySorter.getMostCommonItem(event.getInventory())); diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/listeners/StorageListener.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/listeners/StorageListener.java index b7c2bf0..77d6426 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/listeners/StorageListener.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/listeners/StorageListener.java @@ -89,8 +89,7 @@ public class StorageListener implements Listener { @EventHandler public void onSignBreak(BlockBreakEvent event) { - if (event.getBlock().getState() instanceof Sign) { - Sign sign = (Sign) event.getBlock().getState(); + if (event.getBlock().getState() instanceof Sign sign) { //Get blockface of sign. if (sign.getBlockData() instanceof Directional) { diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/menus/PartySelectorMenu.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/menus/PartySelectorMenu.java index 757f385..2286428 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/menus/PartySelectorMenu.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/menus/PartySelectorMenu.java @@ -110,15 +110,10 @@ public class PartySelectorMenu implements InventoryProvider { } private List getParties(OfflinePlayer player) { - switch (type) { - case ALL: - return PartyUtils.getPlayerPartyStorage(player).getAllParties(); - case OWNED: - return PartyUtils.getPlayerPartyStorage(player).getOwnedPartiesList(); - case MEMBER_OF: - return PartyUtils.getPlayerPartyStorage(player).getPartiesMemberOf(); - default: - return new ArrayList<>(); - } + return switch (type) { + case ALL -> PartyUtils.getPlayerPartyStorage(player).getAllParties(); + case OWNED -> PartyUtils.getPlayerPartyStorage(player).getOwnedPartiesList(); + case MEMBER_OF -> PartyUtils.getPlayerPartyStorage(player).getPartiesMemberOf(); + }; } } diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/misc/ItemBuilder.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/misc/ItemBuilder.java index 79b8dd3..2ddc2a7 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/misc/ItemBuilder.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/misc/ItemBuilder.java @@ -75,8 +75,7 @@ public class ItemBuilder { meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); } - if (skullOwner != null && meta instanceof SkullMeta) { - SkullMeta skullMeta = (SkullMeta) meta; + if (skullOwner != null && meta instanceof SkullMeta skullMeta) { skullMeta.setOwningPlayer(skullOwner); } itemStack.setItemMeta(meta); diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/misc/Stats.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/misc/Stats.java index f3f68b9..486dcc7 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/misc/Stats.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/misc/Stats.java @@ -3,25 +3,26 @@ package com.jamesdpeters.minecraft.chests.misc; import com.jamesdpeters.minecraft.chests.serialize.Config; import com.jamesdpeters.minecraft.chests.serialize.PluginConfig; import org.bstats.bukkit.Metrics; +import org.bstats.charts.SimplePie; public class Stats { public static void addCharts(Metrics metrics) { - metrics.addCustomChart(new Metrics.SimplePie("chestlink-amount", () -> { + metrics.addCustomChart(new SimplePie("chestlink-amount", () -> { int chestlinks = Config.getChestLink().getTotalLocations(); return chestlinks + ""; })); - metrics.addCustomChart(new Metrics.SimplePie("autocraft-amount", () -> { + metrics.addCustomChart(new SimplePie("autocraft-amount", () -> { int locations = Config.getAutoCraft().getTotalLocations(); return locations + ""; })); - metrics.addCustomChart(new Metrics.SimplePie("update_checker_setting", () -> { + metrics.addCustomChart(new SimplePie("update_checker_setting", () -> { if (PluginConfig.IS_UPDATE_CHECKER_ENABLED.get()) return "enabled"; else return "disabled"; })); - metrics.addCustomChart(new Metrics.SimplePie("language-file", PluginConfig.LANG_FILE::get)); + metrics.addCustomChart(new SimplePie("language-file", PluginConfig.LANG_FILE::get)); } } diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/misc/Utils.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/misc/Utils.java index c6a8d82..bcd48c6 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/misc/Utils.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/misc/Utils.java @@ -62,8 +62,7 @@ public class Utils { private static void containerAnimation(Inventory inventory, LocationInfo location, boolean open) { if (location != null && Utils.isLocationChunkLoaded(location.getLocation())) { Block block = location.getLocation().getBlock(); - if (block.getState() instanceof Container) { - Container chest = (Container) block.getState(); + if (block.getState() instanceof Container chest) { if (open) { location.setTileEntityOpener(ApiSpecific.getChestOpener().updateState(inventory, chest, location.getTileEntityOpener())); } else { diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/runnables/ChestLinkVerifier.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/runnables/ChestLinkVerifier.java index 7efad3b..40d4921 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/runnables/ChestLinkVerifier.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/runnables/ChestLinkVerifier.java @@ -35,8 +35,7 @@ public class ChestLinkVerifier extends BukkitRunnable { public void run() { Chest chest = (Chest) block.getState(); - if (chest.getInventory().getHolder() instanceof DoubleChest) { - DoubleChest doubleChest = (DoubleChest) chest.getInventory().getHolder(); + if (chest.getInventory().getHolder() instanceof DoubleChest doubleChest) { InventoryHolder right = doubleChest.getRightSide(); InventoryHolder left = doubleChest.getLeftSide(); if (isChestLinked(doubleChest) && left != null && right != null) { @@ -80,8 +79,7 @@ public class ChestLinkVerifier extends BukkitRunnable { } private void manualCheck(Chest chest) { - if (chest.getBlockData() instanceof Directional) { - Directional directional = (Directional) chest.getBlockData(); + if (chest.getBlockData() instanceof Directional directional) { BlockFace facing = directional.getFacing(); BlockFace[] perpendulcarFaces = getPerpendicularFaces(facing); if (perpendulcarFaces == null) return; @@ -100,14 +98,10 @@ public class ChestLinkVerifier extends BukkitRunnable { private static final BlockFace[] WE = new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH}; private BlockFace[] getPerpendicularFaces(BlockFace face) { - switch (face) { - case NORTH: - case SOUTH: - return NS; - case WEST: - case EAST: - return WE; - } - return null; + return switch (face) { + case NORTH, SOUTH -> NS; + case WEST, EAST -> WE; + default -> null; + }; } } diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/runnables/VirtualChestToHopper.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/runnables/VirtualChestToHopper.java index b35df65..d8e36e8 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/runnables/VirtualChestToHopper.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/runnables/VirtualChestToHopper.java @@ -38,8 +38,7 @@ public class VirtualChestToHopper extends BukkitRunnable { if (!PluginConfig.SHOULD_RUN_HOPPERS_UNLOADED_CHUNKS.get() && !Utils.isLocationChunkLoaded(location.getLocation())) continue; Location below = location.getLocation().clone().subtract(0, 1, 0); - if (below.getBlock().getState() instanceof Hopper) { - Hopper hopper = (Hopper) below.getBlock().getState(); + if (below.getBlock().getState() instanceof Hopper hopper) { if (below.getBlock().isBlockIndirectlyPowered() || below.getBlock().isBlockPowered()) { continue; } diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/serialize/Config.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/serialize/Config.java index e871dc7..11baed9 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/serialize/Config.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/serialize/Config.java @@ -119,9 +119,9 @@ public class Config { try { Path path = Paths.get(legacyFile.toURI()); - String content = new String(Files.readAllBytes(path), Charsets.UTF_8); + String content = Files.readString(path, Charsets.UTF_8); content = legacyContentConverter(content); - Files.write(getStorageFile().toPath(), content.getBytes(Charsets.UTF_8)); + Files.writeString(getStorageFile().toPath(), content, Charsets.UTF_8); legacyFile.createNewFile(); legacyFile.delete(); } catch (IOException e) { @@ -139,9 +139,9 @@ public class Config { private void configConverter() { try { Path path = Paths.get(getStorageFile().toURI()); - String content = new String(Files.readAllBytes(path), Charsets.UTF_8); + String content = Files.readString(path, Charsets.UTF_8); content = content.replaceAll("==: Recipe", "==: C++Recipe"); - Files.write(getStorageFile().toPath(), content.getBytes(Charsets.UTF_8)); + Files.writeString(getStorageFile().toPath(), content, Charsets.UTF_8); } catch (IOException e) { e.printStackTrace(); } diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/abstracts/AbstractStorage.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/abstracts/AbstractStorage.java index e9c9e21..60353ad 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/abstracts/AbstractStorage.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/abstracts/AbstractStorage.java @@ -287,8 +287,7 @@ public abstract class AbstractStorage implements ConfigurationSerializable { BlockFace face = getStorageType().getStorageFacing(block); if (face != null) { Block signBlock = block.getRelative(face); - if (signBlock.getState() instanceof Sign) { - Sign sign = (Sign) signBlock.getState(); + if (signBlock.getState() instanceof Sign sign) { sign.setLine(1, ChatColor.GREEN + ChatColor.stripColor("[" + newName + "]")); sign.update(); } @@ -407,8 +406,7 @@ public abstract class AbstractStorage implements ConfigurationSerializable { List locationInfos = locationInfoList.stream().filter(locationInfo -> locationInfo.isInWorld(player)).collect(Collectors.toList()); // Create a utility method for this locationInfos.forEach(locationInfo -> { if (Utils.isLocationInViewDistance(player, locationInfo.getSignLocation())) { - if (locationInfo.getSignLocation().getBlock().getState() instanceof Sign) { - Sign sign = (Sign) locationInfo.getSignLocation().getBlock().getState(); + if (locationInfo.getSignLocation().getBlock().getState() instanceof Sign sign) { player.sendBlockChange(locationInfo.getSignLocation(), sign.getBlockData()); player.sendSignChange(locationInfo.getSignLocation(), sign.getLines()); } diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/abstracts/StorageInfo.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/abstracts/StorageInfo.java index b934048..834c12e 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/abstracts/StorageInfo.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/abstracts/StorageInfo.java @@ -27,8 +27,7 @@ public class StorageInfo { this.player = Bukkit.getOfflinePlayer(playerUUID); this.storage = storageType.getStorage(playerUUID, group); if (storage == null) { - if (sign.getBlockData() instanceof Directional) { - Directional directional = (Directional) sign.getBlockData(); + if (sign.getBlockData() instanceof Directional directional) { BlockFace storageFace = directional.getFacing().getOppositeFace(); Block storageBlock = sign.getBlock().getRelative(storageFace); Player player = Bukkit.getPlayer(playerUUID); diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/chestlink/ChestLinkStorage.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/chestlink/ChestLinkStorage.java index 7480ded..af2cd36 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/chestlink/ChestLinkStorage.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/chestlink/ChestLinkStorage.java @@ -49,8 +49,7 @@ public class ChestLinkStorage extends AbstractStorage implements ConfigurationSe this.sortMethod = SortMethod.OFF; Block block = location.getBlock(); - if (block.getState() instanceof Container) { - Container container = (Container) block.getState(); + if (block.getState() instanceof Container container) { getInventory().setContents(container.getInventory().getContents()); container.getInventory().clear(); updateDisplayItem(); @@ -103,8 +102,7 @@ public class ChestLinkStorage extends AbstractStorage implements ConfigurationSe @Override public void onStorageAdded(Block block, Player player) { //Migrates that chest into InventoryStorage and if full drops it at the chest location. - if (block.getState() instanceof Container) { - Container chest = (Container) block.getState(); + if (block.getState() instanceof Container chest) { boolean hasOverflow = false; for (ItemStack chestItem : chest.getInventory().getContents()) { if (chestItem != null) { @@ -149,10 +147,9 @@ public class ChestLinkStorage extends AbstractStorage implements ConfigurationSe public ClickableItem getClickableItem(Player player) { return ClickableItem.from(getIventoryIcon(player), event -> { InventoryHolder inventoryHolder = getInventory().getHolder(); - if (inventoryHolder instanceof VirtualInventoryHolder) { - ((VirtualInventoryHolder) inventoryHolder).setPreviousInventory(() -> { - Bukkit.getScheduler().runTask(ChestsPlusPlus.PLUGIN, () -> ChestLinkMenu.getMenu(player).openLastPage(player)); - }); + if (inventoryHolder instanceof VirtualInventoryHolder virtualInventoryHolder) { + virtualInventoryHolder.setPreviousInventory(() -> + Bukkit.getScheduler().runTask(ChestsPlusPlus.PLUGIN, () -> ChestLinkMenu.getMenu(player).openLastPage(player))); } Utils.openChestInventory(player, getInventory()); }); diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/chestlink/ChestLinkStorageType.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/chestlink/ChestLinkStorageType.java index 215d075..a685ceb 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/chestlink/ChestLinkStorageType.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/chestlink/ChestLinkStorageType.java @@ -68,8 +68,7 @@ public class ChestLinkStorageType extends StorageType { } private void createStorageForBlock(Player player, OfflinePlayer owner, Block block, String identifier, boolean requireSign) { - if (block.getBlockData() instanceof Directional) { - Directional chest = (Directional) block.getBlockData(); + if (block.getBlockData() instanceof Directional chest) { BlockFace facing = chest.getFacing(); Block toReplace = block.getRelative(facing); placeSign(block, toReplace, facing, player, owner, identifier, Values.ChestLinkTag, requireSign); @@ -98,8 +97,7 @@ public class ChestLinkStorageType extends StorageType { @Override public BlockFace getStorageFacing(Block block) { - if (block.getBlockData() instanceof Directional) { - Directional chest = (Directional) block.getBlockData(); + if (block.getBlockData() instanceof Directional chest) { return chest.getFacing(); } return null; diff --git a/ChestsPlusPlus_Main/src/main/resources/lang/en_GB.properties b/ChestsPlusPlus_Main/src/main/resources/lang/en_GB.properties index 9006b7f..1d4939f 100644 --- a/ChestsPlusPlus_Main/src/main/resources/lang/en_GB.properties +++ b/ChestsPlusPlus_Main/src/main/resources/lang/en_GB.properties @@ -1,9 +1,10 @@ -# Chests++ Language File (Version 2.5-Beta) +# Chests++ Language File (Version 2.5-Release) # NOTE: This file gets replaced when the plugin launches! If you want to make modifications create a copy first! # To create a new language file simply create a copy of this file and rename it to your desired choice for example 'en_US.properties' # It should be located in the 'lang' folder # Then in config.yml 'language-file: default' would be renamed to 'language-file: en_US' # To help contribute to the plugin and provide new language files you can create a pull-request at https://github.com/JamesPeters98/ChestsPlusPlus or join our Discord https://discord.gg/YRs3mP5 +# ADDED_MEMBER = Successfully added {player_name} to {storage_type} group {storage_identifier} ADDED_MEMBER_TO_ALL = Successfully added {player_name} to all {storage_type} groups ALREADY_EXISTS_ANVIL = Already exists\! diff --git a/POEditorImport/pom.xml b/POEditorImport/pom.xml index 97ba039..5b418b7 100644 --- a/POEditorImport/pom.xml +++ b/POEditorImport/pom.xml @@ -24,12 +24,12 @@ com.squareup.okhttp3 okhttp - 4.9.0 + 4.9.3 com.google.code.gson gson - 2.8.0 + 2.8.9 compile