diff --git a/build.gradle b/build.gradle index 1779c3611..49919bf0f 100644 --- a/build.gradle +++ b/build.gradle @@ -28,26 +28,34 @@ group = 'fr.openmc' repositories { mavenCentral() + // * PlaceholderAPI maven { url "https://repo.extendedclip.com/content/repositories/placeholderapi/" } + // * WorldGuard & WorldEdit maven { url "https://maven.enginehub.org/repo/" } + // * FancyNpc maven { url "https://repo.fancyinnovations.com/releases" } + // * PaperMC maven { url = "https://repo.papermc.io/repository/maven-public/" } + // * GeyserMC + maven { + url "https://repo.opencollab.dev/main/" + } + // * ItemsAdder maven { url "https://maven.devs.beer/" } + // * ProtocolLib maven { url "https://repo.dmulloy2.net/repository/public/" } - // * GeyserMC - //maven {url "https://repo.opencollab.dev/main/"} maven { url "https://jitpack.io" // Toujours à la fin } @@ -71,9 +79,9 @@ dependencies { compileOnly "net.dmulloy2:ProtocolLib:${protocolLibVersion}" // Bedrock Dependencies - //compileOnly files("libs/RiftEngine-${riftEngineVersion}.jar") - //compileOnly "org.geysermc.geyser:api:${geyserApiVersion}" - //compileOnly "org.geysermc.floodgate:api:${floodgateApiVersion}" + compileOnly files("libs/RiftEngine-${riftEngineVersion}.jar") + compileOnly "org.geysermc.geyser:api:${geyserApiVersion}" + compileOnly "org.geysermc.floodgate:api:${floodgateApiVersion}" implementation "org.jetbrains:annotations:${jetbrainsAnnotationsVersion}" implementation "io.github.revxrsal:lamp.common:${revxrsalLampVersion}" diff --git a/gradle.properties b/gradle.properties index 9a217b732..6f08ebe8c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ protocolLibVersion = 5.4.0 # Dependencies jetbrainsAnnotationsVersion = 26.1.0 -revxrsalLampVersion = 4.0.0-rc.18 +revxrsalLampVersion = 4.0.0-rc.19 ormVersion = 6.1 lombokVersion = 1.18.48 diff --git a/local.properties b/local.properties index e483db0bb..3b69739b9 100644 --- a/local.properties +++ b/local.properties @@ -1 +1 @@ -minecraftServerDir=/home/iambibi_/Documents/ServeurMinecraftLocal/26.3-OMC \ No newline at end of file +minecraftServerDir=/home/iambibi_/Documents/ServeurMinecraftLocal/26.3-OMC-Rift \ No newline at end of file diff --git a/src/main/java/fr/openmc/core/OMCPlugin.java b/src/main/java/fr/openmc/core/OMCPlugin.java index a8ef81f23..ecacf61c3 100644 --- a/src/main/java/fr/openmc/core/OMCPlugin.java +++ b/src/main/java/fr/openmc/core/OMCPlugin.java @@ -221,11 +221,11 @@ public void loadAfterItemsAdder() { ItemsAddersListener.setLoaded(true); // todo: a rewrite lors registre hook et features -// try { -// new BedrockHook().startInit(); -// } catch (NoClassDefFoundError e) { -// OMCLogger.error("Hook BedrockHook désactivé (package non trouvé) " + e.getMessage()); -// } + try { + new BedrockHook().startInit(); + } catch (NoClassDefFoundError e) { + OMCLogger.error("Hook BedrockHook désactivé (package non trouvé) " + e.getMessage()); + } /* LOAD ITEMS ADDER CONTENTS */ ItemsAdderHook.loadContents(); diff --git a/src/main/java/fr/openmc/core/OMCRegistry.java b/src/main/java/fr/openmc/core/OMCRegistry.java index 94db57547..c64a1fa5c 100644 --- a/src/main/java/fr/openmc/core/OMCRegistry.java +++ b/src/main/java/fr/openmc/core/OMCRegistry.java @@ -14,8 +14,8 @@ import fr.openmc.core.registry.loottable.CustomLootTableRegistry; import fr.openmc.core.registry.mobs.CustomMobRegistry; import fr.openmc.core.registry.regions.CustomRegionRegistry; -import fr.openmc.riftengine.api.registry.scanner.ScannerRegistry; import fr.openmc.core.registry.worldtemplates.WorldTemplateRegistry; +import fr.openmc.riftengine.api.registry.scanner.ScannerRegistry; import io.papermc.paper.plugin.bootstrap.BootstrapContext; import java.io.IOException; @@ -87,7 +87,7 @@ public static void bootstrapAll(BootstrapContext context) { r.bootstrap(context); } catch (IOException e) { OMCLogger.errorFormatted("Erreur lors du chargement du registre lors du bootstrap"); - OMCLogger.error(e.getMessage()); + OMCLogger.error(e.getMessage(), e); } OMCLogger.successFormatted("Registre {} chargé pendant le bootstrap", r.getClass().getSimpleName()); } @@ -108,7 +108,7 @@ public static void initAll() { r.init(); } catch (Exception e) { OMCLogger.errorFormatted("Erreur lors du chargement du registre lors du runtime"); - OMCLogger.error(e.getMessage()); + OMCLogger.error(e.getMessage(), e); } OMCLogger.successFormatted("Registre {} chargé pendant le runtime", r.getClass().getSimpleName()); } @@ -130,7 +130,7 @@ public static void postInitAll() { r.postInit(); } catch (Exception e) { OMCLogger.errorFormatted("Erreur lors du chargement du registre apres ItemsAdder"); - OMCLogger.error(e.getMessage()); + OMCLogger.error(e.getMessage(), e); } OMCLogger.successFormatted("Registre {} chargé après ItemsAdder", r.getClass().getSimpleName()); diff --git a/src/main/java/fr/openmc/core/features/bits/BitsManager.java b/src/main/java/fr/openmc/core/features/bits/BitsManager.java index 14ebb9cba..a57e2ece1 100644 --- a/src/main/java/fr/openmc/core/features/bits/BitsManager.java +++ b/src/main/java/fr/openmc/core/features/bits/BitsManager.java @@ -14,6 +14,7 @@ import fr.openmc.core.features.bits.commands.BitsCommands; import fr.openmc.core.features.bits.models.BitsPlayer; import fr.openmc.core.features.city.sub.bank.CityBankManager; +import fr.openmc.core.features.economy.EconomyManager; import fr.openmc.core.hooks.github.GitHubHook; import fr.openmc.core.hooks.github.models.ContributorStats; import fr.openmc.core.hooks.itemsadder.ItemsAdderHook; @@ -21,9 +22,7 @@ import org.bukkit.Bukkit; import org.bukkit.scheduler.BukkitTask; -import java.math.BigDecimal; import java.sql.SQLException; -import java.text.NumberFormat; import java.util.*; @Credit(developers = {"iambibi_"}) @@ -117,13 +116,7 @@ public static BitsPlayer getBitsPlayer(UUID playerUUID) { } public static String getFormattedBits(UUID playerUUID) { - String balance = String.valueOf(getBits(playerUUID)); - Currency currency = Currency.getInstance(Locale.FRANCE); - NumberFormat format = NumberFormat.getCurrencyInstance(Locale.FRANCE); - format.setCurrency(currency); - BigDecimal bd = new BigDecimal(balance); - return format.format(bd).replace(NumberFormat.getCurrencyInstance(Locale.FRANCE).getCurrency().getSymbol(), - getBitsIcon()); + return EconomyManager.getFormattedNumber(getBits(playerUUID)); } public static String getBitsIcon() { diff --git a/src/main/java/fr/openmc/core/features/city/menu/CityTopMenu.java b/src/main/java/fr/openmc/core/features/city/menu/CityTopMenu.java index a2f3c627a..a8c90e888 100644 --- a/src/main/java/fr/openmc/core/features/city/menu/CityTopMenu.java +++ b/src/main/java/fr/openmc/core/features/city/menu/CityTopMenu.java @@ -92,7 +92,7 @@ public List getItems() { Component membersCurrent = Component.text(city.getMembers().size()).color(NamedTextColor.GREEN); Component membersLimit = Component.text(MemberLimitRewards.getMemberLimit(city.getLevel())).color(NamedTextColor.GREEN); Component areaComponent = Component.text(city.getChunks().size()).color(NamedTextColor.GOLD); - Component wealthComponent = Component.text(EconomyManager.getFormattedSimplifiedNumber(city.getBalance())).color(NamedTextColor.GOLD); + Component wealthComponent = Component.text(EconomyManager.getFormattedNumber(city.getBalance())).color(NamedTextColor.GOLD); Component wealthIcon = Component.text(EconomyManager.getEconomyIcon()).color(NamedTextColor.GOLD); Component powerComponent = Component.text(city.getPowerPoints()).color(NamedTextColor.RED); diff --git a/src/main/java/fr/openmc/core/features/city/menu/list/CityListDetailsMenu.java b/src/main/java/fr/openmc/core/features/city/menu/list/CityListDetailsMenu.java index ea01d3e67..e247f544d 100644 --- a/src/main/java/fr/openmc/core/features/city/menu/list/CityListDetailsMenu.java +++ b/src/main/java/fr/openmc/core/features/city/menu/list/CityListDetailsMenu.java @@ -158,7 +158,7 @@ public void onInventoryClick(InventoryClickEvent inventoryClickEvent) { map.put(22, new ItemMenuBuilder(this, new ItemStack(Material.DIAMOND), itemMeta -> itemMeta.displayName(TranslationManager.translation( "feature.city.menus.list.details.wealth", - Component.text(EconomyManager.getFormattedSimplifiedNumber(city.getBalance())).color(NamedTextColor.GOLD), + Component.text(EconomyManager.getFormattedNumber(city.getBalance())).color(NamedTextColor.GOLD), Component.text(EconomyManager.getEconomyIcon()).color(NamedTextColor.GOLD) )))); diff --git a/src/main/java/fr/openmc/core/features/city/menu/list/CityListMenu.java b/src/main/java/fr/openmc/core/features/city/menu/list/CityListMenu.java index 2642a0201..0a576f02b 100644 --- a/src/main/java/fr/openmc/core/features/city/menu/list/CityListMenu.java +++ b/src/main/java/fr/openmc/core/features/city/menu/list/CityListMenu.java @@ -89,7 +89,7 @@ public List getItems() { Component membersLimit = Component.text(MemberLimitRewards.getMemberLimit(city.getLevel())).color(NamedTextColor.GREEN); Component membersSuffix = Component.text(city.getMembers().size() > 1 ? "s" : ""); Component typeComponent = city.getType().getDisplayName(); - Component wealthComponent = Component.text(EconomyManager.getFormattedSimplifiedNumber(city.getBalance())).color(NamedTextColor.GOLD); + Component wealthComponent = Component.text(EconomyManager.getFormattedNumber(city.getBalance())).color(NamedTextColor.GOLD); Component wealthIcon = Component.text(EconomyManager.getEconomyIcon()).color(NamedTextColor.GOLD); if (MayorManager.phaseMayor == 2 && FeaturesRewards.hasUnlockFeature(city, FeaturesRewards.Feature.MAYOR)) { Component mayorCity = city.getMayor() == null diff --git a/src/main/java/fr/openmc/core/features/city/menu/main/buttons/NotationsButton.java b/src/main/java/fr/openmc/core/features/city/menu/main/buttons/NotationsButton.java index 1c0fa881e..e83e7c7c7 100644 --- a/src/main/java/fr/openmc/core/features/city/menu/main/buttons/NotationsButton.java +++ b/src/main/java/fr/openmc/core/features/city/menu/main/buttons/NotationsButton.java @@ -47,7 +47,7 @@ private static List getDynamicLore(City city, CityNotation notation) "feature.city.menus.main.notation.lore", Component.text(Math.floor(notation.getTotalNote())).color(NamedTextColor.BLUE), Component.text(NotationNote.getMaxTotalNote()).color(NamedTextColor.BLUE), - Component.text(EconomyManager.getFormattedSimplifiedNumber(notation.getMoney())).color(NamedTextColor.GOLD), + Component.text(EconomyManager.getFormattedNumber(notation.getMoney())).color(NamedTextColor.GOLD), Component.text(EconomyManager.getEconomyIcon()).color(NamedTextColor.GOLD) ); } else { diff --git a/src/main/java/fr/openmc/core/features/city/sub/bank/CityBankManager.java b/src/main/java/fr/openmc/core/features/city/sub/bank/CityBankManager.java index 82560b5e0..6b04fae0a 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/bank/CityBankManager.java +++ b/src/main/java/fr/openmc/core/features/city/sub/bank/CityBankManager.java @@ -104,7 +104,7 @@ public static void withdrawCityBank(City city, Player player, String input) { MessagesManager.sendMessage(player, TranslationManager.translation( "feature.city.bank.withdraw.success", - Component.text(EconomyManager.getFormattedSimplifiedNumber(amount)).color(NamedTextColor.LIGHT_PURPLE), + Component.text(EconomyManager.getFormattedNumber(amount)).color(NamedTextColor.LIGHT_PURPLE), Component.text(EconomyManager.getEconomyIcon()).color(NamedTextColor.LIGHT_PURPLE) ), Prefix.CITY, MessageType.SUCCESS, false); diff --git a/src/main/java/fr/openmc/core/features/city/sub/bank/menu/CityBankDepositMenu.java b/src/main/java/fr/openmc/core/features/city/sub/bank/menu/CityBankDepositMenu.java index 83009dd08..fc7434d6e 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/bank/menu/CityBankDepositMenu.java +++ b/src/main/java/fr/openmc/core/features/city/sub/bank/menu/CityBankDepositMenu.java @@ -69,7 +69,7 @@ public void onInventoryClick(InventoryClickEvent click) { if (hasPermissionMoneyGive) { loreBankDepositAll = TranslationManager.translationLore( "feature.city.bank.menu.deposit.all.lore", - Component.text(EconomyManager.getFormattedSimplifiedNumber(moneyPlayer)).color(NamedTextColor.LIGHT_PURPLE), + Component.text(EconomyManager.getFormattedNumber(moneyPlayer)).color(NamedTextColor.LIGHT_PURPLE), Component.text(EconomyManager.getEconomyIcon()).color(NamedTextColor.LIGHT_PURPLE) ); } else { @@ -90,7 +90,7 @@ public void onInventoryClick(InventoryClickEvent click) { if (hasPermissionMoneyGive) { loreBankDepositHalf = TranslationManager.translationLore( "feature.city.bank.menu.deposit.half.lore", - Component.text(EconomyManager.getFormattedSimplifiedNumber(halfMoneyPlayer)).color(NamedTextColor.LIGHT_PURPLE), + Component.text(EconomyManager.getFormattedNumber(halfMoneyPlayer)).color(NamedTextColor.LIGHT_PURPLE), Component.text(EconomyManager.getEconomyIcon()).color(NamedTextColor.LIGHT_PURPLE) ); } else { diff --git a/src/main/java/fr/openmc/core/features/city/sub/bank/menu/CityBankMenu.java b/src/main/java/fr/openmc/core/features/city/sub/bank/menu/CityBankMenu.java index b83f93ea3..22048c06c 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/bank/menu/CityBankMenu.java +++ b/src/main/java/fr/openmc/core/features/city/sub/bank/menu/CityBankMenu.java @@ -91,7 +91,7 @@ public void onInventoryClick(InventoryClickEvent click) { itemMeta.itemName(TranslationManager.translation("feature.city.bank.menu.balance.title")); itemMeta.lore(TranslationManager.translationLore( "feature.city.bank.menu.balance.lore", - Component.text(EconomyManager.getFormattedSimplifiedNumber(city.getBalance())).color(NamedTextColor.LIGHT_PURPLE), + Component.text(EconomyManager.getFormattedNumber(city.getBalance())).color(NamedTextColor.LIGHT_PURPLE), Component.text(EconomyManager.getEconomyIcon()).color(NamedTextColor.LIGHT_PURPLE), Component.text(city.calculateCityInterest() * 100 + "%").color(NamedTextColor.AQUA), Component.text(DateUtils.convertSecondToTime(BankManager.getSecondsUntilInterest())).color(NamedTextColor.AQUA) diff --git a/src/main/java/fr/openmc/core/features/city/sub/bank/menu/CityBankWithdrawMenu.java b/src/main/java/fr/openmc/core/features/city/sub/bank/menu/CityBankWithdrawMenu.java index eecccdf65..7a9b793df 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/bank/menu/CityBankWithdrawMenu.java +++ b/src/main/java/fr/openmc/core/features/city/sub/bank/menu/CityBankWithdrawMenu.java @@ -69,7 +69,7 @@ public void onInventoryClick(InventoryClickEvent click) { if (hasPermissionMoneyTake) { loreBankWithdrawAll = TranslationManager.translationLore( "feature.city.bank.menu.withdraw.all.lore", - Component.text(EconomyManager.getFormattedSimplifiedNumber(moneyBankCity)).color(NamedTextColor.LIGHT_PURPLE), + Component.text(EconomyManager.getFormattedNumber(moneyBankCity)).color(NamedTextColor.LIGHT_PURPLE), Component.text(EconomyManager.getEconomyIcon()).color(NamedTextColor.LIGHT_PURPLE) ); } else { @@ -89,7 +89,7 @@ public void onInventoryClick(InventoryClickEvent click) { if (hasPermissionMoneyTake) { loreBankWithdrawHalf = TranslationManager.translationLore( "feature.city.bank.menu.withdraw.half.lore", - Component.text(EconomyManager.getFormattedSimplifiedNumber(halfMoneyBankCity)).color(NamedTextColor.LIGHT_PURPLE), + Component.text(EconomyManager.getFormattedNumber(halfMoneyBankCity)).color(NamedTextColor.LIGHT_PURPLE), Component.text(EconomyManager.getEconomyIcon()).color(NamedTextColor.LIGHT_PURPLE) ); } else { diff --git a/src/main/java/fr/openmc/core/features/city/sub/milestone/CityLevels.java b/src/main/java/fr/openmc/core/features/city/sub/milestone/CityLevels.java index 2c8b9ec57..beb2471a5 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/milestone/CityLevels.java +++ b/src/main/java/fr/openmc/core/features/city/sub/milestone/CityLevels.java @@ -127,7 +127,7 @@ public enum CityLevels { return TranslationManager.translation( "feature.city.levels.requirements.bank.progress", Component.text("5k"), - Component.text(EconomyManager.getFormattedSimplifiedNumber(city.getBalance())) + Component.text(EconomyManager.getFormattedNumber(city.getBalance())) ); } ), @@ -214,7 +214,7 @@ public enum CityLevels { return TranslationManager.translation( "feature.city.levels.requirements.bank.progress", Component.text("15k"), - Component.text(EconomyManager.getFormattedSimplifiedNumber(city.getBalance())) + Component.text(EconomyManager.getFormattedNumber(city.getBalance())) ); } ), @@ -294,7 +294,7 @@ public enum CityLevels { return TranslationManager.translation( "feature.city.levels.requirements.bank.progress", Component.text("20k"), - Component.text(EconomyManager.getFormattedSimplifiedNumber(city.getBalance())) + Component.text(EconomyManager.getFormattedNumber(city.getBalance())) ); } ), @@ -364,7 +364,7 @@ public enum CityLevels { return TranslationManager.translation( "feature.city.levels.requirements.bank.progress", Component.text("30k"), - Component.text(EconomyManager.getFormattedSimplifiedNumber(city.getBalance())) + Component.text(EconomyManager.getFormattedNumber(city.getBalance())) ); } ), @@ -455,7 +455,7 @@ public enum CityLevels { return TranslationManager.translation( "feature.city.levels.requirements.bank.progress", Component.text("40k"), - Component.text(EconomyManager.getFormattedSimplifiedNumber(city.getBalance())) + Component.text(EconomyManager.getFormattedNumber(city.getBalance())) ); } ), @@ -528,7 +528,7 @@ public enum CityLevels { return TranslationManager.translation( "feature.city.levels.requirements.bank.progress", Component.text("60k"), - Component.text(EconomyManager.getFormattedSimplifiedNumber(city.getBalance())) + Component.text(EconomyManager.getFormattedNumber(city.getBalance())) ); } ), @@ -620,7 +620,7 @@ public enum CityLevels { return TranslationManager.translation( "feature.city.levels.requirements.bank.progress", Component.text("80k"), - Component.text(EconomyManager.getFormattedSimplifiedNumber(city.getBalance())) + Component.text(EconomyManager.getFormattedNumber(city.getBalance())) ); } ), @@ -700,7 +700,7 @@ public enum CityLevels { return TranslationManager.translation( "feature.city.levels.requirements.bank.progress", Component.text("200k"), - Component.text(EconomyManager.getFormattedSimplifiedNumber(city.getBalance())) + Component.text(EconomyManager.getFormattedNumber(city.getBalance())) ); } ), diff --git a/src/main/java/fr/openmc/core/features/city/sub/war/WarManager.java b/src/main/java/fr/openmc/core/features/city/sub/war/WarManager.java index 9c79f2939..791c4b011 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/war/WarManager.java +++ b/src/main/java/fr/openmc/core/features/city/sub/war/WarManager.java @@ -332,14 +332,14 @@ public static void broadcastWarResult(War war, City winner, City loser, WinReaso Component rewardMoney = bonusMoney > 0 ? TranslationManager.translation( "feature.city.war.result.reward.money_bonus", - Component.text(EconomyManager.getFormattedSimplifiedNumber(amountStolen) + EconomyManager.getEconomyIcon()) + Component.text(EconomyManager.getFormattedNumber(amountStolen) + EconomyManager.getEconomyIcon()) .color(NamedTextColor.GOLD), - Component.text(EconomyManager.getFormattedSimplifiedNumber(bonusMoney) + EconomyManager.getEconomyIcon()) + Component.text(EconomyManager.getFormattedNumber(bonusMoney) + EconomyManager.getEconomyIcon()) .color(NamedTextColor.GOLD) ) : TranslationManager.translation( "feature.city.war.result.reward.money", - Component.text(EconomyManager.getFormattedSimplifiedNumber(amountStolen) + EconomyManager.getEconomyIcon()) + Component.text(EconomyManager.getFormattedNumber(amountStolen) + EconomyManager.getEconomyIcon()) .color(NamedTextColor.GOLD) ); Component rewardClaims = TranslationManager.translation( @@ -378,7 +378,7 @@ public static void broadcastWarResult(War war, City winner, City loser, WinReaso ); Component lossMoney = TranslationManager.translation( "feature.city.war.result.loss.money", - Component.text(EconomyManager.getFormattedSimplifiedNumber(amountStolen) + EconomyManager.getEconomyIcon()) + Component.text(EconomyManager.getFormattedNumber(amountStolen) + EconomyManager.getEconomyIcon()) .color(NamedTextColor.RED) ); Component lossClaims = TranslationManager.translation( diff --git a/src/main/java/fr/openmc/core/features/city/sub/war/menu/main/MainWarMenu.java b/src/main/java/fr/openmc/core/features/city/sub/war/menu/main/MainWarMenu.java index 3dea8d151..8f03db553 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/war/menu/main/MainWarMenu.java +++ b/src/main/java/fr/openmc/core/features/city/sub/war/menu/main/MainWarMenu.java @@ -132,7 +132,7 @@ public List getItems() { loreCity.add(TranslationManager.translation( "feature.city.war.menu.main.wealth", - Component.text(EconomyManager.getFormattedSimplifiedNumber(city.getBalance()) + EconomyManager.getEconomyIcon()) + Component.text(EconomyManager.getFormattedNumber(city.getBalance()) + EconomyManager.getEconomyIcon()) .color(NamedTextColor.GOLD) ).color(NamedTextColor.GRAY)); diff --git a/src/main/java/fr/openmc/core/features/city/sub/war/menu/main/WarCityDetailsMenu.java b/src/main/java/fr/openmc/core/features/city/sub/war/menu/main/WarCityDetailsMenu.java index 44ffff6c6..08442549c 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/war/menu/main/WarCityDetailsMenu.java +++ b/src/main/java/fr/openmc/core/features/city/sub/war/menu/main/WarCityDetailsMenu.java @@ -124,7 +124,7 @@ public void onInventoryClick(InventoryClickEvent inventoryClickEvent) { map.put(22, new ItemMenuBuilder(this, new ItemStack(Material.DIAMOND), itemMeta -> itemMeta.displayName(TranslationManager.translation( "feature.city.war.menu.details.wealth", - Component.text(EconomyManager.getFormattedSimplifiedNumber(city.getBalance()) + " " + EconomyManager.getEconomyIcon()) + Component.text(EconomyManager.getFormattedNumber(city.getBalance()) + " " + EconomyManager.getEconomyIcon()) .color(NamedTextColor.GOLD) ).color(NamedTextColor.GRAY)))); diff --git a/src/main/java/fr/openmc/core/features/displays/scoreboards/sb/MainScoreboard.java b/src/main/java/fr/openmc/core/features/displays/scoreboards/sb/MainScoreboard.java index f953efcde..f69407f62 100644 --- a/src/main/java/fr/openmc/core/features/displays/scoreboards/sb/MainScoreboard.java +++ b/src/main/java/fr/openmc/core/features/displays/scoreboards/sb/MainScoreboard.java @@ -96,9 +96,9 @@ public void update(Player player, SternalBoard board) { } public static List getDefaultLines(Player player, boolean inWar) { - Component rank = LuckPermsHook.isEnable() - ? Component.text(LuckPermsHook.getFormattedPAPIPrefix(player)) - : TranslationManager.translation("feature.displays.scoreboard.rank.none", true).color(TextColor.color(0xFF1FCC)); + String rank = LuckPermsHook.isEnable() + ? LuckPermsHook.getFormattedPAPIPrefix(player) + : null; City city = CityManager.getPlayerCity(player.getUniqueId()); @@ -118,11 +118,13 @@ public static List getDefaultLines(Player player, boolean inWar) { lines.add(MiniMessage.miniMessage().deserialize( "%s".formatted( player.getName())).decoration(TextDecoration.BOLD, true)); - lines.add(text(" " + CharRemplacementUtils.getPointChar(player) + " ", NamedTextColor.DARK_GRAY) - .append(TranslationManager.translation(player, "feature.displays.scoreboard.rank.label", true).color(NamedTextColor.GRAY)) - .appendSpace() - .append(rank) - ); + if (rank != null) { + lines.add(text(" " + CharRemplacementUtils.getPointChar(player) + " ", NamedTextColor.DARK_GRAY) + .append(TranslationManager.translation(player, "feature.displays.scoreboard.rank.label", true).color(NamedTextColor.GRAY)) + .appendSpace() + .append(Component.text(rank)) + ); + } lines.add(text(" " + CharRemplacementUtils.getPointChar(player) + " ", NamedTextColor.DARK_GRAY) .append(TranslationManager.translation(player, "feature.displays.scoreboard.city.label", true).color(NamedTextColor.GRAY)) .appendSpace() @@ -142,7 +144,7 @@ public static List getDefaultLines(Player player, boolean inWar) { lines.add(text(" " + CharRemplacementUtils.getPointChar(player) + " ", NamedTextColor.DARK_GRAY) .append(TranslationManager.translation(player, "feature.displays.scoreboard.bits.label", true).color(NamedTextColor.GRAY)) .appendSpace() - .append(toSmall(player, EconomyManager.getFormattedSimplifiedNumber(bits)).color(TextColor.color(0x07A0F5))) + .append(toSmall(player, EconomyManager.getFormattedNumber(bits)).color(TextColor.color(0x07A0F5))) .appendSpace() .append(text(BitsManager.getBitsIcon())) ); @@ -160,7 +162,7 @@ public static List getDefaultLines(Player player, boolean inWar) { if (npcManager != null) halloweenNPC = npcManager.getNpc("halloween_pumpkin_deposit_npc"); if (halloweenNPC != null) { - String pumpkinCount = EconomyManager.getFormattedSimplifiedNumber(HalloweenManager.getPumpkinCount(player.getUniqueId())); + String pumpkinCount = EconomyManager.getFormattedNumber(HalloweenManager.getPumpkinCount(player.getUniqueId())); lines.add(text(" " + CharRemplacementUtils.getPointChar(player) + " ", NamedTextColor.DARK_GRAY) .append(TranslationManager.translation(player, "feature.displays.scoreboard.pumpkins.label", true).color(NamedTextColor.GRAY)) .appendSpace() diff --git a/src/main/java/fr/openmc/core/features/dream/registries/items/armors/cold/ColdBoots.java b/src/main/java/fr/openmc/core/features/dream/registries/items/armors/cold/ColdBoots.java index 2920e4fbf..3e2224ba2 100644 --- a/src/main/java/fr/openmc/core/features/dream/registries/items/armors/cold/ColdBoots.java +++ b/src/main/java/fr/openmc/core/features/dream/registries/items/armors/cold/ColdBoots.java @@ -13,8 +13,8 @@ public ColdBoots() { super(new DreamItemMeta( "omc_dream:cold_boots", TranslationManager.translation("feature.dream.item.cold_boots.name"), - DreamRarity.EPIC, - Material.LEATHER_LEGGINGS, + DreamRarity.LEGENDARY, + Material.LEATHER_BOOTS, true )); } diff --git a/src/main/java/fr/openmc/core/features/economy/BankManager.java b/src/main/java/fr/openmc/core/features/economy/BankManager.java index 1664ff486..ce95f0fcb 100644 --- a/src/main/java/fr/openmc/core/features/economy/BankManager.java +++ b/src/main/java/fr/openmc/core/features/economy/BankManager.java @@ -188,7 +188,7 @@ public static void withdraw(UUID playerUUID, String input) { MessagesManager.sendMessage(offlinePlayer, TranslationManager.translation( "feature.economy.bank.withdraw.transferred", - Component.text(EconomyManager.getFormattedSimplifiedNumber(amount)).color(NamedTextColor.LIGHT_PURPLE), + Component.text(EconomyManager.getFormattedNumber(amount)).color(NamedTextColor.LIGHT_PURPLE), Component.text(EconomyManager.getEconomyIcon()) ), Prefix.BANK, MessageType.SUCCESS, false); @@ -241,7 +241,7 @@ public static void applyPlayerInterest(UUID playerUUID) { TranslationManager.translation( "feature.economy.bank.interest.received", Component.text(interest * 100 + "%").color(NamedTextColor.LIGHT_PURPLE), - Component.text(EconomyManager.getFormattedSimplifiedNumber(allowedAmount)).color(NamedTextColor.LIGHT_PURPLE), + Component.text(EconomyManager.getFormattedNumber(allowedAmount)).color(NamedTextColor.LIGHT_PURPLE), Component.text(EconomyManager.getEconomyIcon()) ), Prefix.CITY, MessageType.SUCCESS, false); diff --git a/src/main/java/fr/openmc/core/features/economy/EconomyManager.java b/src/main/java/fr/openmc/core/features/economy/EconomyManager.java index e704c1f8a..a62b76f6a 100644 --- a/src/main/java/fr/openmc/core/features/economy/EconomyManager.java +++ b/src/main/java/fr/openmc/core/features/economy/EconomyManager.java @@ -20,10 +20,8 @@ import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; -import java.math.BigDecimal; import java.sql.SQLException; import java.text.DecimalFormat; -import java.text.NumberFormat; import java.util.*; @Credit(developers = {"Axeno", "Piquel Chips", "PuppyTransGirl", "Gyro"}) @@ -161,7 +159,7 @@ public static void setBalance(UUID playerUUID, double amount) { public static String getMiniBalance(UUID playerUUID) { double balance = getBalance(playerUUID); - return getFormattedSimplifiedNumber(balance); + return getFormattedNumber(balance); } public static EconomyPlayer getPlayerBank(UUID playerUUID) { @@ -197,25 +195,10 @@ public static Map loadAllBalances() { } public static String getFormattedBalance(UUID playerUUID) { - String balance = String.valueOf(getBalance(playerUUID)); - Currency currency = Currency.getInstance(Locale.FRANCE); - NumberFormat format = NumberFormat.getCurrencyInstance(Locale.FRANCE); - format.setCurrency(currency); - BigDecimal bd = new BigDecimal(balance); - return format.format(bd).replace(NumberFormat.getCurrencyInstance(Locale.FRANCE).getCurrency().getSymbol(), - getEconomyIcon()); + return getFormattedNumber(getBalance(playerUUID)); } - public static String getFormattedNumber(double number) { - Currency currency = Currency.getInstance(Locale.FRANCE); - NumberFormat format = NumberFormat.getCurrencyInstance(Locale.FRANCE); - format.setCurrency(currency); - BigDecimal bd = new BigDecimal(number); - return format.format(bd).replace(NumberFormat.getCurrencyInstance(Locale.FRANCE).getCurrency().getSymbol(), - getEconomyIcon()); - } - - public static String getFormattedSimplifiedNumber(double balance) { + public static String getFormattedNumber(double balance) { if (balance == 0) { return "0"; } diff --git a/src/main/java/fr/openmc/core/features/economy/commands/BankCommands.java b/src/main/java/fr/openmc/core/features/economy/commands/BankCommands.java index 7822ab301..991752bf6 100644 --- a/src/main/java/fr/openmc/core/features/economy/commands/BankCommands.java +++ b/src/main/java/fr/openmc/core/features/economy/commands/BankCommands.java @@ -87,7 +87,7 @@ void withdraw(OMCPlayer player) { player.message().sendInfo( TranslationManager.translation( "feature.economy.bank.command.balance", - Component.text(EconomyManager.getFormattedSimplifiedNumber(balance)).color(NamedTextColor.LIGHT_PURPLE), + Component.text(EconomyManager.getFormattedNumber(balance)).color(NamedTextColor.LIGHT_PURPLE), Component.text(EconomyManager.getEconomyIcon()) ), Prefix.BANK diff --git a/src/main/java/fr/openmc/core/features/economy/menu/PersonalBankDepositMenu.java b/src/main/java/fr/openmc/core/features/economy/menu/PersonalBankDepositMenu.java index e1f487a5b..8cf8f0c0f 100644 --- a/src/main/java/fr/openmc/core/features/economy/menu/PersonalBankDepositMenu.java +++ b/src/main/java/fr/openmc/core/features/economy/menu/PersonalBankDepositMenu.java @@ -59,7 +59,7 @@ public void onInventoryClick(InventoryClickEvent click) { List loreBankDepositAll = TranslationManager.translationLore( "feature.economy.bank.deposit.all.lore", - Component.text(EconomyManager.getFormattedSimplifiedNumber(moneyPlayer)).color(NamedTextColor.LIGHT_PURPLE), + Component.text(EconomyManager.getFormattedNumber(moneyPlayer)).color(NamedTextColor.LIGHT_PURPLE), Component.text(EconomyManager.getEconomyIcon()).decoration(TextDecoration.ITALIC, false) ); @@ -74,7 +74,7 @@ public void onInventoryClick(InventoryClickEvent click) { List loreBankDepositHalf = TranslationManager.translationLore( "feature.economy.bank.deposit.half.lore", - Component.text(EconomyManager.getFormattedSimplifiedNumber(halfMoneyPlayer)).color(NamedTextColor.LIGHT_PURPLE), + Component.text(EconomyManager.getFormattedNumber(halfMoneyPlayer)).color(NamedTextColor.LIGHT_PURPLE), Component.text(EconomyManager.getEconomyIcon()).decoration(TextDecoration.ITALIC, false) ); diff --git a/src/main/java/fr/openmc/core/features/economy/menu/PersonalBankMenu.java b/src/main/java/fr/openmc/core/features/economy/menu/PersonalBankMenu.java index 76b734063..58e653d75 100644 --- a/src/main/java/fr/openmc/core/features/economy/menu/PersonalBankMenu.java +++ b/src/main/java/fr/openmc/core/features/economy/menu/PersonalBankMenu.java @@ -83,9 +83,9 @@ public void onInventoryClick(InventoryClickEvent click) { itemMeta.itemName(TranslationManager.translation("feature.economy.bank.menu.balance.name")); itemMeta.lore(TranslationManager.translationLore( "feature.economy.bank.menu.balance.lore", - Component.text(EconomyManager.getFormattedSimplifiedNumber(BankManager.getBankBalance(player.getUniqueId()))).color(NamedTextColor.LIGHT_PURPLE), + Component.text(EconomyManager.getFormattedNumber(BankManager.getBankBalance(player.getUniqueId()))).color(NamedTextColor.LIGHT_PURPLE), Component.text(EconomyManager.getEconomyIcon()).decoration(TextDecoration.ITALIC, false), - Component.text(EconomyManager.getFormattedSimplifiedNumber(PlayerBankLimitRewards.getBankBalanceLimit(playerCity.getLevel()))).color(NamedTextColor.LIGHT_PURPLE), + Component.text(EconomyManager.getFormattedNumber(PlayerBankLimitRewards.getBankBalanceLimit(playerCity.getLevel()))).color(NamedTextColor.LIGHT_PURPLE), Component.text(EconomyManager.getEconomyIcon()).decoration(TextDecoration.ITALIC, false), Component.text(BankManager.calculatePlayerInterest(player.getUniqueId()) * 100 + "%").color(NamedTextColor.AQUA), Component.text(DateUtils.convertSecondToTime(BankManager.getSecondsUntilInterest())).color(NamedTextColor.AQUA) diff --git a/src/main/java/fr/openmc/core/features/economy/menu/PersonalBankWithdrawMenu.java b/src/main/java/fr/openmc/core/features/economy/menu/PersonalBankWithdrawMenu.java index 22eb007be..20ed7479f 100644 --- a/src/main/java/fr/openmc/core/features/economy/menu/PersonalBankWithdrawMenu.java +++ b/src/main/java/fr/openmc/core/features/economy/menu/PersonalBankWithdrawMenu.java @@ -59,7 +59,7 @@ public void onInventoryClick(InventoryClickEvent click) { List loreBankWithdrawAll = TranslationManager.translationLore( "feature.economy.bank.withdraw.all.lore", - Component.text(EconomyManager.getFormattedSimplifiedNumber(moneyBankPlayer)).color(NamedTextColor.LIGHT_PURPLE), + Component.text(EconomyManager.getFormattedNumber(moneyBankPlayer)).color(NamedTextColor.LIGHT_PURPLE), Component.text(EconomyManager.getEconomyIcon()).decoration(TextDecoration.ITALIC, false) ); @@ -73,7 +73,7 @@ public void onInventoryClick(InventoryClickEvent click) { List loreBankWithdrawHalf = TranslationManager.translationLore( "feature.economy.bank.withdraw.half.lore", - Component.text(EconomyManager.getFormattedSimplifiedNumber(halfMoneyBankPlayer)).color(NamedTextColor.LIGHT_PURPLE), + Component.text(EconomyManager.getFormattedNumber(halfMoneyBankPlayer)).color(NamedTextColor.LIGHT_PURPLE), Component.text(EconomyManager.getEconomyIcon()).decoration(TextDecoration.ITALIC, false) ); diff --git a/src/main/java/fr/openmc/core/features/events/contents/halloween/managers/HalloweenManager.java b/src/main/java/fr/openmc/core/features/events/contents/halloween/managers/HalloweenManager.java index 27a5eaee2..41c42dadc 100644 --- a/src/main/java/fr/openmc/core/features/events/contents/halloween/managers/HalloweenManager.java +++ b/src/main/java/fr/openmc/core/features/events/contents/halloween/managers/HalloweenManager.java @@ -127,7 +127,7 @@ public static void endEvent() { .limit(10) .toList()) { String playerName = CachePlayerName.getName(entry.getKey()); - String formattedPumpkinCount = EconomyManager.getFormattedSimplifiedNumber(entry.getValue().getPumpkinCount()); + String formattedPumpkinCount = EconomyManager.getFormattedNumber(entry.getValue().getPumpkinCount()); newMap.put(rank++, new AbstractMap.SimpleEntry<>(playerName, formattedPumpkinCount)); } diff --git a/src/main/java/fr/openmc/core/features/leaderboards/LeaderboardManager.java b/src/main/java/fr/openmc/core/features/leaderboards/LeaderboardManager.java new file mode 100644 index 000000000..e69de29bb diff --git a/src/main/java/fr/openmc/core/features/leaderboards/leaderboards/CityMoneyLeaderBoard.java b/src/main/java/fr/openmc/core/features/leaderboards/leaderboards/CityMoneyLeaderBoard.java index 7bc664c45..f1e606aef 100644 --- a/src/main/java/fr/openmc/core/features/leaderboards/leaderboards/CityMoneyLeaderBoard.java +++ b/src/main/java/fr/openmc/core/features/leaderboards/leaderboards/CityMoneyLeaderBoard.java @@ -39,7 +39,7 @@ public Component createComponent(){ for (int i = 0; i < cities.size(); i++){ City city = cities.get(i); Component rank = Component.text("#" + (i+1)).color(ColorUtils.getRankColor(i+1)); - Component cityBalance = Component.text(EconomyManager.getFormattedSimplifiedNumber(city.getBalance()) + " " + EconomyManager.getEconomyIcon()) + Component cityBalance = Component.text(EconomyManager.getFormattedNumber(city.getBalance()) + " " + EconomyManager.getEconomyIcon()) .color(NamedTextColor.WHITE); text = text.append(Component.text("\n").append(TranslationManager.translation( "feature.leaderboards.line.city_money", diff --git a/src/main/java/fr/openmc/core/features/leaderboards/leaderboards/MoneyLeaderBoard.java b/src/main/java/fr/openmc/core/features/leaderboards/leaderboards/MoneyLeaderBoard.java index 84425d928..8895489e7 100644 --- a/src/main/java/fr/openmc/core/features/leaderboards/leaderboards/MoneyLeaderBoard.java +++ b/src/main/java/fr/openmc/core/features/leaderboards/leaderboards/MoneyLeaderBoard.java @@ -4,7 +4,6 @@ import fr.openmc.core.features.economy.BankManager; import fr.openmc.core.features.economy.EconomyManager; import fr.openmc.core.features.leaderboards.LeaderBoard; -import fr.openmc.core.utils.cache.CachePlayerName; import fr.openmc.core.utils.text.ColorUtils; import fr.openmc.core.utils.text.messages.TranslationManager; import net.kyori.adventure.text.Component; @@ -56,7 +55,7 @@ public Component createComponent() { "feature.leaderboards.line.money", rank, player.getNameWithHead().color(NamedTextColor.LIGHT_PURPLE), - Component.text(EconomyManager.getFormattedSimplifiedNumber(balance.getValue()) + " " + EconomyManager.getEconomyIcon()) + Component.text(EconomyManager.getFormattedNumber(balance.getValue()) + " " + EconomyManager.getEconomyIcon()) .color(NamedTextColor.WHITE) ))); } diff --git a/src/main/java/fr/openmc/core/features/leaderboards/leaderboards/PumpkinCountLeaderBoard.java b/src/main/java/fr/openmc/core/features/leaderboards/leaderboards/PumpkinCountLeaderBoard.java index 2b696b5d1..d62d53e6a 100644 --- a/src/main/java/fr/openmc/core/features/leaderboards/leaderboards/PumpkinCountLeaderBoard.java +++ b/src/main/java/fr/openmc/core/features/leaderboards/leaderboards/PumpkinCountLeaderBoard.java @@ -5,7 +5,6 @@ import fr.openmc.core.features.events.contents.halloween.managers.HalloweenManager; import fr.openmc.core.features.events.contents.halloween.models.HalloweenData; import fr.openmc.core.features.leaderboards.LeaderBoard; -import fr.openmc.core.utils.cache.CachePlayerName; import fr.openmc.core.utils.text.ColorUtils; import fr.openmc.core.utils.text.messages.TranslationManager; import net.kyori.adventure.text.Component; @@ -49,7 +48,7 @@ public Component createComponent() { HalloweenData data = datas.get(i); OMCOfflinePlayer player = OMCOfflinePlayer.of(data.getPlayerUUID()); Component name = player.getNameWithHead(); - String formattedPumpkinCount = EconomyManager.getFormattedSimplifiedNumber(data.getPumpkinCount()); + String formattedPumpkinCount = EconomyManager.getFormattedNumber(data.getPumpkinCount()); Component rank = Component.text("#" + (i+1)).color(ColorUtils.getRankColor(i+1)); text = text.append(Component.text("\n").append(TranslationManager.translation( "feature.leaderboards.line.pumpkin", diff --git a/src/main/java/fr/openmc/core/features/mainmenu/menus/buttons/ProfileButton.java b/src/main/java/fr/openmc/core/features/mainmenu/menus/buttons/ProfileButton.java index e8bfb3bf9..6179c567b 100644 --- a/src/main/java/fr/openmc/core/features/mainmenu/menus/buttons/ProfileButton.java +++ b/src/main/java/fr/openmc/core/features/mainmenu/menus/buttons/ProfileButton.java @@ -6,6 +6,7 @@ import fr.openmc.core.features.mainmenu.menus.ButtonMenu; import fr.openmc.core.features.profile.menu.ProfileMenu; import net.kyori.adventure.text.format.TextDecoration; +import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.SkullMeta; @@ -30,7 +31,10 @@ public ItemStack item(OMCPlayer player) { public ItemStack itemAt(OMCPlayer player, int slot) { if (slot != 60) return item(player); - ItemStack head = CustomStack.getInstance("omc_main_menu:player_head").getItemStack(); + CustomStack playerHead = CustomStack.getInstance("omc_main_menu:player_head"); + if (playerHead == null) return ItemStack.of(Material.PLAYER_HEAD); + + ItemStack head = playerHead.getItemStack(); head.editMeta(meta -> { meta.customName(ButtonItems.name("feature.mainmenu.item.profile.name") .decoration(TextDecoration.ITALIC, false)); diff --git a/src/main/java/fr/openmc/core/features/quests/menus/QuestsMenu.java b/src/main/java/fr/openmc/core/features/quests/menus/QuestsMenu.java index c20d8ab3e..63536ed51 100644 --- a/src/main/java/fr/openmc/core/features/quests/menus/QuestsMenu.java +++ b/src/main/java/fr/openmc/core/features/quests/menus/QuestsMenu.java @@ -247,7 +247,7 @@ private void createItems(Quest quest, ItemStack item, ItemMeta meta) { .decoration(TextDecoration.ITALIC, false)); } else if (reward instanceof QuestMoneyReward(double amount)) { lore.add(Component.text(" - ", NamedTextColor.DARK_GRAY) - .append(Component.text(EconomyManager.getFormattedSimplifiedNumber(amount), NamedTextColor.GOLD)) + .append(Component.text(EconomyManager.getFormattedNumber(amount), NamedTextColor.GOLD)) .append(Component.space()) .append(Component.text(EconomyManager.getEconomyIcon(), NamedTextColor.WHITE)) .decoration(TextDecoration.ITALIC, false)); @@ -273,7 +273,7 @@ private void createItems(Quest quest, ItemStack item, ItemMeta meta) { .decoration(TextDecoration.ITALIC, false)); } else if (reward instanceof QuestMoneyReward(double amount)) { lore.add(Component.text(" - ", NamedTextColor.DARK_GRAY) - .append(Component.text(EconomyManager.getFormattedSimplifiedNumber(amount), NamedTextColor.GOLD)) + .append(Component.text(EconomyManager.getFormattedNumber(amount), NamedTextColor.GOLD)) .append(Component.space()) .append(Component.text(EconomyManager.getEconomyIcon(), NamedTextColor.WHITE)) .decoration(TextDecoration.ITALIC, false)); diff --git a/src/main/java/fr/openmc/core/features/quests/rewards/QuestMoneyReward.java b/src/main/java/fr/openmc/core/features/quests/rewards/QuestMoneyReward.java index 3fa0bdda8..4531b1d0c 100644 --- a/src/main/java/fr/openmc/core/features/quests/rewards/QuestMoneyReward.java +++ b/src/main/java/fr/openmc/core/features/quests/rewards/QuestMoneyReward.java @@ -25,7 +25,7 @@ public record QuestMoneyReward(double amount) implements QuestReward { @Override public void giveReward(OMCPlayer player) { EconomyManager.addBalance(player.getUniqueId(), amount, "Récompense de quête"); - Component amountComponent = Component.text(EconomyManager.getFormattedSimplifiedNumber(amount) + " " + EconomyManager.getEconomyIcon()) + Component amountComponent = Component.text(EconomyManager.getFormattedNumber(amount) + " " + EconomyManager.getEconomyIcon()) .color(NamedTextColor.YELLOW); Component message = TranslationManager.translation("feature.quests.message.money_reward", amountComponent) .color(NamedTextColor.GREEN); diff --git a/src/main/java/fr/openmc/core/hooks/BedrockHook.java b/src/main/java/fr/openmc/core/hooks/BedrockHook.java index d0631c4be..a4d6d949e 100644 --- a/src/main/java/fr/openmc/core/hooks/BedrockHook.java +++ b/src/main/java/fr/openmc/core/hooks/BedrockHook.java @@ -1,15 +1,18 @@ package fr.openmc.core.hooks; import fr.openmc.core.bootstrap.hooks.Hooks; +import fr.openmc.riftengine.core.RiftRegistry; +import fr.openmc.riftengine.core.registry.glyphs.Glyph; +import lombok.Getter; import org.bukkit.entity.Player; -//import org.geysermc.floodgate.api.FloodgateApi; -//import org.geysermc.geyser.api.GeyserApi; +import org.geysermc.floodgate.api.FloodgateApi; +import org.geysermc.geyser.api.GeyserApi; import java.util.Set; public class BedrockHook extends Hooks { public static boolean isEnabled() { - return false; // return Hooks.isEnabled(FancyNpcsHook.class); + return Hooks.isEnabled(FancyNpcsHook.class); } @Override @@ -17,15 +20,15 @@ protected Set getPluginsName() { return Set.of("Geyser-Spigot", "floodgate", "RiftEngine"); } -// @Getter -// private static GeyserApi geyserApi; -// @Getter -// private static FloodgateApi floodgateApi; + @Getter + private static GeyserApi geyserApi; + @Getter + private static FloodgateApi floodgateApi; @Override public void init() { -// floodgateApi = FloodgateApi.getInstance(); -// geyserApi = GeyserApi.api(); + floodgateApi = FloodgateApi.getInstance(); + geyserApi = GeyserApi.api(); } /** @@ -35,15 +38,13 @@ public void init() { */ public static boolean isBedrockPlayer(Player player) { if (!isEnabled()) return false; - return false; -// return floodgateApi.isFloodgatePlayer(player.getUniqueId()); + return floodgateApi.isFloodgatePlayer(player.getUniqueId()); } public static Character getGlyph(String namespacedId) { -// Glyph glyph = RiftRegistry.GLYPHS.get(namespacedId).orElse(null); -// if (glyph == null) return null; -// -// return glyph.getBedrockChar(); - return null; + Glyph glyph = RiftRegistry.GLYPHS.get(namespacedId).orElse(null); + if (glyph == null) return null; + + return glyph.getBedrockChar(); } } diff --git a/src/main/java/fr/openmc/core/hooks/LuckPermsHook.java b/src/main/java/fr/openmc/core/hooks/LuckPermsHook.java index ebf7173b9..ea3ef51fc 100644 --- a/src/main/java/fr/openmc/core/hooks/LuckPermsHook.java +++ b/src/main/java/fr/openmc/core/hooks/LuckPermsHook.java @@ -55,10 +55,10 @@ public static String getPrefix(Player player) { } public static String getFormattedPAPIPrefix(Player player) { - if (!isEnable()) return ""; + if (!isEnable()) return null; String prefix = getPrefix(player); - if (prefix == null || prefix.isEmpty()) return ""; + if (prefix == null || prefix.isEmpty()) return null; String formattedPrefix = prefix.replace("&", "§"); if (ItemsAdderHook.isEnable()) { diff --git a/src/main/java/fr/openmc/core/hooks/itemsadder/sprite/SpriteUtils.java b/src/main/java/fr/openmc/core/hooks/itemsadder/sprite/SpriteUtils.java index 9fdbedbe7..e497b3511 100644 --- a/src/main/java/fr/openmc/core/hooks/itemsadder/sprite/SpriteUtils.java +++ b/src/main/java/fr/openmc/core/hooks/itemsadder/sprite/SpriteUtils.java @@ -1,7 +1,5 @@ package fr.openmc.core.hooks.itemsadder.sprite; -import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.registry.items.CustomItem; import fr.openmc.riftengine.api.scanner.items.ItemEntry; import fr.openmc.riftengine.api.utils.IdentifierUtils; @@ -11,7 +9,7 @@ import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.object.ObjectContents; -import java.util.Set; +import java.util.Map; public class SpriteUtils { public static ObjectComponent getSprite(CustomItem item) { @@ -19,17 +17,18 @@ public static ObjectComponent getSprite(CustomItem item) { if (itemEntry == null) return null; - Key atlasKey = itemEntry.getBehaviour().isBlockBehaviour() ? Key.key("minecraft", "blocks") + Key atlasKey = itemEntry.getBehaviour().isBlock() ? Key.key("minecraft", "blocks") : Key.key("minecraft", "items"); - Set bestResourcesId = itemEntry.getBestResourcesId(); + + Map bestResourcesId = itemEntry.getBestResourcesId(); if (bestResourcesId == null || bestResourcesId.isEmpty()) return null; - String bestResourceId = bestResourcesId.stream().findFirst().orElseThrow(); + String bestResourceId = bestResourcesId.values().stream().findFirst().orElseThrow(); String prefix = "_"; - if (itemEntry.getBehaviour().isBlockBehaviour() + if (itemEntry.getBehaviour().isBlock() && itemEntry.getGraphics() != null && itemEntry.getGraphics().hasTextures()) { prefix += "b_"; diff --git a/src/main/java/fr/openmc/core/listeners/AsyncChatListener.java b/src/main/java/fr/openmc/core/listeners/AsyncChatListener.java index 60ff29faa..e4fd2b9b8 100644 --- a/src/main/java/fr/openmc/core/listeners/AsyncChatListener.java +++ b/src/main/java/fr/openmc/core/listeners/AsyncChatListener.java @@ -34,9 +34,10 @@ public void onChat(AsyncChatEvent event) { final Player player = event.getPlayer(); final CachedMetaData metaData = this.luckperms.getPlayerAdapter(Player.class).getMetaData(player); + String prefix = LuckPermsHook.getFormattedPAPIPrefix(player); String message = PlainTextComponentSerializer.plainText().serialize(event.message()); String rawMessage = plugin.getConfig().getString("chat.message", "{prefix}{name}§7: {message}") - .replace("{prefix}", LuckPermsHook.getFormattedPAPIPrefix(player)) + .replace("{prefix}", prefix != null ? prefix : "") .replace("{suffix}", metaData.getSuffix() != null ? metaData.getSuffix() : "") .replace("{name}", player.getName()) .replace("{message}", message); diff --git a/src/main/java/fr/openmc/core/listeners/JoinQuitMessageListener.java b/src/main/java/fr/openmc/core/listeners/JoinQuitMessageListener.java index 03ebdaa9b..cbdbc2dd8 100644 --- a/src/main/java/fr/openmc/core/listeners/JoinQuitMessageListener.java +++ b/src/main/java/fr/openmc/core/listeners/JoinQuitMessageListener.java @@ -44,6 +44,7 @@ public void onPlayerJoin(PlayerJoinEvent event) { player.message().send(TranslationManager.translation("core.player.join.welcome"), Prefix.OPENMC, MessageType.INFO, false); TabList.updateTabList(player); + String prefix = LuckPermsHook.getFormattedPAPIPrefix(player); FriendManager.getFriendsAsync(player.getUniqueId()).thenAccept(friendsUUIDS -> { for (UUID friendUUID : friendsUUIDS) { @@ -53,7 +54,7 @@ public void onPlayerJoin(PlayerJoinEvent event) { "core.player.join.friend_online", Component.object(ObjectContents.playerHead(player.getUniqueId())).color(NamedTextColor.WHITE) .appendSpace() - .append(Component.text(LuckPermsHook.getFormattedPAPIPrefix(player) + player.getName()).color(NamedTextColor.GREEN)) + .append(Component.text((prefix != null ? prefix : "") + player.getName()).color(NamedTextColor.GREEN)) ), Prefix.FRIEND, MessageType.NONE, true); } } @@ -152,18 +153,20 @@ public void onPlayerQuit(PlayerQuitEvent event) { } public static Component getJoinMessageComponent(Player player) { + String prefix = LuckPermsHook.getFormattedPAPIPrefix(player); return Component.text("§8[§a§l+§8] §r") .append(Component.object(ObjectContents.playerHead(player.getUniqueId())).color(NamedTextColor.WHITE)) .appendSpace() - .append(Component.text(LuckPermsHook.getFormattedPAPIPrefix(player))) + .append(Component.text(prefix == null ? "" : prefix)) .append(Component.text(player.getName())); } public static Component getQuitMessageComponent(Player player) { + String prefix = LuckPermsHook.getFormattedPAPIPrefix(player); return Component.text("§8[§c§l-§8] §r") .append(Component.object(ObjectContents.playerHead(player.getUniqueId())).color(NamedTextColor.WHITE)) .appendSpace() - .append(Component.text(LuckPermsHook.getFormattedPAPIPrefix(player))) + .append(Component.text(prefix == null ? "" : prefix)) .append(Component.text(player.getName())); } } diff --git a/src/main/java/fr/openmc/core/listeners/PlayerDeathListener.java b/src/main/java/fr/openmc/core/listeners/PlayerDeathListener.java index 66d21a6d5..7b71e357e 100644 --- a/src/main/java/fr/openmc/core/listeners/PlayerDeathListener.java +++ b/src/main/java/fr/openmc/core/listeners/PlayerDeathListener.java @@ -30,8 +30,8 @@ public void onPlayerDead(PlayerDeathEvent event) { withdrawBalance(player.getUniqueId(), balance * LOSS_MONEY); MessagesManager.sendMessage(player, TranslationManager.translation( "core.player.death.message", - Component.text(getFormattedSimplifiedNumber(balance) + EconomyManager.getEconomyIcon()).color(NamedTextColor.GOLD), - Component.text(getFormattedSimplifiedNumber(balance * LOSS_MONEY) + EconomyManager.getEconomyIcon()).color(NamedTextColor.GOLD) + Component.text(getFormattedNumber(balance) + EconomyManager.getEconomyIcon()).color(NamedTextColor.GOLD), + Component.text(getFormattedNumber(balance * LOSS_MONEY) + EconomyManager.getEconomyIcon()).color(NamedTextColor.GOLD) ), Prefix.OPENMC, MessageType.INFO, false); } diff --git a/src/main/java/fr/openmc/core/utils/JsonUtils.java b/src/main/java/fr/openmc/core/utils/JsonUtils.java new file mode 100644 index 000000000..0204ab4a0 --- /dev/null +++ b/src/main/java/fr/openmc/core/utils/JsonUtils.java @@ -0,0 +1,63 @@ +package fr.openmc.core.utils; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +public class JsonUtils { + public static JsonObject loadJson(Path path) { + JsonObject root; + try { + root = JsonParser.parseString(Files.readString(path)).getAsJsonObject(); + } catch (IOException e) { + return null; + } + return root; + } + + public static JsonArray loadJsonArray(Path path) { + JsonArray root; + try { + root = JsonParser.parseString(Files.readString(path)).getAsJsonArray(); + } catch (IOException e) { + return null; + } + return root; + } + + public static JsonObject parseJson(String content) { + return JsonParser.parseString(content).getAsJsonObject(); + } + + public static JsonArray parseJsonArray(String content) { + return JsonParser.parseString(content).getAsJsonArray(); + } + + public static String getString(JsonObject object, String key, String def) { + return object.has(key) ? object.get(key).getAsString() : def; + } + + public static Integer getInt(JsonObject object, String key, Integer def) { + return object.has(key) ? object.get(key).getAsInt() : def; + } + + public static Boolean getBool(JsonObject object, String key, Boolean def) { + return object.has(key) ? object.get(key).getAsBoolean() : def; + } + + public static Float getFloat(JsonObject object, String key, Float def) { + return object.has(key) ? object.get(key).getAsFloat() : def; + } + + public static JsonObject getJsonObject(JsonObject object, String key, JsonObject def) { + return object.has(key) && object.get(key).isJsonObject() ? object.get(key).getAsJsonObject() : def; + } + + public static JsonArray getJsonArray(JsonObject object, String key, JsonArray def) { + return object.has(key) && object.get(key).isJsonArray() ? object.get(key).getAsJsonArray() : def; + } +} diff --git a/src/main/java/fr/openmc/core/utils/YmlUtils.java b/src/main/java/fr/openmc/core/utils/YmlUtils.java index 3f644e2c1..4be360c8d 100644 --- a/src/main/java/fr/openmc/core/utils/YmlUtils.java +++ b/src/main/java/fr/openmc/core/utils/YmlUtils.java @@ -20,30 +20,61 @@ public static Map loadYml(Path path) throws IOException { } } - public static String getString(Object obj, String def) { + public static String getString(Map map, String key, String def) { + if (map == null) return def; + Object obj = map.get(key); if (obj == null) return def; if (obj instanceof String s) return s; return String.valueOf(obj); } - public static Integer getInt(Object obj, Integer def) { + public static Integer getInt(Map map, String key, Integer def) { + if (map == null) return def; + Object obj = map.get(key); if (obj == null) return def; if (obj instanceof Number n) return n.intValue(); return Integer.parseInt(obj.toString()); } - public static Boolean getBool(Object obj, Boolean def) { + public static Boolean getBool(Map map, String key, Boolean def) { + if (map == null) return def; + Object obj = map.get(key); if (obj == null) return def; if (obj instanceof Boolean b) return b; return Boolean.parseBoolean(obj.toString()); } - public static Double getDouble(Object obj, Double def) { + public static Double getDouble(Map map, String key, Double def) { + if (map == null) return def; + Object obj = map.get(key); if (obj == null) return def; if (obj instanceof Number n) return n.doubleValue(); return Double.parseDouble(obj.toString()); } + public static Map getStringMap(Map map, String key) { + Map section = getMap(map, key); + if (section == null) return null; + + Map result = new HashMap<>(); + for (Map.Entry e : section.entrySet()) { + result.put(String.valueOf(e.getKey()), String.valueOf(e.getValue())); + } + return result; + } + + public static Map getMap(Map map, String key) { + if (map == null) return null; + return map.get(key) instanceof Map m ? m : null; + } + + public static List getStringList(Map map, String key) { + if (map == null) return List.of(); + return map.get(key) instanceof List l + ? l.stream().map(String::valueOf).toList() + : List.of(); + } + public static Object deepCopyObject(Object value) { if (value instanceof Map map) { Map copy = new HashMap<>(); diff --git a/src/main/java/fr/openmc/core/utils/text/DateUtils.java b/src/main/java/fr/openmc/core/utils/text/DateUtils.java index 1a69ea521..fe0675a82 100644 --- a/src/main/java/fr/openmc/core/utils/text/DateUtils.java +++ b/src/main/java/fr/openmc/core/utils/text/DateUtils.java @@ -2,10 +2,7 @@ import fr.openmc.core.utils.text.messages.TranslationManager; import net.kyori.adventure.text.Component; -import java.time.DayOfWeek; -import java.time.Duration; -import java.time.LocalDate; -import java.time.LocalDateTime; + import java.time.*; import java.time.format.DateTimeFormatter; import java.time.format.TextStyle; @@ -224,7 +221,11 @@ public static long getSecondsUntilDayOfWeekTime(DayOfWeek dayOfWeek, int hour, i public static long getDelayBetweenNow(LocalDateTime time) { LocalDateTime now = getLocalDateTime(); - return ChronoUnit.SECONDS.between(now, time); } + + public static long getDelayBetweenNowMillis(LocalDateTime time) { + LocalDateTime now = getLocalDateTime(); + return ChronoUnit.MILLIS.between(now, time); + } } diff --git a/src/main/java/fr/openmc/core/utils/text/fonts/SmallCapsUtils.java b/src/main/java/fr/openmc/core/utils/text/fonts/SmallCapsUtils.java index ccc30bc38..28f98dc4c 100644 --- a/src/main/java/fr/openmc/core/utils/text/fonts/SmallCapsUtils.java +++ b/src/main/java/fr/openmc/core/utils/text/fonts/SmallCapsUtils.java @@ -13,7 +13,7 @@ public class SmallCapsUtils { public final static Key SMALL_CAPS_FONT = Key.key("omc_fonts", "small_caps"); public static Component toSmall(Player player, String text){ - Component component = Component.text(text.toLowerCase()); + Component component = Component.text(text); return BedrockHook.isBedrockPlayer(player) ? component : component.font(SMALL_CAPS_FONT); } diff --git a/src/main/java/fr/openmc/riftengine/api/registry/scanner/ScannerRegistry.java b/src/main/java/fr/openmc/riftengine/api/registry/scanner/ScannerRegistry.java index 8a5df67c6..b15b8a257 100644 --- a/src/main/java/fr/openmc/riftengine/api/registry/scanner/ScannerRegistry.java +++ b/src/main/java/fr/openmc/riftengine/api/registry/scanner/ScannerRegistry.java @@ -2,18 +2,32 @@ import fr.openmc.core.bootstrap.registries.KeyedRegistry; import fr.openmc.core.bootstrap.registries.Registry; +import fr.openmc.riftengine.api.scanner.blocks.BlockStateScanner; +import fr.openmc.riftengine.api.scanner.equipements.EquipementsScanner; import fr.openmc.riftengine.api.scanner.general.YamlNamespaceIAScanner; import fr.openmc.riftengine.api.scanner.general.YamlScanner; +import fr.openmc.riftengine.api.scanner.icons.CaracterUnicodeCacheScanner; import fr.openmc.riftengine.api.scanner.icons.IconScanner; +import fr.openmc.riftengine.api.scanner.icons.OffsetCaracterScanner; import fr.openmc.riftengine.api.scanner.items.CustomModelDataScanner; import fr.openmc.riftengine.api.scanner.items.ItemScanner; +import fr.openmc.riftengine.api.scanner.sounds.SoundScanner; public class ScannerRegistry extends Registry> implements KeyedRegistry> { + public final SoundScanner SOUNDS = register(new SoundScanner()); + + public final CaracterUnicodeCacheScanner CARACTER_UNICODE_CACHE = register(new CaracterUnicodeCacheScanner()); + public final OffsetCaracterScanner OFFSET_CARACTER = register(new OffsetCaracterScanner()); public final IconScanner ICONS = register(new IconScanner()); + public final ItemScanner ITEMS = register(new ItemScanner()); + public final EquipementsScanner ARMORS = register(new EquipementsScanner()); + public final CustomModelDataScanner CUSTOM_MODEL_DATA_CACHE = register(new CustomModelDataScanner()); + public final BlockStateScanner BLOCKSTATES_CACHE = register(new BlockStateScanner()); + public final YamlNamespaceIAScanner YAML_ITEMSADDER_NAMESPACE = register(new YamlNamespaceIAScanner()); public final YamlScanner YAML = register(new YamlScanner()); diff --git a/src/main/java/fr/openmc/riftengine/api/scanner/blocks/BlockStateScanner.java b/src/main/java/fr/openmc/riftengine/api/scanner/blocks/BlockStateScanner.java new file mode 100644 index 000000000..d485c03f2 --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/api/scanner/blocks/BlockStateScanner.java @@ -0,0 +1,67 @@ +package fr.openmc.riftengine.api.scanner.blocks; + +import fr.openmc.core.OMCPlugin; +import fr.openmc.core.hooks.itemsadder.ItemsAdderHook; +import fr.openmc.core.utils.FilesUtils; +import fr.openmc.core.utils.YmlUtils; +import fr.openmc.riftengine.api.registry.scanner.AbstractScanner; +import fr.openmc.riftengine.api.utils.IdentifierUtils; +import org.bukkit.Material; + +import java.nio.file.Path; +import java.util.Arrays; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * Scan le cache des BlockStates et des BlockMaterials qui sont assignés par ItemsAdder + */ +public class BlockStateScanner extends AbstractScanner, Void> { + + public Map scan(Void voyd) throws Exception { + Path blockstatesFolderPath = ItemsAdderHook.getItemsAdderPath(OMCPlugin.getInstance().getDataPath()) + .resolve("storage").resolve("blockstates"); + Map blockstates = new HashMap<>(); // + + for (String fileName : FilesUtils.listFileNames(blockstatesFolderPath.toAbsolutePath().toString())) { + Path filePath = blockstatesFolderPath.resolve(fileName); + Map root = YmlUtils.loadYml(filePath); + if (root == null) continue; + + for (var iterRoot : root.entrySet()) { + String key = iterRoot.getKey(); + + if (!(iterRoot.getValue() instanceof String valueStr)) continue; + + blockstates.put(key, new CustomBlockState(key, + "minecraft:" + IdentifierUtils.removeExtensionPath(fileName), + normalizeState(valueStr) + )); + } + } + + return blockstates; + } + + // ex d'id: omc_blocks:aywenite_ore, javaBlock: minecraft:note_block, state: [powered=true] + public record CustomBlockState(String id, String javaBlock, String state) { + public Material materialBlock() { + return Material.matchMaterial(javaBlock); + } + } + + /** + * Enleve les crochets et mets dans l'ordre les states afin que geyser ne throw pas d'erreur + * @param state le state d'un block [powered=true, gngng...] + * @return le state normalisé + */ + private String normalizeState(String state) { + return Arrays.stream(state.replace("[", "").replace("]", "").split(",")) + .map(String::trim) + .filter(p -> !p.isEmpty()) + .sorted(Comparator.comparing((String p) -> p.substring(0, p.indexOf('=')))) + .collect(Collectors.joining(",")); + } +} diff --git a/src/main/java/fr/openmc/riftengine/api/scanner/equipements/EquipementEntry.java b/src/main/java/fr/openmc/riftengine/api/scanner/equipements/EquipementEntry.java new file mode 100644 index 000000000..5bcd88bea --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/api/scanner/equipements/EquipementEntry.java @@ -0,0 +1,30 @@ +package fr.openmc.riftengine.api.scanner.equipements; + +import java.nio.file.Path; + +public record EquipementEntry(String namespace, String key, String layer1Path, String layer2Path) { + public String namespacedId() { + return namespace + ":" + key; + } + + public Path getLayer1Path(Path javaRootPath) { + return baseLayerPath(javaRootPath).resolve("humanoid").resolve(key + ".png"); + } + + public Path getLayer2Path(Path javaRootPath) { + return baseLayerPath(javaRootPath).resolve("humanoid_leggings").resolve(key + ".png"); + } + + private Path baseLayerPath(Path javaRootPath) { + return javaRootPath.resolve("assets") + .resolve(namespace).resolve("textures/entity/equipment/"); + } + + public Path getLayer1BedrockPath(Path bedrockRootPath) { + return bedrockRootPath.resolve("textures").resolve(layer1Path + ".png"); + } + + public Path getLayer2BedrockPath(Path bedrockRootPath) { + return bedrockRootPath.resolve("textures").resolve(layer2Path + ".png"); + } +} diff --git a/src/main/java/fr/openmc/riftengine/api/scanner/equipements/EquipementsScanner.java b/src/main/java/fr/openmc/riftengine/api/scanner/equipements/EquipementsScanner.java new file mode 100644 index 000000000..798b1b9a0 --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/api/scanner/equipements/EquipementsScanner.java @@ -0,0 +1,49 @@ +package fr.openmc.riftengine.api.scanner.equipements; + +import fr.openmc.core.OMCRegistry; +import fr.openmc.core.utils.YmlUtils; +import fr.openmc.riftengine.api.registry.scanner.AbstractScanner; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * Scan tout les equipements initialisé par ItemsAdder + */ +public class EquipementsScanner extends AbstractScanner, Path> { + public List scan(Path itemsAdderContentsPath) throws Exception { + if (!Files.isDirectory(itemsAdderContentsPath)) return new ArrayList<>(); + + List ymlFiles = OMCRegistry.SCANNERS.YAML.scan(itemsAdderContentsPath); + + List result = new ArrayList<>(); + + for (Path ymlFile : ymlFiles) { + Map root = YmlUtils.loadYml(ymlFile); + + if (root == null) continue; + + Map equipments = YmlUtils.getMap(root, "equipments"); + + if (equipments == null) continue; + + String namespace = OMCRegistry.SCANNERS.YAML_ITEMSADDER_NAMESPACE.scan(root); + + for (Map.Entry entry : equipments.entrySet()) { + String key = String.valueOf(entry.getKey()); + Map keyInfo = YmlUtils.getMap(equipments, key); + + result.add(new EquipementEntry( + namespace, + key, + YmlUtils.getString(keyInfo, "layer_1", null), + YmlUtils.getString(keyInfo, "layer_2", null))); + } + } + + return result; + } +} diff --git a/src/main/java/fr/openmc/riftengine/api/scanner/icons/CaracterUnicodeCacheScanner.java b/src/main/java/fr/openmc/riftengine/api/scanner/icons/CaracterUnicodeCacheScanner.java new file mode 100644 index 000000000..fcfabe315 --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/api/scanner/icons/CaracterUnicodeCacheScanner.java @@ -0,0 +1,31 @@ +package fr.openmc.riftengine.api.scanner.icons; + +import fr.openmc.core.utils.YmlUtils; +import fr.openmc.riftengine.api.registry.scanner.AbstractScanner; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Map; + +public class CaracterUnicodeCacheScanner extends AbstractScanner, Path> { + private final String TARGET_FILE = "storage/font_images_unicode_cache.yml"; + + public Map scan(Path itemsAdderDataPath) throws IOException { + Map caractersByNamespacedId = new HashMap<>(); + + Map cache = YmlUtils.loadYml(itemsAdderDataPath.resolve(TARGET_FILE)); + if (cache == null) return caractersByNamespacedId; + + for (Map.Entry entry : cache.entrySet()) { + String namespacedId = entry.getKey(); + String character = YmlUtils.getString(cache, namespacedId, ""); + + if (character.isEmpty()) continue; + + caractersByNamespacedId.put(character.charAt(0), namespacedId); + } + + return caractersByNamespacedId; + } +} diff --git a/src/main/java/fr/openmc/riftengine/api/scanner/icons/IconEntry.java b/src/main/java/fr/openmc/riftengine/api/scanner/icons/IconEntry.java index 26e95b0d8..7fdccc7e7 100644 --- a/src/main/java/fr/openmc/riftengine/api/scanner/icons/IconEntry.java +++ b/src/main/java/fr/openmc/riftengine/api/scanner/icons/IconEntry.java @@ -34,9 +34,9 @@ public static IconEntry from(Path sourceYml, String namespace, String key, Map IdentifierUtils.resolveTextureId(javaRoot, IdentifierUtils.normalizeId(String.valueOf(data.get("path")), namespace)), permission, - YmlUtils.getBool(data.get("show_in_gui"), true), - YmlUtils.getDouble(data.get("scale_ratio"), null), - YmlUtils.getInt(data.get("y_position"), null), + YmlUtils.getBool(data, "show_in_gui", true), + YmlUtils.getDouble(data, "scale_ratio", null), + YmlUtils.getInt(data, "y_position", null), sourceYml ); } diff --git a/src/main/java/fr/openmc/riftengine/api/scanner/icons/OffsetCaracterScanner.java b/src/main/java/fr/openmc/riftengine/api/scanner/icons/OffsetCaracterScanner.java new file mode 100644 index 000000000..fc40630ce --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/api/scanner/icons/OffsetCaracterScanner.java @@ -0,0 +1,35 @@ +package fr.openmc.riftengine.api.scanner.icons; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import fr.openmc.core.utils.JsonUtils; +import fr.openmc.riftengine.api.registry.scanner.AbstractScanner; + +import java.nio.file.Path; +import java.util.HashSet; +import java.util.Set; + +public class OffsetCaracterScanner extends AbstractScanner, Path> { + private final String TARGET_FILE = "assets/minecraft/font/default.json"; + + public Set scan(Path javaRootPath) { + Set offsetCaracters = new HashSet<>(); + + JsonObject jsonObject = JsonUtils.loadJson(javaRootPath.resolve(TARGET_FILE)); + for (JsonElement elt : jsonObject.getAsJsonArray("providers")) { + JsonObject provider = elt.getAsJsonObject(); + + if (!(provider.has("file") && + JsonUtils.getString(provider, "file", "e").equals("char/black.png"))) continue; + + JsonArray chars = provider.getAsJsonArray("chars"); + + for (JsonElement charElt : chars) { + offsetCaracters.add(charElt.getAsString().charAt(0)); + } + } + + return offsetCaracters; + } +} diff --git a/src/main/java/fr/openmc/riftengine/api/scanner/items/ItemEntry.java b/src/main/java/fr/openmc/riftengine/api/scanner/items/ItemEntry.java index c241a9318..96985850d 100644 --- a/src/main/java/fr/openmc/riftengine/api/scanner/items/ItemEntry.java +++ b/src/main/java/fr/openmc/riftengine/api/scanner/items/ItemEntry.java @@ -1,30 +1,41 @@ package fr.openmc.riftengine.api.scanner.items; - -import fr.openmc.riftengine.api.scanner.items.entry.ItemBehaviour; +import fr.openmc.core.OMCRegistry; +import fr.openmc.core.utils.YmlUtils; +import fr.openmc.riftengine.api.scanner.equipements.EquipementEntry; import fr.openmc.riftengine.api.scanner.items.entry.ItemGraphics; +import fr.openmc.riftengine.api.scanner.items.entry.ItemInfo; +import fr.openmc.riftengine.api.scanner.items.entry.ItemModel; import fr.openmc.riftengine.api.scanner.items.entry.ItemResource; +import fr.openmc.riftengine.api.scanner.items.entry.behaviours.IABehaviour; +import fr.openmc.riftengine.api.scanner.items.entry.behaviours.block.BlocksBehaviour; import fr.openmc.riftengine.api.utils.IdentifierUtils; import lombok.Getter; import org.bukkit.Material; import java.nio.file.Path; -import java.util.*; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; @Getter public class ItemEntry { + public static final String DEFAULT_STATE = "normal"; + private final String namespace; private final String key; private final Integer customModelData; private final Material material; + private final String tooltipResourceId; private final ItemResource resource; private final ItemGraphics graphics; - private final Function> resourcePath; + private final ItemModel model; + private final Function> resourcePath; - private final ItemBehaviour behaviour; + private final IABehaviour behaviour; private final Path sourceYml; @@ -33,14 +44,15 @@ private ItemEntry( String key, Integer customModelData, Material material, + String tooltipResourceId, // * Méthodes de création d'items (moderne ou legacy) ItemResource resource, ItemGraphics graphics, - Function> resourcePath, + ItemModel model, + Function> resourcePath, - // tqdq rift engine faire un mapping des behavours (blocks et furnitures) - ItemBehaviour behaviour, + IABehaviour behaviour, Path sourceYml ) { @@ -48,23 +60,35 @@ private ItemEntry( this.key = key; this.customModelData = customModelData; this.material = material; + this.tooltipResourceId = tooltipResourceId; this.resource = resource; this.graphics = graphics; + this.model = model; this.resourcePath = resourcePath; this.behaviour = behaviour; this.sourceYml = sourceYml; } - public static ItemEntry from(Map> cmdCache, Path sourceYml, String namespace, String key, Map data) { + public static ItemEntry from(Path sourceYml, + String namespace, + String key, + Map data, + List equipements) throws Exception { ItemResource itemResource = ItemResource.from(data); ItemGraphics itemGraphics = ItemGraphics.from(data); - ItemBehaviour behaviour = ItemBehaviour.from(data); - Material material = getMaterial(itemResource, itemGraphics); + ItemInfo itemInfo = ItemInfo.from(namespace, key, material); + ItemModel itemModel = new ItemModel(itemInfo, itemResource, itemGraphics); + String tooltipResourceId = YmlUtils.getString(data, "tooltip_style", null); + + IABehaviour behaviour = IABehaviour.from(itemInfo, data, equipements); Integer customModelData = null; - Map map = cmdCache.get(material); + if (behaviour.isBlock() && behaviour instanceof BlocksBehaviour blockBehaviour) + material = blockBehaviour.blockState().materialBlock(); + + Map map = OMCRegistry.SCANNERS.CUSTOM_MODEL_DATA_CACHE.getCache(null).get(material); if (map != null && map.get(namespace + ":" + key) != null) customModelData = map.get(namespace + ":" + key); @@ -73,40 +97,36 @@ public static ItemEntry from(Map> cmdCache, Path key, customModelData, material, + tooltipResourceId, itemResource, itemGraphics, + itemModel, resolvePathFunction(namespace, itemGraphics, itemResource), behaviour, sourceYml ); } - public Set getBestResourcesId() { + public Map getBestResourcesId() { if (resource != null) { if (resource.hasTextures()) return resource.textures().stream() .map(id -> IdentifierUtils.normalizeId(id, namespace)) - .collect(Collectors.toSet()); + .collect(Collectors.toMap(id -> DEFAULT_STATE, id -> id)); else if (resource.hasModel()) - return Collections.singleton(IdentifierUtils.normalizeId(resource.model(), namespace)); + return getMapResource(IdentifierUtils.normalizeId(resource.model(), namespace)); } // * Méthode graphics if (graphics != null) { if (graphics.hasModel()) { - return Collections.singleton(IdentifierUtils.normalizeId(graphics.model(), namespace)); + return getMapResource(IdentifierUtils.normalizeId(graphics.model(), namespace)); } if (graphics.hasTexture()) { - return Collections.singleton(IdentifierUtils.normalizeId(graphics.texture(), namespace)); + return getMapResource(IdentifierUtils.normalizeId(graphics.texture(), namespace)); } if (graphics.hasTextures()) { - Set texturesNormalized = new HashSet<>(); - - for (String value : graphics.textures().values()) { - texturesNormalized.add(IdentifierUtils.normalizeId(value, namespace)); - } - - return texturesNormalized; + return new HashMap<>(graphics.textures()); } } @@ -126,29 +146,35 @@ private static Material getMaterial(ItemResource resource, ItemGraphics graphics return byDefault; } - private static Function> resolvePathFunction(String namespace, ItemGraphics graphics, ItemResource resource) { + private static Function> resolvePathFunction(String namespace, ItemGraphics graphics, ItemResource resource) { // * Méthode legacy if (resource != null) { if (resource.hasTextures()) return javaRoot -> resource.textures().stream() .map(id -> IdentifierUtils.resolveTextureId(javaRoot, IdentifierUtils.normalizeId(id, namespace))) - .collect(Collectors.toSet()); + .collect(Collectors.toMap(v -> DEFAULT_STATE, k -> k)); else if (resource.hasModel()) - return javaRoot -> Collections.singleton(IdentifierUtils.resolveModelId(javaRoot, + return javaRoot -> getMapResource(IdentifierUtils.resolveModelId(javaRoot, IdentifierUtils.normalizeId(resource.model(), namespace))); } // * Méthode graphics if (graphics != null) { if (graphics.hasModel()) { - return javaRoot -> Collections.singleton(IdentifierUtils.resolveModelId(javaRoot, + return javaRoot -> getMapResource(IdentifierUtils.resolveModelId(javaRoot, IdentifierUtils.normalizeId(graphics.model(), namespace))); } if (graphics.hasTexture()) { - return javaRoot -> Collections.singleton(IdentifierUtils.resolveTextureId(javaRoot, + return javaRoot -> getMapResource(IdentifierUtils.resolveTextureId(javaRoot, IdentifierUtils.normalizeId(graphics.texture(), namespace))); } + if (graphics.hasTextures()) { + return javaRoot -> graphics.textures().entrySet().stream() + .map(entry -> Map.entry(entry.getKey(), IdentifierUtils.resolveTextureId(javaRoot, + IdentifierUtils.normalizeId(entry.getValue(), namespace)))) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + } } return _ -> null; @@ -157,4 +183,8 @@ else if (resource.hasModel()) public String namespacedId() { return namespace + ":" + key; } + + public static Map getMapResource(T value) { + return Map.of(DEFAULT_STATE, value); + } } \ No newline at end of file diff --git a/src/main/java/fr/openmc/riftengine/api/scanner/items/ItemScanner.java b/src/main/java/fr/openmc/riftengine/api/scanner/items/ItemScanner.java index a51b8e568..4bf30848b 100644 --- a/src/main/java/fr/openmc/riftengine/api/scanner/items/ItemScanner.java +++ b/src/main/java/fr/openmc/riftengine/api/scanner/items/ItemScanner.java @@ -4,7 +4,7 @@ import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.utils.YmlUtils; import fr.openmc.riftengine.api.registry.scanner.AbstractScanner; -import org.bukkit.Material; +import fr.openmc.riftengine.api.scanner.equipements.EquipementEntry; import java.nio.file.Files; import java.nio.file.Path; @@ -20,6 +20,11 @@ public List scan(Path itemsAdderContentsPath) throws Exception { if (!Files.isDirectory(itemsAdderContentsPath)) return new ArrayList<>(); List ymlFiles = OMCRegistry.SCANNERS.YAML.scan(itemsAdderContentsPath); + List equipements = OMCRegistry.SCANNERS.ARMORS.scan(itemsAdderContentsPath); + + // actualise les caches + OMCRegistry.SCANNERS.CUSTOM_MODEL_DATA_CACHE.getCache(null); + OMCRegistry.SCANNERS.BLOCKSTATES_CACHE.getCache(null); List result = new ArrayList<>(); @@ -32,13 +37,12 @@ public List scan(Path itemsAdderContentsPath) throws Exception { if (!(itemsObj instanceof Map itemsMap)) continue; String namespace = OMCRegistry.SCANNERS.YAML_ITEMSADDER_NAMESPACE.scan(root); - Map> mappedCache = OMCRegistry.SCANNERS.CUSTOM_MODEL_DATA_CACHE.scan(null); for (Map.Entry entry : itemsMap.entrySet()) { String key = String.valueOf(entry.getKey()); if (!(entry.getValue() instanceof Map data)) continue; - result.add(ItemEntry.from(mappedCache, ymlFile, namespace, key, data)); + result.add(ItemEntry.from(ymlFile, namespace, key, data, equipements)); } } diff --git a/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/ItemBehaviour.java b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/ItemBehaviour.java deleted file mode 100644 index 5615cad1b..000000000 --- a/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/ItemBehaviour.java +++ /dev/null @@ -1,28 +0,0 @@ -package fr.openmc.riftengine.api.scanner.items.entry; - -import java.util.Map; - -public record ItemBehaviour(boolean isBlockBehaviour) { - public static ItemBehaviour from(Map data) { - Object resourceObj = data.get("behaviours"); - if (!(resourceObj instanceof Map behaviour)) - return new ItemBehaviour(false); - - Object blockObj = behaviour.get("block"); - - if (blockObj != null) - return new ItemBehaviour(true); - - Object specificPropertiesObj = data.get("specific_properties"); - - if (!(specificPropertiesObj instanceof Map specificProperties)) - return new ItemBehaviour(false); - - Object blockObj2 = specificProperties.get("block"); - - if (blockObj2 != null) - return new ItemBehaviour(true); - - return new ItemBehaviour(false); - } -} diff --git a/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/ItemGraphics.java b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/ItemGraphics.java index 42b492061..45e56b23d 100644 --- a/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/ItemGraphics.java +++ b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/ItemGraphics.java @@ -3,40 +3,30 @@ import fr.openmc.core.utils.YmlUtils; import org.bukkit.Material; -import java.util.HashMap; import java.util.Map; public record ItemGraphics( String texture, Map textures, String model, + String parent, // ex block/cross Material material ) { public static ItemGraphics from(Map data) { - if (!(data.get("graphics") instanceof Map graphics)) - return new ItemGraphics(null, null, null, Material.PAPER); - - - Map textures = null; - - Object texturesObj = graphics.get("textures"); - if (texturesObj instanceof Map texturesMap) { - textures = new HashMap<>(); - - for (Map.Entry entry : texturesMap.entrySet()) { - textures.put( - entry.getKey().toString(), - entry.getValue().toString() - ); - } - } - - String texture = YmlUtils.getString(graphics.get("texture"), null); - String model = YmlUtils.getString(graphics.get("model"), null); - Material material = Material.valueOf(YmlUtils.getString( - data.get("material"), ItemResource.DEFAULT_MATERIAL).toUpperCase()); - - return new ItemGraphics(texture, textures, model, material); + Map graphics = YmlUtils.getMap(data, "graphics"); + if (graphics == null) + return new ItemGraphics(null, null, null, null, Material.PAPER); + + Material material = Material.valueOf( + YmlUtils.getString(data, "material", ItemResource.DEFAULT_MATERIAL).toUpperCase()); + + return new ItemGraphics( + YmlUtils.getString(graphics, "texture", null), + YmlUtils.getStringMap(graphics, "textures"), + YmlUtils.getString(graphics, "model", null), + YmlUtils.getString(graphics, "parent", null), + material + ); } public boolean hasTexture() { diff --git a/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/ItemInfo.java b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/ItemInfo.java new file mode 100644 index 000000000..3647a08f1 --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/ItemInfo.java @@ -0,0 +1,17 @@ +package fr.openmc.riftengine.api.scanner.items.entry; + +import org.bukkit.Material; + +public record ItemInfo(String namespace, + String key, + Material material) { + public static ItemInfo from(String namespace, + String key, + Material material) { + return new ItemInfo(namespace, key, material); + } + + public String namespacedId() { + return namespace + ":" + key; + } +} diff --git a/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/ItemModel.java b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/ItemModel.java new file mode 100644 index 000000000..ed4293610 --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/ItemModel.java @@ -0,0 +1,104 @@ +package fr.openmc.riftengine.api.scanner.items.entry; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import fr.openmc.core.utils.JsonUtils; +import fr.openmc.riftengine.api.utils.IdentifierUtils; + +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public record ItemModel(ItemInfo info, ItemResource resource, ItemGraphics graphics) { + public List texturesPath(Path javaRootPath) { + List texturesPath = new ArrayList<>(); + + String model = getModel(); + + if (model == null) return texturesPath; + + Path targetJson = IdentifierUtils.resolveModelId(javaRootPath, info.namespace(), model); + JsonObject rootModelJson = JsonUtils.loadJson(targetJson); + + if (rootModelJson == null) return texturesPath; + + JsonObject textures = rootModelJson.getAsJsonObject("textures"); + + if (textures == null) return texturesPath; + Map texturesMap = textures.asMap(); + + if (texturesMap == null) return texturesPath; + + for (JsonElement textureName : texturesMap.values()) { + String textureNameStr = textureName.getAsString(); + if (textureNameStr.startsWith("#")) continue; + if (textureNameStr.startsWith("_")) + textureNameStr = textureNameStr.substring(1); + + String[] textureSplit = textureNameStr.split(":"); + + texturesPath.add(textureSplit[1]); + } + return texturesPath; + } + + public String namespace() { + return this.info.namespace(); + } + + /** + * ex omc_dream:orb/orb_cloud en models/entity/attachable/omc_dream/orb/orb_cloud.geo.json + */ + public String toBedrockModelPath() { + String[] id = IdentifierUtils.normalizeId(modelId()).split(":"); + return "models/entity/attachable/" + id[0] + "/" + id[1] + ".geo.json"; + } + + /** + * ex omc_dream:orb/orb_cloud en geometry.omc_dream.orb.orb_cloud + */ + public String toBedrockGeometryId() { + String[] id = IdentifierUtils.normalizeId(modelId()).split(":"); + return "geometry." + id[0] + "." + id[1].replace('/', '.'); + } + + /** + * ex omc_dream:orb/orb_cloud en textures/omc_dream/atlas/orb_cloud + */ + public String toBedrockAtlasPath() { + String[] id = IdentifierUtils.normalizeId(modelId()).split(":"); + return "textures/" + id[0] + "/atlas/" + id[1]; + } + + public String toBedrockAnimationId() { + String[] id = IdentifierUtils.normalizeId(modelId()).split(":"); + return "animation." + id[0] + "." + id[1].replace('/', '.'); + } + + public String toBedrockAnimationPath() { + String[] id = IdentifierUtils.normalizeId(modelId()).split(":"); + return "animations/" + id[0] + "/" + id[1] + ".animation.json"; + } + + public boolean hasModel() { + return getModel() != null; + } + + public String getModel() { + if (graphics != null && graphics.hasModel()) { + return graphics.model(); + } else if (resource != null && resource.hasModel()) { + return resource.model(); + } + return null; + } + + /** + * @return l'id du model avec namespace, ex omc_dream:orb/orb_cloud + */ + public String modelId() { + if (getModel() == null) return null; + return IdentifierUtils.normalizeId(this.getModel(), info.namespace()); + } +} diff --git a/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/ItemResource.java b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/ItemResource.java index 7a526f264..9801a7805 100644 --- a/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/ItemResource.java +++ b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/ItemResource.java @@ -19,26 +19,23 @@ public static ItemResource from(Map data) { if (!(resourceObj instanceof Map resource)) return new ItemResource(Material.valueOf(DEFAULT_MATERIAL), false, List.of(), null); - Material material = Material.valueOf(YmlUtils.getString( - resource.get("material"), DEFAULT_MATERIAL).toUpperCase()); + Material material = Material.matchMaterial(YmlUtils.getString(resource, "material", DEFAULT_MATERIAL).toUpperCase()); - boolean generate = YmlUtils.getBool(resource.get("generate"), false); - - List textures = resource.get("textures") instanceof List list && resource.get("textures") != null - ? list.stream().map(String::valueOf).toList() - : List.of(); - - if (resource.get("textures") == null && resource.get("texture") != null && textures.isEmpty()) - textures = List.of(String.valueOf(resource.get("texture"))); + return new ItemResource(material, + YmlUtils.getBool(resource, "generate", false), + getTextures(resource), + YmlUtils.getString(resource, "model_path", null) + ); + } - if (textures.isEmpty() && resource.get("textures") instanceof String string) - textures = List.of(string); + private static List getTextures(Map resource) { + if (resource.get("textures") instanceof List) + return YmlUtils.getStringList(resource, "textures"); - String modelPath = resource.get("model_path") != null - ? String.valueOf(resource.get("model_path")) - : null; + String single = YmlUtils.getString(resource, "textures", + YmlUtils.getString(resource, "texture", null)); - return new ItemResource(material, generate, textures, modelPath); + return single == null ? List.of() : List.of(single); } public boolean hasTextures() { diff --git a/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/EmptyBehaviour.java b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/EmptyBehaviour.java new file mode 100644 index 000000000..c0ac87c42 --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/EmptyBehaviour.java @@ -0,0 +1,4 @@ +package fr.openmc.riftengine.api.scanner.items.entry.behaviours; + +public class EmptyBehaviour implements IABehaviour { +} diff --git a/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/IABehaviour.java b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/IABehaviour.java new file mode 100644 index 000000000..542b9a61d --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/IABehaviour.java @@ -0,0 +1,36 @@ +package fr.openmc.riftengine.api.scanner.items.entry.behaviours; + +import fr.openmc.riftengine.api.scanner.equipements.EquipementEntry; +import fr.openmc.riftengine.api.scanner.items.entry.ItemInfo; +import fr.openmc.riftengine.api.scanner.items.entry.behaviours.armors.ArmorsBehaviour; +import fr.openmc.riftengine.api.scanner.items.entry.behaviours.block.BlocksBehaviour; + +import java.util.List; +import java.util.Map; + +public interface IABehaviour { + static IABehaviour from(ItemInfo info, Map data, List equipements) throws Exception { + if (data == null) return new EmptyBehaviour(); + Object resourceObj = data.get("behaviours"); + + IABehaviour behaviour = BlocksBehaviour.detectBlockBehaviour(info, data, resourceObj); + + if (behaviour instanceof EmptyBehaviour) { + return ArmorsBehaviour.detectArmorBehaviour(info, data, equipements); + } + + return behaviour; + } + + default boolean isItem() { + return !this.isBlock(); + } + + default boolean isArmor() { + return this instanceof ArmorsBehaviour; + } + + default boolean isBlock() { + return this instanceof BlocksBehaviour; + } +} diff --git a/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/armors/ArmorType.java b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/armors/ArmorType.java new file mode 100644 index 000000000..a2b8e4130 --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/armors/ArmorType.java @@ -0,0 +1,36 @@ +package fr.openmc.riftengine.api.scanner.items.entry.behaviours.armors; + +import lombok.Getter; +import org.bukkit.Material; + +import java.util.Arrays; + +@Getter +public enum ArmorType { + HELMET("helmet", "helmet"), + CHESTPLATE("chestplate", "chest"), + LEGGINGS("leggings", "leg"), + BOOTS("boots", "boot") + ; + + private final String type; + private final String shortType; + + ArmorType(String type, String shortType) { + this.type = type; + this.shortType = shortType; + } + + public static ArmorType from(Material material) { + return Arrays.stream(ArmorType.values()) + .filter(t -> material.name().toLowerCase().contains(t.type)) + .findFirst() + .orElse(null); + } + + public String selectLayer(String layer1, String layer2) { + if (this.equals(ArmorType.LEGGINGS)) + return layer2; + return layer1; + } +} diff --git a/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/armors/ArmorsBehaviour.java b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/armors/ArmorsBehaviour.java new file mode 100644 index 000000000..19a0e2cdf --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/armors/ArmorsBehaviour.java @@ -0,0 +1,33 @@ +package fr.openmc.riftengine.api.scanner.items.entry.behaviours.armors; + +import fr.openmc.core.utils.YmlUtils; +import fr.openmc.riftengine.api.scanner.equipements.EquipementEntry; +import fr.openmc.riftengine.api.scanner.items.entry.ItemInfo; +import fr.openmc.riftengine.api.scanner.items.entry.behaviours.EmptyBehaviour; +import fr.openmc.riftengine.api.scanner.items.entry.behaviours.IABehaviour; + +import java.util.List; +import java.util.Map; + +public record ArmorsBehaviour(EquipementEntry entry, ArmorType type) implements IABehaviour { + private static ArmorsBehaviour from(ItemInfo itemInfo, List equipements, Map equipement) { + String id = YmlUtils.getString(equipement, "id", null); + + EquipementEntry entry = equipements.stream() + .filter(e -> e.namespacedId().equals(id)) + .findFirst() + .orElse(null); + + ArmorType type = ArmorType.from(itemInfo.material()); + + return new ArmorsBehaviour(entry, type); + } + + public static IABehaviour detectArmorBehaviour(ItemInfo info, Map data, List equipements) { + Map equipment = YmlUtils.getMap(data, "equipment"); + + if (equipment == null) return new EmptyBehaviour(); + + return ArmorsBehaviour.from(info, equipements, equipment); + } +} diff --git a/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/block/BlockFaces.java b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/block/BlockFaces.java new file mode 100644 index 000000000..a69cca672 --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/block/BlockFaces.java @@ -0,0 +1,46 @@ +package fr.openmc.riftengine.api.scanner.items.entry.behaviours.block; + +import fr.openmc.riftengine.api.utils.IdentifierUtils; + +import java.util.List; +import java.util.Map; + +public record BlockFaces(String north, String south, String east, String west, String up, String down) { + private static final List BLOCK_FACES = List.of( + "north", "south", "east", "west", "up", "down" + ); + + public static BlockFaces from(Map faces) { + if (faces == null) return null; + + if (!faces.keySet().containsAll(BLOCK_FACES) && !faces.isEmpty()) { + String face = removeExt(faces.values().stream().findFirst().get()); + return new BlockFaces(face, face, face, face, face, face); + } + + return new BlockFaces( + removeExt(faces.get("north")), + removeExt(faces.get("south")), + removeExt(faces.get("east")), + removeExt(faces.get("west")), + removeExt(faces.get("up")), + removeExt(faces.get("down")) + ); + } + + private static String removeExt(String face) { + return IdentifierUtils.removeExtensionPath(face); + } + + + public Map getFaces() { + return Map.of( + "north", north, + "south", south, + "east", east, + "west", west, + "up", up, + "down", down + ); + } +} diff --git a/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/block/BlockType.java b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/block/BlockType.java new file mode 100644 index 000000000..6920ddb11 --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/block/BlockType.java @@ -0,0 +1,21 @@ +package fr.openmc.riftengine.api.scanner.items.entry.behaviours.block; + +public enum BlockType { + REAL_WIRE, + REAL_NOTE, + REAL, + REAL_TRANSPARENT, + ENTITY, + FIRE, // le feu est un bloc cool + UNKNOWN + ; + + static BlockType from(String s) { + if (s == null) return UNKNOWN; + try { + return valueOf(s.toUpperCase()); + } catch (IllegalArgumentException e) { + return UNKNOWN; + } + } +} diff --git a/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/block/BlocksBehaviour.java b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/block/BlocksBehaviour.java new file mode 100644 index 000000000..fdb9a5b2a --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/block/BlocksBehaviour.java @@ -0,0 +1,63 @@ +package fr.openmc.riftengine.api.scanner.items.entry.behaviours.block; + +import fr.openmc.core.OMCRegistry; +import fr.openmc.core.utils.YmlUtils; +import fr.openmc.riftengine.api.scanner.blocks.BlockStateScanner; +import fr.openmc.riftengine.api.scanner.items.entry.ItemInfo; +import fr.openmc.riftengine.api.scanner.items.entry.behaviours.EmptyBehaviour; +import fr.openmc.riftengine.api.scanner.items.entry.behaviours.IABehaviour; + +import java.util.List; +import java.util.Map; + +public record BlocksBehaviour(PlacedModel placedModel, + BlockStateScanner.CustomBlockState blockState, + boolean dropWhenMined, + int lightLevel, + List breakToolsBlacklist, + List breakToolsWhitelist, + double hardness, + double blastResistance, + boolean noExplosion, + BlocksSound sounds +) implements IABehaviour { + private static BlocksBehaviour from(ItemInfo info, Map block) throws Exception { + double hardness = YmlUtils.getDouble(block, "hardness", 2d); + + BlockStateScanner.CustomBlockState blockState = OMCRegistry.SCANNERS.BLOCKSTATES_CACHE.getCache(null) + .get(info.namespacedId()); + + return new BlocksBehaviour( + PlacedModel.from(YmlUtils.getMap(block, "placed_model")), + blockState, + YmlUtils.getBool(block, "drop_when_mined", true), + YmlUtils.getInt(block, "light_level", 0), + YmlUtils.getStringList(block, "break_tools_blacklist"), + YmlUtils.getStringList(block, "break_tools_whitelist"), + hardness, + YmlUtils.getDouble(block, "blast_resistance", hardness * 3), + YmlUtils.getBool(block, "no_explosion", false), + BlocksSound.from(YmlUtils.getMap(block, "sound")) + ); + } + + public static IABehaviour detectBlockBehaviour(ItemInfo info, Map data, Object resourceObj) throws Exception { + Object specificPropertiesObj = data.get("specific_properties"); + + if (resourceObj == null && specificPropertiesObj == null) return new EmptyBehaviour(); + + Map behaviours; + + if (resourceObj instanceof Map b) { + behaviours = b; + } else if (specificPropertiesObj instanceof Map b) { + behaviours = b; + } else return new EmptyBehaviour(); + + + if (behaviours.get("block") instanceof Map block) + return BlocksBehaviour.from(info, block); + + return new EmptyBehaviour(); + } +} diff --git a/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/block/BlocksSound.java b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/block/BlocksSound.java new file mode 100644 index 000000000..d426d7f6a --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/block/BlocksSound.java @@ -0,0 +1,26 @@ +package fr.openmc.riftengine.api.scanner.items.entry.behaviours.block; + +import fr.openmc.core.utils.YmlUtils; + +import java.util.Map; + +public record BlocksSound(IASound breakSound, IASound placeSound) { + static BlocksSound from(Map m) { + return new BlocksSound( + IASound.from(YmlUtils.getMap(m, "break")), + IASound.from(YmlUtils.getMap(m, "place")) + ); + } + + public record IASound(String name, float volume, float pitch) { + static IASound from(Map m) { + if (m == null) return null; + return new IASound( + YmlUtils.getString(m, "name", null), + YmlUtils.getDouble(m, "volume", 1.0).floatValue(), + YmlUtils.getDouble(m, "pitch", 1.0).floatValue() + ); + } + } +} + diff --git a/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/block/PlacedModel.java b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/block/PlacedModel.java new file mode 100644 index 000000000..66597a122 --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/api/scanner/items/entry/behaviours/block/PlacedModel.java @@ -0,0 +1,16 @@ +package fr.openmc.riftengine.api.scanner.items.entry.behaviours.block; + +import fr.openmc.core.utils.YmlUtils; + +import java.util.Map; + +public record PlacedModel(BlockType type, String breakParticles, int rotX, int rotY) { + static PlacedModel from(Map m) { + return new PlacedModel( + BlockType.from(YmlUtils.getString(m, "type", null)), + YmlUtils.getString(m, "break_particles", "BLOCK"), + YmlUtils.getInt(m, "rotx", 0), + YmlUtils.getInt(m, "roty", 0) + ); + } +} \ No newline at end of file diff --git a/src/main/java/fr/openmc/riftengine/api/scanner/sounds/SoundEntry.java b/src/main/java/fr/openmc/riftengine/api/scanner/sounds/SoundEntry.java new file mode 100644 index 000000000..ef1379679 --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/api/scanner/sounds/SoundEntry.java @@ -0,0 +1,36 @@ +package fr.openmc.riftengine.api.scanner.sounds; + +import java.util.List; + +public record SoundEntry(String namespace, String path, List soundResourcesId) { + public String toBedrockEventId() { + return namespace + "." + path; + } + + public String toJavaPath(String defaultNamespace, String resourceId) { + String namespace = defaultNamespace; + String path = resourceId; + String[] split = resourceId.split(":"); + if (split.length == 2) { + namespace = split[0]; + path = split[1]; + } + + return "assets/" + namespace + "/sounds/" + path; + } + + /** + * omc_sounds:ambient/join_rift -> sounds/omc_sounds/ambient/join_rift + */ + public String toBedrockPath(String defaultNamespace, String resourceId) { + String namespace = defaultNamespace; + String path = resourceId; + + String[] split = resourceId.split(":"); + if (split.length == 2) { + namespace = split[0]; + path = split[1]; + } + return "sounds/" + namespace + "/" + path; + } +} \ No newline at end of file diff --git a/src/main/java/fr/openmc/riftengine/api/scanner/sounds/SoundScanner.java b/src/main/java/fr/openmc/riftengine/api/scanner/sounds/SoundScanner.java new file mode 100644 index 000000000..900d0ceeb --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/api/scanner/sounds/SoundScanner.java @@ -0,0 +1,52 @@ +package fr.openmc.riftengine.api.scanner.sounds; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import fr.openmc.core.utils.FilesUtils; +import fr.openmc.core.utils.JsonUtils; +import fr.openmc.riftengine.api.registry.scanner.AbstractScanner; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * Scan tout les sons initialisé par ItemsAdder + */ +public class SoundScanner extends AbstractScanner, Path> { + @Override + public List scan(Path javaRootPath) { + List result = new ArrayList<>(); + Path assetsPath = javaRootPath.resolve("assets"); + + for (String namespace : FilesUtils.listFolderNames(assetsPath.toString())) { + Path file = assetsPath.resolve(namespace).resolve("sounds.json"); + if (!Files.exists(file)) continue; + + JsonObject root = JsonUtils.loadJson(file); + if (root == null) continue; + + for (Map.Entry entry : root.entrySet()) { + SoundEntry soundEntry = parseEntry(namespace, entry.getKey(), entry.getValue()); + if (soundEntry != null) result.add(soundEntry); + } + } + return result; + } + + private SoundEntry parseEntry(String namespace, String eventId, JsonElement element) { + if (!(element instanceof JsonObject eventObj)) return null; + if (!(eventObj.get("sounds") instanceof JsonArray soundsArray)) return null; + + List soundResourceId = new ArrayList<>(); + for (JsonElement elt : soundsArray) { + if (!(elt instanceof JsonObject jsonObject)) continue; + + soundResourceId.add(JsonUtils.getString(jsonObject, "name", null)); + } + return soundResourceId.isEmpty() ? null : new SoundEntry(namespace, eventId, soundResourceId); + } +} diff --git a/src/main/java/fr/openmc/riftengine/api/utils/IdentifierUtils.java b/src/main/java/fr/openmc/riftengine/api/utils/IdentifierUtils.java index 953fc1157..1999fbba3 100644 --- a/src/main/java/fr/openmc/riftengine/api/utils/IdentifierUtils.java +++ b/src/main/java/fr/openmc/riftengine/api/utils/IdentifierUtils.java @@ -24,14 +24,48 @@ public static String normalizeId(String id, String defaultNamespace) { return defaultNamespace + ":" + id; } + public static String removeNamespace(String namespacedId) { + String[] splited = namespacedId.split(":"); + if (splited.length != 2) return namespacedId; + + return splited[1]; + } + /** - * Résout un identifiant en un chemin de fichier dans les assets + * Résout un identifiant en un chemin vers une image (.png) dans les assets */ public static Path resolveTextureId(Path rootPath, String id) { - String normalizedId = normalizeId(id); + return resolveFileId(rootPath, id, ".png"); + } + + /** + * Résout un identifiant en un chemin vers une image (.png) dans les assets + */ + public static Path resolveTextureId(Path rootPath, String namespace, String id) { + return resolveFileId(rootPath, namespace, id, ".png"); + } + + /** + * Résout un identifiant en un chemin vers des meta donnée de mc (.mcmeta) dans les assets + */ + public static Path resolveMetaId(Path rootPath, String id, String ext) { + return resolveFileId(rootPath, id, ext + ".mcmeta"); + } + + /** + * Résout un identifiant en un chemin de fichier dans les assets + */ + public static Path resolveFileId(Path rootPath, String id, String ext) { + return resolveFileId(rootPath, "minecraft", id, ext); + } + + /** + * Résout un identifiant en un chemin de fichier dans les assets + */ + public static Path resolveFileId(Path rootPath, String namespace, String id, String ext) { + String normalizedId = normalizeId(id, namespace); String[] split = normalizedId.split(":", 2); - String namespace; String texturePath; if (split.length == 2) { @@ -42,8 +76,8 @@ public static Path resolveTextureId(Path rootPath, String id) { texturePath = split[0]; } - if (!texturePath.endsWith(".png")) - texturePath += ".png"; + if (!texturePath.endsWith(ext)) + texturePath += ext; return rootPath @@ -56,11 +90,10 @@ public static Path resolveTextureId(Path rootPath, String id) { /** * Résout un identifiant en un chemin de fichier dans les assets pour les models */ - public static Path resolveModelId(Path rootPath, String id) { - String normalizedId = normalizeId(id); + public static Path resolveModelId(Path rootPath, String namespace, String id) { + String normalizedId = normalizeId(id, namespace); String[] split = normalizedId.split(":", 2); - String namespace; String modelPath; if (split.length == 2) { @@ -81,7 +114,17 @@ public static Path resolveModelId(Path rootPath, String id) { .resolve(modelPath); } + /** + * Résout un identifiant en un chemin de fichier dans les assets pour les models + */ + public static Path resolveModelId(Path rootPath, String id) { + return resolveModelId(rootPath, "minecraft", id); + } + public static String toBedrockTexturePath(String javaPath) { + if (!javaPath.endsWith(".png")) + javaPath = javaPath + ".png"; + if (javaPath.startsWith("textures/item/")) return "textures/items/" + javaPath.substring("textures/item/".length()); if (javaPath.startsWith("textures/block/")) diff --git a/src/main/resources/contents/omc_dream/items.yml b/src/main/resources/contents/omc_dream/items.yml index beca51b6a..4afadbdba 100644 --- a/src/main/resources/contents/omc_dream/items.yml +++ b/src/main/resources/contents/omc_dream/items.yml @@ -6,7 +6,7 @@ items: resource: material: {dream_item_material:corrupted_sculk} generate: false - model_path: "minecraft:item/sculk" + model_path: "minecraft:block/sculk" lore: - tooltip_style: "{dream_rarity:corrupted_sculk}" diff --git a/src/main/resources/paper-plugin.yml b/src/main/resources/paper-plugin.yml index 9fc4f692d..9c063effe 100644 --- a/src/main/resources/paper-plugin.yml +++ b/src/main/resources/paper-plugin.yml @@ -30,15 +30,15 @@ dependencies: FastAsyncWorldEdit: load: BEFORE required: false -# Geyser-Spigot: -# load: BEFORE -# required: false -# floodgate: -# load: BEFORE -# required: false -# RiftEngine: -# load: AFTER -# required: false + Geyser-Spigot: + load: BEFORE + required: false + floodgate: + load: BEFORE + required: false + RiftEngine: + load: AFTER + required: false prefix: OMC authors: [ La communauté ] diff --git a/src/test/java/fr/openmc/core/features/economy/EconomyFormattingTest.java b/src/test/java/fr/openmc/core/features/economy/EconomyFormattingTest.java index c0443cd71..205694a39 100644 --- a/src/test/java/fr/openmc/core/features/economy/EconomyFormattingTest.java +++ b/src/test/java/fr/openmc/core/features/economy/EconomyFormattingTest.java @@ -17,50 +17,50 @@ static void setUpLocale() { @Test @DisplayName("Format zero balance") void testFormat_Zero() { - Assertions.assertEquals("0", EconomyManager.getFormattedSimplifiedNumber(0)); + Assertions.assertEquals("0", EconomyManager.getFormattedNumber(0)); } @Test @DisplayName("Format small number without suffix") void testFormat_SmallNumber() { - Assertions.assertEquals("500", EconomyManager.getFormattedSimplifiedNumber(500)); + Assertions.assertEquals("500", EconomyManager.getFormattedNumber(500)); } @Test @DisplayName("Format thousands with k suffix") void testFormat_Thousands() { - String result = EconomyManager.getFormattedSimplifiedNumber(1500); + String result = EconomyManager.getFormattedNumber(1500); Assertions.assertEquals("1.5k", result); } @Test @DisplayName("Format exact thousand") void testFormat_ExactThousand() { - Assertions.assertEquals("1k", EconomyManager.getFormattedSimplifiedNumber(1000)); + Assertions.assertEquals("1k", EconomyManager.getFormattedNumber(1000)); } @Test @DisplayName("Format millions with M suffix") void testFormat_Millions() { - Assertions.assertEquals("3M", EconomyManager.getFormattedSimplifiedNumber(3_000_000)); + Assertions.assertEquals("3M", EconomyManager.getFormattedNumber(3_000_000)); } @Test @DisplayName("Format billions with B suffix") void testFormat_Billions() { - Assertions.assertEquals("1B", EconomyManager.getFormattedSimplifiedNumber(1_000_000_000)); + Assertions.assertEquals("1B", EconomyManager.getFormattedNumber(1_000_000_000)); } @Test @DisplayName("Format with decimal truncation") void testFormat_Decimal() { - String result = EconomyManager.getFormattedSimplifiedNumber(2_500_000); + String result = EconomyManager.getFormattedNumber(2_500_000); Assertions.assertEquals("2.5M", result); } @Test @DisplayName("Format number under 1000") void testFormat_Under1000() { - Assertions.assertEquals("999", EconomyManager.getFormattedSimplifiedNumber(999)); + Assertions.assertEquals("999", EconomyManager.getFormattedNumber(999)); } }