diff --git a/pom.xml b/pom.xml index f77cac7..d6c7820 100644 --- a/pom.xml +++ b/pom.xml @@ -31,13 +31,9 @@ - codemc-snapshots - https://repo.codemc.org/repository/maven-snapshots + codemc + https://repo.codemc.org/repository/bentoboxworld/ - - codemc-releases - https://repo.codemc.org/repository/maven-releases - @@ -46,8 +42,8 @@ 17 2.0.2 - 1.20-R0.1-SNAPSHOT - 2.0.0-SNAPSHOT + 1.21.3-R0.1-SNAPSHOT + 2.7.1-SNAPSHOT 1.4.0 2.5.0 1.4.0-SNAPSHOT @@ -56,7 +52,7 @@ ${build.version}-SNAPSHOT - 2.2.0 + 2.3.0 -LOCAL BentoBoxWorld_Biomes @@ -135,7 +131,7 @@ codemc-repo - https://repo.codemc.org/repository/maven-public/ + https://repo.codemc.org/repository/bentoboxworld/ vault-repo diff --git a/src/main/java/world/bentobox/biomes/managers/BiomesImportManager.java b/src/main/java/world/bentobox/biomes/managers/BiomesImportManager.java index 3e6ddea..75bab94 100644 --- a/src/main/java/world/bentobox/biomes/managers/BiomesImportManager.java +++ b/src/main/java/world/bentobox/biomes/managers/BiomesImportManager.java @@ -12,6 +12,7 @@ import com.google.gson.GsonBuilder; import com.google.gson.annotations.Expose; import org.bukkit.Material; +import org.bukkit.Registry; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.configuration.ConfigurationSection; @@ -232,9 +233,12 @@ private int importBiomes(@NotNull ConfigurationSection reader, GameModeAddon gam biomesObject.setUniqueId(Utils.sanitizeInput(prefix + biomeId.toLowerCase())); // Read biome or replace it with VOID - biomesObject.setBiome( - Enums.getIfPresent(Biome.class, details.getString("biome", "").toUpperCase()). - or(Biome.THE_VOID)); + Biome b = Registry.BIOME.match(details.getString("biome", "")); + if (b != null) { + biomesObject.setBiome(b); + } else { + biomesObject.setBiome(Biome.THE_VOID); + } // Read environment or replace with Normal biomesObject.setEnvironment( Enums.getIfPresent(World.Environment.class, details.getString("environment", "").toUpperCase()). diff --git a/src/main/java/world/bentobox/biomes/tasks/BiomeUpdateTask.java b/src/main/java/world/bentobox/biomes/tasks/BiomeUpdateTask.java index f75e406..9b647ab 100644 --- a/src/main/java/world/bentobox/biomes/tasks/BiomeUpdateTask.java +++ b/src/main/java/world/bentobox/biomes/tasks/BiomeUpdateTask.java @@ -18,7 +18,6 @@ import org.bukkit.util.BlockVector; import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.paperlib.PaperLib; import world.bentobox.bentobox.util.Util; import world.bentobox.biomes.BiomesAddon; import world.bentobox.biomes.database.objects.BiomesObject; @@ -88,7 +87,7 @@ public void processBiomeChange(UpdateQueue updateQueue) // Scan the next chunk this.scanNextChunk().thenAccept(result -> { - if (!PaperLib.isPaper() && !Bukkit.isPrimaryThread()) + if (!Util.isPaper() && !Bukkit.isPrimaryThread()) { this.addon.logError("scanChunk not on Primary Thread!"); } @@ -179,7 +178,7 @@ private CompletableFuture scanChunk(ChunkData chunkData, Chunk chunk) return completed; } - if (PaperLib.isPaper()) + if (Util.isPaper()) { Bukkit.getScheduler().runTaskAsynchronously(this.addon.getPlugin(), () -> this.runBiomeChange(chunkData, chunk, completed)); diff --git a/src/main/java/world/bentobox/biomes/utils/Utils.java b/src/main/java/world/bentobox/biomes/utils/Utils.java index f267914..f76975c 100644 --- a/src/main/java/world/bentobox/biomes/utils/Utils.java +++ b/src/main/java/world/bentobox/biomes/utils/Utils.java @@ -65,7 +65,7 @@ public static List groupEqualItems(List requiredItems, Set // Merge items which meta can be ignored or is similar to item in required list. if (required.isSimilar(item) || - ignoreMetaData.contains(item.getType()) && item.getType().equals(required.getType())) + ignoreMetaData.contains(item.getType()) && item.getType().equals(required.getType())) { required.setAmount(required.getAmount() + item.getAmount()); isUnique = false; @@ -94,8 +94,7 @@ public static List groupEqualItems(List requiredItems, Set * @return {@code true} if item is in his inventory, otherwise {@code false} */ public static boolean hasRequiredItem(@Nullable User user, - ItemStack requiredItem, - Set ignoreMetaData) + ItemStack requiredItem, Set ignoreMetaData) { if (user == null) { @@ -114,18 +113,14 @@ else if (user.getPlayer().getGameMode() == GameMode.CREATIVE) if (!ignoreMetaData.isEmpty() && ignoreMetaData.contains(requiredItem.getType())) { numInInventory = Arrays.stream(user.getInventory().getContents()). - filter(Objects::nonNull). - filter(i -> i.getType().equals(requiredItem.getType())). - mapToInt(ItemStack::getAmount). - sum(); + filter(Objects::nonNull).filter(i -> i.getType().equals(requiredItem.getType())) + .mapToInt(ItemStack::getAmount).sum(); } else { numInInventory = Arrays.stream(user.getInventory().getContents()). - filter(Objects::nonNull). - filter(i -> i.isSimilar(requiredItem)). - mapToInt(ItemStack::getAmount). - sum(); + filter(Objects::nonNull).filter(i -> i.isSimilar(requiredItem)).mapToInt(ItemStack::getAmount) + .sum(); } return numInInventory >= requiredItem.getAmount(); @@ -154,9 +149,8 @@ public static String getPermissionValue(User user, String permissionPrefix, Stri String permPrefix = permissionPrefix + "."; List permissions = user.getEffectivePermissions().stream(). - map(PermissionAttachmentInfo::getPermission). - filter(permission -> permission.startsWith(permPrefix)). - collect(Collectors.toList()); + map(PermissionAttachmentInfo::getPermission).filter(permission -> permission.startsWith(permPrefix)) + .collect(Collectors.toList()); for (String permission : permissions) { @@ -206,8 +200,7 @@ public static String getPermissionString(World world, String permissionTemplate) public static boolean matchAllPermissions(User user, Collection permissions) { return permissions.isEmpty() || - user.isOp() || - permissions.stream().allMatch(user::hasPermission); + user.isOp() || permissions.stream().allMatch(user::hasPermission); } @@ -222,15 +215,13 @@ public static boolean matchAllPermissions(User user, Collection permissi * otherwise. */ public static boolean hasUserUpdateModePermission(User user, - String permissionPrefix, - Settings.UpdateMode updateMode, - String biomeId) + String permissionPrefix, Settings.UpdateMode updateMode, String biomeId) { String updateModePermission = - permissionPrefix + "biomes.set." + updateMode.name().toLowerCase(); + permissionPrefix + "biomes.set." + updateMode.name().toLowerCase(); return user.hasPermission(updateModePermission + ".*") || - user.hasPermission(updateModePermission + "." + biomeId.toLowerCase()); + user.hasPermission(updateModePermission + "." + biomeId.toLowerCase()); } @@ -244,9 +235,7 @@ public static boolean hasUserUpdateModePermission(User user, public static String sanitizeInput(String input) { return ChatColor.stripColor( - Util.translateColorCodes(input.toLowerCase(Locale.ENGLISH). - replace(" ", "_"). - replace("-", "_"))); + Util.translateColorCodes(input.toLowerCase(Locale.ENGLISH).replace(" ", "_").replace("-", "_"))); } @@ -260,8 +249,7 @@ public static String sanitizeInput(String input) public static String getGameMode(World world) { return BentoBox.getInstance().getIWM().getAddon(world). - map(gameModeAddon -> gameModeAddon.getDescription().getName()). - orElse("").toLowerCase(); + map(gameModeAddon -> gameModeAddon.getDescription().getName()).orElse("").toLowerCase(); } @@ -364,16 +352,8 @@ public static Map getBiomeNameMap() */ public static boolean isSnowyBiome(Biome biome) { - return switch (biome) - { - //case SNOWY_SLOPES: - case SNOWY_PLAINS, - SNOWY_TAIGA, - ICE_SPIKES, - FROZEN_RIVER, - SNOWY_BEACH -> true; - default -> false; - }; + return (biome == Biome.SNOWY_PLAINS || biome == Biome.SNOWY_TAIGA || biome == Biome.ICE_SPIKES + || biome == Biome.FROZEN_RIVER || biome == Biome.SNOWY_BEACH); } @@ -385,17 +365,9 @@ public static boolean isSnowyBiome(Biome biome) */ public static boolean isColdBiome(Biome biome) { - return switch (biome) - { - case WINDSWEPT_HILLS, - WINDSWEPT_GRAVELLY_HILLS, - WINDSWEPT_FOREST, - TAIGA, - OLD_GROWTH_PINE_TAIGA, - OLD_GROWTH_SPRUCE_TAIGA, - STONY_SHORE -> true; - default -> false; - }; + return (biome == Biome.WINDSWEPT_HILLS || biome == Biome.WINDSWEPT_GRAVELLY_HILLS + || biome == Biome.WINDSWEPT_FOREST || biome == Biome.TAIGA || biome == Biome.OLD_GROWTH_PINE_TAIGA + || biome == Biome.OLD_GROWTH_SPRUCE_TAIGA || biome == Biome.STONY_SHORE); } @@ -407,25 +379,12 @@ public static boolean isColdBiome(Biome biome) */ public static boolean isTemperateBiome(Biome biome) { - return switch (biome) - { - case PLAINS, - SUNFLOWER_PLAINS, - FOREST, - FLOWER_FOREST, - BIRCH_FOREST, - OLD_GROWTH_BIRCH_FOREST, - DARK_FOREST, - SWAMP, - MANGROVE_SWAMP, - JUNGLE, - SPARSE_JUNGLE, - BAMBOO_JUNGLE, - RIVER, - BEACH, - MUSHROOM_FIELDS -> true; - default -> false; - }; + return (biome == Biome.PLAINS || biome == Biome.SUNFLOWER_PLAINS || biome == Biome.FOREST + || biome == Biome.FLOWER_FOREST || biome == Biome.BIRCH_FOREST || biome == Biome.OLD_GROWTH_BIRCH_FOREST + || biome == Biome.DARK_FOREST || biome == Biome.SWAMP || biome == Biome.MANGROVE_SWAMP + || biome == Biome.JUNGLE || biome == Biome.SPARSE_JUNGLE || biome == Biome.BAMBOO_JUNGLE + || biome == Biome.RIVER || biome == Biome.BEACH || biome == Biome.MUSHROOM_FIELDS); + } @@ -437,19 +396,11 @@ public static boolean isTemperateBiome(Biome biome) */ public static boolean isWarmBiome(Biome biome) { - return switch (biome) - { - // case BADLANDS_PLATEAU: - case DESERT, - SAVANNA, - WINDSWEPT_SAVANNA, - BADLANDS, - ERODED_BADLANDS, - WOODED_BADLANDS, - CHERRY_GROVE, - SAVANNA_PLATEAU -> true; - default -> false; - }; + return (biome==Biome.DESERT + || biome == Biome.SAVANNA + || biome == Biome.WINDSWEPT_SAVANNA || biome == Biome.BADLANDS || biome == Biome.ERODED_BADLANDS + || biome == Biome.WOODED_BADLANDS || biome == Biome.CHERRY_GROVE || biome == Biome.SAVANNA_PLATEAU); + } @@ -461,19 +412,16 @@ public static boolean isWarmBiome(Biome biome) */ public static boolean isAquaticBiome(Biome biome) { - return switch (biome) - { - case WARM_OCEAN, - LUKEWARM_OCEAN, - DEEP_LUKEWARM_OCEAN, - OCEAN, - DEEP_OCEAN, - COLD_OCEAN, - DEEP_COLD_OCEAN, - FROZEN_OCEAN, - DEEP_FROZEN_OCEAN -> true; - default -> false; - }; + return (biome==Biome.WARM_OCEAN + || biome==Biome.LUKEWARM_OCEAN + || biome==Biome.DEEP_LUKEWARM_OCEAN + || biome==Biome.OCEAN + || biome==Biome.DEEP_OCEAN + || biome==Biome.COLD_OCEAN + || biome==Biome.DEEP_COLD_OCEAN + || biome == Biome.FROZEN_OCEAN + || biome==Biome.DEEP_FROZEN_OCEAN ); + } @@ -483,8 +431,7 @@ public static boolean isAquaticBiome(Biome biome) * @param biome Biome that must be checked. * @return {@code true} if I think it is neutral biome, {@code false} otherwise. */ - public static boolean isNeutralBiome(Biome biome) - { + public static boolean isNeutralBiome(Biome biome) { return biome == Biome.THE_VOID; } @@ -495,15 +442,8 @@ public static boolean isNeutralBiome(Biome biome) * @param biome Biome that must be checked. * @return {@code true} if I think it is cave biome, {@code false} otherwise. */ - public static boolean isCaveBiome(Biome biome) - { - return switch (biome) - { - case LUSH_CAVES, - DRIPSTONE_CAVES, - DEEP_DARK -> true; - default -> false; - }; + public static boolean isCaveBiome(Biome biome) { + return (biome == Biome.LUSH_CAVES || biome == Biome.DRIPSTONE_CAVES || biome == Biome.DEEP_DARK); } @@ -513,17 +453,9 @@ public static boolean isCaveBiome(Biome biome) * @param biome Biome that must be checked. * @return {@code true} if I think it is nether biome, {@code false} otherwise. */ - public static boolean isNetherBiome(Biome biome) - { - return switch (biome) - { - case NETHER_WASTES, - SOUL_SAND_VALLEY, - CRIMSON_FOREST, - WARPED_FOREST, - BASALT_DELTAS -> true; - default -> false; - }; + public static boolean isNetherBiome(Biome biome) { + return biome == Biome.NETHER_WASTES || biome == Biome.SOUL_SAND_VALLEY || biome == Biome.CRIMSON_FOREST + || biome == Biome.WARPED_FOREST || biome == Biome.BASALT_DELTAS; } @@ -533,28 +465,18 @@ public static boolean isNetherBiome(Biome biome) * @param biome Biome that must be checked. * @return {@code true} if I think it is the end biome, {@code false} otherwise. */ - public static boolean isTheEndBiome(Biome biome) - { - return switch (biome) - { - case THE_END, - SMALL_END_ISLANDS, - END_MIDLANDS, - END_HIGHLANDS, - END_BARRENS -> true; - default -> false; - }; + public static boolean isTheEndBiome(Biome biome) { + return biome == Biome.THE_END || biome == Biome.SMALL_END_ISLANDS || biome == Biome.END_MIDLANDS + || biome == Biome.END_HIGHLANDS || biome == Biome.END_BARRENS; } - /** * Send given message to user and add prefix to the start of the message. * * @param user User who need to receive message. * @param message String of message that must be send. */ - public static void sendMessage(User user, String message) - { + public static void sendMessage(User user, String message) { user.sendMessage(user.getTranslation(Constants.CONVERSATIONS + "prefix") + message); } @@ -568,12 +490,8 @@ public static void sendMessage(User user, String message) * @param addon instance of biome addon. * @param available the available */ - public static void sendUnlockMessage(UUID uuid, - Island island, - BiomesObject biome, - BiomesAddon addon, - boolean available) - { + public static void sendUnlockMessage(UUID uuid, Island island, BiomesObject biome, BiomesAddon addon, + boolean available) { User user = User.getInstance(uuid); WorldSettings settings = addon.getPlugin().getIWM().getWorldSettings(island.getWorld()); @@ -588,15 +506,13 @@ public static void sendUnlockMessage(UUID uuid, commandBuilder.append(" "); commandBuilder.append(addon.getSettings().getPlayerCommand().split(" ")[0]); - if (!available) - { + if (!available) { component = new TextComponent(user.getTranslation(Constants.CONVERSATIONS + "click-text-to-purchase", - Constants.PARAMETER_BIOME, biome.getFriendlyName())); - } - else + Constants.PARAMETER_BIOME, biome.getFriendlyName())); + } else { component = new TextComponent(user.getTranslation(Constants.CONVERSATIONS + "click-text-to-set", - Constants.PARAMETER_BIOME, biome.getFriendlyName())); + Constants.PARAMETER_BIOME, biome.getFriendlyName())); } component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, commandBuilder.toString())); @@ -613,18 +529,16 @@ public static void sendUnlockMessage(UUID uuid, * @param user User who will see the object. * @return Prettified string for World.Environment. */ - public static String prettifyObject(World.Environment object, User user) - { + public static String prettifyObject(World.Environment object, User user) { // Find addon structure with: // [addon]: // environments: // [environment]: // name: [name] - String translation = - user.getTranslationOrNothing(Constants.ENVIRONMENTS + object.name().toLowerCase() + ".name"); + String translation = user + .getTranslationOrNothing(Constants.ENVIRONMENTS + object.name().toLowerCase() + ".name"); - if (!translation.isEmpty()) - { + if (!translation.isEmpty()) { // We found our translation. return translation; } @@ -648,8 +562,7 @@ public static String prettifyObject(World.Environment object, User user) translation = user.getTranslationOrNothing("environments." + object.name().toLowerCase()); - if (!translation.isEmpty()) - { + if (!translation.isEmpty()) { // We found our translation. return translation; } @@ -669,18 +582,16 @@ public static String prettifyObject(World.Environment object, User user) * @param user User who will see the object. * @return Prettified description string for World.Environment. */ - public static String prettifyDescription(World.Environment object, User user) - { + public static String prettifyDescription(World.Environment object, User user) { // Find addon structure with: // [addon]: // environments: // [environment]: // description: [text] - String translation = - user.getTranslationOrNothing(Constants.ENVIRONMENTS + object.name().toLowerCase() + ".description"); + String translation = user + .getTranslationOrNothing(Constants.ENVIRONMENTS + object.name().toLowerCase() + ".description"); - if (!translation.isEmpty()) - { + if (!translation.isEmpty()) { // We found our translation. return translation; } @@ -697,8 +608,7 @@ public static String prettifyDescription(World.Environment object, User user) * @param user User who will see the object. * @return Prettified string for Material. */ - public static String prettifyObject(@Nullable Material object, User user) - { + public static String prettifyObject(@Nullable Material object, User user) { // Nothing to translate if (object == null) { @@ -712,8 +622,7 @@ public static String prettifyObject(@Nullable Material object, User user) // name: [name] String translation = user.getTranslationOrNothing(Constants.MATERIALS + object.name().toLowerCase() + ".name"); - if (!translation.isEmpty()) - { + if (!translation.isEmpty()) { // We found our translation. return translation; } @@ -725,8 +634,7 @@ public static String prettifyObject(@Nullable Material object, User user) translation = user.getTranslationOrNothing(Constants.MATERIALS + object.name().toLowerCase()); - if (!translation.isEmpty()) - { + if (!translation.isEmpty()) { // We found our translation. return translation; } @@ -737,8 +645,7 @@ public static String prettifyObject(@Nullable Material object, User user) translation = user.getTranslationOrNothing("materials." + object.name().toLowerCase()); - if (!translation.isEmpty()) - { + if (!translation.isEmpty()) { // We found our translation. return translation; } @@ -755,11 +662,9 @@ public static String prettifyObject(@Nullable Material object, User user) * @param user User who will see the object. * @return Prettified description string for Material. */ - public static String prettifyDescription(@Nullable Material object, User user) - { + public static String prettifyDescription(@Nullable Material object, User user) { // Nothing to translate - if (object == null) - { + if (object == null) { return ""; } @@ -768,11 +673,10 @@ public static String prettifyDescription(@Nullable Material object, User user) // materials: // [material]: // description: [text] - String translation = - user.getTranslationOrNothing(Constants.MATERIALS + object.name().toLowerCase() + ".description"); + String translation = user + .getTranslationOrNothing(Constants.MATERIALS + object.name().toLowerCase() + ".description"); - if (!translation.isEmpty()) - { + if (!translation.isEmpty()) { // We found our translation. return translation; } @@ -789,11 +693,9 @@ public static String prettifyDescription(@Nullable Material object, User user) * @param user User who will see the object. * @return Prettified string for Biome. */ - public static String prettifyObject(@Nullable Biome object, User user) - { + public static String prettifyObject(@Nullable Biome object, User user) { // Nothing to translate - if (object == null) - { + if (object == null) { return ""; } @@ -804,8 +706,7 @@ public static String prettifyObject(@Nullable Biome object, User user) // name: [name] String translation = user.getTranslationOrNothing(Constants.BIOMES + object.name().toLowerCase() + ".name"); - if (!translation.isEmpty()) - { + if (!translation.isEmpty()) { // We found our translation. return translation; } @@ -817,8 +718,7 @@ public static String prettifyObject(@Nullable Biome object, User user) translation = user.getTranslationOrNothing(Constants.BIOMES + object.name().toLowerCase()); - if (!translation.isEmpty()) - { + if (!translation.isEmpty()) { // We found our translation. return translation; } @@ -829,8 +729,7 @@ public static String prettifyObject(@Nullable Biome object, User user) translation = user.getTranslationOrNothing("biomes." + object.name().toLowerCase()); - if (!translation.isEmpty()) - { + if (!translation.isEmpty()) { // We found our translation. return translation; } @@ -847,11 +746,9 @@ public static String prettifyObject(@Nullable Biome object, User user) * @param user User who will see the object. * @return Prettified description string for Biome. */ - public static String prettifyDescription(@Nullable Biome object, User user) - { + public static String prettifyDescription(@Nullable Biome object, User user) { // Nothing to translate - if (object == null) - { + if (object == null) { return ""; } @@ -860,11 +757,10 @@ public static String prettifyDescription(@Nullable Biome object, User user) // biomes: // [biome]: // description: [text] - String translation = - user.getTranslationOrNothing(Constants.BIOMES + object.name().toLowerCase() + ".description"); + String translation = user + .getTranslationOrNothing(Constants.BIOMES + object.name().toLowerCase() + ".description"); - if (!translation.isEmpty()) - { + if (!translation.isEmpty()) { // We found our translation. return translation; } @@ -873,7 +769,6 @@ public static String prettifyDescription(@Nullable Biome object, User user) return ""; } - /** * Prettify ItemStack object for user. * @@ -881,11 +776,9 @@ public static String prettifyDescription(@Nullable Biome object, User user) * @param user User who will see the object. * @return Prettified string for ItemStack. */ - public static String prettifyObject(@Nullable ItemStack object, User user) - { + public static String prettifyObject(@Nullable ItemStack object, User user) { // Nothing to translate - if (object == null) - { + if (object == null) { return ""; } @@ -898,32 +791,30 @@ public static String prettifyObject(@Nullable ItemStack object, User user) // ... // generic: [amount] [name] [meta] String translation; - switch (object.getType()) - { - case POTION, SPLASH_POTION, LINGERING_POTION, TIPPED_ARROW -> - // Get Potion Meta - translation = prettifyObject(object, (PotionMeta) object.getItemMeta(), user); - case PLAYER_HEAD, PLAYER_WALL_HEAD -> translation = - prettifyObject(object, (SkullMeta) object.getItemMeta(), user); - case ENCHANTED_BOOK -> translation = - prettifyObject(object, (EnchantmentStorageMeta) object.getItemMeta(), user); - case WRITTEN_BOOK, WRITABLE_BOOK -> translation = - prettifyObject(object, (BookMeta) object.getItemMeta(), user); - case LEATHER_BOOTS, LEATHER_CHESTPLATE, LEATHER_HELMET, LEATHER_LEGGINGS, LEATHER_HORSE_ARMOR, - TRIDENT, CROSSBOW, CHAINMAIL_HELMET, CHAINMAIL_CHESTPLATE, CHAINMAIL_LEGGINGS, CHAINMAIL_BOOTS, IRON_HELMET, - IRON_CHESTPLATE, IRON_LEGGINGS, IRON_BOOTS, DIAMOND_HELMET, DIAMOND_CHESTPLATE, DIAMOND_LEGGINGS, DIAMOND_BOOTS, - GOLDEN_HELMET, GOLDEN_CHESTPLATE, GOLDEN_LEGGINGS, GOLDEN_BOOTS, NETHERITE_HELMET, NETHERITE_CHESTPLATE, - NETHERITE_LEGGINGS, NETHERITE_BOOTS, WOODEN_SWORD, WOODEN_SHOVEL, WOODEN_PICKAXE, WOODEN_AXE, WOODEN_HOE, - STONE_SWORD, STONE_SHOVEL, STONE_PICKAXE, STONE_AXE, STONE_HOE, GOLDEN_SWORD, GOLDEN_SHOVEL, GOLDEN_PICKAXE, - GOLDEN_AXE, GOLDEN_HOE, IRON_SWORD, IRON_SHOVEL, IRON_PICKAXE, IRON_AXE, IRON_HOE, DIAMOND_SWORD, DIAMOND_SHOVEL, - DIAMOND_PICKAXE, DIAMOND_AXE, DIAMOND_HOE, NETHERITE_SWORD, NETHERITE_SHOVEL, NETHERITE_PICKAXE, NETHERITE_AXE, - NETHERITE_HOE, TURTLE_HELMET, SHEARS, SHIELD, FLINT_AND_STEEL, BOW -> translation = - prettifyObject(object, object.getItemMeta(), user); - default -> translation = ""; + switch (object.getType()) { + case POTION, SPLASH_POTION, LINGERING_POTION, TIPPED_ARROW -> + // Get Potion Meta + translation = prettifyObject(object, (PotionMeta) object.getItemMeta(), user); + case PLAYER_HEAD, PLAYER_WALL_HEAD -> + translation = prettifyObject(object, (SkullMeta) object.getItemMeta(), user); + case ENCHANTED_BOOK -> + translation = prettifyObject(object, (EnchantmentStorageMeta) object.getItemMeta(), user); + case WRITTEN_BOOK, WRITABLE_BOOK -> translation = prettifyObject(object, (BookMeta) object.getItemMeta(), user); + case LEATHER_BOOTS, LEATHER_CHESTPLATE, LEATHER_HELMET, LEATHER_LEGGINGS, LEATHER_HORSE_ARMOR, TRIDENT, + CROSSBOW, CHAINMAIL_HELMET, CHAINMAIL_CHESTPLATE, CHAINMAIL_LEGGINGS, CHAINMAIL_BOOTS, IRON_HELMET, + IRON_CHESTPLATE, IRON_LEGGINGS, IRON_BOOTS, DIAMOND_HELMET, DIAMOND_CHESTPLATE, DIAMOND_LEGGINGS, + DIAMOND_BOOTS, GOLDEN_HELMET, GOLDEN_CHESTPLATE, GOLDEN_LEGGINGS, GOLDEN_BOOTS, NETHERITE_HELMET, + NETHERITE_CHESTPLATE, NETHERITE_LEGGINGS, NETHERITE_BOOTS, WOODEN_SWORD, WOODEN_SHOVEL, WOODEN_PICKAXE, + WOODEN_AXE, WOODEN_HOE, STONE_SWORD, STONE_SHOVEL, STONE_PICKAXE, STONE_AXE, STONE_HOE, GOLDEN_SWORD, + GOLDEN_SHOVEL, GOLDEN_PICKAXE, GOLDEN_AXE, GOLDEN_HOE, IRON_SWORD, IRON_SHOVEL, IRON_PICKAXE, IRON_AXE, + IRON_HOE, DIAMOND_SWORD, DIAMOND_SHOVEL, DIAMOND_PICKAXE, DIAMOND_AXE, DIAMOND_HOE, NETHERITE_SWORD, + NETHERITE_SHOVEL, NETHERITE_PICKAXE, NETHERITE_AXE, NETHERITE_HOE, TURTLE_HELMET, SHEARS, SHIELD, + FLINT_AND_STEEL, BOW -> + translation = prettifyObject(object, object.getItemMeta(), user); + default -> translation = ""; } - if (!translation.isEmpty()) - { + if (!translation.isEmpty()) { // We found our translation. return translation; } @@ -935,8 +826,7 @@ public static String prettifyObject(@Nullable ItemStack object, User user) translation = user.getTranslationOrNothing(Constants.MATERIALS + object.getType().name().toLowerCase()); - if (!translation.isEmpty()) - { + if (!translation.isEmpty()) { // We found our translation. return translation; } @@ -947,8 +837,7 @@ public static String prettifyObject(@Nullable ItemStack object, User user) translation = user.getTranslationOrNothing("materials." + object.getType().name().toLowerCase()); - if (!translation.isEmpty()) - { + if (!translation.isEmpty()) { // We found our translation. return translation; } @@ -965,17 +854,14 @@ public static String prettifyObject(@Nullable ItemStack object, User user) * @param user the user * @return the string */ - public static String prettifyObject(Enchantment enchantment, User user) - { - if (enchantment == null) - { + public static String prettifyObject(Enchantment enchantment, User user) { + if (enchantment == null) { return ""; } String type = user.getTranslationOrNothing(Constants.ITEM_STACKS + "enchant." + enchantment.getKey().getKey()); - if (type.isEmpty()) - { + if (type.isEmpty()) { type = LangUtilsHook.getEnchantName(enchantment, user); } @@ -990,17 +876,14 @@ public static String prettifyObject(Enchantment enchantment, User user) * @param user the user * @return the string */ - public static String prettifyObject(PotionType type, User user) - { - if (type == null) - { + public static String prettifyObject(PotionType type, User user) { + if (type == null) { return ""; } String text = user.getTranslationOrNothing(Constants.ITEM_STACKS + "potion-type." + type.name().toLowerCase()); - if (text.isEmpty()) - { + if (text.isEmpty()) { text = LangUtilsHook.getPotionBaseEffectName(type, user); } @@ -1016,10 +899,8 @@ public static String prettifyObject(PotionType type, User user) * @param user the user * @return the string */ - public static String prettifyObject(ItemStack item, @Nullable PotionMeta potionMeta, User user) - { - if (potionMeta == null) - { + public static String prettifyObject(ItemStack item, @Nullable PotionMeta potionMeta, User user) { + if (potionMeta == null) { return ""; } @@ -1033,8 +914,7 @@ public static String prettifyObject(ItemStack item, @Nullable PotionMeta potionM // Check custom translation for potions. String type = user.getTranslationOrNothing(itemReference + potionData.getType().name().toLowerCase()); - if (type.isEmpty()) - { + if (type.isEmpty()) { // Check potion types translation. type = prettifyObject(potionData.getType(), user); } @@ -1043,22 +923,16 @@ public static String prettifyObject(ItemStack item, @Nullable PotionMeta potionM String extended = user.getTranslationOrNothing(metaReference + "extended"); // Get item specific translation. - String specific = user.getTranslationOrNothing(itemReference + "name", - "[type]", type, - "[upgraded]", (potionData.isUpgraded() ? upgraded : ""), - "[extended]", (potionData.isExtended() ? extended : "")); + String specific = user.getTranslationOrNothing(itemReference + "name", "[type]", type, "[upgraded]", + (potionData.isUpgraded() ? upgraded : ""), "[extended]", (potionData.isExtended() ? extended : "")); - if (specific.isEmpty()) - { + if (specific.isEmpty()) { // Use generic translation. - String meta = user.getTranslationOrNothing(metaReference + "potion-meta", - "[type]", type, - "[upgraded]", (potionData.isUpgraded() ? upgraded : ""), - "[extended]", (potionData.isExtended() ? extended : "")); + String meta = user.getTranslationOrNothing(metaReference + "potion-meta", "[type]", type, "[upgraded]", + (potionData.isUpgraded() ? upgraded : ""), "[extended]", (potionData.isExtended() ? extended : "")); - specific = user.getTranslationOrNothing(Constants.ITEM_STACKS + "generic", - "[type]", prettifyObject(itemType, user), - "[meta]", meta); + specific = user.getTranslationOrNothing(Constants.ITEM_STACKS + "generic", "[type]", + prettifyObject(itemType, user), "[meta]", meta); } return specific; @@ -1073,22 +947,19 @@ public static String prettifyObject(ItemStack item, @Nullable PotionMeta potionM * @param user the user * @return the string */ - public static String prettifyObject(ItemStack item, @Nullable SkullMeta skullMeta, User user) - { - if (skullMeta == null) - { + public static String prettifyObject(ItemStack item, @Nullable SkullMeta skullMeta, User user) { + if (skullMeta == null) { return ""; } Material itemType = item.getType(); final String metaReference = Constants.ITEM_STACKS + "meta."; - String meta = user.getTranslationOrNothing(metaReference + "skull-meta", - "[player-name]", skullMeta.getDisplayName()); + String meta = user.getTranslationOrNothing(metaReference + "skull-meta", "[player-name]", + skullMeta.getDisplayName()); - return user.getTranslationOrNothing(Constants.ITEM_STACKS + "generic", - "[type]", prettifyObject(itemType, user), - "[meta]", meta); + return user.getTranslationOrNothing(Constants.ITEM_STACKS + "generic", "[type]", prettifyObject(itemType, user), + "[meta]", meta); } @@ -1100,36 +971,29 @@ public static String prettifyObject(ItemStack item, @Nullable SkullMeta skullMet * @param user the user * @return the string */ - public static String prettifyObject(ItemStack item, @Nullable ItemMeta itemMeta, User user) - { - if (itemMeta == null) - { + public static String prettifyObject(ItemStack item, @Nullable ItemMeta itemMeta, User user) { + if (itemMeta == null) { return ""; } StringBuilder builder = new StringBuilder(); - itemMeta.getEnchants().forEach((enchantment, level) -> - { + itemMeta.getEnchants().forEach((enchantment, level) -> { builder.append("\n"); - builder.append(user.getTranslationOrNothing(Constants.ITEM_STACKS + "meta.enchant-meta", - "[type]", prettifyObject(enchantment, user), - "[level]", String.valueOf(level))); + builder.append(user.getTranslationOrNothing(Constants.ITEM_STACKS + "meta.enchant-meta", "[type]", + prettifyObject(enchantment, user), "[level]", String.valueOf(level))); }); Material itemType = item.getType(); final String itemReference = Constants.ITEM_STACKS + itemType.name().toLowerCase() + "."; - String translation = user.getTranslationOrNothing(itemReference + "name", - "[type]", prettifyObject(itemType, user), - "[enchant]", builder.toString()); + String translation = user.getTranslationOrNothing(itemReference + "name", "[type]", + prettifyObject(itemType, user), "[enchant]", builder.toString()); - if (translation.isEmpty()) - { - translation = user.getTranslationOrNothing(Constants.ITEM_STACKS + "generic", - "[type]", prettifyObject(itemType, user), - "[meta]", builder.toString()); + if (translation.isEmpty()) { + translation = user.getTranslationOrNothing(Constants.ITEM_STACKS + "generic", "[type]", + prettifyObject(itemType, user), "[meta]", builder.toString()); } return translation; @@ -1144,36 +1008,29 @@ public static String prettifyObject(ItemStack item, @Nullable ItemMeta itemMeta, * @param user the user * @return the string */ - public static String prettifyObject(ItemStack item, @Nullable EnchantmentStorageMeta enchantmentMeta, User user) - { - if (enchantmentMeta == null) - { + public static String prettifyObject(ItemStack item, @Nullable EnchantmentStorageMeta enchantmentMeta, User user) { + if (enchantmentMeta == null) { return ""; } StringBuilder builder = new StringBuilder(); - enchantmentMeta.getEnchants().forEach((enchantment, level) -> - { + enchantmentMeta.getEnchants().forEach((enchantment, level) -> { builder.append("\n"); - builder.append(user.getTranslationOrNothing(Constants.ITEM_STACKS + "meta.enchant-meta", - "[type]", prettifyObject(enchantment, user), - "[level]", String.valueOf(level))); + builder.append(user.getTranslationOrNothing(Constants.ITEM_STACKS + "meta.enchant-meta", "[type]", + prettifyObject(enchantment, user), "[level]", String.valueOf(level))); }); Material itemType = item.getType(); final String itemReference = Constants.ITEM_STACKS + itemType.name().toLowerCase() + "."; - String translation = user.getTranslationOrNothing(itemReference + "name", - "[type]", prettifyObject(itemType, user), - "[enchant]", builder.toString()); + String translation = user.getTranslationOrNothing(itemReference + "name", "[type]", + prettifyObject(itemType, user), "[enchant]", builder.toString()); - if (translation.isEmpty()) - { - translation = user.getTranslationOrNothing(Constants.ITEM_STACKS + "generic", - "[type]", prettifyObject(itemType, user), - "[meta]", builder.toString()); + if (translation.isEmpty()) { + translation = user.getTranslationOrNothing(Constants.ITEM_STACKS + "generic", "[type]", + prettifyObject(itemType, user), "[meta]", builder.toString()); } return translation; @@ -1188,22 +1045,18 @@ public static String prettifyObject(ItemStack item, @Nullable EnchantmentStorage * @param user the user * @return the string */ - public static String prettifyObject(ItemStack item, @Nullable BookMeta bookMeta, User user) - { - if (bookMeta == null) - { + public static String prettifyObject(ItemStack item, @Nullable BookMeta bookMeta, User user) { + if (bookMeta == null) { return ""; } Material itemType = item.getType(); final String metaReference = Constants.ITEM_STACKS + "meta."; - String meta = user.getTranslationOrNothing(metaReference + "book-meta", - "[title]", bookMeta.getTitle(), - "[author]", bookMeta.getAuthor()); + String meta = user.getTranslationOrNothing(metaReference + "book-meta", "[title]", bookMeta.getTitle(), + "[author]", bookMeta.getAuthor()); - return user.getTranslationOrNothing(Constants.ITEM_STACKS + "generic", - "[type]", prettifyObject(itemType, user), - "[meta]", meta); + return user.getTranslationOrNothing(Constants.ITEM_STACKS + "generic", "[type]", prettifyObject(itemType, user), + "[meta]", meta); } }