From fe6d37f3de6cc30b6ca1bdc1ebeffa231b330d4e Mon Sep 17 00:00:00 2001 From: nulli0n Date: Mon, 12 Aug 2024 21:36:20 +0500 Subject: [PATCH] v4.2.0 --- .gitignore | 14 +- API/pom.xml | 2 +- .../excellentenchants/api/ConfigBridge.java | 14 + .../api/DistributionMode.java | 8 - .../api/DistributionWay.java | 24 - .../api/EnchantingBridge.java | 21 - .../excellentenchants/api/EnchantmentID.java | 6 + .../api/enchantment/Charges.java | 26 + .../api/enchantment/Cost.java | 11 +- .../api/enchantment/CustomEnchantment.java | 90 +++ .../api/enchantment/Definition.java | 37 + .../api/enchantment/Distribution.java | 22 + .../api/enchantment/EnchantmentData.java | 201 ----- .../api/enchantment/ItemCategory.java | 54 -- .../api/enchantment/ItemsCategory.java | 59 +- .../api/enchantment/Rarity.java | 38 +- .../api/enchantment/TradeType.java | 19 + .../api/enchantment/bridge/FlameWalker.java | 24 + .../api/enchantment/data/ArrowData.java | 14 - .../api/enchantment/data/ArrowSettings.java | 9 - .../api/enchantment/data/ChanceData.java | 21 - .../api/enchantment/data/ChanceSettings.java | 8 - .../api/enchantment/data/PeriodicData.java | 24 - .../enchantment/data/PeriodicSettings.java | 12 - .../api/enchantment/data/PotionData.java | 35 - .../api/enchantment/data/PotionSettings.java | 21 - .../distribution/DistributionOptions.java | 10 - .../distribution/VanillaOptions.java | 12 - .../api/enchantment/meta/ArrowEffects.java | 18 +- .../api/enchantment/meta/ArrowMeta.java | 12 + .../api/enchantment/meta/ChanceMeta.java | 12 + .../api/enchantment/meta/EnchantMeta.java | 45 ++ .../api/enchantment/meta/MetaHolder.java | 8 + .../api/enchantment/meta/Period.java | 48 ++ .../api/enchantment/meta/PeriodMeta.java | 20 + .../api/enchantment/meta/PotionEffects.java | 51 +- .../api/enchantment/meta/PotionMeta.java | 33 + .../api/enchantment/meta/Probability.java | 21 +- .../enchantment/type/BlockBreakEnchant.java | 4 +- .../enchantment/type/BlockDropEnchant.java | 4 +- .../api/enchantment/type/BowEnchant.java | 4 +- .../api/enchantment/type/CombatEnchant.java | 4 +- .../api/enchantment/type/DamageEnchant.java | 4 +- .../api/enchantment/type/DeathEnchant.java | 4 +- .../api/enchantment/type/FishingEnchant.java | 4 +- .../api/enchantment/type/GenericEnchant.java | 4 +- .../api/enchantment/type/InteractEnchant.java | 4 +- .../api/enchantment/type/PassiveEnchant.java | 6 +- Core/pom.xml | 51 +- .../excellentenchants/EnchantsAPI.java | 31 + .../excellentenchants/EnchantsPlugin.java | 135 ++-- .../excellentenchants/Placeholders.java | 69 +- .../command/BaseCommands.java | 209 +++++ .../command/BookCommand.java | 80 -- .../command/CommandArguments.java | 67 ++ .../command/EnchantCommand.java | 95 --- .../command/GetFuelCommand.java | 69 -- .../command/ListCommand.java | 52 -- .../command/RarityBookCommand.java | 91 --- .../excellentenchants/config/Config.java | 168 +--- .../config/DistributionWaySettings.java | 61 -- .../excellentenchants/config/Keys.java | 4 - .../excellentenchants/config/Lang.java | 76 +- .../enchantment/EnchantManager.java | 83 +- .../enchantment/EnchantPopulator.java | 262 ------- .../data/AbstractEnchantmentData.java | 742 ------------------ .../enchantment/data/CustomDistribution.java | 154 ---- .../enchantment/data/PeriodSettingsImpl.java | 55 -- .../enchantment/data/VanillaDistribution.java | 43 - .../enchantment/impl/EnchantCharges.java | 114 +++ .../enchantment/impl/EnchantDefinition.java | 226 ++++++ .../enchantment/impl/EnchantDistribution.java | 170 ++++ .../enchantment/impl/GameEnchantment.java | 315 ++++++++ .../impl/armor/ColdSteelEnchant.java | 70 +- .../impl/armor/DarknessCloakEnchant.java | 70 +- .../armor/ElementalProtectionEnchant.java | 67 +- .../impl/armor/FireShieldEnchant.java | 55 +- .../impl/armor/FlameWalkerEnchant.java | 141 ++-- .../impl/armor/HardenedEnchant.java | 70 +- .../impl/armor/IceShieldEnchant.java | 72 +- .../impl/armor/JumpingEnchant.java | 66 +- .../impl/armor/KamikadzeEnchant.java | 59 +- .../impl/armor/NightVisionEnchant.java | 66 +- .../impl/armor/RegrowthEnchant.java | 67 +- .../impl/armor/SaturationEnchant.java | 52 +- .../enchantment/impl/armor/SpeedyEnchant.java | 66 +- .../impl/armor/StoppingForceEnchant.java | 55 +- .../impl/armor/TreasureHunterEnchant.java | 58 +- .../impl/armor/WaterBreathingEnchant.java | 66 +- .../enchantment/impl/bow/BomberEnchant.java | 76 +- .../impl/bow/ConfusingArrowsEnchant.java | 76 +- .../impl/bow/DarknessArrowsEnchant.java | 78 +- .../impl/bow/DragonfireArrowsEnchant.java | 75 +- .../impl/bow/ElectrifiedArrowsEnchant.java | 78 +- .../enchantment/impl/bow/EnderBowEnchant.java | 73 +- .../impl/bow/ExplosiveArrowsEnchant.java | 71 +- .../enchantment/impl/bow/FlareEnchant.java | 67 +- .../enchantment/impl/bow/GhastEnchant.java | 78 +- .../enchantment/impl/bow/HoverEnchant.java | 73 +- .../impl/bow/PoisonedArrowsEnchant.java | 78 +- .../enchantment/impl/bow/SniperEnchant.java | 54 +- .../impl/bow/VampiricArrowsEnchant.java | 72 +- .../impl/bow/WitheredArrowsEnchant.java | 78 +- .../impl/fishing/AutoReelEnchant.java | 41 +- .../impl/fishing/CurseOfDrownedEnchant.java | 56 +- .../impl/fishing/DoubleCatchEnchant.java | 54 +- .../impl/fishing/RiverMasterEnchant.java | 49 +- .../impl/fishing/SeasonedAnglerEnchant.java | 39 +- .../impl/fishing/SurvivalistEnchant.java | 56 +- .../impl/tool/BlastMiningEnchant.java | 75 +- .../impl/tool/CurseOfBreakingEnchant.java | 58 +- .../impl/tool/CurseOfMediocrityEnchant.java | 72 +- .../impl/tool/CurseOfMisfortuneEnchant.java | 77 +- .../enchantment/impl/tool/HasteEnchant.java | 66 +- .../impl/tool/LuckyMinerEnchant.java | 68 +- .../impl/tool/ReplanterEnchant.java | 67 +- .../impl/tool/SilkChestEnchant.java | 52 +- .../impl/tool/SilkSpawnerEnchant.java | 72 +- .../enchantment/impl/tool/SmelterEnchant.java | 80 +- .../impl/tool/TelekinesisEnchant.java | 60 +- .../enchantment/impl/tool/TunnelEnchant.java | 55 +- .../impl/tool/VeinminerEnchant.java | 56 +- .../universal/CurseOfFragilityEnchant.java | 54 +- .../impl/universal/RestoreEnchant.java | 61 +- .../impl/universal/SoulboundEnchant.java | 49 +- .../impl/weapon/BaneOfNetherspawnEnchant.java | 59 +- .../impl/weapon/BlindnessEnchant.java | 73 +- .../impl/weapon/ConfusionEnchant.java | 71 +- .../enchantment/impl/weapon/CureEnchant.java | 60 +- .../impl/weapon/CurseOfDeathEnchant.java | 53 +- .../impl/weapon/CutterEnchant.java | 59 +- .../impl/weapon/DecapitatorEnchant.java | 59 +- .../impl/weapon/DoubleStrikeEnchant.java | 56 +- .../impl/weapon/ExhaustEnchant.java | 70 +- .../impl/weapon/IceAspectEnchant.java | 70 +- .../impl/weapon/InfernusEnchant.java | 45 +- .../impl/weapon/NimbleEnchant.java | 54 +- .../impl/weapon/ParalyzeEnchant.java | 72 +- .../enchantment/impl/weapon/RageEnchant.java | 70 +- .../impl/weapon/RocketEnchant.java | 57 +- .../impl/weapon/ScavengerEnchant.java | 56 +- .../impl/weapon/SurpriseEnchant.java | 78 +- .../impl/weapon/SwiperEnchant.java | 55 +- .../impl/weapon/TemperEnchant.java | 39 +- .../impl/weapon/ThriftyEnchant.java | 56 +- .../impl/weapon/ThunderEnchant.java | 59 +- .../impl/weapon/VampireEnchant.java | 57 +- .../enchantment/impl/weapon/VenomEnchant.java | 72 +- .../impl/weapon/VillageDefenderEnchant.java | 41 +- .../impl/weapon/WisdomEnchant.java | 39 +- .../impl/weapon/WitherEnchant.java | 70 +- ...tAnvilListener.java => AnvilListener.java} | 35 +- .../listener/EnchantGenericListener.java | 169 ---- .../listener/EnchantPopulationListener.java | 132 ---- .../listener/EnchantVanillaListener.java | 91 --- .../enchantment/listener/GenericListener.java | 94 +++ ...ntmentsListMenu.java => EnchantsMenu.java} | 95 +-- .../hook/impl/PlaceholderHook.java | 12 +- .../hook/impl/ProtocolLibHook.java | 50 +- .../rarity/EnchantRarity.java | 98 +++ .../rarity/RarityManager.java | 78 ++ .../registry/EnchantRegistry.java | 99 +-- .../registry/wrapper/DataGather.java | 8 +- .../registry/wrapper/DataGathers.java | 12 +- .../registry/wrapper/WrappedEvent.java | 13 +- .../util/EnchantPlaceholders.java | 2 +- .../{enchantment => }/util/EnchantUtils.java | 217 ++--- .../util/EnchantedProjectile.java | 2 +- .../data => util}/ItemCategories.java | 63 +- Core/src/main/resources/lang/messages_ru.yml | 36 - Core/src/main/resources/plugin.yml | 4 +- MC_1_20_6/pom.xml | 79 -- MC_1_20_6/pom.xml.versionsBackup | 79 -- .../excellentenchants/CustomEnchantment.java | 149 ---- .../excellentenchants/Internal1_20_6.java | 239 ------ MC_1_21/pom.xml | 16 +- .../excellentenchants/Internal_1_21.java | 338 +++++--- NMS/pom.xml | 7 +- .../excellentenchants/nms/EnchantNMS.java | 23 +- V1_19_R3/pom.xml | 72 -- .../nms/v1_19_R3/CustomEnchantment.java | 147 ---- .../nms/v1_19_R3/V1_19_R3.java | 216 ----- V1_20_R1/pom.xml | 72 -- .../nms/v1_20_R1/CustomEnchantment.java | 147 ---- .../nms/v1_20_R1/V1_20_R1.java | 247 ------ V1_20_R2/pom.xml | 72 -- .../nms/v1_20_R2/CustomEnchantment.java | 147 ---- .../nms/v1_20_R2/V1_20_R2.java | 216 ----- V1_20_R3/pom.xml | 77 -- .../nms/v1_20_R3/CustomEnchantment.java | 148 ---- .../nms/v1_20_R3/V1_20_R3.java | 233 ------ pom.xml | 9 +- 192 files changed, 4562 insertions(+), 9043 deletions(-) create mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/ConfigBridge.java delete mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/DistributionMode.java delete mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/DistributionWay.java delete mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/EnchantingBridge.java create mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/EnchantmentID.java create mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/Charges.java create mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/CustomEnchantment.java create mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/Definition.java create mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/Distribution.java delete mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/EnchantmentData.java delete mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/ItemCategory.java create mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/TradeType.java create mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/bridge/FlameWalker.java delete mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/ArrowData.java delete mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/ArrowSettings.java delete mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/ChanceData.java delete mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/ChanceSettings.java delete mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/PeriodicData.java delete mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/PeriodicSettings.java delete mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/PotionData.java delete mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/PotionSettings.java delete mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/distribution/DistributionOptions.java delete mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/distribution/VanillaOptions.java rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/ArrowSettingsImpl.java => API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/ArrowEffects.java (54%) create mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/ArrowMeta.java create mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/ChanceMeta.java create mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/EnchantMeta.java create mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/MetaHolder.java create mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/Period.java create mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/PeriodMeta.java rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/PotionSettingsImpl.java => API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/PotionEffects.java (56%) create mode 100644 API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/PotionMeta.java rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/ChanceSettingsImpl.java => API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/Probability.java (53%) create mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/EnchantsAPI.java create mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/command/BaseCommands.java delete mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/command/BookCommand.java create mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/command/CommandArguments.java delete mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/command/EnchantCommand.java delete mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/command/GetFuelCommand.java delete mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/command/ListCommand.java delete mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/command/RarityBookCommand.java delete mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/config/DistributionWaySettings.java delete mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantPopulator.java delete mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/AbstractEnchantmentData.java delete mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/CustomDistribution.java delete mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/PeriodSettingsImpl.java delete mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/VanillaDistribution.java create mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/EnchantCharges.java create mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/EnchantDefinition.java create mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/EnchantDistribution.java create mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/GameEnchantment.java rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/{EnchantAnvilListener.java => AnvilListener.java} (87%) delete mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantGenericListener.java delete mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantPopulationListener.java delete mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantVanillaListener.java create mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/GenericListener.java rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/menu/{EnchantmentsListMenu.java => EnchantsMenu.java} (68%) create mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/rarity/EnchantRarity.java create mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/rarity/RarityManager.java rename Core/src/main/java/su/nightexpress/excellentenchants/{enchantment => }/registry/EnchantRegistry.java (78%) rename Core/src/main/java/su/nightexpress/excellentenchants/{enchantment => }/registry/wrapper/DataGather.java (76%) rename Core/src/main/java/su/nightexpress/excellentenchants/{enchantment => }/registry/wrapper/DataGathers.java (97%) rename Core/src/main/java/su/nightexpress/excellentenchants/{enchantment => }/registry/wrapper/WrappedEvent.java (78%) rename Core/src/main/java/su/nightexpress/excellentenchants/{enchantment => }/util/EnchantPlaceholders.java (97%) rename Core/src/main/java/su/nightexpress/excellentenchants/{enchantment => }/util/EnchantUtils.java (61%) rename Core/src/main/java/su/nightexpress/excellentenchants/{enchantment => }/util/EnchantedProjectile.java (96%) rename Core/src/main/java/su/nightexpress/excellentenchants/{enchantment/data => util}/ItemCategories.java (76%) delete mode 100644 Core/src/main/resources/lang/messages_ru.yml delete mode 100644 MC_1_20_6/pom.xml delete mode 100644 MC_1_20_6/pom.xml.versionsBackup delete mode 100644 MC_1_20_6/src/main/java/su/nightexpress/excellentenchants/CustomEnchantment.java delete mode 100644 MC_1_20_6/src/main/java/su/nightexpress/excellentenchants/Internal1_20_6.java delete mode 100644 V1_19_R3/pom.xml delete mode 100644 V1_19_R3/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R3/CustomEnchantment.java delete mode 100644 V1_19_R3/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R3/V1_19_R3.java delete mode 100644 V1_20_R1/pom.xml delete mode 100644 V1_20_R1/src/main/java/su/nightexpress/excellentenchants/nms/v1_20_R1/CustomEnchantment.java delete mode 100644 V1_20_R1/src/main/java/su/nightexpress/excellentenchants/nms/v1_20_R1/V1_20_R1.java delete mode 100644 V1_20_R2/pom.xml delete mode 100644 V1_20_R2/src/main/java/su/nightexpress/excellentenchants/nms/v1_20_R2/CustomEnchantment.java delete mode 100644 V1_20_R2/src/main/java/su/nightexpress/excellentenchants/nms/v1_20_R2/V1_20_R2.java delete mode 100644 V1_20_R3/pom.xml delete mode 100644 V1_20_R3/src/main/java/su/nightexpress/excellentenchants/nms/v1_20_R3/CustomEnchantment.java delete mode 100644 V1_20_R3/src/main/java/su/nightexpress/excellentenchants/nms/v1_20_R3/V1_20_R3.java diff --git a/.gitignore b/.gitignore index ceb3fef..e3b50bd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,17 +5,7 @@ /Core/pom.xml.versionsBackup /NMS/target/ /NMS/pom.xml.versionsBackup -/V1_18_R2/target/ -/V1_18_R2/pom.xml.versionsBackup -/V1_19_R3/target/ -/V1_19_R3/pom.xml.versionsBackup -/V1_20_R1/target/ -/V1_20_R1/pom.xml.versionsBackup -/V1_20_R2/target/ -/V1_20_R2/pom.xml.versionsBackup -/V1_20_R3/target/ -/V1_20_R3/pom.xml.versionsBackup /API/target/ /API/pom.xml.versionsBackup -/MC_1_20_6/target/ -/MC_1_20_6/pom.xml.versionsBackup \ No newline at end of file +/MC_1_21/target/ +/MC_1_21/pom.xml.versionsBackup \ No newline at end of file diff --git a/API/pom.xml b/API/pom.xml index 0e5f2ee..5a8f377 100644 --- a/API/pom.xml +++ b/API/pom.xml @@ -5,7 +5,7 @@ ExcellentEnchants su.nightexpress.excellentenchants - 4.1.0 + 4.2.0 4.0.0 diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/ConfigBridge.java b/API/src/main/java/su/nightexpress/excellentenchants/api/ConfigBridge.java new file mode 100644 index 0000000..963f831 --- /dev/null +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/ConfigBridge.java @@ -0,0 +1,14 @@ +package su.nightexpress.excellentenchants.api; + +public class ConfigBridge { + + private static int enchantsTickInterval; + + public static int getEnchantsTickInterval() { + return enchantsTickInterval; + } + + public static void setEnchantsTickInterval(int enchantsTickInterval) { + ConfigBridge.enchantsTickInterval = enchantsTickInterval; + } +} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/DistributionMode.java b/API/src/main/java/su/nightexpress/excellentenchants/api/DistributionMode.java deleted file mode 100644 index e4dd0d0..0000000 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/DistributionMode.java +++ /dev/null @@ -1,8 +0,0 @@ -package su.nightexpress.excellentenchants.api; - -@Deprecated -public enum DistributionMode { - - VANILLA, - CUSTOM -} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/DistributionWay.java b/API/src/main/java/su/nightexpress/excellentenchants/api/DistributionWay.java deleted file mode 100644 index 6696cb7..0000000 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/DistributionWay.java +++ /dev/null @@ -1,24 +0,0 @@ -package su.nightexpress.excellentenchants.api; - -import org.jetbrains.annotations.NotNull; - -@Deprecated -public enum DistributionWay { - - ENCHANTING("Enchanting_Table"), - VILLAGER("Villagers"), - LOOT_GENERATION("Loot_Generation"), - FISHING("Fishing"), - MOB_EQUIPMENT("Mob_Equipment"); - - private final String pathName; - - DistributionWay(@NotNull String pathName) { - this.pathName = pathName; - } - - @NotNull - public String getPathName() { - return pathName; - } -} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/EnchantingBridge.java b/API/src/main/java/su/nightexpress/excellentenchants/api/EnchantingBridge.java deleted file mode 100644 index acff70b..0000000 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/EnchantingBridge.java +++ /dev/null @@ -1,21 +0,0 @@ -package su.nightexpress.excellentenchants.api; - -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.Nullable; - -public class EnchantingBridge { - - private static ItemStack enchantingItem; - - public static ItemStack getEnchantingItem() { - return enchantingItem; - } - - public static void setEnchantingItem(@Nullable ItemStack itemStack) { - enchantingItem = itemStack; - } - - public static void clear() { - enchantingItem = null; - } -} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/EnchantmentID.java b/API/src/main/java/su/nightexpress/excellentenchants/api/EnchantmentID.java new file mode 100644 index 0000000..7f8a995 --- /dev/null +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/EnchantmentID.java @@ -0,0 +1,6 @@ +package su.nightexpress.excellentenchants.api; + +public class EnchantmentID { + + public static final String FLAME_WALKER = "flame_walker"; +} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/Charges.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/Charges.java new file mode 100644 index 0000000..edc465e --- /dev/null +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/Charges.java @@ -0,0 +1,26 @@ +package su.nightexpress.excellentenchants.api.enchantment; + +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import su.nightexpress.excellentenchants.api.Modifier; + +public interface Charges { + + boolean isEnabled(); + + boolean isCustomFuel(); + + int getMaxAmount(int level); + + int getConsumeAmount(int level); + + int getRechargeAmount(int level); + + @NotNull ItemStack getFuel(); + + @NotNull Modifier getMaxAmount(); + + @NotNull Modifier getConsumeAmount(); + + @NotNull Modifier getRechargeAmount(); +} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/Cost.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/Cost.java index 29d4d9d..6ffdb6c 100644 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/Cost.java +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/Cost.java @@ -26,8 +26,15 @@ public class Cost { @NotNull public static Cost read(@NotNull FileConfig config, @NotNull String path) { - int base = ConfigValue.create(path + ".Base", 0).read(config); - int perLevel = ConfigValue.create(path + ".Per_Level", 0).read(config); + int base = ConfigValue.create(path + ".Base", + 0, + "The cost for a level I enchantment." + ).read(config); + + int perLevel = ConfigValue.create(path + ".Per_Level", + 0, + "The amount of levels added to the Base for each level above level I" + ).read(config); return new Cost(base, perLevel); } diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/CustomEnchantment.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/CustomEnchantment.java new file mode 100644 index 0000000..f1e0bac --- /dev/null +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/CustomEnchantment.java @@ -0,0 +1,90 @@ +package su.nightexpress.excellentenchants.api.enchantment; + +import org.bukkit.World; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.LivingEntity; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.NotNull; +import su.nightexpress.excellentenchants.api.enchantment.meta.MetaHolder; +import su.nightexpress.nightcore.config.FileConfig; +import su.nightexpress.nightcore.util.placeholder.PlaceholderMap; +import su.nightexpress.nightcore.util.random.Rnd; + +import java.util.List; + +public interface CustomEnchantment extends MetaHolder { + + default void clear() { + + } + + @NotNull PlaceholderMap getPlaceholders(int level); + + @NotNull FileConfig getConfig(); + + @NotNull Enchantment getBukkitEnchantment(); + + @NotNull Definition getDefinition(); + + @NotNull Distribution getDistribution(); + + @NotNull Charges getCharges(); + + boolean load(); + + boolean checkServerRequirements(); + + boolean isAvailableToUse(@NotNull LivingEntity entity); + + boolean isAvailableToUse(@NotNull World world); + + default boolean isSupportedItem(@NotNull ItemStack itemStack) { + return this.getDefinition().getSupportedItems().is(itemStack); + } + + default boolean isPrimaryItem(@NotNull ItemStack itemStack) { + return this.getDefinition().getPrimaryItems().is(itemStack); + } + + @NotNull String getId(); + + @NotNull String getDisplayName(); + + @NotNull String getFormattedName(); + + @NotNull List getDescription(); + + @NotNull List getDescription(int level); + + @NotNull List getDescription(int level, int charges); + + boolean isCurse(); + + boolean isHiddenFromList(); + + boolean hasVisualEffects(); + + boolean hasCharges(); + + boolean isChargesFuel(@NotNull ItemStack item); + + int getCharges(@NotNull ItemStack item); + + int getCharges(@NotNull ItemMeta meta); + + void setCharges(@NotNull ItemStack item, int level, int amount); + + boolean isFullOfCharges(@NotNull ItemStack item); + + boolean isOutOfCharges(@NotNull ItemStack item); + + void restoreCharges(@NotNull ItemStack item, int level); + + void fuelCharges(@NotNull ItemStack item, int level); + + void consumeCharges(@NotNull ItemStack item, int level); + + @Deprecated + void consumeChargesNoUpdate(@NotNull ItemStack item, int level); +} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/Definition.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/Definition.java new file mode 100644 index 0000000..bed5b5a --- /dev/null +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/Definition.java @@ -0,0 +1,37 @@ +package su.nightexpress.excellentenchants.api.enchantment; + +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.Set; + +public interface Definition { + + boolean hasConflicts(); + + @NotNull String getDisplayName(); + + @NotNull List getDescription(); + + /** + * Items on which this enchantment can be applied using an anvil or using the /enchant command. + */ + @NotNull ItemsCategory getSupportedItems(); + + /** + * Items for which this enchantment appears in an enchanting table. + */ + @NotNull ItemsCategory getPrimaryItems(); + + @NotNull Set getConflicts(); + + @NotNull Rarity getRarity(); + + int getMaxLevel(); + + @NotNull Cost getMinCost(); + + @NotNull Cost getMaxCost(); + + int getAnvilCost(); +} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/Distribution.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/Distribution.java new file mode 100644 index 0000000..46f41bf --- /dev/null +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/Distribution.java @@ -0,0 +1,22 @@ +package su.nightexpress.excellentenchants.api.enchantment; + +import org.jetbrains.annotations.NotNull; + +import java.util.Set; + +public interface Distribution { + + boolean isTreasure(); + + boolean isDiscoverable(); + + boolean isTradable(); + + @NotNull Set getTrades(); + + boolean isOnMobSpawnEquipment(); + + boolean isOnRandomLoot(); + + boolean isOnTradedEquipment(); +} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/EnchantmentData.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/EnchantmentData.java deleted file mode 100644 index 31b95da..0000000 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/EnchantmentData.java +++ /dev/null @@ -1,201 +0,0 @@ -package su.nightexpress.excellentenchants.api.enchantment; - -import org.bukkit.World; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.LivingEntity; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.distribution.DistributionOptions; -import su.nightexpress.nightcore.config.FileConfig; -import su.nightexpress.nightcore.util.Lists; -import su.nightexpress.nightcore.util.placeholder.PlaceholderMap; - -import java.util.List; -import java.util.Set; - -public interface EnchantmentData { - - default void clear() { - - } - - @NotNull PlaceholderMap getPlaceholders(int level); - - @NotNull FileConfig getConfig(); - - boolean load(); - - boolean checkServerRequirements(); - - boolean isAvailableToUse(@NotNull LivingEntity entity); - - boolean isAvailableToUse(@NotNull World world); - - boolean checkEnchantLimit(@NotNull ItemStack item); - - default boolean isSupportedItem(@NotNull ItemStack itemStack) { - return this.getSupportedItems().is(itemStack); - } - - default boolean isPrimaryItem(@NotNull ItemStack itemStack) { - return this.getPrimaryItems().is(itemStack); - } - - /** - * Items on which this enchantment can be applied using an anvil or using the /enchant command. - */ - @NotNull ItemsCategory getSupportedItems(); - - /** - * Items for which this enchantment appears in an enchanting table. - */ - @NotNull default ItemsCategory getPrimaryItems() { - return this.getSupportedItems(); - } - - @NotNull DistributionOptions getDistributionOptions(); - - @NotNull Rarity getRarity(); - - void setRarity(@NotNull Rarity rarity); - - @NotNull String getId(); - - @NotNull String getName(); - - @Deprecated - @NotNull - default String getNameFormatted(int level) { - return this.getNameFormatted(level, -1); - } - - @Deprecated - @NotNull String getNameFormatted(int level, int charges); - - @NotNull List getDescription(); - - @NotNull List getDescriptionFormatted(); - - @NotNull List getDescriptionReplaced(int level); - - @NotNull List getDescriptionReplaced(int level, int charges); - - @NotNull Enchantment getEnchantment(); - - void setEnchantment(@NotNull Enchantment enchantment); - - default boolean hasConflicts() { - return !this.getConflicts().isEmpty(); - } - - @NotNull Set getConflicts(); - - int getMaxLevel(); - - int getMinCost(int level); - - int getMaxCost(int level); - - default boolean isCurse() { - return false; - } - - boolean isTreasure(); - - boolean hasVisualEffects(); - - boolean isChargesEnabled(); - - boolean isChargesCustomFuel(); - - int getChargesMax(int level); - - int getChargesConsumeAmount(int level); - - int getChargesRechargeAmount(int level); - - @NotNull ItemStack getChargesFuel(); - - boolean isChargesFuel(@NotNull ItemStack item); - - default int getCharges(@NotNull ItemStack item) { - ItemMeta meta = item.getItemMeta(); - return meta == null ? 0 : this.getCharges(meta); - } - - int getCharges(@NotNull ItemMeta meta); - - void setCharges(@NotNull ItemStack item, int level, int amount); - - boolean isFullOfCharges(@NotNull ItemStack item); - - boolean isOutOfCharges(@NotNull ItemStack item); - - void restoreCharges(@NotNull ItemStack item, int level); - - void fuelCharges(@NotNull ItemStack item, int level); - - void consumeCharges(@NotNull ItemStack item, int level); - - void consumeChargesNoUpdate(@NotNull ItemStack item, int level); - - - - - void setDisplayName(@NotNull String displayName); - - default void setDescription(@NotNull String... description) { - this.setDescription(Lists.newList(description)); - } - - void setDescription(@NotNull List description); - - boolean isHiddenFromList(); - - void setHiddenFromList(boolean hiddenFromList); - - void setTreasure(boolean treasure); - - void setMaxLevel(int levelMax); - - @NotNull Cost getMinCost(); - - void setMinCost(@NotNull Cost minCost); - - @NotNull Cost getMaxCost(); - - void setMaxCost(@NotNull Cost maxCost); - - int getAnvilCost(); - - void setAnvilCost(int anvilCost); - - default void setConflicts(@NotNull String... conflicts) { - this.setConflicts(Lists.newSet(conflicts)); - } - - void setConflicts(@NotNull Set conflicts); - - void setVisualEffects(boolean visualEffects); - - void setChargesEnabled(boolean chargesEnabled); - - void setChargesCustomFuel(boolean chargesCustomFuel); - - @NotNull Modifier getChargesMax(); - - void setChargesMax(@NotNull Modifier chargesMax); - - void setChargesFuel(@Nullable ItemStack chargesFuel); - - @NotNull Modifier getChargesConsumeAmount(); - - void setChargesConsumeAmount(@NotNull Modifier chargesConsumeAmount); - - @NotNull Modifier getChargesRechargeAmount(); - - void setChargesRechargeAmount(@NotNull Modifier chargesRechargeAmount); -} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/ItemCategory.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/ItemCategory.java deleted file mode 100644 index ee1a5a5..0000000 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/ItemCategory.java +++ /dev/null @@ -1,54 +0,0 @@ -package su.nightexpress.excellentenchants.api.enchantment; - -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import su.nightexpress.nightcore.util.ItemUtil; - -import java.util.function.Predicate; - -@Deprecated -public enum ItemCategory { - - HELMET(ItemUtil::isHelmet), - CHESTPLATE(ItemUtil::isChestplate), - LEGGINGS(ItemUtil::isLeggings), - BOOTS(ItemUtil::isBoots), - ELYTRA(item -> item.getType() == Material.ELYTRA), - - SWORD(ItemUtil::isSword), - TRIDENT(ItemUtil::isTrident), - AXE(ItemUtil::isAxe), - BOW(item -> item.getType() == Material.BOW), - CROSSBOW(item -> item.getType() == Material.CROSSBOW), - HOE(ItemUtil::isHoe), - PICKAXE(ItemUtil::isPickaxe), - SHOVEL(ItemUtil::isShovel), - FISHING_ROD(ItemUtil::isFishingRod), - SHIELD(itemStack -> itemStack.getType() == Material.SHIELD), - - //@Deprecated WEAPON(item -> SWORD.isIncluded(item) || TRIDENT.isIncluded(item)), - TOOL(ItemUtil::isTool), - //@Deprecated ARMOR(ItemUtil::isArmor), - //UNIVERSAL(item -> WEAPON.isIncluded(item) || TOOL.isIncluded(item) || ARMOR.isIncluded(item)), - ; - - private Predicate predicate; - - ItemCategory(@NotNull Predicate predicate) { - this.setPredicate(predicate); - } - - @NotNull - public Predicate getPredicate() { - return predicate; - } - - public void setPredicate(@NotNull Predicate predicate) { - this.predicate = predicate; - } - - public boolean isIncluded(@NotNull ItemStack item) { - return this.getPredicate().test(item); - } -} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/ItemsCategory.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/ItemsCategory.java index a521f1e..cdcaac9 100644 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/ItemsCategory.java +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/ItemsCategory.java @@ -2,7 +2,6 @@ package su.nightexpress.excellentenchants.api.enchantment; import org.bukkit.Material; import org.bukkit.Tag; -import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -19,13 +18,13 @@ public class ItemsCategory { private final Supplier> supplier; private final EquipmentSlot[] slots; - private final EnchantmentTarget target; +// private final EnchantmentTarget target; private final String localized; - public ItemsCategory(@NotNull Supplier> supplier, EquipmentSlot[] slots, @Nullable EnchantmentTarget target, @Nullable String localized) { + public ItemsCategory(@NotNull Supplier> supplier, EquipmentSlot[] slots/*, @Nullable EnchantmentTarget target*/, @Nullable String localized) { this.supplier = supplier; this.slots = slots; - this.target = target; +// this.target = target; this.localized = localized; } @@ -63,47 +62,22 @@ public class ItemsCategory { return slots; } - /** - * Only for compatibility reasons with versions < 1.21 - */ - public EnchantmentTarget getTarget() { - return target; - } +// /** +// * Only for compatibility reasons with versions < 1.21 +// */ +// public EnchantmentTarget getTarget() { +// return target; +// } public String getLocalized() { return localized; } - /*@NotNull - public static ItemsCategory create(@NotNull Set materials, EquipmentSlot... slots) { - return new ItemsCategory(() -> materials); - } - - @NotNull - public static ItemsCategory create(Material... materials) { - return create(Stream.of(materials).collect(Collectors.toSet())); - } - - @SafeVarargs - @NotNull - public static ItemsCategory create(Tag... tags) { - return create(Stream.of(tags).flatMap(tag -> tag.getValues().stream()).collect(Collectors.toSet())); - }*/ - -// @NotNull -// @Deprecated -// public static ItemsCategory fusion(ItemsCategory... categories) { -// Set>> suppliers = Stream.of(categories).map(category -> category.supplier).collect(Collectors.toSet()); -// Supplier> result = () -> suppliers.stream().flatMap(supplier -> supplier.get().stream()).collect(Collectors.toSet()); -// -// return new ItemsCategory(result, categories[0].getSlots(), categories[0].target, categories[0].localized); -// } - public static class Builder { private Supplier> supplier; private EquipmentSlot[] slots; - private EnchantmentTarget target; +// private EnchantmentTarget target; private String localized; public Builder() { @@ -113,7 +87,7 @@ public class ItemsCategory { @NotNull public ItemsCategory build() { - return new ItemsCategory(this.supplier, this.slots, this.target, this.localized); + return new ItemsCategory(this.supplier, this.slots, /*this.target,*/ this.localized); } @NotNull @@ -128,11 +102,12 @@ public class ItemsCategory { return this; } - @NotNull - public Builder target(EnchantmentTarget target) { - this.target = target; - return this; - } +// @NotNull +// @Deprecated +// public Builder target(EnchantmentTarget target) { +// this.target = target; +// return this; +// } @NotNull public Builder localized(@NotNull LangString localized) { diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/Rarity.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/Rarity.java index 1884db9..d533433 100644 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/Rarity.java +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/Rarity.java @@ -1,41 +1,17 @@ package su.nightexpress.excellentenchants.api.enchantment; import org.jetbrains.annotations.NotNull; -import su.nightexpress.nightcore.util.random.Rnd; +import su.nightexpress.nightcore.config.FileConfig; -import java.util.HashMap; -import java.util.Map; +public interface Rarity { -@Deprecated -public enum Rarity { + void write(@NotNull FileConfig config, @NotNull String path); - COMMON(10), - UNCOMMON(5), - RARE(2), - VERY_RARE(1); + @NotNull String getId(); - private int weight; + @NotNull String getName(); - Rarity(int weight) { - this.weight = weight; - } + @NotNull String getNameFormat(); - public int getWeight() { - return this.weight; - } - - public void setWeight(int weight) { - this.weight = weight; - } - - @NotNull - public static Rarity getByWeight() { - Map map = new HashMap<>(); - - for (Rarity rarity : Rarity.values()) { - map.put(rarity, (double) rarity.getWeight()); - } - - return Rnd.getByWeight(map); - } + int getWeight(); } diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/TradeType.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/TradeType.java new file mode 100644 index 0000000..2c3ee7c --- /dev/null +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/TradeType.java @@ -0,0 +1,19 @@ +package su.nightexpress.excellentenchants.api.enchantment; + +public enum TradeType { + DESERT_COMMON, + DESERT_SPECIAL, + PLAINS_COMMON, + PLAINS_SPECIAL, + SAVANNA_COMMON, + SAVANNA_SPECIAL, + JUNGLE_COMMON, + JUNGLE_SPECIAL, + SNOW_COMMON, + SNOW_SPECIAL, + SWAMP_COMMON, + SWAMP_SPECIAL, + TAIGA_COMMON, + TAIGA_SPECIAL + ; +} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/bridge/FlameWalker.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/bridge/FlameWalker.java new file mode 100644 index 0000000..03a03a8 --- /dev/null +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/bridge/FlameWalker.java @@ -0,0 +1,24 @@ +package su.nightexpress.excellentenchants.api.enchantment.bridge; + +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.jetbrains.annotations.NotNull; +import su.nightexpress.excellentenchants.api.Modifier; +import su.nightexpress.nightcore.util.Pair; +import su.nightexpress.nightcore.util.random.Rnd; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public interface FlameWalker { + + Map> MAGMA_BLOCKS = new ConcurrentHashMap<>(); + + static void addBlock(@NotNull Block block, double seconds) { + MAGMA_BLOCKS.put(block.getLocation(), Pair.of(System.currentTimeMillis() + (long) seconds * 1000L, Rnd.get(1000))); + } + + @NotNull Modifier getRadius(); + + double getBlockDecayTime(int level); +} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/ArrowData.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/ArrowData.java deleted file mode 100644 index 9e41d5d..0000000 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/ArrowData.java +++ /dev/null @@ -1,14 +0,0 @@ -package su.nightexpress.excellentenchants.api.enchantment.data; - -import org.jetbrains.annotations.NotNull; -import su.nightexpress.nightcore.util.wrapper.UniParticle; - -public interface ArrowData { - - @NotNull ArrowSettings getArrowSettings(); - - @NotNull - default UniParticle getProjectileTrail() { - return this.getArrowSettings().getProjectileTrail(); - } -} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/ArrowSettings.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/ArrowSettings.java deleted file mode 100644 index 2be85b5..0000000 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/ArrowSettings.java +++ /dev/null @@ -1,9 +0,0 @@ -package su.nightexpress.excellentenchants.api.enchantment.data; - -import org.jetbrains.annotations.NotNull; -import su.nightexpress.nightcore.util.wrapper.UniParticle; - -public interface ArrowSettings { - - @NotNull UniParticle getProjectileTrail(); -} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/ChanceData.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/ChanceData.java deleted file mode 100644 index 3017045..0000000 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/ChanceData.java +++ /dev/null @@ -1,21 +0,0 @@ -package su.nightexpress.excellentenchants.api.enchantment.data; - -import org.jetbrains.annotations.NotNull; - -public interface ChanceData { - - @NotNull ChanceSettings getChanceSettings(); - - /*@NotNull - default UnaryOperator replacePlaceholders(int level) { - return this.getChanceImplementation().replacePlaceholders(level); - }*/ - - default double getTriggerChance(int level) { - return this.getChanceSettings().getTriggerChance(level); - } - - default boolean checkTriggerChance(int level) { - return getChanceSettings().checkTriggerChance(level); - } -} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/ChanceSettings.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/ChanceSettings.java deleted file mode 100644 index b15dac8..0000000 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/ChanceSettings.java +++ /dev/null @@ -1,8 +0,0 @@ -package su.nightexpress.excellentenchants.api.enchantment.data; - -public interface ChanceSettings { - - double getTriggerChance(int level); - - boolean checkTriggerChance(int level); -} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/PeriodicData.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/PeriodicData.java deleted file mode 100644 index e92a5e2..0000000 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/PeriodicData.java +++ /dev/null @@ -1,24 +0,0 @@ -package su.nightexpress.excellentenchants.api.enchantment.data; - -import org.jetbrains.annotations.NotNull; - -public interface PeriodicData { - - @NotNull PeriodicSettings getPeriodSettings(); - - default long getInterval() { - return this.getPeriodSettings().getInterval(); - } - - default long getNextTriggerTime() { - return this.getPeriodSettings().getNextTriggerTime(); - } - - default boolean isTriggerTime() { - return this.getPeriodSettings().isTriggerTime(); - } - - default void updateTriggerTime() { - this.getPeriodSettings().updateTriggerTime(); - } -} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/PeriodicSettings.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/PeriodicSettings.java deleted file mode 100644 index 31cfad9..0000000 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/PeriodicSettings.java +++ /dev/null @@ -1,12 +0,0 @@ -package su.nightexpress.excellentenchants.api.enchantment.data; - -public interface PeriodicSettings { - - long getInterval(); - - long getNextTriggerTime(); - - boolean isTriggerTime(); - - void updateTriggerTime(); -} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/PotionData.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/PotionData.java deleted file mode 100644 index a747352..0000000 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/PotionData.java +++ /dev/null @@ -1,35 +0,0 @@ -package su.nightexpress.excellentenchants.api.enchantment.data; - -import org.bukkit.entity.LivingEntity; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.jetbrains.annotations.NotNull; - -public interface PotionData { - - @NotNull PotionSettings getPotionSettings(); - - default boolean isPermanent() { - return this.getPotionSettings().isPermanent(); - } - - default PotionEffectType getEffectType() { - return this.getPotionSettings().getEffectType(); - } - - default int getEffectAmplifier(int level) { - return this.getPotionSettings().getEffectAmplifier(level); - } - - default int getEffectDuration(int level) { - return this.getPotionSettings().getEffectDuration(level); - } - - default PotionEffect createEffect(int level) { - return this.getPotionSettings().createEffect(level); - } - - default boolean addEffect(@NotNull LivingEntity target, int level) { - return this.getPotionSettings().addEffect(target, level); - } -} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/PotionSettings.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/PotionSettings.java deleted file mode 100644 index 727bea2..0000000 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/data/PotionSettings.java +++ /dev/null @@ -1,21 +0,0 @@ -package su.nightexpress.excellentenchants.api.enchantment.data; - -import org.bukkit.entity.LivingEntity; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.jetbrains.annotations.NotNull; - -public interface PotionSettings { - - boolean isPermanent(); - - PotionEffectType getEffectType(); - - int getEffectAmplifier(int level); - - int getEffectDuration(int level); - - PotionEffect createEffect(int level); - - boolean addEffect(@NotNull LivingEntity target, int level); -} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/distribution/DistributionOptions.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/distribution/DistributionOptions.java deleted file mode 100644 index dfacfd5..0000000 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/distribution/DistributionOptions.java +++ /dev/null @@ -1,10 +0,0 @@ -package su.nightexpress.excellentenchants.api.enchantment.distribution; - -import org.jetbrains.annotations.NotNull; -import su.nightexpress.nightcore.config.FileConfig; - -@Deprecated -public interface DistributionOptions { - - void load(@NotNull FileConfig config); -} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/distribution/VanillaOptions.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/distribution/VanillaOptions.java deleted file mode 100644 index 14be8c9..0000000 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/distribution/VanillaOptions.java +++ /dev/null @@ -1,12 +0,0 @@ -package su.nightexpress.excellentenchants.api.enchantment.distribution; - -public interface VanillaOptions extends DistributionOptions { - - boolean isDiscoverable(); - - void setDiscoverable(boolean discoverable); - - boolean isTradeable(); - - void setTradeable(boolean tradeable); -} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/ArrowSettingsImpl.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/ArrowEffects.java similarity index 54% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/ArrowSettingsImpl.java rename to API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/ArrowEffects.java index fca338c..5824f05 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/ArrowSettingsImpl.java +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/ArrowEffects.java @@ -1,29 +1,26 @@ -package su.nightexpress.excellentenchants.enchantment.data; +package su.nightexpress.excellentenchants.api.enchantment.meta; import org.bukkit.Particle; import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.enchantment.data.ArrowSettings; import su.nightexpress.nightcore.config.ConfigValue; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.wrapper.UniParticle; -public class ArrowSettingsImpl implements ArrowSettings { +public class ArrowEffects { - //private final EnchantmentData enchantmentData; private final UniParticle trailParticle; - private ArrowSettingsImpl(@NotNull UniParticle trailParticle) { - //this.enchantmentData = enchantmentData; + private ArrowEffects(@NotNull UniParticle trailParticle) { this.trailParticle = trailParticle; } @NotNull - public static ArrowSettingsImpl create(@NotNull FileConfig config) { - return create(config, UniParticle.of(Particle.REDSTONE)); + public static ArrowEffects create(@NotNull FileConfig config) { + return create(config, UniParticle.of(Particle.CLOUD)); } @NotNull - public static ArrowSettingsImpl create(@NotNull FileConfig config, @NotNull UniParticle particle) { + public static ArrowEffects create(@NotNull FileConfig config, @NotNull UniParticle particle) { UniParticle effect = ConfigValue.create("Settings.VisualEffects.Trail", (cfg, path, def) -> UniParticle.read(cfg, path), (cfg, path, particle1) -> particle1.write(cfg, path), @@ -31,10 +28,9 @@ public class ArrowSettingsImpl implements ArrowSettings { "Sets projectile particle trail effect." ).read(config); - return new ArrowSettingsImpl(effect); + return new ArrowEffects(effect); } - @Override @NotNull public UniParticle getProjectileTrail() { return this.trailParticle; diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/ArrowMeta.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/ArrowMeta.java new file mode 100644 index 0000000..a18b243 --- /dev/null +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/ArrowMeta.java @@ -0,0 +1,12 @@ +package su.nightexpress.excellentenchants.api.enchantment.meta; + +import org.jetbrains.annotations.NotNull; +import su.nightexpress.nightcore.util.wrapper.UniParticle; + +public interface ArrowMeta extends MetaHolder { + + @NotNull + default UniParticle getProjectileTrail() { + return this.getMeta().getArrowEffects().getProjectileTrail(); + } +} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/ChanceMeta.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/ChanceMeta.java new file mode 100644 index 0000000..8c49ed9 --- /dev/null +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/ChanceMeta.java @@ -0,0 +1,12 @@ +package su.nightexpress.excellentenchants.api.enchantment.meta; + +public interface ChanceMeta extends MetaHolder { + + default double getTriggerChance(int level) { + return this.getMeta().getProbability().getTriggerChance(level); + } + + default boolean checkTriggerChance(int level) { + return this.getMeta().getProbability().checkTriggerChance(level); + } +} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/EnchantMeta.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/EnchantMeta.java new file mode 100644 index 0000000..f6e3b3e --- /dev/null +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/EnchantMeta.java @@ -0,0 +1,45 @@ +package su.nightexpress.excellentenchants.api.enchantment.meta; + +public class EnchantMeta { + + private Probability probability; + private PotionEffects potionEffects; + private ArrowEffects arrowEffects; + private Period period; + + public EnchantMeta() { + + } + + public Probability getProbability() { + return probability; + } + + public void setProbability(Probability probability) { + this.probability = probability; + } + + public PotionEffects getPotionEffects() { + return potionEffects; + } + + public void setPotionEffects(PotionEffects potionEffects) { + this.potionEffects = potionEffects; + } + + public ArrowEffects getArrowEffects() { + return arrowEffects; + } + + public void setArrowEffects(ArrowEffects arrowEffects) { + this.arrowEffects = arrowEffects; + } + + public Period getPeriod() { + return period; + } + + public void setPeriod(Period period) { + this.period = period; + } +} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/MetaHolder.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/MetaHolder.java new file mode 100644 index 0000000..c5e1b50 --- /dev/null +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/MetaHolder.java @@ -0,0 +1,8 @@ +package su.nightexpress.excellentenchants.api.enchantment.meta; + +import org.jetbrains.annotations.NotNull; + +public interface MetaHolder { + + @NotNull EnchantMeta getMeta(); +} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/Period.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/Period.java new file mode 100644 index 0000000..860eb45 --- /dev/null +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/Period.java @@ -0,0 +1,48 @@ +package su.nightexpress.excellentenchants.api.enchantment.meta; + +import org.jetbrains.annotations.NotNull; +import su.nightexpress.excellentenchants.api.ConfigBridge; +import su.nightexpress.nightcore.config.ConfigValue; +import su.nightexpress.nightcore.config.FileConfig; + +public class Period { + + private final long interval; + + private long waitTicks; + + public Period(long interval) { + this.interval = interval; + this.updateTriggerTime(); + } + + @NotNull + public static Period create(@NotNull FileConfig config) { + long baseTick = ConfigBridge.getEnchantsTickInterval(); + long interval = ConfigValue.create("Settings.Trigger-Interval", + baseTick, + "Sets how often (in ticks) this enchantment will be triggered.", + "20 ticks = 1 second." + ).read(config); + + return new Period(interval); + } + + public long getInterval() { + return this.interval; + } + + public void consumeTicks() { + this.waitTicks -= ConfigBridge.getEnchantsTickInterval(); + } + + public boolean isTriggerTime() { + return this.waitTicks <= 0; + } + + public void updateTriggerTime() { + if (this.waitTicks <= 0) { + this.waitTicks = this.getInterval(); + } + } +} diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/PeriodMeta.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/PeriodMeta.java new file mode 100644 index 0000000..3b5d8e0 --- /dev/null +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/PeriodMeta.java @@ -0,0 +1,20 @@ +package su.nightexpress.excellentenchants.api.enchantment.meta; + +public interface PeriodMeta extends MetaHolder { + + default long getInterval() { + return this.getMeta().getPeriod().getInterval(); + } + + default void consumeTicks() { + this.getMeta().getPeriod().consumeTicks(); + } + + default boolean isTriggerTime() { + return this.getMeta().getPeriod().isTriggerTime(); + } + + default void updateTriggerTime() { + this.getMeta().getPeriod().updateTriggerTime(); + } +} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/PotionSettingsImpl.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/PotionEffects.java similarity index 56% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/PotionSettingsImpl.java rename to API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/PotionEffects.java index f6db99d..aef8e0f 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/PotionSettingsImpl.java +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/PotionEffects.java @@ -1,37 +1,36 @@ -package su.nightexpress.excellentenchants.enchantment.data; +package su.nightexpress.excellentenchants.api.enchantment.meta; import org.bukkit.entity.LivingEntity; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; +import su.nightexpress.excellentenchants.api.ConfigBridge; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionSettings; -import su.nightexpress.excellentenchants.config.Config; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; import su.nightexpress.nightcore.config.FileConfig; -public class PotionSettingsImpl implements PotionSettings { +public class PotionEffects { private final PotionEffectType effectType; private final Modifier duration; private final Modifier amplifier; - private final boolean isPermanent; - private final boolean particles; + private final boolean permanent; + private final boolean particles; - private PotionSettingsImpl(@NotNull PotionEffectType effectType, - boolean isPermanent, - boolean particles, - @NotNull Modifier duration, - @NotNull Modifier amplifier) { + private PotionEffects(@NotNull PotionEffectType effectType, + boolean permanent, + boolean particles, + @NotNull Modifier duration, + @NotNull Modifier amplifier) { this.effectType = effectType; this.duration = duration; this.amplifier = amplifier; - this.isPermanent = isPermanent; + this.permanent = permanent; this.particles = particles; } @NotNull - public static PotionSettingsImpl create(@NotNull EnchantmentData data, @NotNull FileConfig config, @NotNull PotionEffectType type, boolean isPermanent) { + public static PotionEffects create(@NotNull CustomEnchantment data, @NotNull FileConfig config, @NotNull PotionEffectType type, boolean isPermanent) { return create(data, config, type, isPermanent, Modifier.multiply(5, 1, 1), Modifier.add(0, 1, 1, 5) @@ -39,12 +38,12 @@ public class PotionSettingsImpl implements PotionSettings { } @NotNull - public static PotionSettingsImpl create(@NotNull EnchantmentData data, - @NotNull FileConfig config, - @NotNull PotionEffectType type, - boolean isPermanent, - @NotNull Modifier duration, - @NotNull Modifier amplifier) { + public static PotionEffects create(@NotNull CustomEnchantment data, + @NotNull FileConfig config, + @NotNull PotionEffectType type, + boolean isPermanent, + @NotNull Modifier duration, + @NotNull Modifier amplifier) { Modifier durationScale = Modifier.read(config, "Settings.Potion_Effect.Duration", duration, "Potion effect duration (in seconds). This setting is useless for 'permanent' effects."); @@ -52,24 +51,21 @@ public class PotionSettingsImpl implements PotionSettings { Modifier amplifierScale = Modifier.read(config, "Settings.Potion_Effect.Level", amplifier, "Potion effect level."); - return new PotionSettingsImpl(type, isPermanent, data.hasVisualEffects(), durationScale, amplifierScale); + return new PotionEffects(type, isPermanent, data.hasVisualEffects(), durationScale, amplifierScale); } - @Override public boolean isPermanent() { - return this.isPermanent; + return this.permanent; } - @Override @NotNull public PotionEffectType getEffectType() { return this.effectType; } - @Override public int getEffectDuration(int level) { if (this.isPermanent()) { - int duration = Config.CORE_PASSIVE_ENCHANTS_TRIGGER_INTERVAL.get().intValue() * 2; + int duration = ConfigBridge.getEnchantsTickInterval() * 2; if (this.getEffectType().getKey().equals(PotionEffectType.NIGHT_VISION.getKey()) && duration < 600) { duration += 30 * 20; } @@ -78,12 +74,10 @@ public class PotionSettingsImpl implements PotionSettings { return (int) (this.duration.getValue(level) * 20); } - @Override public int getEffectAmplifier(int level) { return (int) this.amplifier.getValue(level); } - @Override @NotNull public PotionEffect createEffect(int level) { int duration = this.getEffectDuration(level); @@ -92,7 +86,6 @@ public class PotionSettingsImpl implements PotionSettings { return new PotionEffect(this.getEffectType(), duration, amplifier, false, this.particles); } - @Override public boolean addEffect(@NotNull LivingEntity target, int level) { target.addPotionEffect(this.createEffect(level)); return true; diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/PotionMeta.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/PotionMeta.java new file mode 100644 index 0000000..c7a525f --- /dev/null +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/PotionMeta.java @@ -0,0 +1,33 @@ +package su.nightexpress.excellentenchants.api.enchantment.meta; + +import org.bukkit.entity.LivingEntity; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.jetbrains.annotations.NotNull; + +public interface PotionMeta extends MetaHolder { + + default boolean isPermanent() { + return this.getMeta().getPotionEffects().isPermanent(); + } + + default PotionEffectType getEffectType() { + return this.getMeta().getPotionEffects().getEffectType(); + } + + default int getEffectAmplifier(int level) { + return this.getMeta().getPotionEffects().getEffectAmplifier(level); + } + + default int getEffectDuration(int level) { + return this.getMeta().getPotionEffects().getEffectDuration(level); + } + + default PotionEffect createEffect(int level) { + return this.getMeta().getPotionEffects().createEffect(level); + } + + default boolean addEffect(@NotNull LivingEntity target, int level) { + return this.getMeta().getPotionEffects().addEffect(target, level); + } +} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/ChanceSettingsImpl.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/Probability.java similarity index 53% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/ChanceSettingsImpl.java rename to API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/Probability.java index 090ac33..0144d69 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/ChanceSettingsImpl.java +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/meta/Probability.java @@ -1,38 +1,37 @@ -package su.nightexpress.excellentenchants.enchantment.data; +package su.nightexpress.excellentenchants.api.enchantment.meta; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.random.Rnd; -public class ChanceSettingsImpl implements ChanceSettings { +public class Probability { private final Modifier triggerChance; - private ChanceSettingsImpl(@NotNull Modifier triggerChance) { + private Probability(@NotNull Modifier triggerChance) { this.triggerChance = triggerChance; } @NotNull - public static ChanceSettingsImpl create(@NotNull FileConfig config) { + public static Probability create(@NotNull FileConfig config) { return create(config, Modifier.add(100, 0, 1, 100)); } @NotNull - public static ChanceSettingsImpl create(@NotNull FileConfig config, @NotNull Modifier def) { - Modifier chanceMod = Modifier.read(config, "Settings.Trigger_Chance", def, - "A chance that this enchantment will be triggered."); + public static Probability create(@NotNull FileConfig config, @NotNull Modifier def) { + Modifier chanceMod = Modifier.read(config, "Settings.Trigger_Chance", + def, + "A chance that this enchantment will be triggered." + ); - return new ChanceSettingsImpl(chanceMod); + return new Probability(chanceMod); } - @Override public double getTriggerChance(int level) { return this.triggerChance.getValue(level); } - @Override public boolean checkTriggerChance(int level) { return Rnd.chance(this.getTriggerChance(level)); } diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/BlockBreakEnchant.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/BlockBreakEnchant.java index 58d6ebd..6ed0b16 100644 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/BlockBreakEnchant.java +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/BlockBreakEnchant.java @@ -5,9 +5,9 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; -public interface BlockBreakEnchant extends EnchantmentData { +public interface BlockBreakEnchant extends CustomEnchantment { boolean onBreak(@NotNull BlockBreakEvent event, @NotNull LivingEntity player, @NotNull ItemStack item, int level); diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/BlockDropEnchant.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/BlockDropEnchant.java index 7522603..d813c36 100644 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/BlockDropEnchant.java +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/BlockDropEnchant.java @@ -5,9 +5,9 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockDropItemEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; -public interface BlockDropEnchant extends EnchantmentData { +public interface BlockDropEnchant extends CustomEnchantment { boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull LivingEntity player, @NotNull ItemStack item, int level); diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/BowEnchant.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/BowEnchant.java index b5c5f16..346cc8b 100644 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/BowEnchant.java +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/BowEnchant.java @@ -8,9 +8,9 @@ import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; -public interface BowEnchant extends EnchantmentData { +public interface BowEnchant extends CustomEnchantment { boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level); diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/CombatEnchant.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/CombatEnchant.java index d298def..727089d 100644 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/CombatEnchant.java +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/CombatEnchant.java @@ -5,9 +5,9 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; -public interface CombatEnchant extends EnchantmentData { +public interface CombatEnchant extends CustomEnchantment { boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/DamageEnchant.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/DamageEnchant.java index beca835..32d945e 100644 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/DamageEnchant.java +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/DamageEnchant.java @@ -5,9 +5,9 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; -public interface DamageEnchant extends EnchantmentData { +public interface DamageEnchant extends CustomEnchantment { boolean onDamage(@NotNull EntityDamageEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, int level); diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/DeathEnchant.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/DeathEnchant.java index 97be5c7..b3542ec 100644 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/DeathEnchant.java +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/DeathEnchant.java @@ -7,9 +7,9 @@ import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityResurrectEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; -public interface DeathEnchant extends EnchantmentData { +public interface DeathEnchant extends CustomEnchantment { boolean onDeath(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, ItemStack item, int level); diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/FishingEnchant.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/FishingEnchant.java index 69b91ea..f98e69f 100644 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/FishingEnchant.java +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/FishingEnchant.java @@ -4,9 +4,9 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; -public interface FishingEnchant extends EnchantmentData { +public interface FishingEnchant extends CustomEnchantment { boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level); diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/GenericEnchant.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/GenericEnchant.java index 4d37a3b..04dcec2 100644 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/GenericEnchant.java +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/GenericEnchant.java @@ -1,7 +1,7 @@ package su.nightexpress.excellentenchants.api.enchantment.type; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; -public interface GenericEnchant extends EnchantmentData { +public interface GenericEnchant extends CustomEnchantment { } diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/InteractEnchant.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/InteractEnchant.java index 57e2fc6..af914fd 100644 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/InteractEnchant.java +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/InteractEnchant.java @@ -5,9 +5,9 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; -public interface InteractEnchant extends EnchantmentData { +public interface InteractEnchant extends CustomEnchantment { boolean onInteract(@NotNull PlayerInteractEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, int level); diff --git a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/PassiveEnchant.java b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/PassiveEnchant.java index c9ce7af..7ed3c5f 100644 --- a/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/PassiveEnchant.java +++ b/API/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/PassiveEnchant.java @@ -3,10 +3,10 @@ package su.nightexpress.excellentenchants.api.enchantment.type; import org.bukkit.entity.LivingEntity; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; -import su.nightexpress.excellentenchants.api.enchantment.data.PeriodicData; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.PeriodMeta; -public interface PassiveEnchant extends EnchantmentData, PeriodicData { +public interface PassiveEnchant extends CustomEnchantment, PeriodMeta { boolean onTrigger(@NotNull LivingEntity entity, @NotNull ItemStack item, int level); } diff --git a/Core/pom.xml b/Core/pom.xml index 6c17899..59181c9 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -5,7 +5,7 @@ ExcellentEnchants su.nightexpress.excellentenchants - 4.1.0 + 4.2.0 4.0.0 @@ -18,92 +18,81 @@ + md_5-releases https://repo.md-5.net/content/repositories/releases/ + dmulloy2-repo https://repo.dmulloy2.net/repository/public/ + placeholderapi https://repo.extendedclip.com/content/repositories/placeholderapi/ + lumine-repo https://mvn.lumine.io/repository/maven-public/ + lumine-snapshot http://mvn.lumine.io/repository/maven-snapshots/ + + org.spigotmc spigot-api - 1.20.4-R0.1-SNAPSHOT + 1.21.1-R0.1-SNAPSHOT + io.lumine Mythic-Dist 5.6.0-SNAPSHOT provided + com.comphenix.protocol ProtocolLib - 5.1.0 + 5.3.0-SNAPSHOT provided + me.clip placeholderapi 2.11.2 provided + su.nightexpress.excellentenchants API - 4.1.0 + 4.2.0 + su.nightexpress.excellentenchants NMS - 4.1.0 + 4.2.0 + su.nightexpress.excellentenchants MC_1_21 - 4.1.0 - - - su.nightexpress.excellentenchants - MC_1_20_6 - 4.1.0 - - - su.nightexpress.excellentenchants - V1_20_R3 - 4.1.0 - - - su.nightexpress.excellentenchants - V1_20_R2 - 4.1.0 - - - su.nightexpress.excellentenchants - V1_20_R1 - 4.1.0 - - - su.nightexpress.excellentenchants - V1_19_R3 - 4.1.0 + 4.2.0 + diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/EnchantsAPI.java b/Core/src/main/java/su/nightexpress/excellentenchants/EnchantsAPI.java new file mode 100644 index 0000000..0f29ed3 --- /dev/null +++ b/Core/src/main/java/su/nightexpress/excellentenchants/EnchantsAPI.java @@ -0,0 +1,31 @@ +package su.nightexpress.excellentenchants; + +import org.jetbrains.annotations.NotNull; +import su.nightexpress.excellentenchants.enchantment.EnchantManager; +import su.nightexpress.excellentenchants.rarity.RarityManager; + +public class EnchantsAPI { + + private static EnchantsPlugin plugin; + + static void load(@NotNull EnchantsPlugin plugin) { + EnchantsAPI.plugin = plugin; + } + + @NotNull + private static EnchantsPlugin plugin() { + if (plugin == null) throw new IllegalStateException("API is not initialized!"); + + return plugin; + } + + @NotNull + public static EnchantManager getEnchantManager() { + return plugin().getEnchantManager(); + } + + @NotNull + public static RarityManager getRarityManager() { + return plugin().getRarityManager(); + } +} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/EnchantsPlugin.java b/Core/src/main/java/su/nightexpress/excellentenchants/EnchantsPlugin.java index 3f50c03..0af6852 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/EnchantsPlugin.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/EnchantsPlugin.java @@ -4,35 +4,29 @@ import org.bukkit.entity.Item; import org.bukkit.event.block.BlockDropItemEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.DistributionWay; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.command.*; +import su.nightexpress.excellentenchants.api.ConfigBridge; +import su.nightexpress.excellentenchants.command.BaseCommands; import su.nightexpress.excellentenchants.config.Config; import su.nightexpress.excellentenchants.config.Keys; import su.nightexpress.excellentenchants.config.Lang; import su.nightexpress.excellentenchants.config.Perms; import su.nightexpress.excellentenchants.enchantment.EnchantManager; -import su.nightexpress.excellentenchants.enchantment.EnchantPopulator; -import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import su.nightexpress.excellentenchants.hook.HookPlugin; import su.nightexpress.excellentenchants.hook.impl.PlaceholderHook; import su.nightexpress.excellentenchants.hook.impl.ProtocolLibHook; import su.nightexpress.excellentenchants.nms.EnchantNMS; -import su.nightexpress.excellentenchants.nms.v1_19_R3.V1_19_R3; -import su.nightexpress.excellentenchants.nms.v1_20_R1.V1_20_R1; -import su.nightexpress.excellentenchants.nms.v1_20_R2.V1_20_R2; -import su.nightexpress.excellentenchants.nms.v1_20_R3.V1_20_R3; +import su.nightexpress.excellentenchants.rarity.RarityManager; +import su.nightexpress.excellentenchants.registry.EnchantRegistry; import su.nightexpress.nightcore.NightPlugin; -import su.nightexpress.nightcore.command.api.NightPluginCommand; -import su.nightexpress.nightcore.command.base.ReloadSubCommand; +import su.nightexpress.nightcore.command.experimental.ImprovedCommands; import su.nightexpress.nightcore.config.PluginDetails; import su.nightexpress.nightcore.util.Plugins; import su.nightexpress.nightcore.util.Version; -public class EnchantsPlugin extends NightPlugin { +public class EnchantsPlugin extends NightPlugin implements ImprovedCommands { private EnchantRegistry registry; + private RarityManager rarityManager; private EnchantManager enchantManager; private EnchantNMS enchantNMS; @@ -40,13 +34,12 @@ public class EnchantsPlugin extends NightPlugin { public void onLoad() { super.onLoad(); this.registry = new EnchantRegistry(this); - EnchantUtils.hook(this); } @Override @NotNull protected PluginDetails getDefaultDetails() { - return PluginDetails.create("Enchants", new String[]{"excellentenchants", "eenchants"}) + return PluginDetails.create("Enchants", new String[]{"eenchants", "excellentenchants"}) .setConfigClass(Config.class) .setLangClass(Lang.class) .setPermissionsClass(Perms.class); @@ -54,98 +47,73 @@ public class EnchantsPlugin extends NightPlugin { @Override public void enable() { - if (!this.setNMS()) { + if (!this.loadInternals()) { this.error("Unsupported server version!"); this.getPluginManager().disablePlugin(this); return; } - //this.getLangManager().loadEnum(ItemCategory.class); - //this.getLangManager().loadEnum(EnchantmentTarget.class); - this.getLangManager().loadEnum(DistributionWay.class); - this.getLangManager().loadEnum(Rarity.class); + this.loadAPI(); + this.loadCommands(); - Keys.loadKeys(this); - Config.loadRarityWeights(this.getConfig()); - - this.registerCommands(); + this.rarityManager = new RarityManager(this); + this.rarityManager.setup(); this.registry.setup(); this.enchantManager = new EnchantManager(this); this.enchantManager.setup(); - if (Plugins.isInstalled(HookPlugin.PROTOCOL_LIB)) { - ProtocolLibHook.setup(this); - } - else { - this.warn(HookPlugin.PROTOCOL_LIB + " is not installed. Enchantment descriptions won't be displayed."); + this.loadHooks(); + } + + @Override + public void disable() { + if (Plugins.hasPlaceholderAPI()) { + PlaceholderHook.shutdown(); } - /*if (Config.ENCHANTMENTS_DISPLAY_MODE.get() == 2) { + if (this.enchantManager != null) this.enchantManager.shutdown(); + if (this.rarityManager != null) this.rarityManager.shutdown(); + + this.registry.shutdown(); + } + + private boolean loadInternals() { + if (Version.getCurrent() == Version.MC_1_21) { + this.enchantNMS = new Internal_1_21(this); + return true; + } + + return false; + } + + private void loadCommands() { + BaseCommands.load(this); + } + + private void loadAPI() { + EnchantsAPI.load(this); + Keys.loadKeys(this); + ConfigBridge.setEnchantsTickInterval(Config.CORE_PASSIVE_ENCHANTS_TRIGGER_INTERVAL.get().intValue()); + } + + private void loadHooks() { + if (Config.isDescriptionEnabled()) { if (Plugins.isInstalled(HookPlugin.PROTOCOL_LIB)) { ProtocolLibHook.setup(this); } else { - this.warn(HookPlugin.PROTOCOL_LIB + " is not installed. Display mode is set to Plain lore."); - Config.ENCHANTMENTS_DISPLAY_MODE.set(1); + this.warn(HookPlugin.PROTOCOL_LIB + " is not installed. Enchantment descriptions won't display."); } - }*/ + } if (Plugins.hasPlaceholderAPI()) { PlaceholderHook.setup(this); } } - @Override - public void disable() { - if (this.enchantManager != null) { - this.enchantManager.shutdown(); - this.enchantManager = null; - } - - if (Plugins.hasPlaceholderAPI()) { - PlaceholderHook.shutdown(); - } - - this.registry.shutdown(); - } - - private boolean setNMS() { - this.enchantNMS = switch (Version.getCurrent()) { - case V1_19_R3 -> new V1_19_R3(); - case V1_20_R1 -> new V1_20_R1(); - case V1_20_R2 -> new V1_20_R2(); - case V1_20_R3 -> new V1_20_R3(); - case MC_1_20_6 -> new Internal1_20_6(); - case MC_1_21 -> new Internal_1_21(this); - default -> null; - }; - return this.enchantNMS != null; - } - - private void registerCommands() { - NightPluginCommand mainCommand = this.getBaseCommand(); - mainCommand.addChildren(new BookCommand(this)); - mainCommand.addChildren(new EnchantCommand(this)); - mainCommand.addChildren(new ListCommand(this)); - mainCommand.addChildren(new RarityBookCommand(this)); - mainCommand.addChildren(new ReloadSubCommand(this, Perms.COMMAND_RELOAD)); - if (Config.ENCHANTMENTS_CHARGES_ENABLED.get()) { - mainCommand.addChildren(new GetFuelCommand(this)); - } - } - - @NotNull - public EnchantPopulator createPopulator(@NotNull ItemStack item, @NotNull DistributionWay distributionWay) { - return new EnchantPopulator(this, item, distributionWay); - } - public void populateResource(@NotNull BlockDropItemEvent event, @NotNull ItemStack itemStack) { - /*if (Plugins.isSpigot()) { - this.warn("Adding items to BlockDropItemEvent is not supported in Spigot, please use Paper or its forks for this feature."); - return; - }*/ Item item = this.getEnchantNMS().popResource(event.getBlock(), itemStack); event.getItems().add(item); } @@ -155,6 +123,11 @@ public class EnchantsPlugin extends NightPlugin { return registry; } + @NotNull + public RarityManager getRarityManager() { + return rarityManager; + } + @NotNull public EnchantManager getEnchantManager() { return this.enchantManager; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/Placeholders.java b/Core/src/main/java/su/nightexpress/excellentenchants/Placeholders.java index 9bc322b..d324338 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/Placeholders.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/Placeholders.java @@ -1,23 +1,28 @@ package su.nightexpress.excellentenchants; +import org.jetbrains.annotations.NotNull; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.PeriodMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionMeta; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.EnchantPlaceholders; +import su.nightexpress.nightcore.language.LangAssets; +import su.nightexpress.nightcore.util.ItemUtil; +import su.nightexpress.nightcore.util.NumberUtil; + public class Placeholders extends su.nightexpress.nightcore.util.Placeholders { - public static final String URL_WIKI = "https://nightexpress.gitbook.io/excellentenchants"; - public static final String URL_PLACEHOLDERS = "https://nightexpress.gitbook.io/excellentenchants/utility/placeholders"; - public static final String URL_CHRAGES = "https://nightexpress.gitbook.io/excellentenchants/features/charges"; - - public static final String VANILLA_DISTRIBUTION_NAME = "Vanilla Distribution Mode"; - public static final String CUSTOM_DISTRIBUTION_NAME = "Custom Distribution Mode"; - - public static final String VANILLA_DISTRIBUTION_HEADER = "=".repeat(15) + " " + VANILLA_DISTRIBUTION_NAME + " " + "=".repeat(15); - public static final String CUSTOM_DISTRIBUTION_HEADER = "=".repeat(15) + " " + CUSTOM_DISTRIBUTION_NAME + " " + "=".repeat(15); + public static final String WIKI_URL = "https://nightexpress.gitbook.io/excellentenchants/"; + public static final String WIKI_PLACEHOLDERS = WIKI_URL + "utility/placeholders"; + public static final String WIKI_CHRAGES = WIKI_URL + "features/charges"; public static final String GENERIC_TYPE = "%type%"; public static final String GENERIC_NAME = "%name%"; public static final String GENERIC_ITEM = "%item%"; public static final String GENERIC_LEVEL = "%level%"; public static final String GENERIC_AMOUNT = "%amount%"; - public static final String GENERIC_MODIFIER = "%modifier%"; + public static final String GENERIC_CHARGES = "%charges%"; + public static final String GENERIC_MODIFIER = "%modifier%"; public static final String GENERIC_DESCRIPTION = "%description%"; public static final String GENERIC_ENCHANT = "%enchant%"; public static final String GENERIC_RADIUS = "%radius%"; @@ -34,24 +39,54 @@ public class Placeholders extends su.nightexpress.nightcore.util.Placeholders { public static final String ENCHANTMENT_POTION_TYPE = "%enchantment_potion_type%"; public static final String ENCHANTMENT_ID = "%enchantment_id%"; public static final String ENCHANTMENT_NAME = "%enchantment_name%"; - public static final String ENCHANTMENT_NAME_FORMATTED = "%enchantment_name_formatted%"; public static final String ENCHANTMENT_DESCRIPTION = "%enchantment_description%"; - public static final String ENCHANTMENT_DESCRIPTION_FORMATTED = "%enchantment_description_formatted%"; + //public static final String ENCHANTMENT_DESCRIPTION_FORMATTED = "%enchantment_description_formatted%"; public static final String ENCHANTMENT_DESCRIPTION_REPLACED = "%enchantment_description_replaced%"; public static final String ENCHANTMENT_LEVEL = "%enchantment_level%"; public static final String ENCHANTMENT_LEVEL_MIN = "%enchantment_level_min%"; public static final String ENCHANTMENT_LEVEL_MAX = "%enchantment_level_max%"; public static final String ENCHANTMENT_RARITY = "%enchantment_rarity%"; public static final String ENCHANTMENT_FIT_ITEM_TYPES = "%enchantment_fit_item_types%"; - public static final String ENCHANTMENT_OBTAIN_CHANCE_ENCHANTING = "%enchantment_obtain_chance_enchanting%"; - public static final String ENCHANTMENT_OBTAIN_CHANCE_VILLAGER = "%enchantment_obtain_chance_villager%"; - public static final String ENCHANTMENT_OBTAIN_CHANCE_LOOT_GENERATION = "%enchantment_obtain_chance_loot_generation%"; - public static final String ENCHANTMENT_OBTAIN_CHANCE_FISHING = "%enchantment_obtain_chance_fishing%"; - public static final String ENCHANTMENT_OBTAIN_CHANCE_MOB_SPAWNING = "%enchantment_obtain_chance_mob_spawning%"; public static final String ENCHANTMENT_CHARGES = "%enchantment_charges%"; public static final String ENCHANTMENT_CHARGES_MAX_AMOUNT = "%enchantment_charges_max_amount%"; public static final String ENCHANTMENT_CHARGES_CONSUME_AMOUNT = "%enchantment_charges_consume_amount%"; public static final String ENCHANTMENT_CHARGES_RECHARGE_AMOUNT = "%enchantment_charges_recharge_amount%"; public static final String ENCHANTMENT_CHARGES_FUEL_ITEM = "%enchantment_charges_fuel_item%"; + + public static EnchantPlaceholders forEnchant(@NotNull GameEnchantment enchantment) { + EnchantPlaceholders placeholders = new EnchantPlaceholders(); + + placeholders + .add(ENCHANTMENT_ID, enchantment::getId) + .add(ENCHANTMENT_NAME, enchantment::getDisplayName) + .add(ENCHANTMENT_DESCRIPTION, () -> String.join("\n", enchantment.getDescription())) + //.add(ENCHANTMENT_DESCRIPTION_FORMATTED, () -> String.join("\n", enchantment.getDescriptionFormatted())) + .add(ENCHANTMENT_DESCRIPTION_REPLACED, level -> String.join("\n", enchantment.getDescription(level))) + .add(ENCHANTMENT_LEVEL, NumberUtil::toRoman) + .add(ENCHANTMENT_LEVEL_MIN, () -> String.valueOf(1)) + .add(ENCHANTMENT_LEVEL_MAX, () -> String.valueOf(enchantment.getDefinition().getMaxLevel())) + .add(ENCHANTMENT_RARITY, () -> enchantment.getDefinition().getRarity().getName()) + .add(ENCHANTMENT_FIT_ITEM_TYPES, () -> enchantment.getDefinition().getSupportedItems().getLocalized()) + .add(ENCHANTMENT_CHARGES_MAX_AMOUNT, level -> NumberUtil.format(enchantment.getCharges().getMaxAmount(level))) + .add(ENCHANTMENT_CHARGES_CONSUME_AMOUNT, level -> NumberUtil.format(enchantment.getCharges().getConsumeAmount(level))) + .add(ENCHANTMENT_CHARGES_RECHARGE_AMOUNT, level -> NumberUtil.format(enchantment.getCharges().getRechargeAmount(level))) + .add(ENCHANTMENT_CHARGES_FUEL_ITEM, () -> ItemUtil.getItemName(enchantment.getCharges().getFuel())); + + if (enchantment instanceof ChanceMeta chanceMeta) { + placeholders.add(ENCHANTMENT_CHANCE, level -> NumberUtil.format(chanceMeta.getTriggerChance(level))); + } + + if (enchantment instanceof PeriodMeta periodMeta) { + placeholders.add(ENCHANTMENT_INTERVAL, () -> NumberUtil.format(periodMeta.getInterval() / 20D)); + } + + if (enchantment instanceof PotionMeta potionMeta) { + placeholders.add(ENCHANTMENT_POTION_LEVEL, level -> NumberUtil.toRoman(potionMeta.getEffectAmplifier(level))); + placeholders.add(ENCHANTMENT_POTION_DURATION, level -> NumberUtil.format(potionMeta.getEffectDuration(level) / 20D)); + placeholders.add(ENCHANTMENT_POTION_TYPE, () -> LangAssets.get(potionMeta.getEffectType())); + } + + return placeholders; + } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/command/BaseCommands.java b/Core/src/main/java/su/nightexpress/excellentenchants/command/BaseCommands.java new file mode 100644 index 0000000..5ed4455 --- /dev/null +++ b/Core/src/main/java/su/nightexpress/excellentenchants/command/BaseCommands.java @@ -0,0 +1,209 @@ +package su.nightexpress.excellentenchants.command; + +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import su.nightexpress.excellentenchants.EnchantsPlugin; +import su.nightexpress.excellentenchants.Placeholders; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.Rarity; +import su.nightexpress.excellentenchants.config.Config; +import su.nightexpress.excellentenchants.config.Lang; +import su.nightexpress.excellentenchants.config.Perms; +import su.nightexpress.excellentenchants.registry.EnchantRegistry; +import su.nightexpress.excellentenchants.util.EnchantUtils; +import su.nightexpress.nightcore.command.experimental.CommandContext; +import su.nightexpress.nightcore.command.experimental.argument.ArgumentTypes; +import su.nightexpress.nightcore.command.experimental.argument.ParsedArguments; +import su.nightexpress.nightcore.command.experimental.impl.ReloadCommand; +import su.nightexpress.nightcore.command.experimental.node.ChainedNode; +import su.nightexpress.nightcore.command.experimental.node.DirectNode; +import su.nightexpress.nightcore.util.*; +import su.nightexpress.nightcore.util.random.Rnd; + +import java.util.Set; + +public class BaseCommands { + + public static void load(@NotNull EnchantsPlugin plugin) { + ChainedNode rootNode = plugin.getRootNode(); + + ReloadCommand.inject(plugin, rootNode, Perms.COMMAND_RELOAD); + + rootNode.addChildren(DirectNode.builder(plugin, "book") + .description(Lang.COMMAND_BOOK_DESC) + .permission(Perms.COMMAND_BOOK) + .withArgument(CommandArguments.enchantArgument(CommandArguments.ENCHANT).required()) + .withArgument(CommandArguments.levelArgument(CommandArguments.LEVEL)) + .withArgument(ArgumentTypes.player(CommandArguments.PLAYER)) + .executes((context, arguments) -> giveBook(plugin, context, arguments)) + ); + + rootNode.addChildren(DirectNode.builder(plugin, "enchant") + .description(Lang.COMMAND_ENCHANT_DESC) + .permission(Perms.COMMAND_ENCHANT) + .withArgument(CommandArguments.enchantArgument(CommandArguments.ENCHANT).required()) + .withArgument(CommandArguments.levelArgument(CommandArguments.LEVEL).required()) + .withArgument(ArgumentTypes.player(CommandArguments.PLAYER)) + .withArgument(CommandArguments.slotArgument(CommandArguments.SLOT)) + .executes((context, arguments) -> enchantItem(plugin, context, arguments)) + ); + + rootNode.addChildren(DirectNode.builder(plugin, "list") + .playerOnly() + .description(Lang.COMMAND_LIST_DESC) + .permission(Perms.COMMAND_LIST) + .withArgument(ArgumentTypes.player(CommandArguments.PLAYER).permission(Perms.COMMAND_LIST_OTHERS)) + .executes((context, arguments) -> openList(plugin, context, arguments)) + ); + + rootNode.addChildren(DirectNode.builder(plugin, "raritybook") + .description(Lang.COMMAND_RARITY_BOOK_DESC) + .permission(Perms.COMMAND_RARITY_BOOK) + .withArgument(CommandArguments.rarityArgument(plugin, CommandArguments.RARITY).required()) + .withArgument(CommandArguments.levelArgument(CommandArguments.LEVEL)) + .withArgument(ArgumentTypes.player(CommandArguments.PLAYER)) + .executes((context, arguments) -> giveRarityBook(plugin, context, arguments)) + ); + + if (Config.isChargesEnabled()) { + rootNode.addChildren(DirectNode.builder(plugin, "getfuel") + .playerOnly() + .description(Lang.COMMAND_GET_FUEL_DESC) + .permission(Perms.COMMAND_GET_FUEL) + .withArgument(CommandArguments.customEnchantArgument(CommandArguments.ENCHANT).required() + .withSamples(context -> EnchantRegistry.getRegistered().stream().filter(CustomEnchantment::hasCharges).map(CustomEnchantment::getId).toList()) + ) + .withArgument(ArgumentTypes.integerAbs(CommandArguments.AMOUNT).withSamples(context -> Lists.newList("1", "8", "16", "32", "64"))) + .executes((context, arguments) -> giveFuel(plugin, context, arguments)) + ); + } + } + + private static int getLevel(@NotNull Enchantment enchantment, @NotNull ParsedArguments arguments) { + int level = arguments.getIntArgument(CommandArguments.LEVEL, -1); + if (level < 1) { + level = EnchantUtils.randomLevel(enchantment); + } + return level; + } + + public static boolean giveBook(@NotNull EnchantsPlugin plugin, @NotNull CommandContext context, @NotNull ParsedArguments arguments) { + Player player = CommandUtil.getPlayerOrSender(context, arguments, CommandArguments.PLAYER); + if (player == null) return false; + + Enchantment enchantment = arguments.getEnchantmentArgument(CommandArguments.ENCHANT); + int level = getLevel(enchantment, arguments); + + ItemStack item = new ItemStack(Material.ENCHANTED_BOOK); + EnchantUtils.add(item, enchantment, level, true); + Players.addItem(player, item); + + Lang.COMMAND_BOOK_DONE.getMessage() + .replace(Placeholders.GENERIC_ENCHANT, EnchantUtils.getLocalized(enchantment)) + .replace(Placeholders.forPlayer(player)) + .send(context.getSender()); + + return true; + } + + public static boolean enchantItem(@NotNull EnchantsPlugin plugin, @NotNull CommandContext context, @NotNull ParsedArguments arguments) { + Player player = CommandUtil.getPlayerOrSender(context, arguments, CommandArguments.PLAYER); + if (player == null) return false; + + EquipmentSlot slot = arguments.getArgument(CommandArguments.SLOT, EquipmentSlot.class, EquipmentSlot.HAND); + + ItemStack item = player.getInventory().getItem(slot); + if (item == null || item.getType().isAir()) { + Lang.COMMAND_ENCHANT_ERROR_NO_ITEM.getMessage().send(context.getSender()); + return false; + } + + Enchantment enchantment = arguments.getEnchantmentArgument(CommandArguments.ENCHANT); + int level = getLevel(enchantment, arguments); + + if (level > 0) { + EnchantUtils.add(item, enchantment, level, true); + } + else EnchantUtils.remove(item, enchantment); + + //player.getInventory().setItem(slot, item); + + (context.getSender() == player ? Lang.COMMAND_ENCHANT_DONE_SELF : Lang.COMMAND_ENCHANT_DONE_OTHERS).getMessage() + .replace(Placeholders.forPlayer(player)) + .replace(Placeholders.GENERIC_ITEM, ItemUtil.getItemName(item)) + .replace(Placeholders.GENERIC_ENCHANT, EnchantUtils.getLocalized(enchantment)) + .replace(Placeholders.GENERIC_LEVEL, NumberUtil.toRoman(level)) + .send(context.getSender()); + + return true; + } + + public static boolean giveFuel(@NotNull EnchantsPlugin plugin, @NotNull CommandContext context, @NotNull ParsedArguments arguments) { + Player player = context.getPlayerOrThrow(); + CustomEnchantment enchantment = arguments.getArgument(CommandArguments.ENCHANT, CustomEnchantment.class); + int amount = arguments.getIntArgument(CommandArguments.AMOUNT, 1); + + if (!enchantment.hasCharges()) { + Lang.COMMAND_GET_FUEL_ERROR_NO_CHARGES.getMessage() + .replace(Placeholders.GENERIC_NAME, enchantment.getDisplayName()) + .send(context.getSender()); + return false; + } + + ItemStack fuel = enchantment.getCharges().getFuel(); + fuel.setAmount(amount); + + Players.addItem(player, fuel); + + Lang.COMMAND_GET_FUEL_DONE.getMessage() + .replace(Placeholders.GENERIC_AMOUNT, NumberUtil.format(amount)) + .replace(Placeholders.GENERIC_NAME, ItemUtil.getItemName(fuel)) + .send(context.getSender()); + + return true; + } + + public static boolean openList(@NotNull EnchantsPlugin plugin, @NotNull CommandContext context, @NotNull ParsedArguments arguments) { + Player player = CommandUtil.getPlayerOrSender(context, arguments, CommandArguments.PLAYER); + if (player == null) return false; + + plugin.getEnchantManager().openEnchantsMenu(player); + + if (player != context.getSender()) { + Lang.COMMAND_LIST_DONE_OTHERS.getMessage().replace(Placeholders.forPlayer(player)).send(context.getSender()); + } + return true; + } + + public static boolean giveRarityBook(@NotNull EnchantsPlugin plugin, @NotNull CommandContext context, @NotNull ParsedArguments arguments) { + Player player = CommandUtil.getPlayerOrSender(context, arguments, CommandArguments.PLAYER); + if (player == null) return false; + + Rarity rarity = arguments.getArgument(CommandArguments.RARITY, Rarity.class); + + Set enchants = EnchantRegistry.getByRarity(rarity); + CustomEnchantment customEnchantment = enchants.isEmpty() ? null : Rnd.get(enchants); + if (customEnchantment == null) { + Lang.COMMAND_RARITY_BOOK_ERROR_EMPTY.getMessage().send(context.getSender()); + return false; + } + + Enchantment enchantment = customEnchantment.getBukkitEnchantment(); + int level = getLevel(enchantment, arguments); + + ItemStack item = new ItemStack(Material.ENCHANTED_BOOK); + EnchantUtils.add(item, enchantment, level, true); + Players.addItem(player, item); + + Lang.COMMAND_RARITY_BOOK_DONE.getMessage() + .replace(Placeholders.GENERIC_NAME, rarity.getName()) + .replace(Placeholders.forPlayer(player)) + .send(context.getSender()); + + return true; + } +} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/command/BookCommand.java b/Core/src/main/java/su/nightexpress/excellentenchants/command/BookCommand.java deleted file mode 100644 index 5da4c6b..0000000 --- a/Core/src/main/java/su/nightexpress/excellentenchants/command/BookCommand.java +++ /dev/null @@ -1,80 +0,0 @@ -package su.nightexpress.excellentenchants.command; - -import org.bukkit.Material; -import org.bukkit.command.CommandSender; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.config.Perms; -import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.config.Lang; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; -import su.nightexpress.nightcore.command.CommandResult; -import su.nightexpress.nightcore.command.impl.AbstractCommand; -import su.nightexpress.nightcore.util.BukkitThing; -import su.nightexpress.nightcore.util.Players; -import su.nightexpress.nightcore.util.random.Rnd; - -import java.util.Arrays; -import java.util.List; - -public class BookCommand extends AbstractCommand { - - public BookCommand(@NotNull EnchantsPlugin plugin) { - super(plugin, new String[]{"book"}, Perms.COMMAND_BOOK); - this.setDescription(Lang.COMMAND_BOOK_DESC); - this.setUsage(Lang.COMMAND_BOOK_USAGE); - } - - @Override - @NotNull - public List getTab(@NotNull Player player, int arg, @NotNull String[] args) { - if (arg == 1) { - return Players.playerNames(player); - } - if (arg == 2) { - return BukkitThing.getEnchantments().stream().map(enchantment -> enchantment.getKey().getKey()).toList(); - } - if (arg == 3) { - return Arrays.asList("-1", "1", "5", "10"); - } - return super.getTab(player, arg, args); - } - - @Override - protected void onExecute(@NotNull CommandSender sender, @NotNull CommandResult result) { - if (result.length() < 4) { - this.errorUsage(sender); - return; - } - - Player player = Players.getPlayer(result.getArg(1)); - if (player == null) { - this.errorPlayer(sender); - return; - } - - Enchantment enchantment = BukkitThing.getEnchantment(result.getArg(2)); - if (enchantment == null) { - Lang.ERROR_INVALID_ENCHANT.getMessage().send(sender); - return; - } - - int level = result.getInt(3, -1); - if (level < 1) { - level = Rnd.get(enchantment.getStartLevel(), enchantment.getMaxLevel()); - } - - ItemStack item = new ItemStack(Material.ENCHANTED_BOOK); - EnchantUtils.add(item, enchantment, level, true); - //EnchantUtils.updateDisplay(item); - Players.addItem(player, item); - - Lang.COMMAND_BOOK_DONE.getMessage() - .replace(Placeholders.GENERIC_ENCHANT, EnchantUtils.getLocalized(enchantment)) - .replace(Placeholders.forPlayer(player)) - .send(sender); - } -} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/command/CommandArguments.java b/Core/src/main/java/su/nightexpress/excellentenchants/command/CommandArguments.java new file mode 100644 index 0000000..5a038e9 --- /dev/null +++ b/Core/src/main/java/su/nightexpress/excellentenchants/command/CommandArguments.java @@ -0,0 +1,67 @@ +package su.nightexpress.excellentenchants.command; + +import org.bukkit.Registry; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.EquipmentSlot; +import org.jetbrains.annotations.NotNull; +import su.nightexpress.excellentenchants.EnchantsPlugin; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.Rarity; +import su.nightexpress.excellentenchants.config.Lang; +import su.nightexpress.excellentenchants.registry.EnchantRegistry; +import su.nightexpress.nightcore.command.experimental.argument.ArgumentTypes; +import su.nightexpress.nightcore.command.experimental.argument.CommandArgument; +import su.nightexpress.nightcore.command.experimental.builder.ArgumentBuilder; +import su.nightexpress.nightcore.util.*; + +import java.util.Arrays; + +public class CommandArguments { + + public static final String PLAYER = "player"; + public static final String AMOUNT = "amount"; + public static final String LEVEL = "level"; + public static final String ENCHANT = "enchant"; + public static final String SLOT = "slot"; + public static final String RARITY = "rarity"; + + @NotNull + public static ArgumentBuilder enchantArgument(@NotNull String name) { + return ArgumentTypes.enchantment(name).withSamples(context -> BukkitThing.getNames(Registry.ENCHANTMENT)); + } + + @NotNull + public static ArgumentBuilder customEnchantArgument(@NotNull String name) { + return CommandArgument.builder(name, (string, context) -> EnchantRegistry.getById(string)) + .localized(Lang.COMMAND_ARGUMENT_NAME_ENCHANTMENT) + .customFailure(Lang.ERROR_COMMAND_INVALID_ENCHANTMENT_ARGUMENT) + .withSamples(context -> EnchantRegistry.getRegisteredNames()) + ; + } + + @NotNull + public static ArgumentBuilder levelArgument(@NotNull String name) { + return ArgumentTypes.integer(CommandArguments.LEVEL) + .localized(Lang.COMMAND_ARGUMENT_NAME_LEVEL) + .withSamples(context -> Lists.newList("-1", "1", "3", "5", "10")); + } + + @NotNull + public static ArgumentBuilder rarityArgument(@NotNull EnchantsPlugin plugin, @NotNull String name) { + return CommandArgument.builder(name, (string, context) -> plugin.getRarityManager().getRarity(string)) + .localized(Lang.COMMAND_ARGUMENT_NAME_RARITY) + .customFailure(Lang.ERROR_COMMAND_INVALID_RARITY_ARGUMENT) + .withSamples(context -> plugin.getRarityManager().getRarityNames()); + } + + @NotNull + public static ArgumentBuilder slotArgument(@NotNull String name) { + return CommandArgument.builder(name, (str, context) -> { + EquipmentSlot slot = StringUtil.getEnum(str, EquipmentSlot.class).orElse(null); + return slot == EquipmentSlot.BODY ? null : slot; + }) + .localized(Lang.COMMAND_ARGUMENT_NAME_SLOT) + .customFailure(Lang.ERROR_COMMAND_INVALID_SLOT_ARGUMENT) + .withSamples(context -> Arrays.stream(EntityUtil.EQUIPMENT_SLOTS).map(Enum::name).map(String::toLowerCase).toList()); + } +} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/command/EnchantCommand.java b/Core/src/main/java/su/nightexpress/excellentenchants/command/EnchantCommand.java deleted file mode 100644 index 3004b6f..0000000 --- a/Core/src/main/java/su/nightexpress/excellentenchants/command/EnchantCommand.java +++ /dev/null @@ -1,95 +0,0 @@ -package su.nightexpress.excellentenchants.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Player; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.config.Lang; -import su.nightexpress.excellentenchants.config.Perms; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; -import su.nightexpress.nightcore.command.CommandResult; -import su.nightexpress.nightcore.command.impl.AbstractCommand; -import su.nightexpress.nightcore.util.*; -import su.nightexpress.nightcore.util.random.Rnd; - -import java.util.Arrays; -import java.util.List; - -public class EnchantCommand extends AbstractCommand { - - public EnchantCommand(@NotNull EnchantsPlugin plugin) { - super(plugin, new String[]{"enchant"}, Perms.COMMAND_ENCHANT); - this.setDescription(Lang.COMMAND_ENCHANT_DESC); - this.setUsage(Lang.COMMAND_ENCHANT_USAGE); - } - - @Override - @NotNull - public List getTab(@NotNull Player player, int arg, @NotNull String[] args) { - if (arg == 1) { - return BukkitThing.getEnchantments().stream().map(enchantment -> enchantment.getKey().getKey()).toList(); - } - if (arg == 2) { - return Arrays.asList("-1", "1", "5", "10"); - } - if (arg == 3) { - return Players.playerNames(player); - } - if (arg == 4) { - return Lists.getEnums(EquipmentSlot.class); - } - return super.getTab(player, arg, args); - } - - @Override - protected void onExecute(@NotNull CommandSender sender, @NotNull CommandResult result) { - if (result.length() < 3) { - this.errorUsage(sender); - return; - } - - Enchantment enchantment = BukkitThing.getEnchantment(result.getArg(1)); - if (enchantment == null) { - Lang.ERROR_INVALID_ENCHANT.getMessage().send(sender); - return; - } - - Player player = Players.getPlayer(result.getArg(3, sender.getName())); - if (player == null) { - this.errorPlayer(sender); - return; - } - - EquipmentSlot slot = StringUtil.getEnum(result.getArg(4, ""), EquipmentSlot.class).orElse(EquipmentSlot.HAND); - - ItemStack item = player.getInventory().getItem(slot); - if (item == null || item.getType().isAir()) { - Lang.COMMAND_ENCHANT_ERROR_NO_ITEM.getMessage().send(sender); - return; - } - - int level = result.getInt(2, -1); - if (level < 0) { - level = Rnd.get(enchantment.getStartLevel(), enchantment.getMaxLevel()); - } - - if (level > 0) { - EnchantUtils.add(item, enchantment, level, true); - } - else EnchantUtils.remove(item, enchantment); - - //EnchantUtils.updateDisplay(item); - player.getInventory().setItem(slot, item); - - (sender == player ? Lang.COMMAND_ENCHANT_DONE_SELF : Lang.COMMAND_ENCHANT_DONE_OTHERS).getMessage() - .replace(Placeholders.forPlayer(player)) - .replace(Placeholders.GENERIC_ITEM, ItemUtil.getItemName(item)) - .replace(Placeholders.GENERIC_ENCHANT, EnchantUtils.getLocalized(enchantment)) - .replace(Placeholders.GENERIC_LEVEL, NumberUtil.toRoman(level)) - .send(sender); - } -} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/command/GetFuelCommand.java b/Core/src/main/java/su/nightexpress/excellentenchants/command/GetFuelCommand.java deleted file mode 100644 index 09d349d..0000000 --- a/Core/src/main/java/su/nightexpress/excellentenchants/command/GetFuelCommand.java +++ /dev/null @@ -1,69 +0,0 @@ -package su.nightexpress.excellentenchants.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; -import su.nightexpress.excellentenchants.config.Lang; -import su.nightexpress.excellentenchants.config.Perms; -import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry; -import su.nightexpress.nightcore.command.CommandResult; -import su.nightexpress.nightcore.command.impl.AbstractCommand; -import su.nightexpress.nightcore.util.ItemUtil; -import su.nightexpress.nightcore.util.Lists; -import su.nightexpress.nightcore.util.NumberUtil; -import su.nightexpress.nightcore.util.Players; - -import java.util.List; - -public class GetFuelCommand extends AbstractCommand { - - public GetFuelCommand(@NotNull EnchantsPlugin plugin) { - super(plugin, new String[]{"getfuel"}, Perms.COMMAND_GET_FUEL); - this.setDescription(Lang.COMMAND_GET_FUEL_DESC); - this.setUsage(Lang.COMMAND_GET_FUEL_USAGE); - this.setPlayerOnly(true); - } - - @Override - @NotNull - public List getTab(@NotNull Player player, int arg, @NotNull String[] args) { - if (arg == 1) { - return EnchantRegistry.getRegistered().stream().filter(EnchantmentData::isChargesEnabled).map(EnchantmentData::getId).toList(); - } - if (arg == 2) { - return Lists.newList("1", "8", "16", "32", "64"); - } - return super.getTab(player, arg, args); - } - - @Override - protected void onExecute(@NotNull CommandSender sender, @NotNull CommandResult result) { - if (result.length() < 2) { - this.errorUsage(sender); - return; - } - - EnchantmentData data = EnchantRegistry.getById(result.getArg(1)); - if (data == null) { - Lang.ERROR_INVALID_ENCHANT.getMessage().send(sender); - return; - } - - int amount = result.getInt(2, 1); - - ItemStack fuel = data.getChargesFuel(); - fuel.setAmount(amount); - - Player player = (Player) sender; - Players.addItem(player, fuel); - - Lang.COMMAND_GET_FUEL_DONE.getMessage() - .replace(Placeholders.GENERIC_AMOUNT, NumberUtil.format(amount)) - .replace(Placeholders.GENERIC_NAME, ItemUtil.getItemName(fuel)) - .send(sender); - } -} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/command/ListCommand.java b/Core/src/main/java/su/nightexpress/excellentenchants/command/ListCommand.java deleted file mode 100644 index c7660f5..0000000 --- a/Core/src/main/java/su/nightexpress/excellentenchants/command/ListCommand.java +++ /dev/null @@ -1,52 +0,0 @@ -package su.nightexpress.excellentenchants.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.config.Perms; -import su.nightexpress.excellentenchants.config.Lang; -import su.nightexpress.nightcore.command.CommandResult; -import su.nightexpress.nightcore.command.impl.AbstractCommand; -import su.nightexpress.nightcore.util.Players; - -import java.util.List; - -public class ListCommand extends AbstractCommand { - - public ListCommand(@NotNull EnchantsPlugin plugin) { - super(plugin, new String[]{"list"}, Perms.COMMAND_LIST); - this.setDescription(Lang.COMMAND_LIST_DESC); - this.setDescription(Lang.COMMAND_LIST_USAGE); - } - - @Override - @NotNull - public List getTab(@NotNull Player player, int arg, @NotNull String[] args) { - if (arg == 1 && player.hasPermission(Perms.COMMAND_LIST_OTHERS)) { - return Players.playerNames(player); - } - return super.getTab(player, arg, args); - } - - @Override - protected void onExecute(@NotNull CommandSender sender, @NotNull CommandResult result) { - if (result.length() >= 2 && !sender.hasPermission(Perms.COMMAND_LIST_OTHERS)) { - this.errorPermission(sender); - return; - } - - Player player = Players.getPlayer(result.getArg(1, sender.getName())); - if (player == null) { - this.errorPlayer(sender); - return; - } - - plugin.getEnchantManager().openEnchantsMenu(player); - - if (player != sender) { - Lang.COMMAND_LIST_DONE_OTHERS.getMessage().replace(Placeholders.forPlayer(player)).send(sender); - } - } -} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/command/RarityBookCommand.java b/Core/src/main/java/su/nightexpress/excellentenchants/command/RarityBookCommand.java deleted file mode 100644 index 6fafb82..0000000 --- a/Core/src/main/java/su/nightexpress/excellentenchants/command/RarityBookCommand.java +++ /dev/null @@ -1,91 +0,0 @@ -package su.nightexpress.excellentenchants.command; - -import org.bukkit.Material; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.config.Perms; -import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.config.Lang; -import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; -import su.nightexpress.nightcore.command.CommandResult; -import su.nightexpress.nightcore.command.impl.AbstractCommand; -import su.nightexpress.nightcore.util.Lists; -import su.nightexpress.nightcore.util.Players; -import su.nightexpress.nightcore.util.StringUtil; -import su.nightexpress.nightcore.util.random.Rnd; - -import java.util.Arrays; -import java.util.List; -import java.util.Set; - -public class RarityBookCommand extends AbstractCommand { - - public RarityBookCommand(@NotNull EnchantsPlugin plugin) { - super(plugin, new String[]{"raritybook"}, Perms.COMMAND_RARITY_BOOK); - this.setDescription(Lang.COMMAND_RARITY_BOOK_DESC); - this.setUsage(Lang.COMMAND_RARITY_BOOK_USAGE); - } - - @Override - @NotNull - public List getTab(@NotNull Player player, int arg, @NotNull String[] args) { - if (arg == 1) { - return Players.playerNames(player); - } - if (arg == 2) { - return Lists.getEnums(Rarity.class); - } - if (arg == 3) { - return Arrays.asList("-1", "1", "5", "10"); - } - return super.getTab(player, arg, args); - } - - @Override - protected void onExecute(@NotNull CommandSender sender, @NotNull CommandResult result) { - if (result.length() < 4) { - this.errorUsage(sender); - return; - } - - Player player = Players.getPlayer(result.getArg(1)); - if (player == null) { - this.errorPlayer(sender); - return; - } - - Rarity rarity = StringUtil.getEnum(result.getArg(2), Rarity.class).orElse(null); - if (rarity == null) { - Lang.ERROR_INVALID_RARITY.getMessage().send(sender); - return; - } - - Set enchants = EnchantRegistry.getByRarity(rarity); - EnchantmentData enchantmentData = enchants.isEmpty() ? null : Rnd.get(enchants); - if (enchantmentData == null) { - Lang.ERROR_INVALID_ENCHANT.getMessage().send(sender); - return; - } - - int level = result.getInt(3, -1); - if (level < 1) { - level = Rnd.get(1, enchantmentData.getMaxLevel()); - } - - ItemStack item = new ItemStack(Material.ENCHANTED_BOOK); - EnchantUtils.add(item, enchantmentData.getEnchantment(), level, true); - //EnchantUtils.updateDisplay(item); - Players.addItem(player, item); - - Lang.COMMAND_RARITY_BOOK_DONE.getMessage() - .replace(Placeholders.GENERIC_NAME, plugin.getLangManager().getEnum(rarity)) - .replace(Placeholders.forPlayer(player)) - .send(sender); - } -} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/config/Config.java b/Core/src/main/java/su/nightexpress/excellentenchants/config/Config.java index 72d5d8f..160df71 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/config/Config.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/config/Config.java @@ -2,16 +2,10 @@ package su.nightexpress.excellentenchants.config; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.DistributionMode; -import su.nightexpress.excellentenchants.api.DistributionWay; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.hook.HookPlugin; import su.nightexpress.nightcore.config.ConfigValue; import su.nightexpress.nightcore.config.FileConfig; +import su.nightexpress.nightcore.util.Lists; import su.nightexpress.nightcore.util.NumberUtil; -import su.nightexpress.nightcore.util.StringUtil; -import su.nightexpress.nightcore.util.wrapper.UniInt; import java.util.*; import java.util.stream.Collectors; @@ -21,7 +15,7 @@ import static su.nightexpress.nightcore.util.text.tag.Tags.*; public class Config { - public static final String DIR_MENU = "/menu/"; + public static final String DIR_MENU = "/menu/"; public static final String DIR_ENCHANTS = "/enchants/"; public static final ConfigValue CORE_PROJECTILE_PARTICLE_INTERVAL = ConfigValue.create("Core.Projectile_Particles_Tick_Interval", @@ -54,7 +48,8 @@ public class Config { public static final ConfigValue CORE_ITEM_ENCHANT_LIMIT = ConfigValue.create("Core.Item_Enchantments_Limit", 3, "Sets max. amount of custom enchantments per item.", - "[Default is 3]"); + "[Default is 3]" + ); public static final ConfigValue CORE_SWORD_ENCHANTS_TO_AXES = ConfigValue.create("Core.Sword_Enchants_To_Axes", true, @@ -79,11 +74,11 @@ public class Config { public static final ConfigValue> ENCHANTMENTS_DISABLED_LIST = ConfigValue.forSet("Enchantments.Disabled.List", String::toLowerCase, FileConfig::set, - Set.of("example_name", "custom_sharpness"), + Lists.newSet("example_name", "custom_sharpness"), "Put here CUSTOM enchantment names that you want to disable and remove completely.", - "Enchantment names are equal to their config file names in '" + DIR_ENCHANTS + "' folder.", - "[*] You MUST REBOOT your server for disabled enchantments to have effect.", - "[*] Once enchantment is disabled, it will be removed from all items in the world on next load!" + "Enchantment names are equal to their config file names in the '" + DIR_ENCHANTS + "' directory.", + "[*] Reboot required when changed!", + "[**] Disabled enchantments will be removed from all items forever!" ); public static final ConfigValue>> ENCHANTMENTS_DISABLED_IN_WORLDS = ConfigValue.forMap("Enchantments.Disabled.ByWorld", @@ -91,117 +86,44 @@ public class Config { (cfg, path, worldName) -> cfg.getStringSet(path + "." + worldName).stream().map(String::toLowerCase).collect(Collectors.toSet()), (cfg, path, map) -> map.forEach((world, enchants) -> cfg.set(path + "." + world, enchants)), () -> Map.of( - "your_world_name", Set.of("enchantment_name", "ice_aspect"), - "another_world", Set.of("another_enchantment", "ice_aspect") + "your_world_name", Lists.newSet("enchantment_name", "ice_aspect"), + "another_world", Lists.newSet("another_enchantment", "ice_aspect") ), "Put here CUSTOM enchantment names that you want to disable in specific worlds.", "To disable all enchantments for a world, use '" + WILDCARD + "' instead of enchantment names.", - "Enchantment names are equal to their config file names in '" + DIR_ENCHANTS + "' folder.", - VANILLA_DISTRIBUTION_HEADER, - "Enchantments will have no effect, but will appear in the world.", - CUSTOM_DISTRIBUTION_HEADER, - "Enchantments will have no effect and won't appear in the world." + "Enchantment names are equal to their config file names in the '" + DIR_ENCHANTS + "' directory.", + "[*] This setting only disables enchantment effects, not the enchantment distribution there!" ); - public static final ConfigValue DISTRIBUTION_MODE = ConfigValue.create("Enchantments.Distribution.Mode", - DistributionMode.class, DistributionMode.VANILLA, - "Sets in a which way new enchantments will be distributed to the worlds.", - "Allowed values: " + StringUtil.inlineEnum(DistributionMode.class, ", "), - "=".repeat(15) + " ! WARNING ! " + "=".repeat(15), - "You MUST REBOOT your server when changing this. Otherwise result is unpredictable.", - VANILLA_DISTRIBUTION_HEADER, - "[+] Very simple to use, almost no need to configure anything.", - "[+] Handled by the server, automatically supports all possible ways to get enchantments.", - "[+] Very accurate generation, repsects all vanilla game mechanics.", - "[-] Customization is almost non-existent.", - CUSTOM_DISTRIBUTION_HEADER, - "[+] Very flexible and customizable.", - "[+] Possibility for new ways to generate / obtain enchantments.", - "[-] Might be difficult to configure and balance everything.", - "[-] Enchantment generation is not such accurate as vanilla does." - ); - - public static final ConfigValue DISTRIBUTION_SINGLE_ENCHANT_IN_VILLAGER_BOOKS = ConfigValue.create("Enchantments.Distribution.Custom.Single_Enchant_In_Villager_Books", - true, - "When enabled, enchanted books in villager trades will have no more than 1 enchantment (vanilla or custom one)."); - - private static final ConfigValue> DISTRIBUTION_WAY_SETTINGS = ConfigValue.forMap("Enchantments.Distribution.Custom.Ways", - id -> StringUtil.getEnum(id, DistributionWay.class).orElse(null), - (cfg, path, def) -> DistributionWaySettings.read(cfg, path + "." + def), - (cfg, path, map) -> map.forEach((type, settings) -> settings.write(cfg, path + "." + type.name())), - () -> Map.of( - DistributionWay.ENCHANTING, new DistributionWaySettings(true, 5, 75, UniInt.of(0, 2)), - DistributionWay.FISHING, new DistributionWaySettings(true, 4, 45, UniInt.of(0, 2)), - DistributionWay.LOOT_GENERATION, new DistributionWaySettings(true, 4, 80, UniInt.of(0, 2)), - DistributionWay.MOB_EQUIPMENT, new DistributionWaySettings(true, 4, 35, UniInt.of(0, 2)), - DistributionWay.VILLAGER, new DistributionWaySettings(true, 4, 60, UniInt.of(0, 2)) - ), - "Settings for the different ways of obtaining enchantments." - ); - - - - @Deprecated - public static final ConfigValue ENCHANTMENTS_DISPLAY_MODE = ConfigValue.create("Enchantments.Display.Mode", - 1, - "Sets how enchantment names and descriptions will be handled on items.", - "=".repeat(15) + " AVAILABLE VALUES " + "=".repeat(15), - "1 = Plain modification of item's lore (lore changes are real and persistent).", - "2 = Packet modification of item's lore (no real changes are made to the items). Requires " + HookPlugin.PROTOCOL_LIB + " to be installed.", - "", - "Plain mode is faster, but may not reflect all changes immediately.", - "Packet mode is slower, but instantly reflect all changes. In creative mode, there is a chance for lore duplication." - ); - - @Deprecated - public static final ConfigValue ENCHANTMENTS_DISPLAY_NAME_HIDE_1ST_LEVEL = ConfigValue.create("Enchantments.Display.Name.Hide_1st_Level", - true, - "Hides enchantment level component from name format for level 1 enchantments."); - - public static final ConfigValue> ENCHANTMENTS_DISPLAY_NAME_RARITY_FORMAT = ConfigValue.forMap("Enchantments.Display.Name.Rarity", - (id) -> StringUtil.getEnum(id, Rarity.class).orElse(null), - (cfg, path, id) -> cfg.getString(path + "." + id, GENERIC_NAME), - (cfg, path, map) -> map.forEach((rarity, format) -> cfg.set(path + "." + rarity.name(), format)), - () -> Map.of( - Rarity.COMMON, WHITE.enclose(GENERIC_NAME), - Rarity.UNCOMMON, LIGHT_GREEN.enclose(GENERIC_NAME), - Rarity.RARE, LIGHT_CYAN.enclose(GENERIC_NAME), - Rarity.VERY_RARE, LIGHT_ORANGE.enclose(GENERIC_NAME) - ), - "Sets enchantment name format depends on enchantment rarity."); - - public static final ConfigValue ENCHANTMENTS_DISPLAY_NAME_CURSE_FORMAT = ConfigValue.create("Enchantments.Display.Name.Curse", - LIGHT_RED.enclose(GENERIC_NAME), - "Sets cursed enchantments name format."); - - public static final ConfigValue ENCHANTMENTS_DISPLAY_NAME_FORMAT = ConfigValue.create("Enchantments.Display.Name.Format", - ENCHANTMENT_NAME + ENCHANTMENT_LEVEL + ENCHANTMENT_CHARGES, - "Enchantment name format created from name components."); - - public static final ConfigValue ENCHANTMENTS_DISPLAY_NAME_COMPONENT_NAME = ConfigValue.create("Enchantments.Display.Name.Component.Name", + public static final ConfigValue ENCHANTMENTS_DISPLAY_NAME_COMPONENT = ConfigValue.create("Enchantments.Display.Name.Component.Name", GENERIC_VALUE, - "Enchantment name display component for name format."); + "Enchantment name display component for name format." + ); - public static final ConfigValue ENCHANTMENTS_DISPLAY_NAME_COMPONENT_LEVEL = ConfigValue.create("Enchantments.Display.Name.Component.Level", + public static final ConfigValue ENCHANTMENTS_DISPLAY_LEVEL_COMPONENT = ConfigValue.create("Enchantments.Display.Name.Component.Level", " " + GENERIC_VALUE, - "Enchantment level display component for name format."); + "Enchantment level display component for name format." + ); - public static final ConfigValue ENCHANTMENTS_DISPLAY_NAME_COMPONENT_CHARGES = ConfigValue.create("Enchantments.Display.Name.Component.Charges", + public static final ConfigValue ENCHANTMENTS_DISPLAY_CHARGES_COMPONENT = ConfigValue.create("Enchantments.Display.Name.Component.Charges", " " + GENERIC_VALUE, - "Enchantment charges display component for name format."); + "Enchantment charges display component for name format." + ); public static final ConfigValue ENCHANTMENTS_DISPLAY_DESCRIPTION_ENABLED = ConfigValue.create("Enchantments.Display.Description.Enabled", true, - "When 'true', adds the enchantment description to item lore under enchantment names.", - "For Display-Mode = 2 description is not shown while you're in Creative gamemode."); + "When 'true', adds the enchantment description to item lore under enchantment names." + ); public static final ConfigValue ENCHANTMENTS_DISPLAY_DESCRIPTION_BOOKS_ONLY = ConfigValue.create("Enchantments.Display.Description.Books_Only", false, - "Sets whether or not only enchanted books will have enchantment descriptions."); + "Sets whether or not only enchanted books will have enchantment descriptions." + ); public static final ConfigValue ENCHANTMENTS_DISPLAY_DESCRIPTION_FORMAT = ConfigValue.create("Enchantments.Display.Description.Format", - LIGHT_GRAY.enclose("• " + ENCHANTMENT_NAME + " " + ENCHANTMENT_CHARGES + ": " + GENERIC_DESCRIPTION), - "Sets enchantment description format."); + LIGHT_GRAY.enclose("• " + GENERIC_NAME + GENERIC_CHARGES + ": " + GENERIC_DESCRIPTION), + "Sets enchantment description format." + ).onRead(str -> str.replace(ENCHANTMENT_NAME, GENERIC_NAME).replace(ENCHANTMENT_CHARGES, GENERIC_CHARGES)); @@ -210,7 +132,8 @@ public class Config { false, "Enables Enchantment Charges feature.", "When enabled in the first time, make sure to check enchantments configs for new 'Charges' section.", - URL_CHRAGES); + WIKI_CHRAGES + ); public static final ConfigValue> ENCHANTMENTS_CHARGES_FORMAT = ConfigValue.forTreeMap("Enchantments.Charges.Format", raw -> NumberUtil.getInteger(raw, 0), @@ -226,38 +149,29 @@ public class Config { }, "Enchantment charges format depends on amount of charges left (in percent).", "If you don't want to display charges, leave only keys with negative values.", - "Use '" + GENERIC_AMOUNT + "' placeholder for charges amount."); + "Use '" + GENERIC_AMOUNT + "' placeholder for charges amount." + ); public static final ConfigValue ENCHANTMENTS_CHARGES_COMPARE_TYPE_ONLY = ConfigValue.create("Enchantments.Charges.Compare_Material_Only", false, "When enabled, only item material will be checked to determine if an item can be used as an enchantment fuel.", "When disabled, it will compare the whole item meta including name, lore, model data etc.", - "[Default is false]"); + "[Default is false]" + ); public static final ConfigValue ENCHANTMENTS_CHARGES_FUEL_ITEM = ConfigValue.create("Enchantments.Charges.Fuel_Item", new ItemStack(Material.LAPIS_LAZULI), "Default item used to recharge item's enchantments on anvils.", "If you want different item for certain enchantments, you can do it in that enchantment configs.", - "Item Options: " + WIKI_ITEMS_URL); + "Item Options: " + WIKI_ITEMS_URL + ); - @NotNull - public static Optional getDistributionWaySettings(@NotNull DistributionWay way) { - DistributionWaySettings settings = DISTRIBUTION_WAY_SETTINGS.get().get(way); - return settings == null || !settings.isEnabled() ? Optional.empty() : Optional.of(settings); + + public static boolean isDescriptionEnabled() { + return ENCHANTMENTS_DISPLAY_DESCRIPTION_ENABLED.get(); } - public static void loadRarityWeights(@NotNull FileConfig config) { - for (Rarity rarity : Rarity.values()) { - int weight = ConfigValue.create("Enchantments.Distribution.Custom.Rarity_Weights." + rarity.name(), rarity.getWeight()).read(config); - rarity.setWeight(weight); - } - } - - public static boolean isVanillaDistribution() { - return Config.DISTRIBUTION_MODE.get() == DistributionMode.VANILLA; - } - - public static boolean isCustomDistribution() { - return Config.DISTRIBUTION_MODE.get() == DistributionMode.CUSTOM; + public static boolean isChargesEnabled() { + return ENCHANTMENTS_CHARGES_ENABLED.get(); } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/config/DistributionWaySettings.java b/Core/src/main/java/su/nightexpress/excellentenchants/config/DistributionWaySettings.java deleted file mode 100644 index 25127b3..0000000 --- a/Core/src/main/java/su/nightexpress/excellentenchants/config/DistributionWaySettings.java +++ /dev/null @@ -1,61 +0,0 @@ -package su.nightexpress.excellentenchants.config; - -import org.jetbrains.annotations.NotNull; -import su.nightexpress.nightcore.config.FileConfig; -import su.nightexpress.nightcore.util.wrapper.UniInt; - -@Deprecated -public class DistributionWaySettings { - - private final boolean enabled; - private final int maxEnchantments; - private final double generationChance; - private final UniInt amount; - - public DistributionWaySettings(boolean enabled, - int maxEnchantments, double generationChance, - @NotNull UniInt amount) { - this.enabled = enabled; - this.maxEnchantments = maxEnchantments; - this.generationChance = generationChance; - this.amount = amount; - } - - @NotNull - public static DistributionWaySettings read(@NotNull FileConfig cfg, @NotNull String path) { - boolean enabled = cfg.getBoolean(path + ".Enabled"); - int maxEnchantments = cfg.getInt(path + ".Max_Enchantments", 4); - double generationChance = cfg.getDouble(path + ".Generation_Chance", 50D); - UniInt amount = UniInt.read(cfg, path + ".Amount"); - - return new DistributionWaySettings(enabled, maxEnchantments, generationChance, amount); - } - - public void write(@NotNull FileConfig cfg, @NotNull String path) { - cfg.set(path + ".Enabled", this.isEnabled()); - cfg.set(path + ".Max_Enchantments", this.getMaxEnchantments()); - cfg.set(path + ".Generation_Chance", this.getGenerationChance()); - this.amount.write(cfg, path + ".Amount"); - } - - public int rollAmount() { - return this.amount.roll(); - } - - public boolean isEnabled() { - return enabled; - } - - public int getMaxEnchantments() { - return maxEnchantments; - } - - public double getGenerationChance() { - return generationChance; - } - - @NotNull - public UniInt getAmount() { - return amount; - } -} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/config/Keys.java b/Core/src/main/java/su/nightexpress/excellentenchants/config/Keys.java index f781340..0d49d3a 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/config/Keys.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/config/Keys.java @@ -6,15 +6,11 @@ import su.nightexpress.excellentenchants.EnchantsPlugin; public class Keys { - @Deprecated - public static NamespacedKey loreSize; - public static NamespacedKey itemRecharged; public static NamespacedKey entitySpawnReason; public static void loadKeys(@NotNull EnchantsPlugin plugin) { - loreSize = new NamespacedKey(plugin, "lore_size"); itemRecharged = new NamespacedKey(plugin, "item.recharged"); entitySpawnReason = new NamespacedKey(plugin, "entity.spawn_reason"); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/config/Lang.java b/Core/src/main/java/su/nightexpress/excellentenchants/config/Lang.java index 82a6973..f733e6d 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/config/Lang.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/config/Lang.java @@ -9,67 +9,65 @@ import static su.nightexpress.nightcore.util.text.tag.Tags.*; public class Lang extends CoreLang { - public static final LangString COMMAND_LIST_DESC = LangString.of("Command.List.Desc", - "List of all custom enchantments."); + public static final LangString COMMAND_ARGUMENT_NAME_LEVEL = LangString.of("Command.Argument.Name.Level", "level"); + public static final LangString COMMAND_ARGUMENT_NAME_SLOT = LangString.of("Command.Argument.Name.Slot", "slot"); + public static final LangString COMMAND_ARGUMENT_NAME_RARITY = LangString.of("Command.Argument.Name.Rarity", "rarity"); - public static final LangString COMMAND_LIST_USAGE = LangString.of("Command.List.Usage", - "[player]"); + public static final LangString COMMAND_LIST_DESC = LangString.of("Command.List.Desc", "List of custom enchantments."); + public static final LangString COMMAND_ENCHANT_DESC = LangString.of("Command.Enchant.Desc", "Enchant item in specific slot."); + public static final LangString COMMAND_BOOK_DESC = LangString.of("Command.Book.Desc", "Give a book with specific enchantment."); + public static final LangString COMMAND_RARITY_BOOK_DESC = LangString.of("Command.RarityBook.Desc", "Give a book with enchantment of specific rarity."); + public static final LangString COMMAND_GET_FUEL_DESC = LangString.of("Command.GetFuel.Desc", "Get enchantment fuel item."); public static final LangText COMMAND_LIST_DONE_OTHERS = LangText.of("Command.List.DoneOthers", - LIGHT_GRAY.enclose("Opened enchantments GUI for " + LIGHT_YELLOW.enclose(PLAYER_NAME) + ".")); + LIGHT_GRAY.enclose("Opened enchantments GUI for " + LIGHT_YELLOW.enclose(PLAYER_NAME) + ".") + ); - public static final LangString COMMAND_GET_FUEL_DESC = LangString.of("Command.GetFuel.Desc", - "Get enchantment fuel item."); - - public static final LangString COMMAND_GET_FUEL_USAGE = LangString.of("Command.GetFuel.Usage", - " [amount]"); - public static final LangText COMMAND_GET_FUEL_DONE = LangText.of("Command.GetFuel.Done", - LIGHT_GRAY.enclose("You got " + LIGHT_YELLOW.enclose("x" + GENERIC_AMOUNT + " " + GENERIC_NAME) + ".")); + LIGHT_GRAY.enclose("You got " + LIGHT_YELLOW.enclose("x" + GENERIC_AMOUNT + " " + GENERIC_NAME) + ".") + ); + public static final LangText COMMAND_GET_FUEL_ERROR_NO_CHARGES = LangText.of("Command.GetFuel.Error.NoCharges", + LIGHT_GRAY.enclose("Enchantment " + LIGHT_RED.enclose(GENERIC_NAME) + " don't have charges.") + ); - public static final LangString COMMAND_ENCHANT_USAGE = LangString.of("Command.Enchant.Usage", - " [player] [slot]"); - - public static final LangString COMMAND_ENCHANT_DESC = LangString.of("Command.Enchant.Desc", - "Enchants the item in your hand."); public static final LangText COMMAND_ENCHANT_DONE_SELF = LangText.of("Command.Enchant.Done.Self", - LIGHT_GRAY.enclose(LIGHT_YELLOW.enclose(GENERIC_ITEM) + " enchanted with " + LIGHT_YELLOW.enclose(GENERIC_ENCHANT + " " + GENERIC_LEVEL) + "!")); + LIGHT_GRAY.enclose(LIGHT_YELLOW.enclose(GENERIC_ITEM) + " enchanted with " + LIGHT_YELLOW.enclose(GENERIC_ENCHANT + " " + GENERIC_LEVEL) + "!") + ); public static final LangText COMMAND_ENCHANT_DONE_OTHERS = LangText.of("Command.Enchant.Done.Others", - LIGHT_GRAY.enclose(LIGHT_YELLOW.enclose(PLAYER_DISPLAY_NAME) + "'s " + LIGHT_YELLOW.enclose(GENERIC_ITEM) + " enchanted with " + LIGHT_YELLOW.enclose(GENERIC_ENCHANT + " " + GENERIC_LEVEL) + "!")); + LIGHT_GRAY.enclose(LIGHT_YELLOW.enclose(PLAYER_DISPLAY_NAME) + "'s " + LIGHT_YELLOW.enclose(GENERIC_ITEM) + " enchanted with " + LIGHT_YELLOW.enclose(GENERIC_ENCHANT + " " + GENERIC_LEVEL) + "!") + ); public static final LangText COMMAND_ENCHANT_ERROR_NO_ITEM = LangText.of("Command.Enchant.Error.NoItem", - RED.enclose("There is no item to enchant!")); + LIGHT_RED.enclose("There is no item to enchant!") + ); - public static final LangString COMMAND_BOOK_USAGE = LangString.of("Command.Book.Usage", - " "); - - public static final LangString COMMAND_BOOK_DESC = LangString.of("Command.Book.Desc", - "Gives custom enchanted book."); - public static final LangText COMMAND_BOOK_DONE = LangText.of("Command.Book.Done", - LIGHT_GRAY.enclose("Given " + LIGHT_YELLOW.enclose(GENERIC_ENCHANT) + " enchanted book to " + LIGHT_YELLOW.enclose(PLAYER_DISPLAY_NAME) + ".")); + LIGHT_GRAY.enclose("Given " + LIGHT_YELLOW.enclose(GENERIC_ENCHANT) + " enchanted book to " + LIGHT_YELLOW.enclose(PLAYER_DISPLAY_NAME) + ".") + ); - public static final LangString COMMAND_RARITY_BOOK_USAGE = LangString.of("Command.RarityBook.Usage", - " "); - - public static final LangString COMMAND_RARITY_BOOK_DESC = LangString.of("Command.RarityBook.Desc", - "Give an enchanted book with enchantment of specified rarity."); - public static final LangText COMMAND_RARITY_BOOK_DONE = LangText.of("Command.RarityBook.Done", - LIGHT_GRAY.enclose("Given " + LIGHT_YELLOW.enclose(GENERIC_NAME) + " enchanted book to " + LIGHT_YELLOW.enclose(PLAYER_DISPLAY_NAME) + ".")); + LIGHT_GRAY.enclose("Given " + LIGHT_YELLOW.enclose(GENERIC_NAME) + " enchanted book to " + LIGHT_YELLOW.enclose(PLAYER_DISPLAY_NAME) + ".") + ); + + public static final LangText COMMAND_RARITY_BOOK_ERROR_EMPTY = LangText.of("Command.RarityBook.Error.Empty", + LIGHT_GRAY.enclose("There is no enchantments with the " + LIGHT_RED.enclose(GENERIC_NAME) + " rarity!") + ); - public static final LangText ERROR_INVALID_ENCHANT = LangText.of("Error.InvalidEnchantment", - RED.enclose("Invalid enchantment.")); - public static final LangText ERROR_INVALID_RARITY = LangText.of("Error.InvalidRarity", - RED.enclose("Invalid rarity!")); + public static final LangText ERROR_COMMAND_INVALID_RARITY_ARGUMENT = LangText.of("Error.Command.Argument.InvalidRarity", + LIGHT_GRAY.enclose(LIGHT_RED.enclose(GENERIC_VALUE) + " is not a valid rarity!") + ); + + public static final LangText ERROR_COMMAND_INVALID_SLOT_ARGUMENT = LangText.of("Error.Command.Argument.InvalidSlot", + LIGHT_GRAY.enclose(LIGHT_RED.enclose(GENERIC_VALUE) + " is not a valid slot!") + ); public static final LangString ITEM_CATEGORY_HELMET = LangString.of("ItemCategory.Helmet", "Helmet"); public static final LangString ITEM_CATEGORY_CHESTPLATE = LangString.of("ItemCategory.Chestplate", "Chestplate"); @@ -96,6 +94,4 @@ public class Lang extends CoreLang { public static final LangString ITEM_CATEGORY_TORSO = LangString.of("ItemCategory.Torso", "Chestplate/Elytra"); public static final LangString ITEM_CATEGORY_ALL_WEAPON = LangString.of("ItemCategory.AllWeapon", "All Weapon"); public static final LangString ITEM_CATEGORY_MINING_TOOLS = LangString.of("ItemCategory.MiningTools", "Mining Tools"); - - } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantManager.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantManager.java index 4a4b6e8..c0779b3 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantManager.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantManager.java @@ -4,79 +4,58 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; +import su.nightexpress.excellentenchants.api.ConfigBridge; +import su.nightexpress.excellentenchants.api.EnchantmentID; +import su.nightexpress.excellentenchants.api.enchantment.meta.PeriodMeta; import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant; import su.nightexpress.excellentenchants.config.Config; import su.nightexpress.excellentenchants.enchantment.impl.armor.FlameWalkerEnchant; -import su.nightexpress.excellentenchants.enchantment.listener.EnchantAnvilListener; -import su.nightexpress.excellentenchants.enchantment.listener.EnchantGenericListener; -import su.nightexpress.excellentenchants.enchantment.listener.EnchantPopulationListener; -import su.nightexpress.excellentenchants.enchantment.listener.EnchantVanillaListener; -import su.nightexpress.excellentenchants.enchantment.menu.EnchantmentsListMenu; -import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; +import su.nightexpress.excellentenchants.enchantment.listener.AnvilListener; +import su.nightexpress.excellentenchants.enchantment.listener.GenericListener; +import su.nightexpress.excellentenchants.enchantment.menu.EnchantsMenu; +import su.nightexpress.excellentenchants.registry.EnchantRegistry; +import su.nightexpress.excellentenchants.util.EnchantUtils; import su.nightexpress.nightcore.manager.AbstractManager; -import su.nightexpress.nightcore.util.Pair; -import su.nightexpress.nightcore.util.Version; -import java.util.*; +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Collectors; public class EnchantManager extends AbstractManager { - private final Set> passiveEnchants; + private final Set passiveEnchants; - private EnchantmentsListMenu enchantmentsListMenu; + + private EnchantsMenu enchantsMenu; public EnchantManager(@NotNull EnchantsPlugin plugin) { super(plugin); - this.passiveEnchants = new HashSet<>(); - EnchantRegistry.getEnchantments(PassiveEnchant.class).forEach(passiveEnchant -> { - EnchantmentData enchantmentData = EnchantRegistry.getById(passiveEnchant.getId()); - if (enchantmentData == null) return; - - this.passiveEnchants.add(Pair.of(passiveEnchant, enchantmentData)); - }); + this.passiveEnchants = new HashSet<>(EnchantRegistry.getEnchantments(PassiveEnchant.class)); } protected void onLoad() { - this.enchantmentsListMenu = new EnchantmentsListMenu(this.plugin); + this.enchantsMenu = new EnchantsMenu(this.plugin); - this.addListener(new EnchantGenericListener(this.plugin, this)); - this.addListener(new EnchantAnvilListener(this.plugin)); - - if (Config.isCustomDistribution()) { - this.plugin.info("Using custom distribution system. Applying patches..."); - this.addListener(new EnchantPopulationListener(this.plugin)); - } - else if (Version.isBehind(Version.MC_1_21)) { - this.plugin.info("Using vanilla distribution. Applying enchanting table patches..."); - this.addListener(new EnchantVanillaListener(this.plugin)); - } + this.addListener(new GenericListener(this.plugin, this)); + this.addListener(new AnvilListener(this.plugin)); this.addTask(this.plugin.createAsyncTask(this::displayProjectileTrails).setTicksInterval(Config.CORE_PROJECTILE_PARTICLE_INTERVAL.get())); - this.addTask(this.plugin.createTask(this::updatePassiveEnchantEffects).setTicksInterval(Config.CORE_PASSIVE_ENCHANTS_TRIGGER_INTERVAL.get())); - if (EnchantRegistry.isRegistered(FlameWalkerEnchant.ID)) { + if (!this.passiveEnchants.isEmpty()) { + this.addTask(this.plugin.createTask(this::updatePassiveEnchantEffects).setTicksInterval(ConfigBridge.getEnchantsTickInterval())); + } + if (EnchantRegistry.isRegistered(EnchantmentID.FLAME_WALKER)) { this.addTask(this.plugin.createTask(FlameWalkerEnchant::tickBlocks).setSecondsInterval(1)); } } @Override protected void onShutdown() { - if (this.enchantmentsListMenu != null) this.enchantmentsListMenu.clear(); - - /*if (EnchantRegistry.isRegistered(FlameWalkerEnchant.ID)) { - FlameWalkerEnchant.clear(); - }*/ - } - - @NotNull - public EnchantmentsListMenu getEnchantmentsListMenu() { - return enchantmentsListMenu; + if (this.enchantsMenu != null) this.enchantsMenu.clear(); } public void openEnchantsMenu(@NotNull Player player) { - this.enchantmentsListMenu.open(player); + this.enchantsMenu.open(player); } private void displayProjectileTrails() { @@ -91,17 +70,17 @@ public class EnchantManager extends AbstractManager { } private void updatePassiveEnchantEffects() { - if (this.passiveEnchants.isEmpty()) return; + Set readyEnchants = this.passiveEnchants.stream() + .peek(PeriodMeta::consumeTicks) + .filter(PeriodMeta::isTriggerTime) + .collect(Collectors.toSet()); + if (readyEnchants.isEmpty()) return; Set entities = this.getPassiveEnchantEntities(); - this.passiveEnchants.forEach(pair -> { - PassiveEnchant enchant = pair.getFirst(); - EnchantmentData enchantmentData = pair.getSecond(); - if (!enchant.isTriggerTime()) return; - + readyEnchants.forEach(enchant -> { for (LivingEntity entity : entities) { - EnchantUtils.getEquipped(entity, enchantmentData).forEach((item, level) -> { + EnchantUtils.getEquipped(entity, enchant).forEach((item, level) -> { if (!enchant.isAvailableToUse(entity)) return; if (enchant.isOutOfCharges(item)) return; if (enchant.onTrigger(entity, item, level)) { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantPopulator.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantPopulator.java deleted file mode 100644 index 8d6a01f..0000000 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantPopulator.java +++ /dev/null @@ -1,262 +0,0 @@ -package su.nightexpress.excellentenchants.enchantment; - -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.DistributionWay; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.config.Config; -import su.nightexpress.excellentenchants.config.DistributionWaySettings; -import su.nightexpress.excellentenchants.enchantment.data.CustomDistribution; -import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; -import su.nightexpress.nightcore.util.random.Rnd; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.function.BiFunction; - -public class EnchantPopulator { - - //private final ExcellentEnchants plugin; - - private final DistributionWay distributionWay; - private final ItemStack item; - private final Map> candidates; - private final Map defaultPopulation; - private final Set> predicates; - - private World world; - private BiFunction levelGenerator; - - public EnchantPopulator(@NotNull EnchantsPlugin plugin, @NotNull ItemStack item, @NotNull DistributionWay distributionWay) { - //this.plugin = plugin; - this.item = item; - this.distributionWay = distributionWay; - this.candidates = new HashMap<>(); - this.defaultPopulation = new HashMap<>(); - this.predicates = new HashSet<>(); - this.withLevelGenerator((data, distribution) -> distribution.generateLevel(this.getDistributionWay())); - - //this.fillDefaultCandidates(); - } - - @NotNull - public EnchantPopulator withWorld(@NotNull World world) { - this.world = world; - return this; - } - - @NotNull - public EnchantPopulator withLevelGenerator(@NotNull BiFunction levelGenerator) { - this.levelGenerator = levelGenerator; - return this; - } - - @NotNull - public EnchantPopulator withCondition(@NotNull BiFunction predicate) { - this.predicates.add(predicate); - return this; - } - - @NotNull - public EnchantPopulator withDefaultPopulation(@NotNull Map population) { - this.defaultPopulation.putAll(population); - //this.getPopulation().putAll(population); - return this; - } - - private void fillDefaultCandidates() { - for (Rarity rarity : Rarity.values()) { - Set dataSet = EnchantRegistry.getEnchantments(rarity); - - dataSet.removeIf(data -> { - CustomDistribution distribution = (CustomDistribution) data.getDistributionOptions(); - - // Check if can be distributed. - if (!distribution.isDistributable(this.getDistributionWay())) return true; - - // Check for custom conditions. - if (!this.predicates.isEmpty() && !this.predicates.stream().allMatch(predicate -> predicate.apply(data, distribution))) return true; - - // Enchanting books is always good. - if (this.getItem().getType() == Material.BOOK && this.getDistributionWay() == DistributionWay.ENCHANTING) return false; - - // Check if item can be enchanted. - return !data.getEnchantment().canEnchantItem(this.getItem()) && !EnchantUtils.isEnchantedBook(this.getItem()); - }); - - this.candidates.put(rarity, dataSet); - } - } - - public boolean isEmpty() { - return this.getCandidates().isEmpty() || this.getCandidates().values().stream().allMatch(Set::isEmpty); - } - - public boolean isEmpty(@NotNull Rarity rarity) { - return this.getCandidates(rarity).isEmpty(); - } - - public void purge(@NotNull Rarity rarity) { - this.getCandidates().remove(rarity); - } - - public void purge(@NotNull Rarity tier, @NotNull EnchantmentData enchant) { - this.getCandidates(tier).remove(enchant); - this.getCandidates().keySet().removeIf(this::isEmpty); - } - - @NotNull - public ItemStack getItem() { - return item; - } - - @NotNull - public DistributionWay getDistributionWay() { - return distributionWay; - } - - @Nullable - public World getWorld() { - return world; - } - - @NotNull - public BiFunction getLevelGenerator() { - return levelGenerator; - } - - @NotNull - public Map> getCandidates() { - return this.candidates; - } - - @NotNull - public Set getCandidates(@NotNull Rarity rarity) { - return this.candidates.getOrDefault(rarity, new HashSet<>()); - } - - @Nullable - public Rarity getRarityByWeight() { - Map map = new HashMap<>(); - - for (Rarity rarity : this.getCandidates().keySet()) { - map.put(rarity, (double) rarity.getWeight()); - } - - return map.isEmpty() ? null : Rnd.getByWeight(map); - } - - @Nullable - public EnchantmentData getEnchantmentByWeight(@NotNull Rarity rarity) { - Map map = new HashMap<>(); - - this.getCandidates(rarity).forEach(enchantmentData -> { - CustomDistribution distribution = (CustomDistribution) enchantmentData.getDistributionOptions(); - map.put(enchantmentData, distribution.getWeight(this.getDistributionWay())); - }); - - return map.isEmpty() ? null : Rnd.getByWeight(map); - } - - @NotNull - public Map createPopulation() { - this.candidates.clear(); - this.fillDefaultCandidates(); - - Map population = new HashMap<>(this.defaultPopulation); - - DistributionWaySettings settings = Config.getDistributionWaySettings(this.getDistributionWay()).orElse(null); - if (settings == null || !Rnd.chance(settings.getGenerationChance())) return population; - - int enchantsLimit = settings.getMaxEnchantments(); - int enchantsRolled = settings.rollAmount(); - - // Try to populate as many as possible. - while (!this.isEmpty() && enchantsRolled > 0) { - // Limit reached. - if (population.size() >= enchantsLimit) break; - - Rarity rarity = this.getRarityByWeight(); - if (rarity == null) break; // no tiers left. - - EnchantmentData enchantmentData = this.getEnchantmentByWeight(rarity); - // Remove entire rarity if no enchants can be selected. - if (enchantmentData == null) { - this.purge(rarity); - continue; - } - - if (!(enchantmentData.getDistributionOptions() instanceof CustomDistribution distribution)) { - this.purge(rarity, enchantmentData); - continue; - } - - // Remove disabled world enchants. - if (this.world != null && !enchantmentData.isAvailableToUse(this.world)) { - this.purge(rarity, enchantmentData); - continue; - } - - // Remove conflicting enchants. - if (population.keySet().stream().anyMatch(has -> has.conflictsWith(enchantmentData.getEnchantment()) || enchantmentData.getEnchantment().conflictsWith(has))) { - this.purge(rarity, enchantmentData); - continue; - } - - // Level generation failed. - int level = this.getLevelGenerator().apply(enchantmentData, distribution); - if (level < 1) { - this.purge(rarity, enchantmentData); - continue; - } - - // All good! - this.purge(rarity, enchantmentData); - population.put(enchantmentData.getEnchantment(), level); - enchantsRolled--; - } - - return population; - } - - public boolean populate() { - ItemStack item = this.getItem(); - AtomicBoolean status = new AtomicBoolean(false); - Map population = this.createPopulation();//this.getPopulation().isEmpty() ? this.createPopulation() : this.getPopulation(); - - boolean singleVillagerBook = this.getDistributionWay() == DistributionWay.VILLAGER - && EnchantUtils.isEnchantedBook(item) - && Config.DISTRIBUTION_SINGLE_ENCHANT_IN_VILLAGER_BOOKS.get(); - - if (singleVillagerBook) { - if (!population.isEmpty()) { - EnchantUtils.removeAll(item); - } - while (population.size() > 1) { - population.remove(Rnd.get(population.keySet())); - } - } - - population.forEach((enchantment, level) -> { - if (EnchantUtils.add(item, enchantment, level, false)) { - status.set(true); - } - }); - - /*if (status.get()) { - EnchantUtils.updateDisplay(item); - }*/ - - return status.get(); - } -} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/AbstractEnchantmentData.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/AbstractEnchantmentData.java deleted file mode 100644 index a70b80d..0000000 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/AbstractEnchantmentData.java +++ /dev/null @@ -1,742 +0,0 @@ -package su.nightexpress.excellentenchants.enchantment.data; - -import org.bukkit.Material; -import org.bukkit.NamespacedKey; -import org.bukkit.World; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.LivingEntity; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.DistributionWay; -import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.Cost; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.PeriodicData; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionData; -import su.nightexpress.excellentenchants.api.enchantment.distribution.DistributionOptions; -import su.nightexpress.excellentenchants.config.Config; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPlaceholders; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; -import su.nightexpress.nightcore.config.ConfigValue; -import su.nightexpress.nightcore.config.FileConfig; -import su.nightexpress.nightcore.language.LangAssets; -import su.nightexpress.nightcore.manager.AbstractFileData; -import su.nightexpress.nightcore.manager.SimpeListener; -import su.nightexpress.nightcore.util.ItemUtil; -import su.nightexpress.nightcore.util.NumberUtil; -import su.nightexpress.nightcore.util.PDCUtil; -import su.nightexpress.nightcore.util.StringUtil; -import su.nightexpress.nightcore.util.placeholder.PlaceholderMap; -import su.nightexpress.nightcore.util.random.Rnd; - -import java.io.File; -import java.util.*; -import java.util.function.Function; -import java.util.stream.Collectors; - -import static su.nightexpress.excellentenchants.Placeholders.*; - -public abstract class AbstractEnchantmentData extends AbstractFileData implements EnchantmentData { - - protected Enchantment enchantment; - - private Rarity rarity; - private String displayName; - private List description; - - private boolean hiddenFromList; - private boolean treasure; - private boolean visualEffects; - - private int maxLevel; - - private Cost minCost; - private Cost maxCost; - private int anvilCost; - - private boolean chargesEnabled; - private boolean chargesCustomFuel; - private Modifier chargesMax; - private Modifier chargesConsumeAmount; - private Modifier chargesRechargeAmount; - private ItemStack chargesFuel; - - private final DistributionOptions distributionOptions; - private final Set conflicts; - private final NamespacedKey chargesKey; - private final EnchantPlaceholders placeholders; - - public AbstractEnchantmentData(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(new ArrayList<>()); - this.setRarity(Rarity.COMMON); - this.setMaxLevel(3); - - this.conflicts = new HashSet<>(); - this.chargesKey = new NamespacedKey(plugin, this.getId() + ".charges"); - this.placeholders = new EnchantPlaceholders(); - - if (!Config.isVanillaDistribution()) { - this.distributionOptions = new CustomDistribution(this); - } - else { - this.distributionOptions = new VanillaDistribution(); - } - } - - public void registerListeners() { - if (this instanceof SimpeListener listener) { - this.plugin.getPluginManager().registerEvents(listener, plugin); - } - } - - @Override - public boolean checkServerRequirements() { - return true; - } - - @Override - protected boolean onLoad(@NotNull FileConfig cfg) { - this.setRarity(ConfigValue.create("Settings.Rarity", Rarity.class, this.rarity, - "The rarity is an attribute of an enchantment.", - "It affects the chance of getting an enchantment from enchanting or loots as well as the combination cost in anvil.", - "[*] Only for versions BELOW 1.20.6!" - ).read(cfg)); - - // TODO Custom rarity class for 1.21 - - this.setDisplayName(ConfigValue.create("Settings.Name", - StringUtil.capitalizeUnderscored(this.getId()), - "Enchantment name." - ).read(cfg)); - - this.setDescription(ConfigValue.create("Settings.Description", - this.getDescription(), - "Enchantment description.", - "You can use 'Enchantment' placeholders: " + URL_PLACEHOLDERS - ).read(cfg)); - - this.setMaxLevel(ConfigValue.create("Settings.Level.Max", - this.getMaxLevel(), - "Max. enchantment level." - ).read(cfg)); - - this.setHiddenFromList(ConfigValue.create("Settings.Hide_From_List", - false, - "Sets whether or not this enchantment will be hidden from Enchants GUI." - ).read(cfg)); - - this.setConflicts(ConfigValue.create("Settings.Conflicts", - this.getConflicts(), - "Makes this enchantment exclusive for ones in the list.", - "Conflicting enchantments can not be combined on anvils and obtained together on the same item." - ).read(cfg)); - - this.setVisualEffects(ConfigValue.create("Settings.VisualEffects.Enabled", - true, - "Enables enchantment visual effects (mostly particles)." - ).read(cfg)); - - - - this.setTreasure(ConfigValue.create("Distribution.Treasure", - false, - "Sets whether this enchantment is a treasure enchantment.", - "Treasure enchantments can only be received via looting, trading, or fishing." - ).read(cfg)); - - //int costAdjust = Math.max(7, 42 - this.getMaxLevel() * 7); - int costBase = Config.isVanillaDistribution() ? 45 : 30; - int costStart = Rnd.get(5) + 1; - int costMod = Rnd.get(10) + 1; - int costPerLevel = (int) ((double) costBase / (double) this.getMaxLevel()); - - this.setMinCost(Cost.read(cfg, "Distribution." + DistributionWay.ENCHANTING.getPathName() + ".Cost.Min", - new Cost(costStart, costPerLevel), - VANILLA_DISTRIBUTION_HEADER, - "Sets min. **modified** level cost for this enchantment to be selected in enchanting table.", - "Explanation: https://minecraft.wiki/w/Enchanting_mechanics#How_enchantments_are_chosen", - "Vanilla costs: https://minecraft.wiki/w/Enchanting/Levels", - CUSTOM_DISTRIBUTION_HEADER, - "Sets min. **plain** level cost for this enchantment to be selected in enchanting table." - ) - ); - - this.setMaxCost(Cost.read(cfg, "Distribution." + DistributionWay.ENCHANTING.getPathName() + ".Cost.Max", - new Cost(costStart * costMod, costPerLevel), - VANILLA_DISTRIBUTION_HEADER, - "Sets max. **modified** level cost for this enchantment to be selected in enchanting table.", - "Explanation: https://minecraft.wiki/w/Enchanting_mechanics#How_enchantments_are_chosen", - "Vanilla costs: https://minecraft.wiki/w/Enchanting/Levels", - CUSTOM_DISTRIBUTION_HEADER, - "Sets max. **plain** level cost for this enchantment to be selected in enchanting table.") - ); - - // TODO Check what actually does - this.setAnvilCost(ConfigValue.create("Anvil.Cost", - Rnd.get(8) + 1, - "The cost when applying this enchantment using an anvil. Halved when adding to a book, multiplied by the level of the enchantment.", - "[*] Works for 1.20.6+ only!" - ).read(cfg)); - - this.distributionOptions.load(cfg); - - - - if (Config.ENCHANTMENTS_CHARGES_ENABLED.get() && !this.isCurse()) { - this.setChargesEnabled(ConfigValue.create("Charges.Enabled", - false, - "When 'true' enables the Charges system for this enchantment.", - "[*] Enchantments in enchanting table are generated with maximum charges." - ).read(cfg)); - - this.setChargesCustomFuel(ConfigValue.create("Charges.Custom_Fuel", - false, - "When 'true' uses different (non-default) fuel item (from the 'Fuel_Item' setting) to recharge." - ).read(cfg)); - - this.setChargesMax(Modifier.read(cfg, "Charges.Maximum", - Modifier.add(100, 25, 1), - "Maximum amount of charges for the enchantment." - )); - - this.setChargesConsumeAmount(Modifier.read(cfg, "Charges.Consume_Amount", - Modifier.add(1, 0, 0), - "How many charges will be consumed when enchantment is triggered?" - )); - - this.setChargesRechargeAmount(Modifier.read(cfg, "Charges.Recharge_Amount", - Modifier.add(25, 5, 1), - "How many charges will be restored when using 'Fuel Item' in anvil?" - )); - - this.setChargesFuel(ConfigValue.create("Charges.Fuel_Item", - new ItemStack(Material.LAPIS_LAZULI), - "An item, that will be used to restore enchantment charges on anvils.", - WIKI_ITEMS_URL - ).read(cfg)); - } - - this.placeholders - .add(ENCHANTMENT_ID, this::getId) - .add(ENCHANTMENT_NAME, this::getName) - .add(ENCHANTMENT_NAME_FORMATTED, this::getNameFormatted) - .add(ENCHANTMENT_DESCRIPTION, () -> String.join("\n", this.getDescription())) - .add(ENCHANTMENT_DESCRIPTION_FORMATTED, () -> String.join("\n", this.getDescriptionFormatted())) - .add(ENCHANTMENT_DESCRIPTION_REPLACED, level -> String.join("\n", this.getDescriptionReplaced(level))) - .add(ENCHANTMENT_LEVEL, NumberUtil::toRoman) - .add(ENCHANTMENT_LEVEL_MIN, () -> String.valueOf(1)) - .add(ENCHANTMENT_LEVEL_MAX, () -> String.valueOf(this.getMaxLevel())) - .add(ENCHANTMENT_RARITY, () -> plugin.getLangManager().getEnum(this.getRarity())) - .add(ENCHANTMENT_FIT_ITEM_TYPES, () -> this.getSupportedItems().getLocalized()) - .add(ENCHANTMENT_CHARGES_MAX_AMOUNT, level -> NumberUtil.format(this.getChargesMax(level))) - .add(ENCHANTMENT_CHARGES_CONSUME_AMOUNT, level -> NumberUtil.format(this.getChargesConsumeAmount(level))) - .add(ENCHANTMENT_CHARGES_RECHARGE_AMOUNT, level -> NumberUtil.format(this.getChargesRechargeAmount(level))) - .add(ENCHANTMENT_CHARGES_FUEL_ITEM, () -> ItemUtil.getItemName(this.getChargesFuel())); - if (this instanceof ChanceData chanceData) { - this.placeholders.add(ENCHANTMENT_CHANCE, level -> NumberUtil.format(chanceData.getTriggerChance(level))); - } - if (this instanceof PeriodicData periodicData) { - this.placeholders.add(ENCHANTMENT_INTERVAL, () -> NumberUtil.format(periodicData.getInterval() / 20D)); - } - if (this instanceof PotionData potionData) { - this.placeholders.add(ENCHANTMENT_POTION_LEVEL, level -> NumberUtil.toRoman(potionData.getEffectAmplifier(level))); - this.placeholders.add(ENCHANTMENT_POTION_DURATION, level -> NumberUtil.format(potionData.getEffectDuration(level) / 20D)); - this.placeholders.add(ENCHANTMENT_POTION_TYPE, () -> LangAssets.get(potionData.getEffectType())); - } - if (this.getDistributionOptions() instanceof CustomDistribution distribution) { - this.placeholders.add(ENCHANTMENT_OBTAIN_CHANCE_ENCHANTING, () -> NumberUtil.format(distribution.getWeight(DistributionWay.ENCHANTING))); - this.placeholders.add(ENCHANTMENT_OBTAIN_CHANCE_VILLAGER, () -> NumberUtil.format(distribution.getWeight(DistributionWay.VILLAGER))); - this.placeholders.add(ENCHANTMENT_OBTAIN_CHANCE_LOOT_GENERATION, () -> NumberUtil.format(distribution.getWeight(DistributionWay.LOOT_GENERATION))); - this.placeholders.add(ENCHANTMENT_OBTAIN_CHANCE_FISHING, () -> NumberUtil.format(distribution.getWeight(DistributionWay.FISHING))); - this.placeholders.add(ENCHANTMENT_OBTAIN_CHANCE_MOB_SPAWNING, () -> NumberUtil.format(distribution.getWeight(DistributionWay.MOB_EQUIPMENT))); - } - - this.loadAdditional(cfg); - this.registerListeners(); - return true; - } - - protected abstract void loadAdditional(@NotNull FileConfig config); - - @Override - protected void onSave(@NotNull FileConfig cfg) { - - } - - @NotNull - private String logPrefix() { - return "[" + this.getId() + "] "; - } - - protected void info(@NotNull String text) { - this.plugin.info(this.logPrefix() + text); - } - - protected void warn(@NotNull String text) { - this.plugin.warn(this.logPrefix() + text); - } - - protected void error(@NotNull String text) { - this.plugin.error(this.logPrefix() + text); - } - - @NotNull - public PlaceholderMap getPlaceholders(int level) { - return this.placeholders.toMap(level); - } - - public void addPlaceholder(@NotNull String key, @NotNull Function replacer) { - this.placeholders.add(key, replacer); - } - -// @Override -// @NotNull -// public ItemCategory[] getItemCategories() { -// return new ItemCategory[0]; -// } - - /*@Override - public EquipmentSlot[] getSlots() { - return switch (this.getCategory()) { - case BOW, CROSSBOW, TRIDENT, FISHING_ROD, WEAPON, TOOL -> new EquipmentSlot[]{EquipmentSlot.HAND}; - case ARMOR_HEAD -> new EquipmentSlot[]{EquipmentSlot.HEAD}; - case ARMOR_TORSO -> new EquipmentSlot[]{EquipmentSlot.CHEST}; - case ARMOR_LEGS -> new EquipmentSlot[]{EquipmentSlot.LEGS}; - case ARMOR_FEET -> new EquipmentSlot[]{EquipmentSlot.FEET}; - case ARMOR, WEARABLE -> new EquipmentSlot[]{EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET}; - case BREAKABLE -> new EquipmentSlot[]{EquipmentSlot.HAND, EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET}; - case VANISHABLE -> EnchantUtils.EQUIPMENT_SLOTS; - default -> throw new IllegalStateException("Unexpected value: " + this.getCategory()); - }; - }*/ - - @Override - public boolean isAvailableToUse(@NotNull World world) { - Set disabled = Config.ENCHANTMENTS_DISABLED_IN_WORLDS.get().getOrDefault(world.getName().toLowerCase(), Collections.emptySet()); - return disabled.isEmpty() || (!disabled.contains(this.getId()) && !disabled.contains(WILDCARD)); - } - - @Override - public boolean isAvailableToUse(@NotNull LivingEntity entity) { - return this.isAvailableToUse(entity.getWorld()); - } - - @Override - public boolean checkEnchantLimit(@NotNull ItemStack item) { - // Allow to re-enchant item with the same enchantment. - if (EnchantUtils.contains(item, this.getEnchantment())) { - return true; - } - - return !EnchantUtils.hasMaximumEnchants(item); - } - - /*@Override - public final boolean checkEnchantCategory(@NotNull ItemStack item) { - EnchantmentTarget category = this.getCategory(); - - if (category == EnchantmentTarget.WEAPON && ItemUtil.isAxe(item)) { - return Config.CORE_SWORD_ENCHANTS_TO_AXES.get(); - } - if (category == EnchantmentTarget.BOW && item.getType() == Material.CROSSBOW) { - return Config.CORE_BOW_ENCHANTS_TO_CROSSBOW.get(); - } - if ((category == EnchantmentTarget.ARMOR || category == EnchantmentTarget.ARMOR_TORSO) && item.getType() == Material.ELYTRA) { - return Config.CORE_CHESTPLATE_ENCHANTS_TO_ELYTRA.get(); - } - return false; - } - - @Override - public boolean checkItemCategory(@NotNull ItemStack item) { - return !this.hasItemCategory() || Stream.of(this.getItemCategories()).anyMatch(itemCategory -> itemCategory.isIncluded(item)); - }*/ - - public int generateLevel() { - return Rnd.get(1, this.getMaxLevel()); - } - - @Override - @NotNull - public String getNameFormatted(int level, int charges) { - String rarityFormat = this.isCurse() ? Config.ENCHANTMENTS_DISPLAY_NAME_CURSE_FORMAT.get() : Config.ENCHANTMENTS_DISPLAY_NAME_RARITY_FORMAT.get() - .getOrDefault(this.getRarity(), GENERIC_NAME); - String nameFormat = this.formatComponents(Config.ENCHANTMENTS_DISPLAY_NAME_FORMAT.get(), level, charges); - - return rarityFormat.replace(GENERIC_NAME, nameFormat); - } - - @Override - @NotNull - public List getDescriptionFormatted() { - return new ArrayList<>(this.getDescription().stream() - .map(line -> Config.ENCHANTMENTS_DISPLAY_DESCRIPTION_FORMAT.get().replace(GENERIC_DESCRIPTION, line)) - .toList()); - } - - @Override - @NotNull - public List getDescriptionReplaced(int level) { - return this.getDescriptionReplaced(level, 0); - } - - @Override - @NotNull - public List getDescriptionReplaced(int level, int charges) { - List description = new ArrayList<>(this.getDescriptionFormatted()); - description.replaceAll(line -> this.getPlaceholders(level).replacer().apply(this.formatComponents(line, level, charges))); - return description; - } - - @NotNull - private String formatComponents(@NotNull String string, int level, int charges) { - String chargesFormat = ""; - boolean showLevel = this.getMaxLevel() > 1; - boolean showCharges = this.isChargesEnabled() && charges >= 0; - - if (showCharges) { - int chargesMax = this.getChargesMax(level); - int percent = (int) Math.ceil((double) charges / (double) chargesMax * 100D); - Map.Entry entry = Config.ENCHANTMENTS_CHARGES_FORMAT.get().floorEntry(percent); - if (entry != null) { - chargesFormat = entry.getValue().replace(GENERIC_AMOUNT, String.valueOf(charges)); - } - } - - String compName = Config.ENCHANTMENTS_DISPLAY_NAME_COMPONENT_NAME.get().replace(GENERIC_VALUE, this.getName()); - String compLevel = showLevel ? Config.ENCHANTMENTS_DISPLAY_NAME_COMPONENT_LEVEL.get().replace(GENERIC_VALUE, NumberUtil.toRoman(level)) : ""; - String compChrages = showCharges ? Config.ENCHANTMENTS_DISPLAY_NAME_COMPONENT_CHARGES.get().replace(GENERIC_VALUE, chargesFormat) : ""; - - return string - .replace(ENCHANTMENT_NAME, compName) - .replace(ENCHANTMENT_LEVEL, compLevel) - .replace(ENCHANTMENT_CHARGES, compChrages); - } - - @Override - public int getMinCost(int level) { - return this.getMinCost().calculate(level); - } - - @Override - public int getMaxCost(int level) { - return this.getMaxCost().calculate(level); - } - - /*@Override - public int getAnvilMergeCost(int level) { - return this.getAnvilMergeCost().getIntValue(level); - }*/ - - @Override - public int getChargesMax(int level) { - return this.isChargesEnabled() ? this.getChargesMax().getIntValue(level) : 0; - } - - @Override - public int getChargesConsumeAmount(int level) { - return this.isChargesEnabled() ? this.getChargesConsumeAmount().getIntValue(level) : 0; - } - - @Override - public int getChargesRechargeAmount(int level) { - return this.isChargesEnabled() ? this.getChargesRechargeAmount().getIntValue(level) : 0; - } - - @Override - public boolean isChargesFuel(@NotNull ItemStack item) { - if (Config.ENCHANTMENTS_CHARGES_COMPARE_TYPE_ONLY.get()) { - return item.getType() == this.getChargesFuel().getType(); - } - return item.isSimilar(this.getChargesFuel()); - } - - @Override - public boolean isOutOfCharges(@NotNull ItemStack item) { - return this.getCharges(item) == 0; - } - - @Override - public boolean isFullOfCharges(@NotNull ItemStack item) { - if (!this.isChargesEnabled()) return true; - - int level = EnchantUtils.getLevel(item, this.getEnchantment()); - int max = this.getChargesMax(level); - - return this.getCharges(item) == max; - } - - @Override - public int getCharges(@NotNull ItemMeta meta) { - return this.isChargesEnabled() ? PDCUtil.getInt(meta, this.chargesKey).orElse(0) : -1; - } - - @Override - public void setCharges(@NotNull ItemStack item, int level, int amount) { - if (!this.isChargesEnabled()) return; - - int max = this.getChargesMax(level); - int set = Math.min(Math.abs(amount), max); - PDCUtil.set(item, this.chargesKey, set); - } - - @Override - public void restoreCharges(@NotNull ItemStack item, int level) { - this.setCharges(item, level, Integer.MAX_VALUE); - } - - @Override - public void fuelCharges(@NotNull ItemStack item, int level) { - int recharge = this.getChargesRechargeAmount(level); - - int has = this.getCharges(item); - int set = has + recharge; - - this.setCharges(item, level, set); - } - - @Override - public void consumeChargesNoUpdate(@NotNull ItemStack item, int level) { - if (!this.isChargesEnabled()) return; - - int charges = this.getCharges(item); - int consumeAmount = this.getChargesConsumeAmount(level); - - this.setCharges(item, level, charges < consumeAmount ? 0 : Math.max(0, charges - consumeAmount)); - } - - @Override - public void consumeCharges(@NotNull ItemStack item, int level) { - if (!this.isChargesEnabled()) return; - - this.consumeChargesNoUpdate(item, level); - //EnchantUtils.updateDisplay(item); - } - - @Override - @NotNull - public Enchantment getEnchantment() { - return this.enchantment; - } - - @Override - public void setEnchantment(@NotNull Enchantment enchantment) { - this.enchantment = enchantment; - } - - @NotNull - @Override - public Rarity getRarity() { - return rarity; - } - - @Override - public void setRarity(@NotNull Rarity rarity) { - this.rarity = rarity; - } - - @NotNull - @Override - public DistributionOptions getDistributionOptions() { - return distributionOptions; - } - - @NotNull - public String getName() { - return displayName; - } - - @Override - public void setDisplayName(@NotNull String displayName) { - this.displayName = displayName; - } - - @Override - @NotNull - public List getDescription() { - return description; - } - - @Override - public void setDescription(@NotNull List description) { - this.description = description; - } - - @Override - public boolean isHiddenFromList() { - return hiddenFromList; - } - - @Override - public void setHiddenFromList(boolean hiddenFromList) { - this.hiddenFromList = hiddenFromList; - } - - @Override - public boolean isTreasure() { - return this.treasure; - } - - @Override - public void setTreasure(boolean treasure) { - this.treasure = treasure; - } - - @Override - public void setMaxLevel(int levelMax) { - this.maxLevel = Math.max(1, levelMax); - } - - @Override - public int getMaxLevel() { - return maxLevel; - } - - @Override - @NotNull - public Cost getMinCost() { - return this.minCost; - } - - @Override - public void setMinCost(@NotNull Cost minCost) { - this.minCost = minCost; - } - - @Override - @NotNull - public Cost getMaxCost() { - return this.maxCost; - } - - @Override - public void setMaxCost(@NotNull Cost maxCost) { - this.maxCost = maxCost; - } - - @Override - public int getAnvilCost() { - return anvilCost; - } - - @Override - public void setAnvilCost(int anvilCost) { - this.anvilCost = anvilCost; - } - - /*@Override - @NotNull - public Modifier getAnvilMergeCost() { - return this.anvilMergeCost; - } - - @Override - public void setAnvilMergeCost(@NotNull Modifier anvilMergeCost) { - this.anvilMergeCost = anvilMergeCost; - } - - @Override - public int getMaxMergeLevel() { - return this.maxMergeLevel; - } - - @Override - public void setMaxMergeLevel(int maxMergeLevel) { - this.maxMergeLevel = Math.min(this.getMaxLevel(), maxMergeLevel); - }*/ - - @Override - @NotNull - public Set getConflicts() { - return this.conflicts; - } - - @Override - public void setConflicts(@NotNull Set conflicts) { - this.conflicts.clear(); - this.conflicts.addAll(conflicts.stream().map(String::toLowerCase).collect(Collectors.toSet())); - } - - @Override - public boolean hasVisualEffects() { - return visualEffects; - } - - @Override - public void setVisualEffects(boolean visualEffects) { - this.visualEffects = visualEffects; - } - - @Override - public boolean isChargesEnabled() { - return chargesEnabled; - } - - @Override - public void setChargesEnabled(boolean chargesEnabled) { - this.chargesEnabled = chargesEnabled; - } - - @Override - public boolean isChargesCustomFuel() { - return chargesCustomFuel; - } - - @Override - public void setChargesCustomFuel(boolean chargesCustomFuel) { - this.chargesCustomFuel = chargesCustomFuel; - } - - @Override - @NotNull - public Modifier getChargesMax() { - return chargesMax; - } - - @Override - public void setChargesMax(@NotNull Modifier chargesMax) { - this.chargesMax = chargesMax; - } - - @NotNull - public ItemStack getChargesFuel() { - ItemStack fuelHas = this.chargesFuel; - if (!this.isChargesCustomFuel() || fuelHas == null || fuelHas.getType().isAir()) { - return new ItemStack(Config.ENCHANTMENTS_CHARGES_FUEL_ITEM.get()); - } - return new ItemStack(fuelHas); - } - - @Override - public void setChargesFuel(@Nullable ItemStack chargesFuel) { - this.chargesFuel = chargesFuel; - } - - @Override - @NotNull - public Modifier getChargesConsumeAmount() { - return chargesConsumeAmount; - } - - @Override - public void setChargesConsumeAmount(@NotNull Modifier chargesConsumeAmount) { - this.chargesConsumeAmount = chargesConsumeAmount; - } - - @Override - @NotNull - public Modifier getChargesRechargeAmount() { - return chargesRechargeAmount; - } - - @Override - public void setChargesRechargeAmount(@NotNull Modifier chargesRechargeAmount) { - this.chargesRechargeAmount = chargesRechargeAmount; - } -} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/CustomDistribution.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/CustomDistribution.java deleted file mode 100644 index 6937e7d..0000000 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/CustomDistribution.java +++ /dev/null @@ -1,154 +0,0 @@ -package su.nightexpress.excellentenchants.enchantment.data; - -import org.bukkit.loot.LootTable; -import org.bukkit.loot.LootTables; -import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.enchantment.distribution.DistributionOptions; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; -import su.nightexpress.excellentenchants.api.DistributionWay; -import su.nightexpress.nightcore.config.ConfigValue; -import su.nightexpress.nightcore.config.FileConfig; -import su.nightexpress.nightcore.util.StringUtil; -import su.nightexpress.nightcore.util.random.Rnd; -import su.nightexpress.nightcore.util.wrapper.UniInt; - -import java.util.*; - -public class CustomDistribution implements DistributionOptions { - - private final EnchantmentData enchantmentData; - - private final Map weightMap; - private final Map levelRangeMap; - private final Set lootTables; - - public CustomDistribution(@NotNull EnchantmentData enchantmentData) { - this.enchantmentData = enchantmentData; - - this.weightMap = new HashMap<>(); - this.levelRangeMap = new HashMap<>(); - this.lootTables = new HashSet<>(); - } - - public void load(@NotNull FileConfig config) { - for (DistributionWay distributionWay : DistributionWay.values()) { - String pathName = distributionWay.getPathName(); - - double obtainChance = ConfigValue.create("Distribution." + pathName + ".Weight", 50D, - "Determines how often this enchantment will appear in " + pathName + ".", - "Greater value = Greater chance.").read(config); - - this.weightMap.put(distributionWay, obtainChance); - - int levelMin = ConfigValue.create("Distribution." + pathName + ".Level.Min", -1, - "Minimal level when obtained via " + pathName, - "Can not be less than enchantment min. level. Set -1 to use enchantment min. level.").read(config); - - int levelMax = ConfigValue.create("Distribution." + pathName + ".Level.Max", -1, - "Maximal level when obtained via " + pathName, - "Can not be greater than enchantment max. level. Set -1 to use enchantment max. level.").read(config); - - this.levelRangeMap.put(distributionWay, UniInt.of(levelMin, levelMax)); - } - - boolean isWhitelist = ConfigValue.create("Distribution." + DistributionWay.LOOT_GENERATION.getPathName() + ".LootTables.Whitelist", - false, - "When 'true', uses only loot tables listed below.", - "When 'false', uses ALL loot tables except ones listed below.", - "[Default is false]" - ).read(config); - - Set tables = ConfigValue.forSet("Distribution." + DistributionWay.LOOT_GENERATION.getPathName() + ".LootTables.List", - id -> StringUtil.getEnum(id, LootTables.class).orElse(null), - (cfg, path, set) -> cfg.set(path, set.stream().map(Enum::name).toList()), - Set.of( - LootTables.DESERT_PYRAMID - ), - "Depends on Whitelist mode, this enchantment will appear on items generated by certain Loot Tables only.", - "=".repeat(15) + " EXAMPLES " + "=".repeat(15), - "==> Set 'Whitelist' on 'true' and add '" + LootTables.DESERT_PYRAMID.name() + "' to the list to make this enchantment appear on items generated inside Desert Pyramid chests only.", - "==> Set 'Whitelist' on 'false' and add '" + LootTables.DESERT_PYRAMID.name() + "' to the list to make this enchantment appear on items generated inside any structure's chests except Deset Pyramids.", - "", - "[*] Keep in mind, that Loot Generation is only applicable to items in chests. Listing here loot tables of mobs, fishing and other sources is useless.", - "Available loot table names: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/loot/LootTables.html" - ).read(config); - - if (isWhitelist) { - this.lootTables.addAll(tables); - } - else { - this.lootTables.addAll(Arrays.asList(LootTables.values())); - this.lootTables.removeAll(tables); - } - } - - @NotNull - public Map getWeightMap() { - return weightMap; - } - - @NotNull - public Map getLevelRangeMap() { - return levelRangeMap; - } - - @NotNull - public Set getLootTables() { - return lootTables; - } - - public boolean isDistributable(@NotNull DistributionWay distributionWay) { - if (distributionWay == DistributionWay.ENCHANTING && (this.enchantmentData.isTreasure() || this.enchantmentData.isCurse())) return false; - - return this.getWeight(distributionWay) > 0D; - } - - public boolean isGoodLootTable(@NotNull LootTable table) { - return this.getLootTables().stream().anyMatch(tables -> tables.getLootTable() == table); - } - - public double getWeight(@NotNull DistributionWay distributionWay) { - return this.getWeightMap().getOrDefault(distributionWay, 0D); - } - - public int getMinLevel(@NotNull DistributionWay distributionWay) { - return this.getLevelRangeMap().getOrDefault(distributionWay, UniInt.of(-1, -1)).getMinValue(); - } - - public int getMaxLevel(@NotNull DistributionWay distributionWay) { - return this.getLevelRangeMap().getOrDefault(distributionWay, UniInt.of(-1, -1)).getMaxValue(); - } - - public int generateLevel(@NotNull DistributionWay distributionWay) { - int levelCapMin = this.getMinLevel(distributionWay); - int levelCapMax = this.getMaxLevel(distributionWay); - - if (levelCapMin < 1) levelCapMin = 1; - if (levelCapMax <= 0 || levelCapMax > this.enchantmentData.getMaxLevel()) levelCapMax = this.enchantmentData.getMaxLevel(); - - return Rnd.get(levelCapMin, levelCapMax); - } - - public int getLevelByEnchantCost(int xpLevel) { - int get = 0; - - for (int level = this.enchantmentData.getMaxLevel(); level > 0; level--) { - if (xpLevel >= this.enchantmentData.getMinCost(level) && xpLevel <= this.enchantmentData.getMaxCost(level)) { - get = level; - break; - } - } - - return get != 0 ? this.fineLevel(get, DistributionWay.ENCHANTING) : 0; - } - - public int fineLevel(int level, @NotNull DistributionWay distributionWay) { - int levelCapMin = this.getMinLevel(distributionWay); - int levelCapMax = this.getMaxLevel(distributionWay); - - if (levelCapMin > 0 && level < levelCapMin) level = levelCapMin; - if (levelCapMax > 0 && level > levelCapMax) level = levelCapMax; - - return level; - } -} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/PeriodSettingsImpl.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/PeriodSettingsImpl.java deleted file mode 100644 index 7f60c38..0000000 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/PeriodSettingsImpl.java +++ /dev/null @@ -1,55 +0,0 @@ -package su.nightexpress.excellentenchants.enchantment.data; - -import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.data.PeriodicSettings; -import su.nightexpress.excellentenchants.config.Config; -import su.nightexpress.nightcore.config.FileConfig; - -public class PeriodSettingsImpl implements PeriodicSettings { - - private final Modifier triggerInterval; - - private long nextTriggerTime; - - public PeriodSettingsImpl(@NotNull Modifier triggerInterval) { - this.triggerInterval = triggerInterval; - this.updateTriggerTime(); - } - - @NotNull - public static PeriodSettingsImpl create(@NotNull FileConfig config) { - long baseTick = Config.CORE_PASSIVE_ENCHANTS_TRIGGER_INTERVAL.get(); - - return create(config, Modifier.add(baseTick, 0, 1)); - } - - @NotNull - public static PeriodSettingsImpl create(@NotNull FileConfig config, @NotNull Modifier def) { - Modifier intervalMod = Modifier.read(config, "Settings.Trigger_Interval", def, - "Sets how often (in ticks) this enchantment will be triggered.", - "20 ticks = 1 second."); - - return new PeriodSettingsImpl(intervalMod); - } - - @Override - public long getInterval() { - return (long) this.triggerInterval.getValue(1); - } - - @Override - public long getNextTriggerTime() { - return nextTriggerTime; - } - - @Override - public boolean isTriggerTime() { - return System.currentTimeMillis() >= this.getNextTriggerTime(); - } - - @Override - public void updateTriggerTime() { - this.nextTriggerTime = System.currentTimeMillis() + this.getInterval() * 50L - 100L; - } -} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/VanillaDistribution.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/VanillaDistribution.java deleted file mode 100644 index 35a5a5c..0000000 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/VanillaDistribution.java +++ /dev/null @@ -1,43 +0,0 @@ -package su.nightexpress.excellentenchants.enchantment.data; - -import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.enchantment.distribution.VanillaOptions; -import su.nightexpress.nightcore.config.ConfigValue; -import su.nightexpress.nightcore.config.FileConfig; - -public class VanillaDistribution implements VanillaOptions { - - private boolean discoverable; - private boolean tradeable; - - @Override - public void load(@NotNull FileConfig config) { - this.setTradeable(ConfigValue.create("Distribution.Tradeable", - true, - "Sets whether or not this enchantment can be populated in villager trades.").read(config)); - - this.setDiscoverable(ConfigValue.create("Distribution.Discoverable", - true, - "Sets whether or not this enchantment can be populated in enchanting table.").read(config)); - } - - @Override - public boolean isTradeable() { - return this.tradeable; - } - - @Override - public void setTradeable(boolean tradeable) { - this.tradeable = tradeable; - } - - @Override - public boolean isDiscoverable() { - return discoverable; - } - - @Override - public void setDiscoverable(boolean discoverable) { - this.discoverable = discoverable; - } -} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/EnchantCharges.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/EnchantCharges.java new file mode 100644 index 0000000..f523a9b --- /dev/null +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/EnchantCharges.java @@ -0,0 +1,114 @@ +package su.nightexpress.excellentenchants.enchantment.impl; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import su.nightexpress.excellentenchants.api.Modifier; +import su.nightexpress.excellentenchants.api.enchantment.Charges; +import su.nightexpress.excellentenchants.config.Config; +import su.nightexpress.nightcore.config.ConfigValue; +import su.nightexpress.nightcore.config.FileConfig; + +import static su.nightexpress.nightcore.util.Placeholders.WIKI_ITEMS_URL; + +public class EnchantCharges implements Charges { + + private boolean enabled; + private boolean customFuel; + private Modifier maxAmount; + private Modifier consumeAmount; + private Modifier rechargeAmount; + private ItemStack fuel; + + public EnchantCharges() { + + } + + public void load(@NotNull FileConfig config) { + this.enabled = ConfigValue.create("Charges.Enabled", + false, + "When 'true' enables the Charges system for this enchantment.", + "[*] Enchantments in enchanting table are generated with maximum charges." + ).read(config); + + if (!this.enabled) return; + + this.customFuel = ConfigValue.create("Charges.Custom_Fuel", + false, + "When 'true' uses different (non-default) fuel item (from the 'Fuel_Item' setting) to recharge." + ).read(config); + + this.maxAmount = Modifier.read(config, "Charges.Maximum", + Modifier.add(100, 25, 1), + "Maximum amount of charges for the enchantment." + ); + + this.consumeAmount = Modifier.read(config, "Charges.Consume_Amount", + Modifier.add(1, 0, 0), + "How many charges will be consumed when enchantment is triggered?" + ); + + this.rechargeAmount = Modifier.read(config, "Charges.Recharge_Amount", + Modifier.add(25, 5, 1), + "How many charges will be restored when using 'Fuel Item' in anvil?" + ); + + this.fuel = ConfigValue.create("Charges.Fuel_Item", + new ItemStack(Material.LAPIS_LAZULI), + "An item, that will be used to restore enchantment charges on anvils.", + WIKI_ITEMS_URL + ).read(config); + } + + @Override + public int getMaxAmount(int level) { + return this.isEnabled() ? this.getMaxAmount().getIntValue(level) : 0; + } + + @Override + public int getConsumeAmount(int level) { + return this.isEnabled() ? this.getConsumeAmount().getIntValue(level) : 0; + } + + @Override + public int getRechargeAmount(int level) { + return this.isEnabled() ? this.getRechargeAmount().getIntValue(level) : 0; + } + + @Override + public boolean isEnabled() { + return enabled; + } + + @Override + public boolean isCustomFuel() { + return customFuel; + } + + @Override + @NotNull + public Modifier getMaxAmount() { + return maxAmount; + } + + @NotNull + public ItemStack getFuel() { + ItemStack fuelHas = this.fuel; + if (!this.isCustomFuel() || fuelHas == null || fuelHas.getType().isAir()) { + return new ItemStack(Config.ENCHANTMENTS_CHARGES_FUEL_ITEM.get()); + } + return new ItemStack(fuelHas); + } + + @Override + @NotNull + public Modifier getConsumeAmount() { + return consumeAmount; + } + + @Override + @NotNull + public Modifier getRechargeAmount() { + return rechargeAmount; + } +} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/EnchantDefinition.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/EnchantDefinition.java new file mode 100644 index 0000000..8a0f93b --- /dev/null +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/EnchantDefinition.java @@ -0,0 +1,226 @@ +package su.nightexpress.excellentenchants.enchantment.impl; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import su.nightexpress.excellentenchants.EnchantsAPI; +import su.nightexpress.excellentenchants.Placeholders; +import su.nightexpress.excellentenchants.api.enchantment.Cost; +import su.nightexpress.excellentenchants.api.enchantment.Definition; +import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; +import su.nightexpress.excellentenchants.api.enchantment.Rarity; +import su.nightexpress.excellentenchants.util.EnchantUtils; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.nightcore.config.ConfigValue; +import su.nightexpress.nightcore.config.FileConfig; +import su.nightexpress.nightcore.util.Lists; +import su.nightexpress.nightcore.util.StringUtil; +import su.nightexpress.nightcore.util.random.Rnd; + +import java.util.List; +import java.util.Set; + +public class EnchantDefinition implements Definition { + + private final String rarityId; + private final ItemsCategory supportedItems; + private final ItemsCategory primaryItems; + + private List description; + private String displayName; + private Rarity rarity; + private Set conflicts; + private int maxLevel; + private Cost minCost; + private Cost maxCost; + private int anvilCost; + + public EnchantDefinition(@NotNull List description, + @NotNull String rarityId, + int maxLevel, + @NotNull ItemsCategory supportedItems, + @Nullable ItemsCategory primaryItems, + @Nullable Set conflicts) { + this.rarityId = rarityId; + + this.description = description; + this.maxLevel = maxLevel; + this.supportedItems = supportedItems; + this.primaryItems = primaryItems; + this.conflicts = conflicts; + } + + @NotNull + public static EnchantDefinition create(@NotNull List description, + @NotNull String rarityId, + int maxLevel, + @NotNull ItemsCategory supportedItems, + @Nullable ItemsCategory primaryItems, + @Nullable Set conflicts) { + return new EnchantDefinition(description, rarityId, maxLevel, supportedItems, primaryItems, conflicts); + } + + @NotNull + public static EnchantDefinition create(@NotNull String description, + @NotNull String rarityId, + int maxLevel, + @NotNull ItemsCategory supportedItems, + @Nullable ItemsCategory primaryItems) { + return create(Lists.newList(description), rarityId, maxLevel, supportedItems, primaryItems, null); + } + + @NotNull + public static EnchantDefinition create(@NotNull String description, + @NotNull String rarityId, + int maxLevel, + @NotNull ItemsCategory supportedItems) { + return create(description, rarityId, maxLevel, supportedItems, (ItemsCategory) null); + } + + @NotNull + public static EnchantDefinition create(@NotNull String description, + @NotNull String rarityId, + int maxLevel, + @NotNull ItemsCategory supportedItems, + @NotNull Set conflicts) { + return create(Lists.newList(description), rarityId, maxLevel, supportedItems, null, conflicts); + } + + public void load(@NotNull GameEnchantment enchantment, @NotNull FileConfig config) { + String rarityId = ConfigValue.create("Settings.Rarity", + this.rarityId, + "Rarity affects the chance of getting an enchantment from enchanting or loots depending on rarity weight value.", + "You can create and edit rarities in the config.yml" + ).read(config); + + Rarity rarity = EnchantsAPI.getRarityManager().getRarity(rarityId); + if (rarity == null) { + enchantment.error("Invalid rarity '" + rarityId + "' for the '" + enchantment.getId() + "' enchantment! Replaced with dummy one."); + rarity = EnchantRarity.DUMMY; + } + this.rarity = rarity; + + this.displayName = ConfigValue.create("Settings.Name", + StringUtil.capitalizeUnderscored(enchantment.getId()), + "Enchantment display name." + ).read(config); + + this.description = ConfigValue.create("Settings.Description", + this.description, + "Enchantment description.", + "You can use 'Enchantment' placeholders: " + Placeholders.WIKI_PLACEHOLDERS + ).read(config); + + this.setMaxLevel(ConfigValue.create("Settings.Level.Max", + this.maxLevel, + "The maximum level of this enchantment.", + "Value between 1 and 255 (inclusive).", + "[*] Reboot required when changed." + ).read(config)); + + this.conflicts = ConfigValue.create("Settings.Conflicts", + this.conflicts, + "Enchantments that are incompatible with this enchantment.", + "[*] Reboot required when changed." + ).read(config); + + int costCap = Rnd.get(45, 65) + 1; + int costPerLevel = (int) ((double) costCap / (double) this.maxLevel); + + int minCost = Rnd.nextInt(5) + 1; + int maxCost = this.maxLevel == 1 ? costPerLevel : Rnd.get(3, 7) + minCost; + +// int costBase = 45; +// int costStart = Rnd.get(5) + 1; +// int costMod = Rnd.get(10) + 1; +// int costPerLevel = (int) ((double) costBase / (double) this.getMaxLevel()); + + this.minCost = Cost.read(config, "Settings.Cost.Min", + new Cost(minCost, costPerLevel), + "The minimum possible cost of this enchantment in levels.", + "Explanation: https://minecraft.wiki/w/Enchanting_mechanics#How_enchantments_are_chosen", + "Vanilla costs: https://minecraft.wiki/w/Enchanting/Levels", + "[*] Reboot required when changed." + ); + + this.maxCost = Cost.read(config, "Settings.Cost.Max", + new Cost(maxCost, costPerLevel), + "The maximum possible cost of this enchantment in levels.", + "Explanation: https://minecraft.wiki/w/Enchanting_mechanics#How_enchantments_are_chosen", + "Vanilla costs: https://minecraft.wiki/w/Enchanting/Levels", + "[*] Reboot required when changed." + ); + + this.anvilCost = ConfigValue.create("Settings.Cost.Anvil", + Rnd.get(8) + 1, + "The base cost when applying this enchantment to another item using an anvil. Halved when adding using a book, multiplied by the level of the enchantment.", + "[*] Reboot required when changed." + ).read(config); + } + + private void setMaxLevel(int levelMax) { + this.maxLevel = Math.clamp(levelMax, 1, EnchantUtils.LEVEL_CAP); + } + + @Override + public boolean hasConflicts() { + return this.conflicts != null && !this.conflicts.isEmpty(); + } + + @NotNull + @Override + public ItemsCategory getSupportedItems() { + return this.supportedItems; + } + + @NotNull + @Override + public ItemsCategory getPrimaryItems() { + return this.primaryItems == null ? this.supportedItems : this.primaryItems; + } + + @NotNull + @Override + public Set getConflicts() { + return conflicts; + } + + @NotNull + @Override + public String getDisplayName() { + return displayName; + } + + @NotNull + @Override + public List getDescription() { + return description; + } + + @NotNull + @Override + public Rarity getRarity() { + return rarity; + } + + @Override + public int getMaxLevel() { + return maxLevel; + } + + @NotNull + @Override + public Cost getMinCost() { + return minCost; + } + + @NotNull + @Override + public Cost getMaxCost() { + return maxCost; + } + + @Override + public int getAnvilCost() { + return anvilCost; + } +} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/EnchantDistribution.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/EnchantDistribution.java new file mode 100644 index 0000000..b19ef3a --- /dev/null +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/EnchantDistribution.java @@ -0,0 +1,170 @@ +package su.nightexpress.excellentenchants.enchantment.impl; + +import org.jetbrains.annotations.NotNull; +import su.nightexpress.excellentenchants.api.enchantment.Distribution; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.nightcore.config.ConfigValue; +import su.nightexpress.nightcore.config.FileConfig; +import su.nightexpress.nightcore.util.StringUtil; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +public class EnchantDistribution implements Distribution { + + private Set tradeTypes; + private boolean treasure; + private boolean discoverable; + private boolean tradable; + private boolean onMobSpawnEquipment; + private boolean onRandomLoot; + private boolean onTradedEquipment; + + public EnchantDistribution(@NotNull Set tradeTypes, + boolean treasure, + boolean discoverable, + boolean tradable, + boolean onMobSpawnEquipment, + boolean onRandomLoot, + boolean onTradedEquipment) { + this.tradeTypes = tradeTypes; + this.treasure = treasure; + this.discoverable = discoverable; + this.tradable = tradable; + this.onMobSpawnEquipment = onMobSpawnEquipment; + this.onRandomLoot = onRandomLoot; + this.onTradedEquipment = onTradedEquipment; + } + + @NotNull + public static EnchantDistribution defaults() { + return new EnchantDistribution( + new HashSet<>(Arrays.asList(TradeType.values())), + false, + true, + true, + true, + true, + true + ); + } + + @NotNull + public static EnchantDistribution regular(@NotNull TradeType... tradeTypes) { + return new EnchantDistribution( + new HashSet<>(Arrays.asList(tradeTypes)), + false, + true, + true, + true, + true, + true + ); + } + + @NotNull + public static EnchantDistribution treasure(@NotNull TradeType... tradeTypes) { + return new EnchantDistribution( + new HashSet<>(Arrays.asList(tradeTypes)), + true, + false, + true, + false, + true, + false + ); + } + + public void load(@NotNull FileConfig config) { + this.treasure = ConfigValue.create("Distribution.Treasure", + this.treasure, + "Sets whether this enchantment is a treasure enchantment.", + "Treasure enchantments are those that can't be obtained using an enchantment table, and won't be generated on randomly enchanted equipment sold by villagers or worn by mobs.", + "Treasure enchantments can only be received via looting, trading, or fishing.", + "If a treasure enchantment is tradable, it will have double the price (before capping to 64 emeralds) compared to a non-treasure enchantment of the same level.", + "[*] Reboot required when changed." + ).read(config); + + this.tradable = ConfigValue.create("Distribution.Tradeable", + this.tradable, + "Tradable enchantments are those that can be generated on Enchanted Books sold by librarians.", + "[*] Reboot required when changed.", + "[**] Has no effect if 'Treasure' is set on 'true' and Villager Trade Rebalance is disabled." + ).read(config); + + this.tradeTypes = ConfigValue.forSet("Distribution.TradeTypes", + name -> StringUtil.getEnum(name, TradeType.class).orElse(null), + (cfg, path, set) -> cfg.set(path, set.stream().map(Enum::name).toList()), + () -> new HashSet<>(this.tradeTypes), + "Sets in which village biomes this enchantment can be found in villager trades.", + "Allowed values: [" + StringUtil.inlineEnum(TradeType.class, ", ") + "]", + "https://minecraft.wiki/w/Villager_Trade_Rebalance#Trading", + "[*] Reboot required when changed.", + "[**] Has no effect if 'Tradeable' is set on 'false' and Villager Trade Rebalance is disabled." + ).read(config); + + this.onMobSpawnEquipment = ConfigValue.create("Distribution.On_Mob_Spawn_Equipment", + this.onMobSpawnEquipment, + "Sets whether or not this enchantment can be found on spawned mobs' equipment.", + "[*] Reboot required when changed.", + "[**] Has no effect if 'Treasure' is set on 'true'." + ).read(config); + + this.onTradedEquipment = ConfigValue.create("Distribution.On_Traded_Equipment", + this.onTradedEquipment, + "Sets whether or not this enchantment can be found on equipment sold by villagers.", + "[*] Reboot required when changed.", + "[**] Has no effect if 'Treasure' is set on 'true'." + ).read(config); + + this.onRandomLoot = ConfigValue.create("Distribution.On_Random_Loot", + this.onRandomLoot, + "Sets whether or not this enchantment can be found on naturally generated equipment from loot tables.", + "[*] Reboot required when changed." + ).read(config); + + this.discoverable = ConfigValue.create("Distribution.Discoverable", + this.discoverable, + "Sets whether or not this enchantment can be generated in enchanting table.", + "[*] Reboot required when changed.", + "[**] Has no effect if 'Treasure' is set on 'true'." + ).read(config); + } + + @Override + public boolean isTreasure() { + return this.treasure; + } + + @Override + public boolean isTradable() { + return this.tradable; + } + + @Override + @NotNull + public Set getTrades() { + return this.tradeTypes; + } + + @Override + public boolean isDiscoverable() { + return discoverable; + } + + @Override + public boolean isOnMobSpawnEquipment() { + return onMobSpawnEquipment; + } + + @Override + public boolean isOnRandomLoot() { + return onRandomLoot; + } + + @Override + public boolean isOnTradedEquipment() { + return onTradedEquipment; + } +} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/GameEnchantment.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/GameEnchantment.java new file mode 100644 index 0000000..75a676d --- /dev/null +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/GameEnchantment.java @@ -0,0 +1,315 @@ +package su.nightexpress.excellentenchants.enchantment.impl; + +import org.bukkit.NamespacedKey; +import org.bukkit.World; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.LivingEntity; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.NotNull; +import su.nightexpress.excellentenchants.EnchantsPlugin; +import su.nightexpress.excellentenchants.Placeholders; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.EnchantMeta; +import su.nightexpress.excellentenchants.config.Config; +import su.nightexpress.excellentenchants.util.EnchantPlaceholders; +import su.nightexpress.excellentenchants.util.EnchantUtils; +import su.nightexpress.nightcore.config.ConfigValue; +import su.nightexpress.nightcore.config.FileConfig; +import su.nightexpress.nightcore.manager.AbstractFileData; +import su.nightexpress.nightcore.manager.SimpeListener; +import su.nightexpress.nightcore.util.PDCUtil; +import su.nightexpress.nightcore.util.placeholder.PlaceholderMap; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.function.Function; + +public abstract class GameEnchantment extends AbstractFileData implements CustomEnchantment { + + protected final EnchantMeta meta; + protected final EnchantDefinition definition; + protected final EnchantDistribution distribution; + protected final EnchantCharges charges; + private final NamespacedKey chargesKey; + private final EnchantPlaceholders placeholders; + private final String logPrefix; + + private Enchantment enchantment; + private boolean hiddenFromList; + private boolean visualEffects; + + public GameEnchantment(@NotNull EnchantsPlugin plugin, @NotNull File file, @NotNull EnchantDefinition definition) { + this(plugin, file, definition, EnchantDistribution.defaults()); + } + + public GameEnchantment(@NotNull EnchantsPlugin plugin, @NotNull File file, @NotNull EnchantDefinition definition, @NotNull EnchantDistribution distribution) { + super(plugin, file); + + this.meta = new EnchantMeta(); + this.definition = definition; + this.distribution = distribution; + this.charges = new EnchantCharges(); + this.chargesKey = new NamespacedKey(plugin, this.getId() + "_charges"); + this.placeholders = Placeholders.forEnchant(this); + this.logPrefix = "[" + this.getId() + "] "; + } + + public void registerListeners() { + if (this instanceof SimpeListener listener) { + this.plugin.getPluginManager().registerEvents(listener, plugin); + } + } + + @Override + public boolean checkServerRequirements() { + return true; + } + + @Override + protected boolean onLoad(@NotNull FileConfig config) { + this.loadMain(config); + this.loadSettings(config); + this.loadAdditional(config); + + this.registerListeners(); + return true; + } + + private void loadMain(@NotNull FileConfig config) { + this.definition.load(this, config); + this.distribution.load(config); + + if (Config.isChargesEnabled() && !this.isCurse()) { + this.charges.load(config); + } + } + + private void loadSettings(@NotNull FileConfig config) { + this.hiddenFromList = ConfigValue.create("Settings.Hide_From_List", + false, + "Sets whether or not this enchantment will be hidden from Enchants GUI." + ).read(config); + + this.visualEffects = ConfigValue.create("Settings.VisualEffects.Enabled", + true, + "Enables enchantment visual effects (mostly particles)." + ).read(config); + } + + protected abstract void loadAdditional(@NotNull FileConfig config); + + @Override + protected void onSave(@NotNull FileConfig config) { + + } + + public void onRegister(@NotNull Enchantment enchantment) { + if (this.enchantment != null) return; + + this.enchantment = enchantment; + } + + protected void info(@NotNull String text) { + this.plugin.info(this.logPrefix + text); + } + + protected void warn(@NotNull String text) { + this.plugin.warn(this.logPrefix + text); + } + + protected void error(@NotNull String text) { + this.plugin.error(this.logPrefix + text); + } + + @NotNull + public PlaceholderMap getPlaceholders(int level) { + return this.placeholders.toMap(level); + } + + public void addPlaceholder(@NotNull String key, @NotNull Function replacer) { + this.placeholders.add(key, replacer); + } + + @Override + @NotNull + public Enchantment getBukkitEnchantment() { + return this.enchantment; + } + + @Override + @NotNull + public EnchantMeta getMeta() { + return this.meta; + } + + @NotNull + @Override + public EnchantDefinition getDefinition() { + return definition; + } + + @NotNull + @Override + public EnchantDistribution getDistribution() { + return distribution; + } + + @NotNull + @Override + public EnchantCharges getCharges() { + return this.charges; + } + + @Override + public boolean isAvailableToUse(@NotNull World world) { + Set disabled = Config.ENCHANTMENTS_DISABLED_IN_WORLDS.get().getOrDefault(world.getName().toLowerCase(), Collections.emptySet()); + return disabled.isEmpty() || (!disabled.contains(this.getId()) && !disabled.contains(Placeholders.WILDCARD)); + } + + @Override + public boolean isAvailableToUse(@NotNull LivingEntity entity) { + return this.isAvailableToUse(entity.getWorld()); + } + + @NotNull + public String getDisplayName() { + return this.definition.getDisplayName(); + } + + @Override + @NotNull + public String getFormattedName() { + return this.isCurse() ? this.getDisplayName() : this.getPlaceholders(1).replacer().apply(this.definition.getRarity().getNameFormat()); + } + + @Override + @NotNull + public List getDescription() { + return this.definition.getDescription(); + } + + @Override + @NotNull + public List getDescription(int level) { + return this.getDescription(level, 0); + } + + @Override + @NotNull + public List getDescription(int level, int charges) { + List description = new ArrayList<>(this.getDescription()); + + String lineFormat = Config.ENCHANTMENTS_DISPLAY_DESCRIPTION_FORMAT.get(); + + description.replaceAll(line -> { + line = lineFormat.replace(Placeholders.GENERIC_DESCRIPTION, line); + line = EnchantUtils.replaceComponents(this, line, level, charges); + line = this.getPlaceholders(level).replacer().apply(line); + return line; + }); + return description; + } + + @Override + public boolean isHiddenFromList() { + return this.hiddenFromList; + } + + @Override + public boolean hasVisualEffects() { + return this.visualEffects; + } + + @Override + public boolean isCurse() { + return false; + } + + @Override + public boolean hasCharges() { + return this.charges != null && this.charges.isEnabled(); + } + + @Override + public boolean isChargesFuel(@NotNull ItemStack item) { + if (!this.hasCharges()) return false; + + if (Config.ENCHANTMENTS_CHARGES_COMPARE_TYPE_ONLY.get()) { + return item.getType() == this.charges.getFuel().getType(); + } + return item.isSimilar(this.charges.getFuel()); + } + + @Override + public boolean isOutOfCharges(@NotNull ItemStack item) { + return this.hasCharges() && this.getCharges(item) == 0; + } + + @Override + public boolean isFullOfCharges(@NotNull ItemStack item) { + if (!this.hasCharges()) return false; + + int level = EnchantUtils.getLevel(item, this.getBukkitEnchantment()); + int max = this.charges.getMaxAmount(level); + + return this.getCharges(item) == max; + } + + @Override + public int getCharges(@NotNull ItemStack item) { + ItemMeta meta = item.getItemMeta(); + return meta == null ? 0 : this.getCharges(meta); + } + + @Override + public int getCharges(@NotNull ItemMeta meta) { + return this.hasCharges() ? PDCUtil.getInt(meta, this.chargesKey).orElse(0) : -1; + } + + @Override + public void setCharges(@NotNull ItemStack item, int level, int amount) { + if (!this.hasCharges()) return; + + int max = this.charges.getMaxAmount(level); + int set = Math.min(Math.abs(amount), max); + PDCUtil.set(item, this.chargesKey, set); + } + + @Override + public void restoreCharges(@NotNull ItemStack item, int level) { + this.setCharges(item, level, Integer.MAX_VALUE); + } + + @Override + public void fuelCharges(@NotNull ItemStack item, int level) { + if (!this.hasCharges()) return; + + int recharge = this.charges.getRechargeAmount(level); + + int has = this.getCharges(item); + int set = has + recharge; + + this.setCharges(item, level, set); + } + + @Override + public void consumeChargesNoUpdate(@NotNull ItemStack item, int level) { + if (!this.hasCharges()) return; + + int charges = this.getCharges(item); + int consumeAmount = this.charges.getConsumeAmount(level); + + this.setCharges(item, level, charges < consumeAmount ? 0 : Math.max(0, charges - consumeAmount)); + } + + @Override + public void consumeCharges(@NotNull ItemStack item, int level) { + if (!this.hasCharges()) return; + + this.consumeChargesNoUpdate(item, level); + } +} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/ColdSteelEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/ColdSteelEnchant.java index 182771b..b4fca7f 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/ColdSteelEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/ColdSteelEnchant.java @@ -8,71 +8,51 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionData; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionSettings; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionEffects; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.data.PotionSettingsImpl; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.*; -public class ColdSteelEnchant extends AbstractEnchantmentData implements ChanceData, PotionData, CombatEnchant { +public class ColdSteelEnchant extends GameEnchantment implements ChanceMeta, PotionMeta, CombatEnchant { public static final String ID = "cold_steel"; - private ChanceSettingsImpl chanceSettings; - private PotionSettingsImpl potionSettings; - public ColdSteelEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to apply " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.) on attacker."); - this.setRarity(Rarity.COMMON); - this.setMaxLevel(3); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.SNOW_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to apply " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.) on attacker.", + EnchantRarity.RARE, + 3, + ItemCategories.TORSO + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(8, 2, 1)); + this.meta.setProbability(Probability.create(config, Modifier.add(8, 2, 1))); - this.potionSettings = PotionSettingsImpl.create(this, config, PotionEffectType.SLOW_DIGGING, false, + this.meta.setPotionEffects(PotionEffects.create(this, config, PotionEffectType.MINING_FATIGUE, false, Modifier.add(4, 1, 1, 300), Modifier.add(0, 1,1, 5) - ); + )); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @NotNull - @Override - public PotionSettings getPotionSettings() { - return potionSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.TORSO; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.ARMOR_TORSO; -// } - @NotNull @Override public EventPriority getProtectPriority() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/DarknessCloakEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/DarknessCloakEnchant.java index 88f89f6..f7e552e 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/DarknessCloakEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/DarknessCloakEnchant.java @@ -9,17 +9,17 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionData; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionSettings; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionEffects; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.data.PotionSettingsImpl; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.wrapper.UniParticle; @@ -27,54 +27,34 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.*; -public class DarknessCloakEnchant extends AbstractEnchantmentData implements ChanceData, PotionData, CombatEnchant { +public class DarknessCloakEnchant extends GameEnchantment implements ChanceMeta, PotionMeta, CombatEnchant { public static final String ID = "darkness_cloak"; - private ChanceSettingsImpl chanceSettings; - private PotionSettingsImpl potionSettings; - public DarknessCloakEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to apply " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.) on attacker."); - this.setMaxLevel(3); - this.setRarity(Rarity.COMMON); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.SWAMP_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to apply " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.) on attacker.", + EnchantRarity.COMMON, + 3, + ItemCategories.TORSO + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(11, 3, 1)); + this.meta.setProbability(Probability.create(config, Modifier.add(11, 3, 1))); - this.potionSettings = PotionSettingsImpl.create(this, config, PotionEffectType.DARKNESS, false, + this.meta.setPotionEffects(PotionEffects.create(this, config, PotionEffectType.DARKNESS, false, Modifier.add(5, 1, 1, 300), Modifier.add(0, 1, 1, 10) - ); + )); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @NotNull - @Override - public PotionSettings getPotionSettings() { - return potionSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.TORSO; - } - - // @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.ARMOR_TORSO; -// } - @NotNull @Override public EventPriority getProtectPriority() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/ElementalProtectionEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/ElementalProtectionEnchant.java index bca3098..ca24b48 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/ElementalProtectionEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/ElementalProtectionEnchant.java @@ -8,53 +8,66 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; import su.nightexpress.excellentenchants.api.enchantment.type.GenericEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.util.EnchantUtils; import su.nightexpress.nightcore.config.ConfigValue; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.manager.SimpeListener; import su.nightexpress.nightcore.util.EntityUtil; +import su.nightexpress.nightcore.util.Lists; import su.nightexpress.nightcore.util.NumberUtil; import java.io.File; import java.util.Set; -import static su.nightexpress.excellentenchants.Placeholders.GENERIC_AMOUNT; -import static su.nightexpress.excellentenchants.Placeholders.GENERIC_MAX; +import static su.nightexpress.excellentenchants.Placeholders.*; +import static org.bukkit.event.entity.EntityDamageEvent.DamageCause; -public class ElementalProtectionEnchant extends AbstractEnchantmentData implements SimpeListener, GenericEnchant { +public class ElementalProtectionEnchant extends GameEnchantment implements SimpeListener, GenericEnchant { public static final String ID = "elemental_protection"; - private static final Set DAMAGE_CAUSES = Set.of( - EntityDamageEvent.DamageCause.POISON, EntityDamageEvent.DamageCause.WITHER, - EntityDamageEvent.DamageCause.MAGIC, EntityDamageEvent.DamageCause.FREEZE, - EntityDamageEvent.DamageCause.LIGHTNING); + private static final Set DAMAGE_CAUSES = Lists.newSet( + DamageCause.POISON, DamageCause.WITHER, + DamageCause.MAGIC, DamageCause.FREEZE, + DamageCause.LIGHTNING + ); private Modifier protectionAmount; private double protectionCapacity; private boolean protectionAsModifier; public ElementalProtectionEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Reduces Poison, Magic, Wither, Lightning, Freeze damage by " + GENERIC_AMOUNT + "%."); - this.setMaxLevel(5); - this.setRarity(Rarity.COMMON); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.SWAMP_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Reduces Poison, Magic, Wither, Lightning, Freeze damage by " + GENERIC_AMOUNT + "%.", + EnchantRarity.COMMON, + 5, + ItemCategories.ARMOR + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { this.protectionAmount = Modifier.read(config, "Settings.Protection.Amount", - Modifier.add(0, 5, 1, 100), - "Protection amount given by enchantment."); + Modifier.add(0, 4, 1, 100), + "Protection amount given by enchantment." + ); this.protectionCapacity = ConfigValue.create("Settings.Protection.Capacity", 100D, - "Maximal possible protection value from all armor pieces together.").read(config); + "Maximal possible protection value from all armor pieces together." + ).read(config); this.protectionAsModifier = ConfigValue.create("Settings.Protection.As_Modifier", true, @@ -65,18 +78,6 @@ public class ElementalProtectionEnchant extends AbstractEnchantmentData implemen this.addPlaceholder(GENERIC_MAX, level -> NumberUtil.format(this.getProtectionCapacity())); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.ARMOR; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.ARMOR; -// } - public double getProtectionAmount(int level) { return this.protectionAmount.getValue(level); } @@ -95,13 +96,11 @@ public class ElementalProtectionEnchant extends AbstractEnchantmentData implemen if (!(event.getEntity() instanceof LivingEntity entity)) return; if (!this.isAvailableToUse(entity)) return; - // TODO Work as percent to ignore damage - double protectionAmount = 0D; for (ItemStack armor : EntityUtil.getEquippedArmor(entity).values()) { if (armor == null || armor.getType().isAir()) continue; - int level = EnchantUtils.getLevel(armor, this.getEnchantment()); + int level = EnchantUtils.getLevel(armor, this.getBukkitEnchantment()); if (level <= 0) continue; protectionAmount += this.getProtectionAmount(level); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/FireShieldEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/FireShieldEnchant.java index 9a07b2b..2c88c89 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/FireShieldEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/FireShieldEnchant.java @@ -9,14 +9,15 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.NumberUtil; import su.nightexpress.nightcore.util.wrapper.UniParticle; @@ -27,23 +28,29 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_DURATION; -public class FireShieldEnchant extends AbstractEnchantmentData implements ChanceData, CombatEnchant { +public class FireShieldEnchant extends GameEnchantment implements ChanceMeta, CombatEnchant { public static final String ID = "fire_shield"; - private Modifier fireDuration; - private ChanceSettingsImpl chanceSettings; + private Modifier fireDuration; public FireShieldEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to ignite attackers for " + GENERIC_DURATION + "s."); - this.setMaxLevel(3); - this.setRarity(Rarity.UNCOMMON); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.DESERT_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to ignite attackers for " + GENERIC_DURATION + "s.", + EnchantRarity.RARE, + 3, + ItemCategories.ARMOR + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(3, 2, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(3, 2, 1, 100))); this.fireDuration = Modifier.read(config, "Settings.Fire.Duration", Modifier.multiply(2, 1, 1, 600), @@ -54,24 +61,6 @@ public class FireShieldEnchant extends AbstractEnchantmentData implements Chance this.addPlaceholder(GENERIC_DURATION, level -> NumberUtil.format(this.getFireDuration(level))); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.ARMOR; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.ARMOR; -// } - @NotNull @Override public EventPriority getProtectPriority() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/FlameWalkerEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/FlameWalkerEnchant.java index 9533633..5ac7a50 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/FlameWalkerEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/FlameWalkerEnchant.java @@ -19,69 +19,88 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; import su.nightexpress.excellentenchants.api.enchantment.type.GenericEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; +import su.nightexpress.excellentenchants.api.enchantment.bridge.FlameWalker; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.EnchantUtils; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.manager.SimpeListener; -import su.nightexpress.nightcore.util.Pair; -import su.nightexpress.nightcore.util.random.Rnd; +import su.nightexpress.nightcore.util.BukkitThing; +import su.nightexpress.nightcore.util.Lists; import su.nightexpress.nightcore.util.wrapper.UniParticle; import java.io.File; import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import java.util.stream.Stream; -public class FlameWalkerEnchant extends AbstractEnchantmentData implements GenericEnchant, SimpeListener { +public class FlameWalkerEnchant extends GameEnchantment implements GenericEnchant, FlameWalker, SimpeListener { - public static final String ID = "flame_walker"; - - private static final BlockFace[] FACES = {BlockFace.SOUTH, BlockFace.NORTH, BlockFace.EAST, BlockFace.WEST}; - private static final Map> BLOCKS_TO_DESTROY = new ConcurrentHashMap<>(); + private static final BlockFace[] FACES = {BlockFace.SOUTH, BlockFace.NORTH, BlockFace.EAST, BlockFace.WEST}; + private Modifier radius; private Modifier blockDecayTime; public FlameWalkerEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Ability to walk on lava, ignore magma block damage."); - this.setMaxLevel(3); - this.setRarity(Rarity.RARE); - this.setConflicts(Enchantment.FROST_WALKER.getKey().getKey()); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.DESERT_SPECIAL)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + Lists.newList("Ability to walk on lava, ignore magma block damage."), + EnchantRarity.LEGENDARY, + 3, + ItemCategories.BOOTS, + null, + Lists.newSet(BukkitThing.toString(Enchantment.FROST_WALKER)) + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { + this.radius = Modifier.read(config, "Settings.Radius", + Modifier.add(3.0, 1.0, 1, 16), + "Sets max radius." + ); + this.blockDecayTime = Modifier.read(config, "Settings.Block_Decay", Modifier.add(8, 1, 1, 120), - "Sets up to how long (in seconds) blocks will stay before turn back to lava."); + "Sets up to how long (in seconds) blocks will stay before turn back into lava." + ); + } + + @NotNull + @Override + public Modifier getRadius() { + return radius; + } + + @Override + public double getBlockDecayTime(int level) { + return this.blockDecayTime.getValue(level); } @Override public void clear() { - BLOCKS_TO_DESTROY.keySet().forEach(location -> location.getBlock().setType(Material.LAVA)); - BLOCKS_TO_DESTROY.clear(); - } - - public static void addBlock(@NotNull Block block, double seconds) { - BLOCKS_TO_DESTROY.put(block.getLocation(), Pair.of(System.currentTimeMillis() + (long) seconds * 1000L, Rnd.get(1000))); + MAGMA_BLOCKS.keySet().forEach(location -> location.getBlock().setType(Material.LAVA)); + MAGMA_BLOCKS.clear(); } public static boolean isBlock(@NotNull Block block) { - return BLOCKS_TO_DESTROY.containsKey(block.getLocation()); + return MAGMA_BLOCKS.containsKey(block.getLocation()); } public static void tickBlocks() { long now = System.currentTimeMillis(); - BLOCKS_TO_DESTROY.keySet().removeIf(location -> location.getBlock().isLiquid() || location.getBlock().getType() != Material.MAGMA_BLOCK); - BLOCKS_TO_DESTROY.forEach((location, pair) -> { + MAGMA_BLOCKS.keySet().removeIf(location -> location.getBlock().isLiquid() || location.getBlock().getType() != Material.MAGMA_BLOCK); + MAGMA_BLOCKS.forEach((location, pair) -> { Block block = location.getBlock(); long time = pair.getFirst(); if (now >= time) { @@ -106,22 +125,6 @@ public class FlameWalkerEnchant extends AbstractEnchantmentData implements Gener }); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.BOOTS; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.ARMOR_FEET; -// } - - public double getBlockDecayTime(int level) { - return this.blockDecayTime.getValue(level); - } - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); @@ -135,22 +138,37 @@ public class FlameWalkerEnchant extends AbstractEnchantmentData implements Gener ItemStack boots = player.getInventory().getBoots(); if (boots == null || boots.getType().isAir()) return; - int level = EnchantUtils.getLevel(boots, this.getEnchantment()); + int level = EnchantUtils.getLevel(boots, this.getBukkitEnchantment()); if (level <= 0) return; Block bTo = to.getBlock().getRelative(BlockFace.DOWN); boolean hasLava = Stream.of(FACES).anyMatch(face -> bTo.getRelative(face).getType() == Material.LAVA); if (!hasLava) return; - Set blocks = plugin.getEnchantNMS().handleFlameWalker(player, player.getLocation(), level); - blocks.forEach(block -> { - addBlock(block, Rnd.getDouble(this.getBlockDecayTime(level)) + 1); - }); - if (!blocks.isEmpty()) { + if (plugin.getEnchantNMS().handleFlameWalker(this, player, level)) { this.consumeCharges(boots, level); } } + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onMagmaDamage(EntityDamageEvent event) { + if (event.getCause() != EntityDamageEvent.DamageCause.HOT_FLOOR) return; + if (!(event.getEntity() instanceof LivingEntity livingEntity)) return; + if (!this.isAvailableToUse(livingEntity)) return; + + EntityEquipment equipment = livingEntity.getEquipment(); + if (equipment == null) return; + + ItemStack boots = equipment.getBoots(); + if (boots == null || boots.getType().isAir()) return; + + int level = EnchantUtils.getLevel(boots, this.getBukkitEnchantment()); + if (level <= 0) return; + + event.setCancelled(true); + this.consumeCharges(boots, level); + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onFlameWalkerBlock(BlockBreakEvent event) { if (isBlock(event.getBlock())) { @@ -179,23 +197,4 @@ public class FlameWalkerEnchant extends AbstractEnchantmentData implements Gener return false; }); } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onMagmaDamage(EntityDamageEvent event) { - if (event.getCause() != EntityDamageEvent.DamageCause.HOT_FLOOR) return; - if (!(event.getEntity() instanceof LivingEntity livingEntity)) return; - if (!this.isAvailableToUse(livingEntity)) return; - - EntityEquipment equipment = livingEntity.getEquipment(); - if (equipment == null) return; - - ItemStack boots = equipment.getBoots(); - if (boots == null || boots.getType().isAir()) return; - - int level = EnchantUtils.getLevel(boots, this.getEnchantment()); - if (level <= 0) return; - - event.setCancelled(true); - this.consumeCharges(boots, level); - } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/HardenedEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/HardenedEnchant.java index cae6982..1320b5d 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/HardenedEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/HardenedEnchant.java @@ -8,71 +8,51 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionData; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionEffects; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.data.PotionSettingsImpl; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.*; -public class HardenedEnchant extends AbstractEnchantmentData implements ChanceData, PotionData, CombatEnchant { +public class HardenedEnchant extends GameEnchantment implements ChanceMeta, PotionMeta, CombatEnchant { public static final String ID = "hardened"; - private ChanceSettingsImpl chanceSettings; - private PotionSettingsImpl potionSettings; - public HardenedEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to get " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.) when damaged."); - this.setMaxLevel(3); - this.setRarity(Rarity.UNCOMMON); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.PLAINS_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to get " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.) when damaged.", + EnchantRarity.RARE, + 3, + ItemCategories.TORSO + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(2, 2, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(2, 2, 1, 100))); - this.potionSettings = PotionSettingsImpl.create(this, config, PotionEffectType.DAMAGE_RESISTANCE, false, + this.meta.setPotionEffects(PotionEffects.create(this, config, PotionEffectType.RESISTANCE, false, Modifier.add(2, 1, 1, 300), Modifier.add(0, 1, 1.5, 5) - ); + )); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @NotNull - @Override - public PotionSettings getPotionSettings() { - return potionSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.TORSO; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.ARMOR_TORSO; -// } - @NotNull @Override public EventPriority getProtectPriority() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/IceShieldEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/IceShieldEnchant.java index a3fc34b..d8b3300 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/IceShieldEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/IceShieldEnchant.java @@ -11,17 +11,17 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionData; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionEffects; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.data.PotionSettingsImpl; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.wrapper.UniParticle; import su.nightexpress.nightcore.util.wrapper.UniSound; @@ -30,41 +30,33 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.*; -public class IceShieldEnchant extends AbstractEnchantmentData implements ChanceData, PotionData, CombatEnchant { +public class IceShieldEnchant extends GameEnchantment implements ChanceMeta, PotionMeta, CombatEnchant { public static final String ID = "ice_shield"; - private ChanceSettingsImpl chanceSettings; - private PotionSettingsImpl potionSettings; - public IceShieldEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to freeze and apply " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.) on attacker."); - this.setMaxLevel(3); - this.setRarity(Rarity.COMMON); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.SNOW_COMMON)); } - @Override - protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(4, 4, 1, 100)); - - this.potionSettings = PotionSettingsImpl.create(this, config, PotionEffectType.SLOW, false, - Modifier.add(2, 2, 1, 300), - Modifier.add(0, 1, 1, 5) + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to freeze and apply " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.) on attacker.", + EnchantRarity.COMMON, + 3, + ItemCategories.TORSO ); } @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.TORSO; - } + protected void loadAdditional(@NotNull FileConfig config) { + this.meta.setProbability(Probability.create(config, Modifier.add(4, 4, 1, 100))); -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.ARMOR_TORSO; -// } + this.meta.setPotionEffects(PotionEffects.create(this, config, PotionEffectType.SLOWNESS, false, + Modifier.add(2, 2, 1, 300), + Modifier.add(0, 1, 1, 5) + )); + } @NotNull @Override @@ -72,18 +64,6 @@ public class IceShieldEnchant extends AbstractEnchantmentData implements ChanceD return EventPriority.HIGHEST; } - @Override - @NotNull - public ChanceSettings getChanceSettings() { - return this.chanceSettings; - } - - @NotNull - @Override - public PotionSettings getPotionSettings() { - return potionSettings; - } - @Override public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/JumpingEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/JumpingEnchant.java index 64db708..4d843fa 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/JumpingEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/JumpingEnchant.java @@ -5,16 +5,16 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.PeriodicSettings; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionData; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.Period; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionEffects; import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.data.PeriodSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.PotionSettingsImpl; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; import java.io.File; @@ -22,50 +22,30 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_POTION_LEVEL; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_POTION_TYPE; -public class JumpingEnchant extends AbstractEnchantmentData implements PotionData, PassiveEnchant { +public class JumpingEnchant extends GameEnchantment implements PotionMeta, PassiveEnchant { public static final String ID = "bunny_hop"; - private PotionSettingsImpl potionSettings; - private PeriodSettingsImpl periodSettings; - public JumpingEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setMaxLevel(3); - this.setRarity(Rarity.COMMON); - this.setDescription("Grants permanent " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " effect."); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.PLAINS_SPECIAL)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Grants permanent " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " effect.", + EnchantRarity.LEGENDARY, + 3, + ItemCategories.BOOTS + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.potionSettings = PotionSettingsImpl.create(this, config, PotionEffectType.JUMP, true); - this.periodSettings = PeriodSettingsImpl.create(config); + this.meta.setPotionEffects(PotionEffects.create(this, config, PotionEffectType.JUMP_BOOST, true)); + this.meta.setPeriod(Period.create(config)); } - @NotNull - @Override - public PotionSettings getPotionSettings() { - return potionSettings; - } - - @NotNull - @Override - public PeriodicSettings getPeriodSettings() { - return periodSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.BOOTS; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.ARMOR_FEET; -// } - @Override public boolean onTrigger(@NotNull LivingEntity entity, @NotNull ItemStack item, int level) { return this.addEffect(entity, level); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/KamikadzeEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/KamikadzeEnchant.java index 9334928..8e68386 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/KamikadzeEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/KamikadzeEnchant.java @@ -14,14 +14,15 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.ConfigValue; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.manager.SimpeListener; @@ -31,26 +32,32 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; -public class KamikadzeEnchant extends AbstractEnchantmentData implements ChanceData, DeathEnchant, SimpeListener { +public class KamikadzeEnchant extends GameEnchantment implements ChanceMeta, DeathEnchant, SimpeListener { public static final String ID = "self_destruction"; - private Modifier explosionSize; - private boolean applyOnResurrect; - private ChanceSettingsImpl chanceSettings; + private Modifier explosionSize; + private boolean applyOnResurrect; private Entity exploder; public KamikadzeEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to create an explosion on death."); - this.setMaxLevel(3); - this.setRarity(Rarity.UNCOMMON); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.JUNGLE_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to create an explosion on death.", + EnchantRarity.RARE, + 3, + ItemCategories.TORSO + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(0, 5, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(0, 5, 1, 100))); this.applyOnResurrect = ConfigValue.create("Settings.Apply_On_Resurrect", true, @@ -63,24 +70,6 @@ public class KamikadzeEnchant extends AbstractEnchantmentData implements ChanceD ); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.TORSO; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.ARMOR_TORSO; -// } - public boolean isApplyOnResurrect() { return this.applyOnResurrect; } @@ -99,7 +88,7 @@ public class KamikadzeEnchant extends AbstractEnchantmentData implements ChanceD this.exploder = null; if (exploded && this.hasVisualEffects()) { - UniParticle.of(Particle.SMOKE_NORMAL).play(entity.getEyeLocation(), 0.5, 0.1, 60); + UniParticle.of(Particle.SMOKE).play(entity.getEyeLocation(), 0.5, 0.1, 60); UniParticle.of(Particle.LAVA).play(entity.getEyeLocation(), 1.25, 0.1, 100); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/NightVisionEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/NightVisionEnchant.java index 9f53796..efbc4dd 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/NightVisionEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/NightVisionEnchant.java @@ -5,16 +5,16 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.PeriodicSettings; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionData; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.Period; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionEffects; import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.data.PeriodSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.PotionSettingsImpl; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; import java.io.File; @@ -22,50 +22,30 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_POTION_LEVEL; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_POTION_TYPE; -public class NightVisionEnchant extends AbstractEnchantmentData implements PotionData, PassiveEnchant { +public class NightVisionEnchant extends GameEnchantment implements PotionMeta, PassiveEnchant { public static final String ID = "night_vision"; - private PotionSettingsImpl potionSettings; - private PeriodSettingsImpl periodSettings; - public NightVisionEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Grants permanent " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " effect."); - this.setMaxLevel(1); - this.setRarity(Rarity.VERY_RARE); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.SWAMP_SPECIAL)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Grants permanent " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " effect.", + EnchantRarity.MYTHIC, + 1, + ItemCategories.HELMET + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.potionSettings = PotionSettingsImpl.create(this, config, PotionEffectType.NIGHT_VISION, true); - this.periodSettings = PeriodSettingsImpl.create(config); + this.meta.setPotionEffects(PotionEffects.create(this, config, PotionEffectType.NIGHT_VISION, true)); + this.meta.setPeriod(Period.create(config)); } - @NotNull - @Override - public PotionSettings getPotionSettings() { - return potionSettings; - } - - @NotNull - @Override - public PeriodicSettings getPeriodSettings() { - return periodSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.HELMET; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.ARMOR_HEAD; -// } - @Override public boolean onTrigger(@NotNull LivingEntity entity, @NotNull ItemStack item, int level) { return this.addEffect(entity, level); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/RegrowthEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/RegrowthEnchant.java index 41e317a..a73192d 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/RegrowthEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/RegrowthEnchant.java @@ -7,16 +7,16 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; -import su.nightexpress.excellentenchants.api.enchantment.data.PeriodicSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.api.enchantment.meta.Period; import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.data.PeriodSettingsImpl; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.EntityUtil; import su.nightexpress.nightcore.util.NumberUtil; @@ -26,7 +26,7 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.*; -public class RegrowthEnchant extends AbstractEnchantmentData implements ChanceData, PassiveEnchant { +public class RegrowthEnchant extends GameEnchantment implements ChanceMeta, PassiveEnchant { public static final String ID = "regrowth"; @@ -34,21 +34,24 @@ public class RegrowthEnchant extends AbstractEnchantmentData implements ChanceDa private Modifier maxHealth; private Modifier healAmount; - private ChanceSettingsImpl chanceSettings; - private PeriodSettingsImpl periodSettings; - public RegrowthEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Restores " + GENERIC_AMOUNT + "❤ every few seconds."); - this.setMaxLevel(5); - this.setRarity(Rarity.VERY_RARE); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.TAIGA_SPECIAL)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Restores " + GENERIC_AMOUNT + "❤ every few seconds.", + EnchantRarity.MYTHIC, + 5, + ItemCategories.TORSO + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(100, 0, 1, 100)); - - this.periodSettings = PeriodSettingsImpl.create(config); + this.meta.setProbability(Probability.create(config, Modifier.add(100, 0, 1, 100))); + this.meta.setPeriod(Period.create(config)); this.minHealth = Modifier.read(config, "Settings.Heal.Min_Health", Modifier.add(0.5, 0, 0), @@ -70,30 +73,6 @@ public class RegrowthEnchant extends AbstractEnchantmentData implements ChanceDa this.addPlaceholder(GENERIC_MAX, level -> NumberUtil.format(this.getMaxHealthToHeal(level))); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @NotNull - @Override - public PeriodicSettings getPeriodSettings() { - return periodSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.TORSO; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.ARMOR_TORSO; -// } - public double getHealAmount(int level) { return this.healAmount.getValue(level); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/SaturationEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/SaturationEnchant.java index d99085f..4d2b9bc 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/SaturationEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/SaturationEnchant.java @@ -6,13 +6,14 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.PeriodicSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.data.PeriodSettingsImpl; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.api.enchantment.meta.Period; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.NumberUtil; @@ -21,25 +22,30 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_AMOUNT; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_MAX; -public class SaturationEnchant extends AbstractEnchantmentData implements PassiveEnchant { +public class SaturationEnchant extends GameEnchantment implements PassiveEnchant { public static final String ID = "saturation"; private Modifier feedAmount; private Modifier maxFoodLevel; - private PeriodSettingsImpl periodSettings; - public SaturationEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Restores " + GENERIC_AMOUNT + " food points every few seconds."); - this.setMaxLevel(3); - this.setRarity(Rarity.RARE); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.SAVANNA_SPECIAL)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Restores " + GENERIC_AMOUNT + " food points every few seconds.", + EnchantRarity.LEGENDARY, + 3, + ItemCategories.HELMET + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.periodSettings = PeriodSettingsImpl.create(config); + this.meta.setPeriod(Period.create(config)); this.feedAmount = Modifier.read(config, "Settings.Saturation.Amount", Modifier.add(0, 1, 1, 10), @@ -53,24 +59,6 @@ public class SaturationEnchant extends AbstractEnchantmentData implements Passiv this.addPlaceholder(GENERIC_MAX, level -> NumberUtil.format(this.getMaxFoodLevel(level))); } - @NotNull - @Override - public PeriodicSettings getPeriodSettings() { - return periodSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.HELMET; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.ARMOR_HEAD; -// } - public final int getFeedAmount(int level) { return (int) this.feedAmount.getValue(level); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/SpeedyEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/SpeedyEnchant.java index 6552b95..2a1c498 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/SpeedyEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/SpeedyEnchant.java @@ -5,16 +5,16 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.PeriodicSettings; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionData; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.Period; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionEffects; import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.data.PeriodSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.PotionSettingsImpl; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; import java.io.File; @@ -22,50 +22,30 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_POTION_LEVEL; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_POTION_TYPE; -public class SpeedyEnchant extends AbstractEnchantmentData implements PotionData, PassiveEnchant { +public class SpeedyEnchant extends GameEnchantment implements PotionMeta, PassiveEnchant { public static final String ID = "sonic"; - private PotionSettingsImpl potionSettings; - private PeriodSettingsImpl periodSettings; - public SpeedyEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Grants permanent " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " effect."); - this.setMaxLevel(3); - this.setRarity(Rarity.UNCOMMON); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.SAVANNA_SPECIAL)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Grants permanent " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " effect.", + EnchantRarity.LEGENDARY, + 3, + ItemCategories.BOOTS + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.potionSettings = PotionSettingsImpl.create(this, config, PotionEffectType.SPEED, true); - this.periodSettings = PeriodSettingsImpl.create(config); + this.meta.setPotionEffects(PotionEffects.create(this, config, PotionEffectType.SPEED, true)); + this.meta.setPeriod(Period.create(config)); } - @NotNull - @Override - public PotionSettings getPotionSettings() { - return potionSettings; - } - - @NotNull - @Override - public PeriodicSettings getPeriodSettings() { - return periodSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.BOOTS; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.ARMOR_FEET; -// } - @Override public boolean onTrigger(@NotNull LivingEntity entity, @NotNull ItemStack item, int level) { return this.addEffect(entity, level); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/StoppingForceEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/StoppingForceEnchant.java index dbca5c0..f6da1a3 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/StoppingForceEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/StoppingForceEnchant.java @@ -7,14 +7,15 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.NumberUtil; @@ -23,23 +24,29 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_AMOUNT; -public class StoppingForceEnchant extends AbstractEnchantmentData implements ChanceData, CombatEnchant { +public class StoppingForceEnchant extends GameEnchantment implements ChanceMeta, CombatEnchant { public static final String ID = "stopping_force"; - private ChanceSettingsImpl chanceSettings; - private Modifier knockbackModifier; + private Modifier knockbackModifier; public StoppingForceEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to get only " + GENERIC_AMOUNT + "% of knockback in combat."); - this.setMaxLevel(3); - this.setRarity(Rarity.UNCOMMON); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.DESERT_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to get only " + GENERIC_AMOUNT + "% of knockback in combat.", + EnchantRarity.RARE, + 3, + ItemCategories.LEGGINGS + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(100, 0, 0, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(100, 0, 0, 100))); this.knockbackModifier = Modifier.read(config, "Settings.Knockback_Modifier", Modifier.add(0.9, -0.2, 1), @@ -52,30 +59,12 @@ public class StoppingForceEnchant extends AbstractEnchantmentData implements Cha return this.knockbackModifier.getValue(level); } -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.ARMOR_LEGS; -// } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.LEGGINGS; - } - @NotNull @Override public EventPriority getProtectPriority() { return EventPriority.HIGHEST; } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return this.chanceSettings; - } - @Override public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/TreasureHunterEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/TreasureHunterEnchant.java index c44c1ac..6cd2c33 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/TreasureHunterEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/TreasureHunterEnchant.java @@ -12,15 +12,16 @@ import org.bukkit.loot.LootTables; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.GenericEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.util.EnchantUtils; import su.nightexpress.nightcore.config.ConfigValue; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.manager.SimpeListener; @@ -35,26 +36,31 @@ import java.util.Set; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; -public class TreasureHunterEnchant extends AbstractEnchantmentData implements ChanceData, GenericEnchant, SimpeListener { +public class TreasureHunterEnchant extends GameEnchantment implements ChanceMeta, GenericEnchant, SimpeListener { public static final String ID = "treasure_hunter"; - private ChanceSettingsImpl chanceSettings; - private final Set lootTables; public TreasureHunterEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to get more items in loot chests."); - this.setMaxLevel(4); - this.setRarity(Rarity.RARE); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.JUNGLE_COMMON)); this.lootTables = new HashSet<>(); } + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to get more items in loot chests.", + EnchantRarity.LEGENDARY, + 4, + ItemCategories.HELMET + ); + } + @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(2.5, 2.5, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(2.5, 2.5, 1, 100))); boolean isWhitelist = ConfigValue.create("Settings.LootTables.Whitelist", false, @@ -88,24 +94,6 @@ public class TreasureHunterEnchant extends AbstractEnchantmentData implements Ch this.lootTables.clear(); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.HELMET; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.ARMOR_HEAD; -// } - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onLootExplore(LootGenerateEvent event) { if (this.lootTables.isEmpty()) return; @@ -116,7 +104,7 @@ public class TreasureHunterEnchant extends AbstractEnchantmentData implements Ch ItemStack helmet = player.getInventory().getHelmet(); if (helmet == null || helmet.getType().isAir()) return; - int level = EnchantUtils.getLevel(helmet, this.getEnchantment()); + int level = EnchantUtils.getLevel(helmet, this.getBukkitEnchantment()); if (level < 1) return; if (!this.checkTriggerChance(level)) return; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/WaterBreathingEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/WaterBreathingEnchant.java index 3b3bd42..afba4ab 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/WaterBreathingEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/WaterBreathingEnchant.java @@ -5,16 +5,16 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.PeriodicSettings; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionData; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.Period; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionEffects; import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.data.PeriodSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.PotionSettingsImpl; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; import java.io.File; @@ -22,50 +22,30 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_POTION_LEVEL; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_POTION_TYPE; -public class WaterBreathingEnchant extends AbstractEnchantmentData implements PotionData, PassiveEnchant { +public class WaterBreathingEnchant extends GameEnchantment implements PotionMeta, PassiveEnchant { public static final String ID = "aquaman"; - private PotionSettingsImpl potionSettings; - private PeriodSettingsImpl periodSettings; - public WaterBreathingEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setMaxLevel(1); - this.setRarity(Rarity.UNCOMMON); - this.setDescription("Grants permanent " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " effect."); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.JUNGLE_SPECIAL)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Grants permanent " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " effect.", + EnchantRarity.MYTHIC, + 1, + ItemCategories.HELMET + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.potionSettings = PotionSettingsImpl.create(this, config, PotionEffectType.WATER_BREATHING, true); - this.periodSettings = PeriodSettingsImpl.create(config); + this.meta.setPotionEffects(PotionEffects.create(this, config, PotionEffectType.WATER_BREATHING, true)); + this.meta.setPeriod(Period.create(config)); } - @NotNull - @Override - public PotionSettings getPotionSettings() { - return potionSettings; - } - - @NotNull - @Override - public PeriodicSettings getPeriodSettings() { - return periodSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.HELMET; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.ARMOR_HEAD; -// } - @Override public boolean onTrigger(@NotNull LivingEntity entity, @NotNull ItemStack item, int level) { return this.addEffect(entity, level); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/BomberEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/BomberEnchant.java index 0dc8bd9..609a955 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/BomberEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/BomberEnchant.java @@ -12,15 +12,18 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.FileConfig; +import su.nightexpress.nightcore.util.BukkitThing; +import su.nightexpress.nightcore.util.Lists; import su.nightexpress.nightcore.util.NumberUtil; import java.io.File; @@ -28,33 +31,40 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_TIME; -public class BomberEnchant extends AbstractEnchantmentData implements ChanceData, BowEnchant { +public class BomberEnchant extends GameEnchantment implements ChanceMeta, BowEnchant { public static final String ID = "bomber"; - private Modifier fuseTicks; - private ChanceSettingsImpl chanceSettings; + private Modifier fuseTicks; public BomberEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to launch TNT that explodes in " + GENERIC_TIME + "s."); - this.setMaxLevel(3); - this.setRarity(Rarity.RARE); - this.setConflicts( - EnderBowEnchant.ID, GhastEnchant.ID, - ExplosiveArrowsEnchant.ID, PoisonedArrowsEnchant.ID, ConfusingArrowsEnchant.ID, - WitheredArrowsEnchant.ID, ElectrifiedArrowsEnchant.ID, DragonfireArrowsEnchant.ID, - DarknessArrowsEnchant.ID, - HoverEnchant.ID, FlareEnchant.ID, - Enchantment.ARROW_FIRE.getKey().getKey(), - Enchantment.ARROW_KNOCKBACK.getKey().getKey(), - Enchantment.ARROW_DAMAGE.getKey().getKey() + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.DESERT_SPECIAL)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + Lists.newList(ENCHANTMENT_CHANCE + "% chance to launch TNT that explodes in " + GENERIC_TIME + "s."), + EnchantRarity.LEGENDARY, + 3, + ItemCategories.BOWS, + null, + Lists.newSet( + EnderBowEnchant.ID, GhastEnchant.ID, + ExplosiveArrowsEnchant.ID, PoisonedArrowsEnchant.ID, ConfusingArrowsEnchant.ID, + WitheredArrowsEnchant.ID, ElectrifiedArrowsEnchant.ID, DragonfireArrowsEnchant.ID, + DarknessArrowsEnchant.ID, + HoverEnchant.ID, FlareEnchant.ID, + BukkitThing.toString(Enchantment.FLAME), + BukkitThing.toString(Enchantment.PUNCH), + BukkitThing.toString(Enchantment.POWER) + ) ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(3.5, 1.5, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(3.5, 1.5, 1, 100))); this.fuseTicks = Modifier.read(config, "Settings.Fuse_Ticks", Modifier.add(110, -10, 1), @@ -63,28 +73,10 @@ public class BomberEnchant extends AbstractEnchantmentData implements ChanceData this.addPlaceholder(GENERIC_TIME, level -> NumberUtil.format((double) this.getFuseTicks(level) / 20D)); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - public int getFuseTicks(int level) { return (int) this.fuseTicks.getValue(level); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.BOWS; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.BOW; -// } - @NotNull @Override public EventPriority getShootPriority() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/ConfusingArrowsEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/ConfusingArrowsEnchant.java index de0a2ec..d7b9278 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/ConfusingArrowsEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/ConfusingArrowsEnchant.java @@ -1,5 +1,6 @@ package su.nightexpress.excellentenchants.enchantment.impl.bow; +import org.bukkit.Color; import org.bukkit.Particle; import org.bukkit.entity.AbstractArrow; import org.bukkit.entity.Arrow; @@ -13,76 +14,55 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.*; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.*; import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant; -import su.nightexpress.excellentenchants.enchantment.data.*; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; +import su.nightexpress.nightcore.util.Lists; import su.nightexpress.nightcore.util.wrapper.UniParticle; import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.*; -public class ConfusingArrowsEnchant extends AbstractEnchantmentData implements ChanceData, ArrowData, PotionData, BowEnchant { +public class ConfusingArrowsEnchant extends GameEnchantment implements ChanceMeta, ArrowMeta, PotionMeta, BowEnchant { public static final String ID = "confusing_arrows"; - private ArrowSettingsImpl arrowSettings; - private ChanceSettingsImpl chanceSettings; - private PotionSettingsImpl potionSettings; - public ConfusingArrowsEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.)"); - this.setMaxLevel(3); - this.setRarity(Rarity.COMMON); - this.setConflicts(EnderBowEnchant.ID, GhastEnchant.ID, BomberEnchant.ID); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.SWAMP_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.)", + EnchantRarity.COMMON, + 3, + ItemCategories.BOWS, + Lists.newSet( + EnderBowEnchant.ID, GhastEnchant.ID, BomberEnchant.ID + ) + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.arrowSettings = ArrowSettingsImpl.create(config, UniParticle.of(Particle.SPELL_MOB)); + this.meta.setArrowEffects(ArrowEffects.create(config, UniParticle.of(Particle.ENTITY_EFFECT, Color.fromRGB(200, 100, 100)))); - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(10, 5, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(10, 5, 1, 100))); - this.potionSettings = PotionSettingsImpl.create(this, config, PotionEffectType.CONFUSION, false, + this.meta.setPotionEffects(PotionEffects.create(this, config, PotionEffectType.NAUSEA, false, Modifier.add(3, 3, 1, 300), Modifier.add(0, 1, 1, 10) - ); + )); } - @NotNull - @Override - public ArrowSettings getArrowSettings() { - return arrowSettings; - } - - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @NotNull - @Override - public PotionSettings getPotionSettings() { - return potionSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.BOWS; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.BOW; -// } - @Override public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { if (!(event.getProjectile() instanceof Arrow arrow)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/DarknessArrowsEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/DarknessArrowsEnchant.java index 6e8f2bc..0505cec 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/DarknessArrowsEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/DarknessArrowsEnchant.java @@ -13,76 +13,58 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.*; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ArrowMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.ArrowEffects; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionEffects; import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant; -import su.nightexpress.excellentenchants.enchantment.data.*; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; +import su.nightexpress.nightcore.util.Lists; import su.nightexpress.nightcore.util.wrapper.UniParticle; import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.*; -public class DarknessArrowsEnchant extends AbstractEnchantmentData implements ChanceData, ArrowData, PotionData, BowEnchant { +public class DarknessArrowsEnchant extends GameEnchantment implements ChanceMeta, ArrowMeta, PotionMeta, BowEnchant { public static final String ID = "darkness_arrows"; - private ArrowSettingsImpl arrowSettings; - private ChanceSettingsImpl chanceSettings; - private PotionSettingsImpl potionSettings; - public DarknessArrowsEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.)"); - this.setMaxLevel(3); - this.setRarity(Rarity.COMMON); - this.setConflicts(EnderBowEnchant.ID, GhastEnchant.ID, BomberEnchant.ID); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.SNOW_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.)", + EnchantRarity.COMMON, + 3, + ItemCategories.BOWS, + Lists.newSet(EnderBowEnchant.ID, GhastEnchant.ID, BomberEnchant.ID) + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.arrowSettings = ArrowSettingsImpl.create(config, UniParticle.of(Particle.ASH)); + this.meta.setArrowEffects(ArrowEffects.create(config, UniParticle.of(Particle.ASH))); - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(8, 4, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(8, 4, 1, 100))); - this.potionSettings = PotionSettingsImpl.create(this, config, PotionEffectType.DARKNESS, false, + this.meta.setPotionEffects(PotionEffects.create(this, config, PotionEffectType.DARKNESS, false, Modifier.add(3.5, 1.5, 1, 300), Modifier.add(0, 1, 1, 5) - ); + )); } - @NotNull - @Override - public ArrowSettings getArrowSettings() { - return arrowSettings; - } - - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @NotNull - @Override - public PotionSettings getPotionSettings() { - return potionSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.BOWS; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.BOW; -// } - @Override public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { if (!(event.getProjectile() instanceof Arrow arrow)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/DragonfireArrowsEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/DragonfireArrowsEnchant.java index 932c98b..d59220c 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/DragonfireArrowsEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/DragonfireArrowsEnchant.java @@ -20,19 +20,20 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ArrowData; -import su.nightexpress.excellentenchants.api.enchantment.data.ArrowSettings; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ArrowMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.ArrowEffects; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ArrowSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.ItemUtil; +import su.nightexpress.nightcore.util.Lists; import su.nightexpress.nightcore.util.NumberUtil; import su.nightexpress.nightcore.util.Version; import su.nightexpress.nightcore.util.wrapper.UniParticle; @@ -41,29 +42,33 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.*; -public class DragonfireArrowsEnchant extends AbstractEnchantmentData implements ChanceData, ArrowData, BowEnchant { +public class DragonfireArrowsEnchant extends GameEnchantment implements ChanceMeta, ArrowMeta, BowEnchant { public static final String ID = "dragonfire_arrows"; private Modifier fireDuration; private Modifier fireRadius; - private ArrowSettingsImpl arrowSettings; - private ChanceSettingsImpl chanceSettings; - public DragonfireArrowsEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to launch an dragonfire arrow (R=" + GENERIC_RADIUS + ", " + GENERIC_DURATION + "s)."); - this.setMaxLevel(3); - this.setRarity(Rarity.RARE); - this.setConflicts(EnderBowEnchant.ID, GhastEnchant.ID, BomberEnchant.ID); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.SAVANNA_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to launch an dragonfire arrow (R=" + GENERIC_RADIUS + ", " + GENERIC_DURATION + "s).", + EnchantRarity.LEGENDARY, + 3, + ItemCategories.BOWS, + Lists.newSet(EnderBowEnchant.ID, GhastEnchant.ID, BomberEnchant.ID) + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.arrowSettings = ArrowSettingsImpl.create(config, UniParticle.of(Particle.DRAGON_BREATH)); + this.meta.setArrowEffects(ArrowEffects.create(config, UniParticle.of(Particle.DRAGON_BREATH))); - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(3, 3, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(3, 3, 1, 100))); this.fireDuration = Modifier.read(config, "Settings.Fire.Duration", Modifier.multiply(100, 1, 1, 60 * 20), @@ -77,30 +82,6 @@ public class DragonfireArrowsEnchant extends AbstractEnchantmentData implements this.addPlaceholder(GENERIC_RADIUS, level -> NumberUtil.format(this.getFireRadius(level))); } - @NotNull - @Override - public ArrowSettings getArrowSettings() { - return arrowSettings; - } - - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.BOWS; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.BOW; -// } - public int getFireDuration(int level) { return (int) this.fireDuration.getValue(level); } @@ -140,7 +121,7 @@ public class DragonfireArrowsEnchant extends AbstractEnchantmentData implements ItemStack item = new ItemStack(Material.LINGERING_POTION); ItemUtil.editMeta(item, meta -> { if (meta instanceof PotionMeta potionMeta) { - potionMeta.addCustomEffect(new PotionEffect(PotionEffectType.HARM, 20, 0), true); + potionMeta.addCustomEffect(new PotionEffect(PotionEffectType.INSTANT_DAMAGE, 20, 0), true); } }); @@ -155,7 +136,7 @@ public class DragonfireArrowsEnchant extends AbstractEnchantmentData implements cloud.setRadius((float) this.getFireRadius(level)); cloud.setDuration(this.getFireDuration(level)); cloud.setRadiusPerTick((7.0F - cloud.getRadius()) / (float) cloud.getDuration()); - cloud.addCustomEffect(new PotionEffect(PotionEffectType.HARM, 1, 1), true); + cloud.addCustomEffect(new PotionEffect(PotionEffectType.INSTANT_DAMAGE, 1, 1), true); LingeringPotionSplashEvent splashEvent; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/ElectrifiedArrowsEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/ElectrifiedArrowsEnchant.java index 9e53d0c..7d056b3 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/ElectrifiedArrowsEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/ElectrifiedArrowsEnchant.java @@ -13,19 +13,20 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ArrowData; -import su.nightexpress.excellentenchants.api.enchantment.data.ArrowSettings; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ArrowMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.ArrowEffects; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ArrowSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.ConfigValue; import su.nightexpress.nightcore.config.FileConfig; +import su.nightexpress.nightcore.util.Lists; import su.nightexpress.nightcore.util.LocationUtil; import su.nightexpress.nightcore.util.NumberUtil; import su.nightexpress.nightcore.util.wrapper.UniParticle; @@ -35,28 +36,33 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_DAMAGE; -public class ElectrifiedArrowsEnchant extends AbstractEnchantmentData implements ChanceData, ArrowData, BowEnchant { +public class ElectrifiedArrowsEnchant extends GameEnchantment implements ChanceMeta, ArrowMeta, BowEnchant { public static final String ID = "electrified_arrows"; - private ArrowSettingsImpl arrowSettings; - private ChanceSettingsImpl chanceSettings; - private Modifier damageModifier; - private boolean thunderstormOnly; + private Modifier damageModifier; + private boolean thunderstormOnly; public ElectrifiedArrowsEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance for an arrow to strike lightning with " + GENERIC_DAMAGE + "❤ extra damage."); - this.setMaxLevel(3); - this.setRarity(Rarity.UNCOMMON); - this.setConflicts(EnderBowEnchant.ID, GhastEnchant.ID, BomberEnchant.ID); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.PLAINS_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance for an arrow to strike lightning with " + GENERIC_DAMAGE + "❤ extra damage.", + EnchantRarity.RARE, + 3, + ItemCategories.BOWS, + Lists.newSet(EnderBowEnchant.ID, GhastEnchant.ID, BomberEnchant.ID) + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.arrowSettings = ArrowSettingsImpl.create(config, UniParticle.of(Particle.FIREWORKS_SPARK)); + this.meta.setArrowEffects(ArrowEffects.create(config, UniParticle.of(Particle.ELECTRIC_SPARK))); - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(0, 5, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(0, 5, 1, 100))); this.thunderstormOnly = ConfigValue.create("Settings.During_Thunderstorm_Only", false, @@ -71,18 +77,6 @@ public class ElectrifiedArrowsEnchant extends AbstractEnchantmentData implements this.addPlaceholder(GENERIC_DAMAGE, level -> NumberUtil.format(this.getDamage(level))); } - @NotNull - @Override - public ArrowSettings getArrowSettings() { - return arrowSettings; - } - - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - public boolean isDuringThunderstormOnly() { return thunderstormOnly; } @@ -91,26 +85,14 @@ public class ElectrifiedArrowsEnchant extends AbstractEnchantmentData implements return this.damageModifier.getValue(level); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.BOWS; - } -// -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.BOW; -// } - private void summonLightning(@NotNull Block block) { Location location = block.getLocation(); block.getWorld().strikeLightningEffect(location); if (this.hasVisualEffects()) { - Location center = LocationUtil.getCenter(location.add(0, 1, 0), false); + Location center = LocationUtil.setCenter2D(location.add(0, 1, 0)); UniParticle.blockCrack(block.getType()).play(center, 0.5, 0.1, 100); - UniParticle.of(Particle.FIREWORKS_SPARK).play(center, 0.75, 0.05, 120); + UniParticle.of(Particle.ELECTRIC_SPARK).play(center, 0.75, 0.05, 120); } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnderBowEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnderBowEnchant.java index 07e0770..12fe2bf 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnderBowEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnderBowEnchant.java @@ -11,65 +11,54 @@ import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.FileConfig; +import su.nightexpress.nightcore.util.BukkitThing; +import su.nightexpress.nightcore.util.Lists; import java.io.File; -public class EnderBowEnchant extends AbstractEnchantmentData implements ChanceData, BowEnchant { +public class EnderBowEnchant extends GameEnchantment implements ChanceMeta, BowEnchant { public static final String ID = "ender_bow"; - private ChanceSettingsImpl chanceSettings; - public EnderBowEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Shoots ender pearls instead of arrows."); - this.setMaxLevel(1); - this.setRarity(Rarity.VERY_RARE); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.PLAINS_SPECIAL)); + } - this.setConflicts( - BomberEnchant.ID, GhastEnchant.ID, - ExplosiveArrowsEnchant.ID, PoisonedArrowsEnchant.ID, ConfusingArrowsEnchant.ID, - WitheredArrowsEnchant.ID, ElectrifiedArrowsEnchant.ID, DragonfireArrowsEnchant.ID, - DarknessArrowsEnchant.ID, VampiricArrowsEnchant.ID, - HoverEnchant.ID, FlareEnchant.ID, - Enchantment.ARROW_FIRE.getKey().getKey(), - Enchantment.ARROW_KNOCKBACK.getKey().getKey(), - Enchantment.ARROW_DAMAGE.getKey().getKey() + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Shoots ender pearls instead of arrows.", + EnchantRarity.MYTHIC, + 1, + ItemCategories.BOWS, + Lists.newSet( + BomberEnchant.ID, GhastEnchant.ID, + ExplosiveArrowsEnchant.ID, PoisonedArrowsEnchant.ID, ConfusingArrowsEnchant.ID, + WitheredArrowsEnchant.ID, ElectrifiedArrowsEnchant.ID, DragonfireArrowsEnchant.ID, + DarknessArrowsEnchant.ID, VampiricArrowsEnchant.ID, + HoverEnchant.ID, FlareEnchant.ID, + BukkitThing.toString(Enchantment.FLAME), + BukkitThing.toString(Enchantment.PUNCH), + BukkitThing.toString(Enchantment.POWER) + ) ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config); + this.meta.setProbability(Probability.create(config)); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.BOWS; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.BOW; -// } - @NotNull @Override public EventPriority getShootPriority() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/ExplosiveArrowsEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/ExplosiveArrowsEnchant.java index c144a95..d779d46 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/ExplosiveArrowsEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/ExplosiveArrowsEnchant.java @@ -13,20 +13,21 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ArrowData; -import su.nightexpress.excellentenchants.api.enchantment.data.ArrowSettings; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ArrowMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.ArrowEffects; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ArrowSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.ConfigValue; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.manager.SimpeListener; +import su.nightexpress.nightcore.util.Lists; import su.nightexpress.nightcore.util.NumberUtil; import su.nightexpress.nightcore.util.wrapper.UniParticle; @@ -35,7 +36,7 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_RADIUS; -public class ExplosiveArrowsEnchant extends AbstractEnchantmentData implements ChanceData, ArrowData, BowEnchant, SimpeListener { +public class ExplosiveArrowsEnchant extends GameEnchantment implements ChanceMeta, ArrowMeta, BowEnchant, SimpeListener { public static final String ID = "explosive_arrows"; @@ -44,24 +45,28 @@ public class ExplosiveArrowsEnchant extends AbstractEnchantmentData implements C private boolean explosionDamageBlocks; private Modifier explosionSize; - private ArrowSettingsImpl arrowSettings; - private ChanceSettingsImpl chanceSettings; - private Entity lastExploder; public ExplosiveArrowsEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to launch an explosive arrow."); - this.setMaxLevel(3); - this.setRarity(Rarity.RARE); - this.setConflicts(EnderBowEnchant.ID, GhastEnchant.ID, BomberEnchant.ID); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.TAIGA_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to launch an explosive arrow.", + EnchantRarity.LEGENDARY, + 3, + ItemCategories.BOWS, + Lists.newSet(EnderBowEnchant.ID, GhastEnchant.ID, BomberEnchant.ID) + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.arrowSettings = ArrowSettingsImpl.create(config, UniParticle.of(Particle.SMOKE_NORMAL)); + this.meta.setArrowEffects(ArrowEffects.create(config, UniParticle.of(Particle.SMOKE))); - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(3, 2, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(3, 2, 1, 100))); this.explosionFireSpread = ConfigValue.create("Settings.Explosion.Fire_Spread", true, @@ -82,30 +87,6 @@ public class ExplosiveArrowsEnchant extends AbstractEnchantmentData implements C this.addPlaceholder(GENERIC_RADIUS, level -> NumberUtil.format(this.getExplosionSize(level))); } - @NotNull - @Override - public ArrowSettings getArrowSettings() { - return arrowSettings; - } - - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.BOWS; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.BOW; -// } - public final double getExplosionSize(int level) { return this.explosionSize.getValue(level); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/FlareEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/FlareEnchant.java index 0b9c9d5..9e9e1d6 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/FlareEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/FlareEnchant.java @@ -18,17 +18,17 @@ import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ArrowData; -import su.nightexpress.excellentenchants.api.enchantment.data.ArrowSettings; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ArrowMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.ArrowEffects; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ArrowSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.wrapper.UniParticle; @@ -36,57 +36,36 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; -public class FlareEnchant extends AbstractEnchantmentData implements ChanceData, ArrowData, BowEnchant { +public class FlareEnchant extends GameEnchantment implements ChanceMeta, ArrowMeta, BowEnchant { public static final String ID = "flare"; - private ChanceSettingsImpl chanceSettings; - private ArrowSettingsImpl arrowSettings; - public FlareEnchant(@NotNull EnchantsPlugin plugin, File file) { - super(plugin, file); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.SNOW_COMMON)); + } - this.setDescription(ENCHANTMENT_CHANCE + "% chance to create a torch where arrow lands."); - this.setMaxLevel(1); - this.setRarity(Rarity.RARE); + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to create a torch where arrow lands.", + EnchantRarity.LEGENDARY, + 1, + ItemCategories.BOWS + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config); - this.arrowSettings = ArrowSettingsImpl.create(config, UniParticle.of(Particle.FIREWORKS_SPARK)); + this.meta.setProbability(Probability.create(config)); + this.meta.setArrowEffects(ArrowEffects.create(config, UniParticle.of(Particle.ELECTRIC_SPARK))); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.BOWS; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.BOW; -// } - @NotNull @Override public EventPriority getHitPriority() { return EventPriority.HIGHEST; } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return this.chanceSettings; - } - - @NotNull - @Override - public ArrowSettings getArrowSettings() { - return this.arrowSettings; - } - @Override public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { if (!(event.getProjectile() instanceof Arrow)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/GhastEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/GhastEnchant.java index c1c2462..c976eb2 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/GhastEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/GhastEnchant.java @@ -13,49 +13,57 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.util.EnchantUtils; import su.nightexpress.nightcore.config.ConfigValue; import su.nightexpress.nightcore.config.FileConfig; +import su.nightexpress.nightcore.util.BukkitThing; +import su.nightexpress.nightcore.util.Lists; import java.io.File; -public class GhastEnchant extends AbstractEnchantmentData implements ChanceData, BowEnchant { +public class GhastEnchant extends GameEnchantment implements ChanceMeta, BowEnchant { public static final String ID = "ghast"; - private boolean fireSpread; - private Modifier yield; - private ChanceSettingsImpl chanceSettings; + private boolean fireSpread; + private Modifier yield; public GhastEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Shoots fireballs instead of arrows."); - this.setMaxLevel(1); - this.setRarity(Rarity.UNCOMMON); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.SWAMP_COMMON)); + } - this.setConflicts( - EnderBowEnchant.ID, BomberEnchant.ID, - ExplosiveArrowsEnchant.ID, PoisonedArrowsEnchant.ID, ConfusingArrowsEnchant.ID, - WitheredArrowsEnchant.ID, ElectrifiedArrowsEnchant.ID, DragonfireArrowsEnchant.ID, - DarknessArrowsEnchant.ID, VampiricArrowsEnchant.ID, - HoverEnchant.ID, FlareEnchant.ID, - Enchantment.ARROW_FIRE.getKey().getKey(), - Enchantment.ARROW_KNOCKBACK.getKey().getKey(), - Enchantment.ARROW_DAMAGE.getKey().getKey() + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Shoots fireballs instead of arrows.", + EnchantRarity.RARE, + 1, + ItemCategories.BOWS, + Lists.newSet( + EnderBowEnchant.ID, BomberEnchant.ID, + ExplosiveArrowsEnchant.ID, PoisonedArrowsEnchant.ID, ConfusingArrowsEnchant.ID, + WitheredArrowsEnchant.ID, ElectrifiedArrowsEnchant.ID, DragonfireArrowsEnchant.ID, + DarknessArrowsEnchant.ID, VampiricArrowsEnchant.ID, + HoverEnchant.ID, FlareEnchant.ID, + BukkitThing.toString(Enchantment.FLAME), + BukkitThing.toString(Enchantment.PUNCH), + BukkitThing.toString(Enchantment.POWER) + ) ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config); + this.meta.setProbability(Probability.create(config)); this.fireSpread = ConfigValue.create("Settings.Fire_Spread", true, @@ -66,12 +74,6 @@ public class GhastEnchant extends AbstractEnchantmentData implements ChanceData, "Fireball explosion size/radius. The more value = the bigger the explosion."); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - public boolean isFireSpread() { return fireSpread; } @@ -80,18 +82,6 @@ public class GhastEnchant extends AbstractEnchantmentData implements ChanceData, return (float) this.yield.getValue(level); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.BOWS; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.BOW; -// } - @NotNull @Override public EventPriority getShootPriority() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/HoverEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/HoverEnchant.java index 36db2c0..da7150a 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/HoverEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/HoverEnchant.java @@ -13,76 +13,53 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.*; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.*; import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant; -import su.nightexpress.excellentenchants.enchantment.data.*; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; +import su.nightexpress.nightcore.util.Lists; import su.nightexpress.nightcore.util.wrapper.UniParticle; import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.*; -public class HoverEnchant extends AbstractEnchantmentData implements ChanceData, ArrowData, PotionData, BowEnchant { +public class HoverEnchant extends GameEnchantment implements ChanceMeta, ArrowMeta, PotionMeta, BowEnchant { public static final String ID = "hover"; - private ArrowSettingsImpl arrowSettings; - private ChanceSettingsImpl chanceSettings; - private PotionSettingsImpl potionSettings; - public HoverEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.)"); - this.setMaxLevel(3); - this.setRarity(Rarity.COMMON); - this.setConflicts(EnderBowEnchant.ID, GhastEnchant.ID, BomberEnchant.ID); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.DESERT_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.)", + EnchantRarity.COMMON, + 3, + ItemCategories.BOWS, + Lists.newSet(EnderBowEnchant.ID, GhastEnchant.ID, BomberEnchant.ID) + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.arrowSettings = ArrowSettingsImpl.create(config, UniParticle.of(Particle.BUBBLE_POP)); + this.meta.setArrowEffects(ArrowEffects.create(config, UniParticle.of(Particle.BUBBLE_POP))); - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(3, 3, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(3, 3, 1, 100))); - this.potionSettings = PotionSettingsImpl.create(this, config, PotionEffectType.LEVITATION, false, + this.meta.setPotionEffects(PotionEffects.create(this, config, PotionEffectType.LEVITATION, false, Modifier.add(2, 1, 1, 15), Modifier.add(0, 1, 1, 5) - ); + )); } - @NotNull - @Override - public ArrowSettings getArrowSettings() { - return arrowSettings; - } - - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @NotNull - @Override - public PotionSettingsImpl getPotionSettings() { - return potionSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.BOWS; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.BOW; -// } - @Override public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { if (!(event.getProjectile() instanceof Arrow arrow)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/PoisonedArrowsEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/PoisonedArrowsEnchant.java index 3d209a7..986c093 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/PoisonedArrowsEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/PoisonedArrowsEnchant.java @@ -13,76 +13,58 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.*; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ArrowMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.ArrowEffects; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionEffects; import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant; -import su.nightexpress.excellentenchants.enchantment.data.*; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; +import su.nightexpress.nightcore.util.Lists; import su.nightexpress.nightcore.util.wrapper.UniParticle; import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.*; -public class PoisonedArrowsEnchant extends AbstractEnchantmentData implements ChanceData, ArrowData, PotionData, BowEnchant { +public class PoisonedArrowsEnchant extends GameEnchantment implements ChanceMeta, ArrowMeta, PotionMeta, BowEnchant { public static final String ID = "poisoned_arrows"; - private ArrowSettingsImpl arrowSettings; - private ChanceSettingsImpl chanceSettings; - private PotionSettingsImpl potionSettings; - public PoisonedArrowsEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.)"); - this.setMaxLevel(3); - this.setRarity(Rarity.COMMON); - this.setConflicts(EnderBowEnchant.ID, GhastEnchant.ID, BomberEnchant.ID); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.SWAMP_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.)", + EnchantRarity.COMMON, + 3, + ItemCategories.BOWS, + Lists.newSet(EnderBowEnchant.ID, GhastEnchant.ID, BomberEnchant.ID) + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.arrowSettings = ArrowSettingsImpl.create(config, UniParticle.of(Particle.SLIME)); + this.meta.setArrowEffects(ArrowEffects.create(config, UniParticle.of(Particle.ITEM_SLIME))); - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(7.5, 2.5, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(7.5, 2.5, 1, 100))); - this.potionSettings = PotionSettingsImpl.create(this, config, PotionEffectType.POISON, false, + this.meta.setPotionEffects(PotionEffects.create(this, config, PotionEffectType.POISON, false, Modifier.add(3, 1, 1, 300), Modifier.add(0, 1, 1, 5) - ); + )); } - @NotNull - @Override - public ArrowSettings getArrowSettings() { - return arrowSettings; - } - - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @NotNull - @Override - public PotionSettings getPotionSettings() { - return potionSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.BOWS; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.BOW; -// } - @Override public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { if (!(event.getProjectile() instanceof Arrow arrow)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/SniperEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/SniperEnchant.java index c4da905..2e622b4 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/SniperEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/SniperEnchant.java @@ -12,14 +12,15 @@ import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.NumberUtil; @@ -27,24 +28,29 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_AMOUNT; -public class SniperEnchant extends AbstractEnchantmentData implements BowEnchant, ChanceData { +public class SniperEnchant extends GameEnchantment implements BowEnchant, ChanceMeta { public static final String ID = "sniper"; - private ChanceSettingsImpl chanceSettings; - private Modifier speedModifier; + private Modifier speedModifier; public SniperEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.PLAINS_SPECIAL)); + } - this.setDescription("Increases projectile speed by " + GENERIC_AMOUNT + "%"); - this.setMaxLevel(5); - this.setRarity(Rarity.UNCOMMON); + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Increases projectile speed by " + GENERIC_AMOUNT + "%", + EnchantRarity.RARE, + 5, + ItemCategories.BOWS + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config); + this.meta.setProbability(Probability.create(config)); this.speedModifier = Modifier.read(config, "Settings.Speed_Modifier", Modifier.add(1, 0.2, 1, 3D), @@ -53,28 +59,10 @@ public class SniperEnchant extends AbstractEnchantmentData implements BowEnchant this.addPlaceholder(GENERIC_AMOUNT, level -> NumberUtil.format(this.getSpeedModifier(level) * 100D)); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return this.chanceSettings; - } - public double getSpeedModifier(int level) { return this.speedModifier.getValue(level); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.BOWS; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.BOW; -// } - @NotNull @Override public EventPriority getShootPriority() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/VampiricArrowsEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/VampiricArrowsEnchant.java index 562fa2f..c2740ec 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/VampiricArrowsEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/VampiricArrowsEnchant.java @@ -15,19 +15,20 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ArrowData; -import su.nightexpress.excellentenchants.api.enchantment.data.ArrowSettings; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ArrowMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.ArrowEffects; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ArrowSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.EntityUtil; +import su.nightexpress.nightcore.util.Lists; import su.nightexpress.nightcore.util.NumberUtil; import su.nightexpress.nightcore.util.wrapper.UniParticle; @@ -36,27 +37,32 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_AMOUNT; -public class VampiricArrowsEnchant extends AbstractEnchantmentData implements BowEnchant, ArrowData, ChanceData { +public class VampiricArrowsEnchant extends GameEnchantment implements BowEnchant, ArrowMeta, ChanceMeta { public static final String ID = "vampiric_arrows"; - private ArrowSettingsImpl arrowSettings; - private ChanceSettingsImpl chanceSettings; - private Modifier healAmount; + private Modifier healAmount; public VampiricArrowsEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to restore " + GENERIC_AMOUNT + "❤ on arrow hit."); - this.setMaxLevel(3); - this.setRarity(Rarity.RARE); - this.setConflicts(EnderBowEnchant.ID, GhastEnchant.ID, BomberEnchant.ID); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.SAVANNA_SPECIAL)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to restore " + GENERIC_AMOUNT + "❤ on arrow hit.", + EnchantRarity.LEGENDARY, + 3, + ItemCategories.BOWS, + Lists.newSet(EnderBowEnchant.ID, GhastEnchant.ID, BomberEnchant.ID) + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.arrowSettings = ArrowSettingsImpl.create(config, UniParticle.redstone(Color.RED, 1f)); + this.meta.setArrowEffects(ArrowEffects.create(config, UniParticle.redstone(Color.RED, 1f))); - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(8, 4, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(8, 4, 1, 100))); this.healAmount = Modifier.read(config, "Settings.Heal_Amount", Modifier.add(0, 1, 1, 10), @@ -66,30 +72,6 @@ public class VampiricArrowsEnchant extends AbstractEnchantmentData implements Bo this.addPlaceholder(GENERIC_AMOUNT, level -> NumberUtil.format(this.getHealAmount(level))); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.BOWS; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.BOW; -// } - - @NotNull - @Override - public ArrowSettings getArrowSettings() { - return this.arrowSettings; - } - - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return this.chanceSettings; - } - public double getHealAmount(int level) { return this.healAmount.getValue(level); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/WitheredArrowsEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/WitheredArrowsEnchant.java index 1d47cf3..efa5155 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/WitheredArrowsEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/WitheredArrowsEnchant.java @@ -13,76 +13,58 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.*; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ArrowMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.ArrowEffects; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionEffects; import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant; -import su.nightexpress.excellentenchants.enchantment.data.*; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; +import su.nightexpress.nightcore.util.Lists; import su.nightexpress.nightcore.util.wrapper.UniParticle; import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.*; -public class WitheredArrowsEnchant extends AbstractEnchantmentData implements ChanceData, ArrowData, PotionData, BowEnchant { +public class WitheredArrowsEnchant extends GameEnchantment implements ChanceMeta, ArrowMeta, PotionMeta, BowEnchant { public static final String ID = "withered_arrows"; - private ArrowSettingsImpl arrowSettings; - private ChanceSettingsImpl chanceSettings; - private PotionSettingsImpl potionSettings; - public WitheredArrowsEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.)"); - this.setMaxLevel(3); - this.setRarity(Rarity.RARE); - this.setConflicts(EnderBowEnchant.ID, GhastEnchant.ID, BomberEnchant.ID); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.SNOW_SPECIAL)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.)", + EnchantRarity.LEGENDARY, + 3, + ItemCategories.BOWS, + Lists.newSet(EnderBowEnchant.ID, GhastEnchant.ID, BomberEnchant.ID) + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.arrowSettings = ArrowSettingsImpl.create(config, UniParticle.of(Particle.SPELL_WITCH)); + this.meta.setArrowEffects(ArrowEffects.create(config, UniParticle.of(Particle.WITCH))); - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(4, 3, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(4, 3, 1, 100))); - this.potionSettings = PotionSettingsImpl.create(this, config, PotionEffectType.WITHER, false, + this.meta.setPotionEffects(PotionEffects.create(this, config, PotionEffectType.WITHER, false, Modifier.add(3, 1, 1, 60), Modifier.add(0, 1, 1, 5) - ); + )); } - @NotNull - @Override - public ArrowSettings getArrowSettings() { - return arrowSettings; - } - - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @NotNull - @Override - public PotionSettings getPotionSettings() { - return potionSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.BOWS; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.BOW; -// } - @Override public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { if (!(event.getProjectile() instanceof Arrow arrow)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/AutoReelEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/AutoReelEnchant.java index 493ff85..aa7899d 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/AutoReelEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/AutoReelEnchant.java @@ -7,25 +7,34 @@ import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.util.EnchantUtils; import su.nightexpress.nightcore.config.FileConfig; import java.io.File; -public class AutoReelEnchant extends AbstractEnchantmentData implements FishingEnchant { +public class AutoReelEnchant extends GameEnchantment implements FishingEnchant { public static final String ID = "auto_reel"; public AutoReelEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Automatically reels in a hook on bite."); - this.setMaxLevel(1); - this.setRarity(Rarity.VERY_RARE); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.JUNGLE_SPECIAL)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Automatically reels in a hook on bite.", + EnchantRarity.MYTHIC, + 1, + ItemCategories.FISHING_ROD + ); } @Override @@ -33,18 +42,6 @@ public class AutoReelEnchant extends AbstractEnchantmentData implements FishingE } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.FISHING_ROD; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.FISHING_ROD; -// } - @Override public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) { if (event.getState() != PlayerFishEvent.State.BITE) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/CurseOfDrownedEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/CurseOfDrownedEnchant.java index f2ab014..b0732a1 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/CurseOfDrownedEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/CurseOfDrownedEnchant.java @@ -9,14 +9,15 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.wrapper.UniParticle; import su.nightexpress.nightcore.util.wrapper.UniSound; @@ -25,42 +26,29 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; -public class CurseOfDrownedEnchant extends AbstractEnchantmentData implements FishingEnchant, ChanceData { +public class CurseOfDrownedEnchant extends GameEnchantment implements FishingEnchant, ChanceMeta { public static final String ID = "curse_of_drowned"; - private ChanceSettingsImpl chanceSettings; - public CurseOfDrownedEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to fish up a Drowned Zombie."); - this.setMaxLevel(5); - this.setRarity(Rarity.UNCOMMON); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.SWAMP_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to fish up a Drowned Zombie.", + EnchantRarity.RARE, + 5, + ItemCategories.FISHING_ROD + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(0, 5, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(0, 5, 1, 100))); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.FISHING_ROD; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.FISHING_ROD; -// } - @Override public boolean isCurse() { return true; @@ -79,7 +67,7 @@ public class CurseOfDrownedEnchant extends AbstractEnchantmentData implements Fi event.setCancelled(true); if (this.hasVisualEffects()) { - UniParticle.of(Particle.WATER_SPLASH).play(hook.getLocation(), 0.75, 0.1, 50); + UniParticle.of(Particle.UNDERWATER).play(hook.getLocation(), 0.75, 0.1, 50); UniSound.of(Sound.ENTITY_DROWNED_AMBIENT).play(event.getPlayer()); } return true; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/DoubleCatchEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/DoubleCatchEnchant.java index fcb5499..9d00371 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/DoubleCatchEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/DoubleCatchEnchant.java @@ -7,62 +7,50 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.FileConfig; import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; -public class DoubleCatchEnchant extends AbstractEnchantmentData implements FishingEnchant, ChanceData { +public class DoubleCatchEnchant extends GameEnchantment implements FishingEnchant, ChanceMeta { public static final String ID = "double_catch"; - private ChanceSettingsImpl chanceSettings; - public DoubleCatchEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Increases amount of caught item by x2 with " + ENCHANTMENT_CHANCE + "% chance."); - this.setMaxLevel(3); - this.setRarity(Rarity.RARE); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.PLAINS_SPECIAL)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Increases amount of caught item by x2 with " + ENCHANTMENT_CHANCE + "% chance.", + EnchantRarity.LEGENDARY, + 3, + ItemCategories.FISHING_ROD + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(4, 2, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(4, 2, 1, 100))); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.FISHING_ROD; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.FISHING_ROD; -// } - @NotNull @Override public EventPriority getFishingPriority() { return EventPriority.HIGHEST; } - @Override - @NotNull - public ChanceSettings getChanceSettings() { - return this.chanceSettings; - } - @Override public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) { if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/RiverMasterEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/RiverMasterEnchant.java index 2a970d8..ecca032 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/RiverMasterEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/RiverMasterEnchant.java @@ -6,32 +6,42 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.ProjectileLaunchEvent; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; import su.nightexpress.excellentenchants.api.enchantment.type.GenericEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.util.EnchantUtils; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.manager.SimpeListener; import java.io.File; -public class RiverMasterEnchant extends AbstractEnchantmentData implements GenericEnchant, SimpeListener { +public class RiverMasterEnchant extends GameEnchantment implements GenericEnchant, SimpeListener { public static final String ID = "river_master"; private Modifier distanceMod; public RiverMasterEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Increases casting distance."); - this.setMaxLevel(5); - this.setRarity(Rarity.COMMON); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.PLAINS_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Increases casting distance.", + EnchantRarity.COMMON, + 5, + ItemCategories.FISHING_ROD + ); } @Override @@ -43,18 +53,6 @@ public class RiverMasterEnchant extends AbstractEnchantmentData implements Gener ); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.FISHING_ROD; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.FISHING_ROD; -// } - public double getDistanceMod(int level) { return this.distanceMod.getValue(level); } @@ -64,10 +62,13 @@ public class RiverMasterEnchant extends AbstractEnchantmentData implements Gener if (!(event.getEntity() instanceof FishHook hook)) return; if (!(hook.getShooter() instanceof Player player)) return; - ItemStack rod = EnchantUtils.getHandItem(player, Material.FISHING_ROD); + EquipmentSlot slot = EnchantUtils.getItemHand(player, Material.FISHING_ROD); + if (slot == null) return; + + ItemStack rod = player.getInventory().getItem(slot); if (rod == null) return; - int level = EnchantUtils.getLevel(rod, this.getEnchantment()); + int level = EnchantUtils.getLevel(rod, this.getBukkitEnchantment()); if (level < 1) return; if (this.isOutOfCharges(rod)) return; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SeasonedAnglerEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SeasonedAnglerEnchant.java index 870fdc7..cb45f32 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SeasonedAnglerEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SeasonedAnglerEnchant.java @@ -5,11 +5,13 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.NumberUtil; @@ -17,17 +19,24 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_AMOUNT; -public class SeasonedAnglerEnchant extends AbstractEnchantmentData implements FishingEnchant { +public class SeasonedAnglerEnchant extends GameEnchantment implements FishingEnchant { public static final String ID = "seasoned_angler"; private Modifier xpModifier; public SeasonedAnglerEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Increases amount of XP gained from fishing by " + GENERIC_AMOUNT + "%."); - this.setMaxLevel(4); - this.setRarity(Rarity.UNCOMMON); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.TAIGA_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Increases amount of XP gained from fishing by " + GENERIC_AMOUNT + "%.", + EnchantRarity.RARE, + 4, + ItemCategories.FISHING_ROD + ); } @Override @@ -43,18 +52,6 @@ public class SeasonedAnglerEnchant extends AbstractEnchantmentData implements Fi return (int) this.xpModifier.getValue(level); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.FISHING_ROD; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.FISHING_ROD; -// } - @Override public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) { if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SurvivalistEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SurvivalistEnchant.java index 09a56af..d5cc3f0 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SurvivalistEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SurvivalistEnchant.java @@ -7,43 +7,49 @@ import org.bukkit.inventory.CookingRecipe; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.FileConfig; import java.io.File; import java.util.HashSet; import java.util.Set; -public class SurvivalistEnchant extends AbstractEnchantmentData implements FishingEnchant, ChanceData { +public class SurvivalistEnchant extends GameEnchantment implements FishingEnchant, ChanceMeta { public static final String ID = "survivalist"; private final Set> cookingRecipes; - private ChanceSettingsImpl chanceSettings; - public SurvivalistEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Automatically cooks fish if what is caught is raw."); - this.setMaxLevel(1); - this.setRarity(Rarity.UNCOMMON); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.SNOW_SPECIAL)); this.cookingRecipes = new HashSet<>(); } + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Automatically cooks fish if what is caught is raw.", + EnchantRarity.RARE, + 1, + ItemCategories.FISHING_ROD + ); + } + @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config); + this.meta.setProbability(Probability.create(config)); this.plugin.getServer().recipeIterator().forEachRemaining(recipe -> { - if (recipe instanceof CookingRecipe cookingRecipe && cookingRecipe.getInput().getType().isItem()) { + if (recipe instanceof CookingRecipe cookingRecipe && cookingRecipe.getInput().getType().isItem() && !cookingRecipe.getResult().getType().isAir()) { this.cookingRecipes.add(cookingRecipe); } }); @@ -54,24 +60,6 @@ public class SurvivalistEnchant extends AbstractEnchantmentData implements Fishi this.cookingRecipes.clear(); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.FISHING_ROD; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.FISHING_ROD; -// } - @NotNull @Override public EventPriority getFishingPriority() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/BlastMiningEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/BlastMiningEnchant.java index d8dd84f..e27d3f5 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/BlastMiningEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/BlastMiningEnchant.java @@ -14,17 +14,19 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.BlockBreakEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.util.EnchantUtils; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.manager.SimpeListener; +import su.nightexpress.nightcore.util.Lists; import su.nightexpress.nightcore.util.NumberUtil; import java.io.File; @@ -33,27 +35,34 @@ import java.util.List; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_RADIUS; -public class BlastMiningEnchant extends AbstractEnchantmentData implements ChanceData, BlockBreakEnchant, SimpeListener { +public class BlastMiningEnchant extends GameEnchantment implements ChanceMeta, BlockBreakEnchant, SimpeListener { public static final String ID = "blast_mining"; - private Modifier explosionPower; - private Modifier minBlockStrength; - private ChanceSettingsImpl chanceSettings; + private Modifier explosionPower; + private Modifier minBlockStrength; private int explodeLevel; public BlastMiningEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to mine blocks by explosion."); - this.setMaxLevel(5); - this.setRarity(Rarity.RARE); - this.setConflicts(VeinminerEnchant.ID, TunnelEnchant.ID); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.SAVANNA_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + Lists.newList(ENCHANTMENT_CHANCE + "% chance to mine blocks by explosion."), + EnchantRarity.LEGENDARY, + 5, + ItemCategories.TOOL, + ItemCategories.PICKAXE, + Lists.newSet(VeinminerEnchant.ID, TunnelEnchant.ID) + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.multiply(10, 1, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.multiply(10, 1, 1, 100))); this.explosionPower = Modifier.read(config, "Settings.Explosion.Power", Modifier.add(3, 0.75, 1, 8), @@ -68,12 +77,6 @@ public class BlastMiningEnchant extends AbstractEnchantmentData implements Chanc this.addPlaceholder(GENERIC_RADIUS, level -> NumberUtil.format(this.getExplosionPower(level))); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - public double getExplosionPower(int level) { return this.explosionPower.getValue(level); } @@ -87,30 +90,6 @@ public class BlastMiningEnchant extends AbstractEnchantmentData implements Chanc return (strength >= this.getMinBlockStrength(level)); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.TOOL; - } - - @Override - @NotNull - public ItemsCategory getPrimaryItems() { - return ItemCategories.PICKAXE; - } - -// @Override -// @NotNull -// public ItemCategory[] getItemCategories() { -// return new ItemCategory[]{ItemCategory.PICKAXE}; -// } -// -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.TOOL; -// } - @Override public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, int level) { if (!(entity instanceof Player player)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/CurseOfBreakingEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/CurseOfBreakingEnchant.java index bc5c282..1d8bbb3 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/CurseOfBreakingEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/CurseOfBreakingEnchant.java @@ -8,15 +8,15 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.GenericEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.util.EnchantUtils; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.manager.SimpeListener; import su.nightexpress.nightcore.util.NumberUtil; @@ -26,23 +26,29 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_AMOUNT; -public class CurseOfBreakingEnchant extends AbstractEnchantmentData implements GenericEnchant, SimpeListener, ChanceData { +public class CurseOfBreakingEnchant extends GameEnchantment implements GenericEnchant, SimpeListener, ChanceMeta { public static final String ID = "curse_of_breaking"; - private Modifier durabilityAmount; - private ChanceSettingsImpl chanceSettings; + private Modifier durabilityAmount; public CurseOfBreakingEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to consume extra " + GENERIC_AMOUNT + " durability points."); - this.setMaxLevel(3); - this.setRarity(Rarity.COMMON); + super(plugin, file, definition(), EnchantDistribution.treasure()); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to consume extra " + GENERIC_AMOUNT + " durability points.", + EnchantRarity.COMMON, + 3, + ItemCategories.BREAKABLE + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.multiply(10, 1, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.multiply(10, 1, 1, 100))); this.durabilityAmount = Modifier.read(config, "Settings.Durability_Amount", Modifier.add(0, 1, 1, 5), @@ -56,35 +62,17 @@ public class CurseOfBreakingEnchant extends AbstractEnchantmentData implements G return true; } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - public int getDurabilityAmount(int level) { return (int) this.durabilityAmount.getValue(level); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.BREAKABLE; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.BREAKABLE; -// } - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onItemDurability(PlayerItemDamageEvent event) { Player player = event.getPlayer(); if (!this.isAvailableToUse(player)) return; ItemStack item = event.getItem(); - int level = EnchantUtils.getLevel(item, this.getEnchantment()); + int level = EnchantUtils.getLevel(item, this.getBukkitEnchantment()); if (level < 1) return; if (!this.checkTriggerChance(level)) return; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/CurseOfMediocrityEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/CurseOfMediocrityEnchant.java index fb490c2..07ef9b2 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/CurseOfMediocrityEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/CurseOfMediocrityEnchant.java @@ -10,79 +10,55 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.BlockDropEnchant; import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.util.EnchantUtils; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.ItemUtil; +import su.nightexpress.nightcore.util.Lists; import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; -public class CurseOfMediocrityEnchant extends AbstractEnchantmentData implements ChanceData, BlockDropEnchant, DeathEnchant { +public class CurseOfMediocrityEnchant extends GameEnchantment implements ChanceMeta, BlockDropEnchant, DeathEnchant { public static final String ID = "curse_of_mediocrity"; - private ChanceSettingsImpl chanceSettings; - public CurseOfMediocrityEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to disenchant item drops."); - this.setMaxLevel(3); - this.setRarity(Rarity.UNCOMMON); + super(plugin, file, definition(), EnchantDistribution.treasure()); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + Lists.newList(ENCHANTMENT_CHANCE + "% chance to disenchant item drops."), + EnchantRarity.RARE, + 3, + ItemCategories.BREAKABLE, + ItemCategories.ALL_RANGE_WEAPON, + null + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.multiply(15, 1, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.multiply(15, 1, 1, 100))); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.BREAKABLE; - } - - @Override - @NotNull - public ItemsCategory getPrimaryItems() { - return ItemCategories.ALL_RANGE_WEAPON; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.BREAKABLE; -// } -// -// @Override -// @NotNull -// public ItemCategory[] getItemCategories() { -// return new ItemCategory[] { -// ItemCategory.SWORD, ItemCategory.BOW, ItemCategory.CROSSBOW, ItemCategory.TRIDENT, ItemCategory.TOOL -// }; -// } - @NotNull @Override public EventPriority getDropPriority() { return EventPriority.HIGHEST; } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return this.chanceSettings; - } - @Override public boolean isCurse() { return true; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/CurseOfMisfortuneEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/CurseOfMisfortuneEnchant.java index f8f6ae7..82e99d5 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/CurseOfMisfortuneEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/CurseOfMisfortuneEnchant.java @@ -11,43 +11,52 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.BlockBreakEnchant; import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.ConfigValue; import su.nightexpress.nightcore.config.FileConfig; +import su.nightexpress.nightcore.util.BukkitThing; +import su.nightexpress.nightcore.util.Lists; import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; -public class CurseOfMisfortuneEnchant extends AbstractEnchantmentData implements ChanceData, BlockBreakEnchant, DeathEnchant { +public class CurseOfMisfortuneEnchant extends GameEnchantment implements ChanceMeta, BlockBreakEnchant, DeathEnchant { public static final String ID = "curse_of_misfortune"; - private boolean dropXP; - private ChanceSettingsImpl chanceImplementation; + private boolean dropXP; public CurseOfMisfortuneEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to have no drops from blocks or mobs."); - this.setMaxLevel(3); - this.setRarity(Rarity.UNCOMMON); - this.setConflicts( - Enchantment.LOOT_BONUS_BLOCKS.getKey().getKey(), - Enchantment.LOOT_BONUS_MOBS.getKey().getKey() + super(plugin, file, definition(), EnchantDistribution.treasure()); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + Lists.newList(ENCHANTMENT_CHANCE + "% chance to have no drops from blocks or mobs."), + EnchantRarity.RARE, + 3, + ItemCategories.BREAKABLE, + ItemCategories.ALL_RANGE_WEAPON, + Lists.newSet( + BukkitThing.toString(Enchantment.FORTUNE), + BukkitThing.toString(Enchantment.LOOTING) + ) ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceImplementation = ChanceSettingsImpl.create(config, Modifier.multiply(7, 1, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.multiply(7, 1, 1, 100))); this.dropXP = ConfigValue.create("Settings.Drop_XP", false, @@ -55,42 +64,10 @@ public class CurseOfMisfortuneEnchant extends AbstractEnchantmentData implements ).read(config); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceImplementation; - } - public boolean isDropXP() { return dropXP; } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.BREAKABLE; - } - - @Override - @NotNull - public ItemsCategory getPrimaryItems() { - return ItemCategories.ALL_RANGE_WEAPON; - } - -// @Override -// @NotNull -// public ItemCategory[] getItemCategories() { -// return new ItemCategory[] { -// ItemCategory.SWORD, ItemCategory.BOW, ItemCategory.CROSSBOW, ItemCategory.TRIDENT, ItemCategory.TOOL -// }; -// } -// -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.BREAKABLE; -// } - @NotNull @Override public EventPriority getBreakPriority() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/HasteEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/HasteEnchant.java index 7e61e02..3886921 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/HasteEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/HasteEnchant.java @@ -5,16 +5,16 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.PeriodicSettings; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionData; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.Period; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionEffects; import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.data.PeriodSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.PotionSettingsImpl; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; import java.io.File; @@ -22,50 +22,30 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_POTION_LEVEL; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_POTION_TYPE; -public class HasteEnchant extends AbstractEnchantmentData implements PotionData, PassiveEnchant { +public class HasteEnchant extends GameEnchantment implements PotionMeta, PassiveEnchant { public static final String ID = "haste"; - private PotionSettingsImpl potionSettings; - private PeriodSettingsImpl periodSettings; - public HasteEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Grants permanent " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " effect."); - this.setMaxLevel(3); - this.setRarity(Rarity.RARE); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.SAVANNA_SPECIAL)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Grants permanent " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " effect.", + EnchantRarity.LEGENDARY, + 3, + ItemCategories.TOOL + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.potionSettings = PotionSettingsImpl.create(this, config, PotionEffectType.FAST_DIGGING, true); - this.periodSettings = PeriodSettingsImpl.create(config); + this.meta.setPotionEffects(PotionEffects.create(this, config, PotionEffectType.HASTE, true)); + this.meta.setPeriod(Period.create(config)); } - @NotNull - @Override - public PotionSettings getPotionSettings() { - return potionSettings; - } - - @NotNull - @Override - public PeriodicSettings getPeriodSettings() { - return periodSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.TOOL; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.TOOL; -// } - @Override public boolean onTrigger(@NotNull LivingEntity entity, @NotNull ItemStack item, int level) { return this.addEffect(entity, level); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/LuckyMinerEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/LuckyMinerEnchant.java index 6b25d83..da3020e 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/LuckyMinerEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/LuckyMinerEnchant.java @@ -6,14 +6,15 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.BlockBreakEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.NumberUtil; @@ -22,23 +23,30 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_AMOUNT; -public class LuckyMinerEnchant extends AbstractEnchantmentData implements ChanceData, BlockBreakEnchant { +public class LuckyMinerEnchant extends GameEnchantment implements ChanceMeta, BlockBreakEnchant { public static final String ID = "lucky_miner"; - private Modifier xpModifier; - private ChanceSettingsImpl chanceSettings; + private Modifier xpModifier; public LuckyMinerEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to gain " + GENERIC_AMOUNT + "% more XP from ores."); - this.setMaxLevel(5); - this.setRarity(Rarity.COMMON); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.DESERT_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to gain " + GENERIC_AMOUNT + "% more XP from ores.", + EnchantRarity.COMMON, + 5, + ItemCategories.TOOL, + ItemCategories.PICKAXE + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(25, 7.5, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(25, 7.5, 1, 100))); this.xpModifier = Modifier.read(config, "Settings.Exp_Modifier", Modifier.add(1, 0.5, 1, 5), @@ -48,40 +56,10 @@ public class LuckyMinerEnchant extends AbstractEnchantmentData implements Chance this.addPlaceholder(GENERIC_AMOUNT, level -> NumberUtil.format(this.getXPModifier(level) * 100D - 100D)); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - public double getXPModifier(int level) { return this.xpModifier.getValue(level); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.TOOL; - } - - @Override - @NotNull - public ItemsCategory getPrimaryItems() { - return ItemCategories.PICKAXE; - } - -// @Override -// @NotNull -// public ItemCategory[] getItemCategories() { -// return new ItemCategory[]{ItemCategory.PICKAXE}; -// } -// -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.TOOL; -// } - @Override public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull LivingEntity player, @NotNull ItemStack item, int level) { if (!this.checkTriggerChance(level)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/ReplanterEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/ReplanterEnchant.java index fdb6e19..cc140e9 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/ReplanterEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/ReplanterEnchant.java @@ -16,15 +16,16 @@ import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.BlockBreakEnchant; import su.nightexpress.excellentenchants.api.enchantment.type.InteractEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.ConfigValue; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.wrapper.UniSound; @@ -32,30 +33,36 @@ import su.nightexpress.nightcore.util.wrapper.UniSound; import java.io.File; import java.util.Set; -public class ReplanterEnchant extends AbstractEnchantmentData implements ChanceData, InteractEnchant, BlockBreakEnchant { +public class ReplanterEnchant extends GameEnchantment implements ChanceMeta, InteractEnchant, BlockBreakEnchant { public static final String ID = "replanter"; private boolean replantOnRightClick; private boolean replantOnPlantBreak; - private ChanceSettingsImpl chanceSettings; - private static final Set CROPS = Set.of( Material.WHEAT_SEEDS, Material.BEETROOT_SEEDS, Material.MELON_SEEDS, Material.PUMPKIN_SEEDS, Material.POTATO, Material.CARROT, Material.NETHER_WART); public ReplanterEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Automatically replant crops on right click and when harvest."); - this.setMaxLevel(1); - this.setRarity(Rarity.RARE); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.DESERT_SPECIAL)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Automatically replant crops on right click and when harvest.", + EnchantRarity.LEGENDARY, + 1, + ItemCategories.TOOL, + ItemCategories.HOE + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config); + this.meta.setProbability(Probability.create(config)); this.replantOnRightClick = ConfigValue.create("Settings.Replant.On_Right_Click", true, @@ -68,12 +75,6 @@ public class ReplanterEnchant extends AbstractEnchantmentData implements ChanceD ).read(config); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - public boolean isReplantOnPlantBreak() { return replantOnPlantBreak; } @@ -98,30 +99,6 @@ public class ReplanterEnchant extends AbstractEnchantmentData implements ChanceD return true; } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.TOOL; - } - - @Override - @NotNull - public ItemsCategory getPrimaryItems() { - return ItemCategories.HOE; - } - -// @Override -// @NotNull -// public ItemCategory[] getItemCategories() { -// return new ItemCategory[]{ItemCategory.HOE}; -// } -// -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.TOOL; -// } - @NotNull @Override public EventPriority getInteractPriority() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/SilkChestEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/SilkChestEnchant.java index 4be095f..077fa90 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/SilkChestEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/SilkChestEnchant.java @@ -21,11 +21,13 @@ import org.bukkit.inventory.meta.BlockStateMeta; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; import su.nightexpress.excellentenchants.api.enchantment.type.BlockDropEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.ConfigValue; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.manager.SimpeListener; @@ -39,7 +41,7 @@ import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Stream; -public class SilkChestEnchant extends AbstractEnchantmentData implements BlockDropEnchant, SimpeListener { +public class SilkChestEnchant extends GameEnchantment implements BlockDropEnchant, SimpeListener { public static final String ID = "silk_chest"; @@ -48,14 +50,22 @@ public class SilkChestEnchant extends AbstractEnchantmentData implements BlockDr private final NamespacedKey keyChest; public SilkChestEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Drop chests and saves all its content."); - this.setMaxLevel(1); - this.setRarity(Rarity.VERY_RARE); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.PLAINS_SPECIAL)); this.keyChest = new NamespacedKey(plugin, ID + ".item"); } + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Drop chests and saves all its content.", + EnchantRarity.MYTHIC, + 1, + ItemCategories.TOOL, + ItemCategories.AXE + ); + } + @Override public boolean checkServerRequirements() { if (Plugins.isSpigot()) { @@ -78,30 +88,6 @@ public class SilkChestEnchant extends AbstractEnchantmentData implements BlockDr ).read(config); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.TOOL; - } - - @Override - @NotNull - public ItemsCategory getPrimaryItems() { - return ItemCategories.AXE; - } - -// @Override -// @NotNull -// public ItemCategory[] getItemCategories() { -// return new ItemCategory[]{ItemCategory.AXE}; -// } -// -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.TOOL; -// } - public boolean isSilkChest(@NotNull ItemStack item) { return PDCUtil.getBoolean(item, this.keyChest).isPresent(); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/SilkSpawnerEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/SilkSpawnerEnchant.java index 7b47550..06554d0 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/SilkSpawnerEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/SilkSpawnerEnchant.java @@ -19,19 +19,21 @@ import org.bukkit.inventory.meta.BlockStateMeta; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.BlockBreakEnchant; import su.nightexpress.excellentenchants.api.enchantment.type.BlockDropEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.ConfigValue; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.language.LangAssets; import su.nightexpress.nightcore.manager.SimpeListener; +import su.nightexpress.nightcore.util.Lists; import su.nightexpress.nightcore.util.LocationUtil; import su.nightexpress.nightcore.util.PDCUtil; import su.nightexpress.nightcore.util.Plugins; @@ -44,25 +46,31 @@ import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_TYPE; import static su.nightexpress.nightcore.util.text.tag.Tags.*; -public class SilkSpawnerEnchant extends AbstractEnchantmentData implements ChanceData, BlockBreakEnchant, BlockDropEnchant, SimpeListener { +public class SilkSpawnerEnchant extends GameEnchantment implements ChanceMeta, BlockBreakEnchant, BlockDropEnchant, SimpeListener { public static final String ID = "divine_touch"; - private String spawnerName; - private ChanceSettingsImpl chanceSettings; + private String spawnerName; private Location handleSpawner; private final NamespacedKey spawnerKey; public SilkSpawnerEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.JUNGLE_SPECIAL)); this.spawnerKey = new NamespacedKey(plugin, "divine_spawner"); + } - this.setDescription(ENCHANTMENT_CHANCE + "% chance to mine spawner."); - this.setMaxLevel(5); - this.setRarity(Rarity.VERY_RARE); - this.setConflicts(SmelterEnchant.ID); + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + Lists.newList(ENCHANTMENT_CHANCE + "% chance to mine spawner."), + EnchantRarity.MYTHIC, + 5, + ItemCategories.TOOL, + ItemCategories.PICKAXE, + Lists.newSet(SmelterEnchant.ID) + ); } @Override @@ -76,7 +84,7 @@ public class SilkSpawnerEnchant extends AbstractEnchantmentData implements Chanc @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.multiply(10, 1, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.multiply(10, 1, 1, 100))); this.spawnerName = ConfigValue.create("Settings.Spawner_Item.Name", YELLOW.enclose("Mob Spawner " + GRAY.enclose("(" + WHITE.enclose(GENERIC_TYPE) + ")")), @@ -85,36 +93,6 @@ public class SilkSpawnerEnchant extends AbstractEnchantmentData implements Chanc ).read(config); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.TOOL; - } - - @Override - @NotNull - public ItemsCategory getPrimaryItems() { - return ItemCategories.PICKAXE; - } - -// @Override -// @NotNull -// public ItemCategory[] getItemCategories() { -// return new ItemCategory[]{ItemCategory.PICKAXE}; -// } -// -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.TOOL; -// } - @NotNull public ItemStack getSpawner(@NotNull CreatureSpawner spawnerBlock) { ItemStack itemSpawner = new ItemStack(Material.SPAWNER); @@ -145,7 +123,7 @@ public class SilkSpawnerEnchant extends AbstractEnchantmentData implements Chanc if (this.hasVisualEffects()) { Location location = LocationUtil.getCenter(block.getLocation()); - UniParticle.of(Particle.VILLAGER_HAPPY).play(location, 0.3, 0.15, 30); + UniParticle.of(Particle.HAPPY_VILLAGER).play(location, 0.3, 0.15, 30); } return true; } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/SmelterEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/SmelterEnchant.java index 4b22539..b00636e 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/SmelterEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/SmelterEnchant.java @@ -16,14 +16,15 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.BlockDropEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.ConfigValue; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.BukkitThing; @@ -40,34 +41,41 @@ import java.util.Set; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; -public class SmelterEnchant extends AbstractEnchantmentData implements ChanceData, BlockDropEnchant { +public class SmelterEnchant extends GameEnchantment implements ChanceMeta, BlockDropEnchant { public static final String ID = "smelter"; - private UniSound sound; - private boolean disableOnCrouch; - private ChanceSettingsImpl chanceSettings; + private UniSound sound; + private boolean disableOnCrouch; private final Set exemptedItems; private final Set recipes; public SmelterEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Smelts mined blocks with " + ENCHANTMENT_CHANCE + "% chance."); - this.setMaxLevel(5); - this.setRarity(Rarity.UNCOMMON); - this.setConflicts( - SilkSpawnerEnchant.ID, - Enchantment.SILK_TOUCH.getKey().getKey() - ); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.PLAINS_COMMON)); this.exemptedItems = new HashSet<>(); this.recipes = new HashSet<>(); } + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + Lists.newList("Smelts mined blocks with " + ENCHANTMENT_CHANCE + "% chance."), + EnchantRarity.RARE, + 5, + ItemCategories.TOOL, + ItemCategories.MINING_TOOLS, + Lists.newSet( + SilkSpawnerEnchant.ID, + BukkitThing.toString(Enchantment.SILK_TOUCH) + ) + ); + } + @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(10, 8, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(10, 8, 1, 100))); this.disableOnCrouch = ConfigValue.create("Settings.Disable_On_Crouch", true, @@ -102,36 +110,6 @@ public class SmelterEnchant extends AbstractEnchantmentData implements ChanceDat this.exemptedItems.clear(); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.TOOL; - } - - @Override - @NotNull - public ItemsCategory getPrimaryItems() { - return ItemCategories.MINING_TOOLS; - } - -// @Override -// @NotNull -// public ItemCategory[] getItemCategories() { -// return new ItemCategory[]{ItemCategory.PICKAXE, ItemCategory.AXE, ItemCategory.SHOVEL}; -// } -// -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.TOOL; -// } - @Override public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, int level) { if (this.disableOnCrouch && entity instanceof Player player && player.isSneaking()) return false; @@ -160,7 +138,7 @@ public class SmelterEnchant extends AbstractEnchantmentData implements ChanceDat Block block = state.getBlock(); if (this.hasVisualEffects()) { - Location location = LocationUtil.getCenter(block.getLocation(), true); + Location location = LocationUtil.setCenter3D(block.getLocation()); UniParticle.of(Particle.FLAME).play(location, 0.25, 0.05, 20); this.sound.play(location); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/TelekinesisEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/TelekinesisEnchant.java index 3156be0..610fdcb 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/TelekinesisEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/TelekinesisEnchant.java @@ -7,62 +7,44 @@ import org.bukkit.event.block.BlockDropItemEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.BlockDropEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.Players; import java.io.File; -public class TelekinesisEnchant extends AbstractEnchantmentData implements ChanceData, BlockDropEnchant { +public class TelekinesisEnchant extends GameEnchantment implements ChanceMeta, BlockDropEnchant { public static final String ID = "telekinesis"; - private ChanceSettingsImpl chanceSettings; - public TelekinesisEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Moves all blocks loot directly to your inventory."); - this.setMaxLevel(1); - this.setRarity(Rarity.VERY_RARE); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.SNOW_SPECIAL)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Moves all blocks loot directly to your inventory.", + EnchantRarity.MYTHIC, + 1, + ItemCategories.TOOL + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config); + this.meta.setProbability(Probability.create(config)); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.TOOL; - } - -// @Override -// @NotNull -// public ItemCategory[] getItemCategories() { -// return new ItemCategory[]{ItemCategory.TOOL}; -// } -// -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.TOOL; -// } - @NotNull @Override public EventPriority getDropPriority() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/TunnelEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/TunnelEnchant.java index 7428228..9510ef7 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/TunnelEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/TunnelEnchant.java @@ -9,12 +9,14 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; import su.nightexpress.excellentenchants.api.enchantment.type.BlockBreakEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.util.EnchantUtils; import su.nightexpress.nightcore.config.ConfigValue; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.Lists; @@ -24,7 +26,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -public class TunnelEnchant extends AbstractEnchantmentData implements BlockBreakEnchant { +public class TunnelEnchant extends GameEnchantment implements BlockBreakEnchant { public static final String ID = "tunnel"; // X and Z offsets for each block AoE mined @@ -39,12 +41,19 @@ public class TunnelEnchant extends AbstractEnchantmentData implements BlockBreak private boolean disableOnSneak; public TunnelEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.SWAMP_SPECIAL)); + } - this.setDescription("Mines multiple blocks at once in a certain shape."); - this.setMaxLevel(3); - this.setRarity(Rarity.VERY_RARE); - this.setConflicts(VeinminerEnchant.ID, BlastMiningEnchant.ID); + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + Lists.newList("Mines multiple blocks at once in a certain shape."), + EnchantRarity.MYTHIC, + 3, + ItemCategories.TOOL, + ItemCategories.PICKAXE, + Lists.newSet(VeinminerEnchant.ID, BlastMiningEnchant.ID) + ); } @Override @@ -54,30 +63,6 @@ public class TunnelEnchant extends AbstractEnchantmentData implements BlockBreak "Sets whether or not enchantment will have no effect when crouching.").read(config); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.TOOL; - } - - @Override - @NotNull - public ItemsCategory getPrimaryItems() { - return ItemCategories.PICKAXE; - } - -// @Override -// @NotNull -// public ItemCategory[] getItemCategories() { -// return new ItemCategory[]{ItemCategory.PICKAXE, ItemCategory.SHOVEL}; -// } -// -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.TOOL; -// } - @Override public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, int level) { if (!(entity instanceof Player player)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/VeinminerEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/VeinminerEnchant.java index 10a6935..8d72733 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/VeinminerEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/VeinminerEnchant.java @@ -11,15 +11,18 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; import su.nightexpress.excellentenchants.api.enchantment.type.BlockBreakEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.util.EnchantUtils; import su.nightexpress.nightcore.config.ConfigValue; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.BukkitThing; +import su.nightexpress.nightcore.util.Lists; import java.io.File; import java.util.HashSet; @@ -29,7 +32,7 @@ import java.util.stream.Stream; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_AMOUNT; -public class VeinminerEnchant extends AbstractEnchantmentData implements BlockBreakEnchant { +public class VeinminerEnchant extends GameEnchantment implements BlockBreakEnchant { public static final String ID = "veinminer"; @@ -43,12 +46,19 @@ public class VeinminerEnchant extends AbstractEnchantmentData implements BlockBr private boolean disableOnCrouch; public VeinminerEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.PLAINS_SPECIAL)); + } - this.setDescription("Mines up to " + GENERIC_AMOUNT + " blocks of the ore vein at once."); - this.setMaxLevel(3); - this.setRarity(Rarity.RARE); - this.setConflicts(BlastMiningEnchant.ID, TunnelEnchant.ID); + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + Lists.newList("Mines up to " + GENERIC_AMOUNT + " blocks of the ore vein at once."), + EnchantRarity.LEGENDARY, + 3, + ItemCategories.TOOL, + ItemCategories.PICKAXE, + Lists.newSet(BlastMiningEnchant.ID, TunnelEnchant.ID) + ); } @Override @@ -94,30 +104,6 @@ public class VeinminerEnchant extends AbstractEnchantmentData implements BlockBr return (int) this.blocksLimit.getValue(level); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.TOOL; - } - - @Override - @NotNull - public ItemsCategory getPrimaryItems() { - return ItemCategories.PICKAXE; - } - -// @Override -// @NotNull -// public ItemCategory[] getItemCategories() { -// return new ItemCategory[]{ItemCategory.PICKAXE}; -// } -// -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.TOOL; -// } - @NotNull private Set getNearby(@NotNull Block block) { return Stream.of(AREA).map(block::getRelative) diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/universal/CurseOfFragilityEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/universal/CurseOfFragilityEnchant.java index 758792a..122baa2 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/universal/CurseOfFragilityEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/universal/CurseOfFragilityEnchant.java @@ -11,26 +11,34 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; import su.nightexpress.excellentenchants.api.enchantment.type.GenericEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.util.EnchantUtils; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.manager.SimpeListener; import java.io.File; -public class CurseOfFragilityEnchant extends AbstractEnchantmentData implements GenericEnchant, SimpeListener { +public class CurseOfFragilityEnchant extends GameEnchantment implements GenericEnchant, SimpeListener { public static final String ID = "curse_of_fragility"; public CurseOfFragilityEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Prevents an item from being grindstoned or anviled."); - this.setMaxLevel(1); - this.setRarity(Rarity.COMMON); + super(plugin, file, definition(), EnchantDistribution.treasure()); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Prevents an item from being grindstoned or anviled.", + EnchantRarity.COMMON, + 1, + ItemCategories.BREAKABLE + ); } @Override @@ -38,24 +46,6 @@ public class CurseOfFragilityEnchant extends AbstractEnchantmentData implements } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.BREAKABLE; - } - -// @Override -// @NotNull -// public ItemsCategory getPrimaryItems() { -// return ItemCategories.PICKAXE; -// } -// -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.BREAKABLE; -// } - @Override public boolean isCurse() { return true; @@ -67,8 +57,8 @@ public class CurseOfFragilityEnchant extends AbstractEnchantmentData implements ItemStack first = inventory.getItem(0); ItemStack second = inventory.getItem(1); - boolean cursedFirst = (first != null && EnchantUtils.getLevel(first, this.getEnchantment()) >= 1); - boolean cursedSecond = (second != null && EnchantUtils.getLevel(second, this.getEnchantment()) >= 1); + boolean cursedFirst = (first != null && EnchantUtils.getLevel(first, this.getBukkitEnchantment()) >= 1); + boolean cursedSecond = (second != null && EnchantUtils.getLevel(second, this.getBukkitEnchantment()) >= 1); if (cursedFirst || cursedSecond) { event.setResult(null); @@ -96,8 +86,8 @@ public class CurseOfFragilityEnchant extends AbstractEnchantmentData implements ItemStack first = inventory.getItem(0); ItemStack second = inventory.getItem(1); - boolean cursedFirst = (first != null && EnchantUtils.getLevel(first, this.getEnchantment()) >= 1); - boolean cursedSecond = (second != null && EnchantUtils.getLevel(second, this.getEnchantment()) >= 1); + boolean cursedFirst = (first != null && EnchantUtils.getLevel(first, this.getBukkitEnchantment()) >= 1); + boolean cursedSecond = (second != null && EnchantUtils.getLevel(second, this.getBukkitEnchantment()) >= 1); if (cursedFirst || cursedSecond) { inventory.setItem(2, null); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/universal/RestoreEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/universal/RestoreEnchant.java index 78f306a..6872325 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/universal/RestoreEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/universal/RestoreEnchant.java @@ -9,15 +9,16 @@ import org.bukkit.inventory.meta.Damageable; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.GenericEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.util.EnchantUtils; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.manager.SimpeListener; import su.nightexpress.nightcore.util.NumberUtil; @@ -28,23 +29,29 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_AMOUNT; -public class RestoreEnchant extends AbstractEnchantmentData implements GenericEnchant, ChanceData, SimpeListener { +public class RestoreEnchant extends GameEnchantment implements GenericEnchant, ChanceMeta, SimpeListener { public static final String ID = "restore"; - private ChanceSettingsImpl chanceSettings; - private Modifier durabilityRestore; + private Modifier durabilityRestore; public RestoreEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to save item from breaking back to " + GENERIC_AMOUNT + "%"); - this.setMaxLevel(5); - this.setRarity(Rarity.RARE); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.SNOW_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to save item from breaking back to " + GENERIC_AMOUNT + "%", + EnchantRarity.LEGENDARY, + 5, + ItemCategories.BREAKABLE + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(20, 6, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(20, 6, 1, 100))); this.durabilityRestore = Modifier.read(config, "Settings.Durability_Restoration", Modifier.add(25, 5, 1, 100), @@ -53,24 +60,6 @@ public class RestoreEnchant extends AbstractEnchantmentData implements GenericEn this.addPlaceholder(GENERIC_AMOUNT, level -> NumberUtil.format(this.getDurabilityRestore(level))); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.BREAKABLE; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.BREAKABLE; -// } - public double getDurabilityRestore(int level) { return this.durabilityRestore.getValue(level); } @@ -84,7 +73,7 @@ public class RestoreEnchant extends AbstractEnchantmentData implements GenericEn int maxDurability = item.getType().getMaxDurability(); if (damageable.getDamage() + damage < maxDurability) return; - int level = EnchantUtils.getLevel(item, this.getEnchantment()); + int level = EnchantUtils.getLevel(item, this.getBukkitEnchantment()); if (level <= 0) return; if (this.isOutOfCharges(item)) return; @@ -98,7 +87,7 @@ public class RestoreEnchant extends AbstractEnchantmentData implements GenericEn damageable.setDamage(restored); item.setItemMeta(damageable); - EnchantUtils.remove(item, this.getEnchantment()); + EnchantUtils.remove(item, this.getBukkitEnchantment()); if (this.hasVisualEffects()) { UniSound.of(Sound.ITEM_TOTEM_USE).play(event.getPlayer()); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/universal/SoulboundEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/universal/SoulboundEnchant.java index 4a72a30..67358ba 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/universal/SoulboundEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/universal/SoulboundEnchant.java @@ -10,29 +10,40 @@ import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; import su.nightexpress.excellentenchants.api.enchantment.type.GenericEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.util.EnchantUtils; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.manager.SimpeListener; +import su.nightexpress.nightcore.util.BukkitThing; +import su.nightexpress.nightcore.util.Lists; import java.io.File; import java.util.ArrayList; import java.util.List; -public class SoulboundEnchant extends AbstractEnchantmentData implements GenericEnchant, SimpeListener { +public class SoulboundEnchant extends GameEnchantment implements GenericEnchant, SimpeListener { public static final String ID = "soulbound"; public SoulboundEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Protects from being dropped on death."); - this.setMaxLevel(1); - this.setRarity(Rarity.VERY_RARE); - this.setConflicts(Enchantment.VANISHING_CURSE.getKey().getKey()); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.TAIGA_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Protects from being dropped on death.", + EnchantRarity.MYTHIC, + 1, + ItemCategories.BREAKABLE, + Lists.newSet(BukkitThing.toString(Enchantment.VANISHING_CURSE)) + ); } @Override @@ -40,18 +51,6 @@ public class SoulboundEnchant extends AbstractEnchantmentData implements Generic } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.BREAKABLE; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.BREAKABLE; -// } - @EventHandler(priority = EventPriority.MONITOR) public void onDeath(@NotNull PlayerDeathEvent deathEvent) { Player player = deathEvent.getEntity(); @@ -63,7 +62,7 @@ public class SoulboundEnchant extends AbstractEnchantmentData implements Generic World world = player.getWorld(); deathEvent.getDrops().removeIf(drop -> { - if (EnchantUtils.getLevel(drop, this.getEnchantment()) > 0) { + if (EnchantUtils.getLevel(drop, this.getBukkitEnchantment()) > 0) { if (this.isOutOfCharges(drop)) return false; saveList.add(drop); @@ -80,7 +79,7 @@ public class SoulboundEnchant extends AbstractEnchantmentData implements Generic world.dropItemNaturally(location, save); } else { - this.consumeChargesNoUpdate(save, EnchantUtils.getLevel(save, this.getEnchantment())); + this.consumeChargesNoUpdate(save, EnchantUtils.getLevel(save, this.getBukkitEnchantment())); player.getInventory().addItem(save); } }); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/BaneOfNetherspawnEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/BaneOfNetherspawnEnchant.java index f8a31fe..cd8a5aa 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/BaneOfNetherspawnEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/BaneOfNetherspawnEnchant.java @@ -8,11 +8,13 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.ConfigValue; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.Lists; @@ -24,7 +26,7 @@ import java.util.Set; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_DAMAGE; -public class BaneOfNetherspawnEnchant extends AbstractEnchantmentData implements CombatEnchant { +public class BaneOfNetherspawnEnchant extends GameEnchantment implements CombatEnchant { public static final String ID = "bane_of_netherspawn"; @@ -37,54 +39,51 @@ public class BaneOfNetherspawnEnchant extends AbstractEnchantmentData implements ); private boolean damageModifier; - private Modifier damageFormula; + private Modifier damageAmount; public BaneOfNetherspawnEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Inflicts " + GENERIC_DAMAGE + "❤ more damage to nether mobs."); - this.setMaxLevel(5); - this.setRarity(Rarity.COMMON); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.JUNGLE_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Inflicts " + GENERIC_DAMAGE + "❤ more damage to nether mobs.", + EnchantRarity.COMMON, + 5, + ItemCategories.WEAPON + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { this.damageModifier = ConfigValue.create("Settings.Damage.As_Modifier", false, - "When 'true' multiplies the damage. When 'false' sums plain values.").read(config); + "When 'true' multiplies the damage. When 'false' sums plain values." + ).read(config); - this.damageFormula = Modifier.read(config, "Settings.Damage.Amount", + this.damageAmount = Modifier.read(config, "Settings.Damage.Amount", Modifier.add(0.75, 0.25, 1, 10000), - "Amount of additional damage."); + "Amount of additional damage." + ); - this.addPlaceholder(GENERIC_DAMAGE, level -> NumberUtil.format(this.getDamageModifier(level))); + this.addPlaceholder(GENERIC_DAMAGE, level -> NumberUtil.format(this.getDamageAmount(level))); } - public double getDamageModifier(int level) { - return this.damageFormula.getValue(level); + public double getDamageAmount(int level) { + return this.damageAmount.getValue(level); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - @Override public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { if (!ENTITY_TYPES.contains(victim.getType())) return false; double damageEvent = event.getDamage(); - double damageAdd = this.getDamageModifier(level); + double damageAdd = this.getDamageAmount(level); event.setDamage(this.damageModifier ? damageEvent * damageAdd : damageEvent + damageAdd); if (this.hasVisualEffects()) { - UniParticle.of(Particle.SMOKE_NORMAL).play(victim.getEyeLocation(), 0.25, 0.1, 25); + UniParticle.of(Particle.SMOKE).play(victim.getEyeLocation(), 0.25, 0.1, 20); UniParticle.of(Particle.LAVA).play(victim.getEyeLocation(), 0.25, 0.1, 5); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/BlindnessEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/BlindnessEnchant.java index 43aa221..dc811fb 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/BlindnessEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/BlindnessEnchant.java @@ -9,17 +9,17 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionData; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionEffects; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.data.PotionSettingsImpl; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.wrapper.UniParticle; @@ -27,53 +27,34 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.*; -public class BlindnessEnchant extends AbstractEnchantmentData implements ChanceData, PotionData, CombatEnchant { +public class BlindnessEnchant extends GameEnchantment implements ChanceMeta, PotionMeta, CombatEnchant { public static final String ID = "blindness"; - private ChanceSettingsImpl chanceSettings; - private PotionSettingsImpl potionSettings; - public BlindnessEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to apply " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.) on hit."); - this.setMaxLevel(3); - this.setRarity(Rarity.COMMON); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.DESERT_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to apply " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.) on hit.", + EnchantRarity.COMMON, + 3, + ItemCategories.WEAPON + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(7, 3, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(7, 3, 1, 100))); - this.potionSettings = PotionSettingsImpl.create(this, config, PotionEffectType.BLINDNESS, false, + this.meta.setPotionEffects(PotionEffects.create(this, config, PotionEffectType.BLINDNESS, false, Modifier.add(4, 1, 1, 300), - Modifier.add(0, 1, 1, 10)); + Modifier.add(0, 1, 1, 10) + )); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @NotNull - @Override - public PotionSettings getPotionSettings() { - return potionSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - @NotNull @Override public EventPriority getAttackPriority() { @@ -86,7 +67,7 @@ public class BlindnessEnchant extends AbstractEnchantmentData implements ChanceD if (!this.addEffect(victim, level)) return false; if (this.hasVisualEffects()) { - UniParticle.of(Particle.SMOKE_NORMAL).play(victim.getEyeLocation(), 0.25, 0.1, 30); + UniParticle.of(Particle.SMOKE).play(victim.getEyeLocation(), 0.25, 0.1, 30); } return true; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/ConfusionEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/ConfusionEnchant.java index 820f684..3844ce5 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/ConfusionEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/ConfusionEnchant.java @@ -9,17 +9,17 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionData; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionEffects; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.data.PotionSettingsImpl; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.wrapper.UniParticle; @@ -27,53 +27,34 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.*; -public class ConfusionEnchant extends AbstractEnchantmentData implements ChanceData, PotionData, CombatEnchant { +public class ConfusionEnchant extends GameEnchantment implements ChanceMeta, PotionMeta, CombatEnchant { public static final String ID = "confusion"; - private ChanceSettingsImpl chanceSettings; - private PotionSettingsImpl potionSettings; - public ConfusionEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to apply " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.) on hit."); - this.setMaxLevel(3); - this.setRarity(Rarity.COMMON); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.SWAMP_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to apply " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.) on hit.", + EnchantRarity.COMMON, + 3, + ItemCategories.WEAPON + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(15, 5, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(15, 5, 1, 100))); - this.potionSettings = PotionSettingsImpl.create(this, config, PotionEffectType.CONFUSION, false, + this.meta.setPotionEffects(PotionEffects.create(this, config, PotionEffectType.NAUSEA, false, Modifier.add(7, 1, 1, 300), - Modifier.add(0, 1, 1, 10)); + Modifier.add(0, 1, 1, 10) + )); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @NotNull - @Override - public PotionSettings getPotionSettings() { - return potionSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - @NotNull @Override public EventPriority getAttackPriority() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/CureEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/CureEnchant.java index 4bf7395..cde9a94 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/CureEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/CureEnchant.java @@ -1,6 +1,5 @@ package su.nightexpress.excellentenchants.enchantment.impl.weapon; -import com.google.common.collect.Sets; import org.bukkit.Particle; import org.bukkit.entity.*; import org.bukkit.event.EventPriority; @@ -9,15 +8,17 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.FileConfig; +import su.nightexpress.nightcore.util.Lists; import su.nightexpress.nightcore.util.wrapper.UniParticle; import java.io.File; @@ -25,44 +26,33 @@ import java.util.Set; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; -public class CureEnchant extends AbstractEnchantmentData implements ChanceData, CombatEnchant { +public class CureEnchant extends GameEnchantment implements ChanceMeta, CombatEnchant { public static final String ID = "cure"; - private ChanceSettingsImpl chanceSettings; - - private static final Set CUREABLE = Sets.newHashSet(EntityType.ZOMBIFIED_PIGLIN, EntityType.ZOMBIE_VILLAGER); + private static final Set CUREABLE = Lists.newSet(EntityType.ZOMBIFIED_PIGLIN, EntityType.ZOMBIE_VILLAGER); public CureEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to cure Zombified Piglins and Zombie Villagers on hit."); - this.setMaxLevel(5); - this.setRarity(Rarity.RARE); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.DESERT_COMMON)); + } + + // TODO On kill only + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to cure Zombified Piglins and Zombie Villagers on hit.", + EnchantRarity.LEGENDARY, + 5, + ItemCategories.WEAPON + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(4, 2.2, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(4, 2.2, 1, 100))); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - @NotNull @Override public EventPriority getAttackPriority() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/CurseOfDeathEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/CurseOfDeathEnchant.java index 8ea20d0..6be8603 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/CurseOfDeathEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/CurseOfDeathEnchant.java @@ -8,52 +8,39 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.FileConfig; import java.io.File; -public class CurseOfDeathEnchant extends AbstractEnchantmentData implements DeathEnchant, ChanceData { +public class CurseOfDeathEnchant extends GameEnchantment implements DeathEnchant, ChanceMeta { public static final String ID = "curse_of_death"; - private ChanceSettingsImpl chanceSettings; - public CurseOfDeathEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("When killing players, you have a chance of dying too."); - this.setMaxLevel(3); - this.setRarity(Rarity.RARE); + super(plugin, file, definition(), EnchantDistribution.treasure()); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "When killing players, you have a chance of dying too.", + EnchantRarity.LEGENDARY, + 3, + ItemCategories.WEAPON + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(0.5, 0.15, 1, 100)); - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return this.chanceSettings; + this.meta.setProbability(Probability.create(config, Modifier.add(0.5, 0.15, 1, 100))); } @Override diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/CutterEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/CutterEnchant.java index 6dd0ff8..c29ae0f 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/CutterEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/CutterEnchant.java @@ -13,14 +13,15 @@ import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.ConfigValue; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.NumberUtil; @@ -33,25 +34,31 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_DAMAGE; -public class CutterEnchant extends AbstractEnchantmentData implements ChanceData, CombatEnchant { +public class CutterEnchant extends GameEnchantment implements ChanceMeta, CombatEnchant { public static final String ID = "cutter"; - private Modifier durabilityReduction; - private ChanceSettingsImpl chanceSettings; - private boolean allowPlayers; - private boolean allowMobs; + private Modifier durabilityReduction; + private boolean allowPlayers; + private boolean allowMobs; public CutterEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to throw away enemy''s armor and damage it for " + GENERIC_DAMAGE + "%."); - this.setMaxLevel(5); - this.setRarity(Rarity.RARE); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.PLAINS_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to throw away enemy''s armor and damage it for " + GENERIC_DAMAGE + "%.", + EnchantRarity.LEGENDARY, + 5, + ItemCategories.WEAPON + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(1, 0.5, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(1, 0.5, 1, 100))); this.durabilityReduction = Modifier.read(config, "Settings.Item.Durability_Reduction", Modifier.add(0, 0.01, 1, 1D), @@ -68,28 +75,10 @@ public class CutterEnchant extends AbstractEnchantmentData implements ChanceData this.addPlaceholder(GENERIC_DAMAGE, level -> NumberUtil.format(this.getDurabilityReduction(level) * 100D)); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - public final double getDurabilityReduction(int level) { return this.durabilityReduction.getValue(level); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - @NotNull @Override public EventPriority getAttackPriority() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/DecapitatorEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/DecapitatorEnchant.java index 4a4d52e..d185f2c 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/DecapitatorEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/DecapitatorEnchant.java @@ -18,14 +18,15 @@ import org.bukkit.inventory.meta.SkullMeta; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.excellentenchants.hook.HookPlugin; import su.nightexpress.excellentenchants.hook.impl.MythicMobsHook; import su.nightexpress.nightcore.config.ConfigValue; @@ -46,30 +47,36 @@ import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_TYPE; import static su.nightexpress.nightcore.util.text.tag.Tags.LIGHT_YELLOW; -public class DecapitatorEnchant extends AbstractEnchantmentData implements ChanceData, DeathEnchant { +public class DecapitatorEnchant extends GameEnchantment implements ChanceMeta, DeathEnchant { public static final String ID = "decapitator"; - private boolean ignoreMythicMobs; + private boolean ignoreMythicMobs; private Set ignoredEntityTypes; private String headName; private Map headTextures; - private ChanceSettingsImpl chanceSettings; private final NamespacedKey skullKey; public DecapitatorEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to obtain player''s or mob''s head."); - this.setMaxLevel(4); - this.setRarity(Rarity.RARE); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.SAVANNA_COMMON)); this.skullKey = new NamespacedKey(plugin, this.getId() + ".entity_type"); } + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to obtain player's or mob's head.", + EnchantRarity.LEGENDARY, + 4, + ItemCategories.WEAPON + ); + } + @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(5, 1.75, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(5, 1.75, 1, 100))); this.ignoreMythicMobs = ConfigValue.create("Settings.Ignore_Mythic_Mobs", true, @@ -124,7 +131,7 @@ public class DecapitatorEnchant extends AbstractEnchantmentData implements Chanc map.put(EntityType.LLAMA, "9f7d90b305aa64313c8d4404d8d652a96eba8a754b67f4347dcccdd5a6a63398"); map.put(EntityType.MAGMA_CUBE, "38957d5023c937c4c41aa2412d43410bda23cf79a9f6ab36b76fef2d7c429"); map.put(EntityType.MULE, "a0486a742e7dda0bae61ce2f55fa13527f1c3b334c57c034bb4cf132fb5f5f"); - map.put(EntityType.MUSHROOM_COW, "45603d539f666fdf0f7a0fe20b81dfef3abe6c51da34b9525a5348432c5523b2"); + map.put(EntityType.MOOSHROOM, "45603d539f666fdf0f7a0fe20b81dfef3abe6c51da34b9525a5348432c5523b2"); map.put(EntityType.OCELOT, "5657cd5c2989ff97570fec4ddcdc6926a68a3393250c1be1f0b114a1db1"); map.put(EntityType.PANDA, "8018a1771d69c11b8dad42cd310375ba2d827932b25ef357f7e572c1bd0f9"); map.put(EntityType.PARROT, "a4ba8d66fecb1992e94b8687d6ab4a5320ab7594ac194a2615ed4df818edbc3"); @@ -139,7 +146,7 @@ public class DecapitatorEnchant extends AbstractEnchantmentData implements Chanc map.put(EntityType.SHEEP, "a723893df4cfb9c7240fc47b560ccf6ddeb19da9183d33083f2c71f46dad290a"); map.put(EntityType.SILVERFISH, "da91dab8391af5fda54acd2c0b18fbd819b865e1a8f1d623813fa761e924540"); map.put(EntityType.SLIME, "a5acd8b24f7389a40404348f4344eec2235d4ca718453be9803b60b71a125891"); - map.put(EntityType.SNOWMAN, "8e8d206f61e6de8a79d0cb0bcd98aced464cbfefc921b4160a25282163112a"); + map.put(EntityType.SNOW_GOLEM, "8e8d206f61e6de8a79d0cb0bcd98aced464cbfefc921b4160a25282163112a"); map.put(EntityType.SPIDER, "cd541541daaff50896cd258bdbdd4cf80c3ba816735726078bfe393927e57f1"); map.put(EntityType.SQUID, "d8705624daa2956aa45956c81bab5f4fdb2c74a596051e24192039aea3a8b8"); map.put(EntityType.STRAY, "9e391c6e535f7aa5a2b6ee6d137f59f2d7c60def88853ba611ceb2d16a7e7c73"); @@ -166,24 +173,6 @@ public class DecapitatorEnchant extends AbstractEnchantmentData implements Chanc ).read(config); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - @Override public boolean onDeath(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, ItemStack item, int level) { return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/DoubleStrikeEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/DoubleStrikeEnchant.java index 24cd42a..f61c6a1 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/DoubleStrikeEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/DoubleStrikeEnchant.java @@ -9,14 +9,15 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.wrapper.UniParticle; import su.nightexpress.nightcore.util.wrapper.UniSound; @@ -25,42 +26,29 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; -public class DoubleStrikeEnchant extends AbstractEnchantmentData implements ChanceData, CombatEnchant { +public class DoubleStrikeEnchant extends GameEnchantment implements ChanceMeta, CombatEnchant { public static final String ID = "double_strike"; - private ChanceSettingsImpl chanceSettings; - public DoubleStrikeEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to inflict double damage."); - this.setMaxLevel(4); - this.setRarity(Rarity.VERY_RARE); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.SNOW_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to inflict double damage.", + EnchantRarity.MYTHIC, + 4, + ItemCategories.WEAPON + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(2, 0.5, 1, 100D)); + this.meta.setProbability(Probability.create(config, Modifier.add(2, 0.5, 1, 100D))); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - @NotNull @Override public EventPriority getAttackPriority() { @@ -74,7 +62,7 @@ public class DoubleStrikeEnchant extends AbstractEnchantmentData implements Chan event.setDamage(event.getDamage() * 2D); if (this.hasVisualEffects()) { - UniParticle.of(Particle.EXPLOSION_NORMAL).play(victim.getEyeLocation(), 0.25, 0.15, 15); + UniParticle.of(Particle.EXPLOSION).play(victim.getEyeLocation(), 0.25, 0.15, 15); UniSound.of(Sound.ENTITY_GENERIC_EXPLODE).play(victim.getLocation()); } return true; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/ExhaustEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/ExhaustEnchant.java index b8c09c0..b65ce67 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/ExhaustEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/ExhaustEnchant.java @@ -9,17 +9,17 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionData; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionEffects; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.data.PotionSettingsImpl; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.wrapper.UniParticle; @@ -27,54 +27,34 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.*; -public class ExhaustEnchant extends AbstractEnchantmentData implements ChanceData, PotionData, CombatEnchant { +public class ExhaustEnchant extends GameEnchantment implements ChanceMeta, PotionMeta, CombatEnchant { public static final String ID = "exhaust"; - private ChanceSettingsImpl chanceSettings; - private PotionSettingsImpl potionSettings; - public ExhaustEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to apply " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.) on hit."); - this.setMaxLevel(3); - this.setRarity(Rarity.COMMON); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.TAIGA_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to apply " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.) on hit.", + EnchantRarity.COMMON, + 3, + ItemCategories.WEAPON + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(5, 5, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(5, 5, 1, 100))); - this.potionSettings = PotionSettingsImpl.create(this, config, PotionEffectType.HUNGER, false, + this.meta.setPotionEffects(PotionEffects.create(this, config, PotionEffectType.HUNGER, false, Modifier.add(8, 2, 1, 600), Modifier.add(0, 1, 1, 10) - ); + )); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @NotNull - @Override - public PotionSettings getPotionSettings() { - return potionSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - @NotNull @Override public EventPriority getAttackPriority() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/IceAspectEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/IceAspectEnchant.java index 5438e67..458dde8 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/IceAspectEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/IceAspectEnchant.java @@ -11,17 +11,17 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionData; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionEffects; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.data.PotionSettingsImpl; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.wrapper.UniParticle; import su.nightexpress.nightcore.util.wrapper.UniSound; @@ -30,54 +30,34 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.*; -public class IceAspectEnchant extends AbstractEnchantmentData implements ChanceData, PotionData, CombatEnchant { +public class IceAspectEnchant extends GameEnchantment implements ChanceMeta, PotionMeta, CombatEnchant { public static final String ID = "ice_aspect"; - private ChanceSettingsImpl chanceSettings; - private PotionSettingsImpl potionSettings; - public IceAspectEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Freezes and applies " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.) on hit."); - this.setMaxLevel(3); - this.setRarity(Rarity.COMMON); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.SNOW_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Freezes and applies " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.) on hit.", + EnchantRarity.COMMON, + 3, + ItemCategories.WEAPON + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config); + this.meta.setProbability(Probability.create(config)); - this.potionSettings = PotionSettingsImpl.create(this, config, PotionEffectType.SLOW, false, + this.meta.setPotionEffects(PotionEffects.create(this, config, PotionEffectType.SLOWNESS, false, Modifier.add(4, 2, 1, 600), Modifier.add(0, 1, 1, 5) - ); + )); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @NotNull - @Override - public PotionSettings getPotionSettings() { - return potionSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - @NotNull @Override public EventPriority getAttackPriority() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/InfernusEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/InfernusEnchant.java index 9b5af1a..8a5d012 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/InfernusEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/InfernusEnchant.java @@ -11,12 +11,14 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; import su.nightexpress.excellentenchants.api.enchantment.type.GenericEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.util.EnchantUtils; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.manager.SimpeListener; import su.nightexpress.nightcore.util.NumberUtil; @@ -25,17 +27,24 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_TIME; -public class InfernusEnchant extends AbstractEnchantmentData implements GenericEnchant, SimpeListener { +public class InfernusEnchant extends GameEnchantment implements GenericEnchant, SimpeListener { public static final String ID = "infernus"; private Modifier fireTicks; public InfernusEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Launched trident will ignite the enemy for " + GENERIC_TIME + "s. on hit."); - this.setMaxLevel(3); - this.setRarity(Rarity.COMMON); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.DESERT_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Launched trident will ignite the enemy for " + GENERIC_TIME + "s. on hit.", + EnchantRarity.COMMON, + 3, + ItemCategories.TRIDENT + ); } @Override @@ -51,18 +60,6 @@ public class InfernusEnchant extends AbstractEnchantmentData implements GenericE return (int) this.fireTicks.getValue(level); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.TRIDENT; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.TRIDENT; -// } - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onInfernusTridentLaunch(ProjectileLaunchEvent event) { Entity entity = event.getEntity(); @@ -72,7 +69,7 @@ public class InfernusEnchant extends AbstractEnchantmentData implements GenericE ItemStack item = trident.getItem(); - int level = EnchantUtils.getLevel(item, this.getEnchantment()); + int level = EnchantUtils.getLevel(item, this.getBukkitEnchantment()); if (level <= 0) return; trident.setFireTicks(Integer.MAX_VALUE); @@ -85,7 +82,7 @@ public class InfernusEnchant extends AbstractEnchantmentData implements GenericE ItemStack item = trident.getItem(); - int level = EnchantUtils.getLevel(item, this.getEnchantment()); + int level = EnchantUtils.getLevel(item, this.getBukkitEnchantment()); if (level <= 0 || trident.getFireTicks() <= 0) return; int ticks = this.getFireTicks(level); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/NimbleEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/NimbleEnchant.java index 5b517fd..a161c60 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/NimbleEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/NimbleEnchant.java @@ -8,55 +8,43 @@ import org.bukkit.event.entity.EntityResurrectEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.Players; import java.io.File; -public class NimbleEnchant extends AbstractEnchantmentData implements ChanceData, DeathEnchant { +public class NimbleEnchant extends GameEnchantment implements ChanceMeta, DeathEnchant { public static final String ID = "nimble"; - private ChanceSettingsImpl chanceSettings; - public NimbleEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Moves all mob's loot directly to your inventory."); - this.setMaxLevel(1); - this.setRarity(Rarity.UNCOMMON); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.SWAMP_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Moves all mob's loot directly to your inventory.", + EnchantRarity.RARE, + 1, + ItemCategories.WEAPON + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config); + this.meta.setProbability(Probability.create(config)); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } -// -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - @NotNull @Override public EventPriority getKillPriority() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/ParalyzeEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/ParalyzeEnchant.java index 15e037c..dca9e00 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/ParalyzeEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/ParalyzeEnchant.java @@ -9,17 +9,17 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionData; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionEffects; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.data.PotionSettingsImpl; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.wrapper.UniParticle; @@ -27,54 +27,34 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.*; -public class ParalyzeEnchant extends AbstractEnchantmentData implements ChanceData, PotionData, CombatEnchant { +public class ParalyzeEnchant extends GameEnchantment implements ChanceMeta, PotionMeta, CombatEnchant { public static final String ID = "paralyze"; - private ChanceSettingsImpl chanceSettings; - private PotionSettingsImpl potionSettings; - public ParalyzeEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to apply " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.) on hit."); - this.setMaxLevel(3); - this.setRarity(Rarity.UNCOMMON); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.JUNGLE_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to apply " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.) on hit.", + EnchantRarity.RARE, + 3, + ItemCategories.WEAPON + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(2, 3, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(2, 3, 1, 100))); - this.potionSettings = PotionSettingsImpl.create(this, config, PotionEffectType.SLOW_DIGGING, false, + this.meta.setPotionEffects(PotionEffects.create(this, config, PotionEffectType.MINING_FATIGUE, false, Modifier.add(3.5, 0.5, 1, 60), Modifier.add(0, 1, 1, 5) - ); + )); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @NotNull - @Override - public PotionSettings getPotionSettings() { - return potionSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - @NotNull @Override public EventPriority getAttackPriority() { @@ -87,7 +67,7 @@ public class ParalyzeEnchant extends AbstractEnchantmentData implements ChanceDa if (!this.addEffect(victim, level)) return false; if (this.hasVisualEffects()) { - UniParticle.of(Particle.CRIT_MAGIC).play(victim.getEyeLocation(), 0.25, 0.1, 30); + UniParticle.of(Particle.ENCHANTED_HIT).play(victim.getEyeLocation(), 0.25, 0.1, 30); } return true; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/RageEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/RageEnchant.java index c48935d..bc2aa36 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/RageEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/RageEnchant.java @@ -9,17 +9,17 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionData; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionEffects; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.data.PotionSettingsImpl; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.wrapper.UniParticle; @@ -27,54 +27,34 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.*; -public class RageEnchant extends AbstractEnchantmentData implements ChanceData, PotionData, CombatEnchant { +public class RageEnchant extends GameEnchantment implements ChanceMeta, PotionMeta, CombatEnchant { public static final String ID = "rage"; - private ChanceSettingsImpl chanceSettings; - private PotionSettingsImpl potionSettings; - public RageEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to get " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.) on hit."); - this.setMaxLevel(3); - this.setRarity(Rarity.RARE); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.SWAMP_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to get " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.) on hit.", + EnchantRarity.LEGENDARY, + 3, + ItemCategories.WEAPON + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(4, 2, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(4, 2, 1, 100))); - this.potionSettings = PotionSettingsImpl.create(this, config, PotionEffectType.INCREASE_DAMAGE, false, + this.meta.setPotionEffects(PotionEffects.create(this, config, PotionEffectType.STRENGTH, false, Modifier.add(3, 1, 1, 300), Modifier.add(0, 1, 1, 5) - ); + )); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @NotNull - @Override - public PotionSettings getPotionSettings() { - return potionSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - @NotNull @Override public EventPriority getAttackPriority() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/RocketEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/RocketEnchant.java index e1f3f61..0aca7af 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/RocketEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/RocketEnchant.java @@ -11,14 +11,15 @@ import org.bukkit.inventory.meta.FireworkMeta; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.random.Rnd; import su.nightexpress.nightcore.util.wrapper.UniSound; @@ -27,51 +28,39 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; -public class RocketEnchant extends AbstractEnchantmentData implements ChanceData, CombatEnchant { +public class RocketEnchant extends GameEnchantment implements ChanceMeta, CombatEnchant { public static final String ID = "rocket"; - private Modifier fireworkPower; - private ChanceSettingsImpl chanceSettings; + private Modifier fireworkPower; public RocketEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to launch your enemy into the space."); - this.setMaxLevel(3); - this.setRarity(Rarity.RARE); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.PLAINS_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to launch your enemy into the space.", + EnchantRarity.LEGENDARY, + 3, + ItemCategories.WEAPON + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.multiply(2, 1, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.multiply(2, 1, 1, 100))); this.fireworkPower = Modifier.read(config, "Settings.Firework_Power", Modifier.multiply(1, 0.25, 1, 3), "Firework power. The more power = the higher fly distance."); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - public final double getFireworkPower(int level) { return this.fireworkPower.getValue(level); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - @NotNull @Override public EventPriority getAttackPriority() { @@ -95,7 +84,7 @@ public class RocketEnchant extends AbstractEnchantmentData implements ChanceData @NotNull private Firework createRocket(@NotNull World world, @NotNull Location location, int level) { - Firework firework = (Firework) world.spawnEntity(location, EntityType.FIREWORK); + Firework firework = (Firework) world.spawnEntity(location, EntityType.FIREWORK_ROCKET); FireworkMeta meta = firework.getFireworkMeta(); FireworkEffect.Type type = Rnd.get(FireworkEffect.Type.values()); Color color = Color.fromBGR(Rnd.nextInt(255), Rnd.nextInt(255), Rnd.nextInt(255)); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/ScavengerEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/ScavengerEnchant.java index 46bc9a3..fd33990 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/ScavengerEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/ScavengerEnchant.java @@ -13,15 +13,16 @@ import org.bukkit.loot.LootTables; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.util.EnchantUtils; import su.nightexpress.nightcore.config.ConfigValue; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.StringUtil; @@ -35,7 +36,7 @@ import java.util.Set; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; -public class ScavengerEnchant extends AbstractEnchantmentData implements ChanceData, DeathEnchant { +public class ScavengerEnchant extends GameEnchantment implements ChanceMeta, DeathEnchant { public static final String ID = "scavenger"; @@ -43,22 +44,27 @@ public class ScavengerEnchant extends AbstractEnchantmentData implements ChanceD private final Set ignoredEntities; private final Set lootTables; - private ChanceSettingsImpl chanceSettings; - public ScavengerEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to get additional loot from mobs."); - this.setMaxLevel(4); - this.setRarity(Rarity.RARE); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.JUNGLE_COMMON)); this.ignoredSpawnReasons = new HashSet<>(); this.ignoredEntities = new HashSet<>(); this.lootTables = new HashSet<>(); } + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to get additional loot from mobs.", + EnchantRarity.LEGENDARY, + 4, + ItemCategories.WEAPON + ); + } + @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(1, 0.5, 1)); + this.meta.setProbability(Probability.create(config, Modifier.add(1, 0.5, 1))); this.ignoredSpawnReasons.addAll(ConfigValue.forSet("Settings.Ignored_SpawnReasons", id -> StringUtil.getEnum(id, CreatureSpawnEvent.SpawnReason.class).orElse(null), @@ -115,24 +121,6 @@ public class ScavengerEnchant extends AbstractEnchantmentData implements ChanceD this.lootTables.clear(); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - @Override public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, @NotNull ItemStack weapon, int level) { if (this.lootTables.isEmpty()) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/SurpriseEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/SurpriseEnchant.java index 871dda5..a103692 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/SurpriseEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/SurpriseEnchant.java @@ -12,20 +12,19 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionData; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionEffects; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.data.PotionSettingsImpl; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.BukkitThing; -import su.nightexpress.nightcore.util.Version; import su.nightexpress.nightcore.util.random.Rnd; import su.nightexpress.nightcore.util.wrapper.UniParticle; @@ -33,63 +32,34 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; -public class SurpriseEnchant extends AbstractEnchantmentData implements ChanceData, PotionData, CombatEnchant { +public class SurpriseEnchant extends GameEnchantment implements ChanceMeta, PotionMeta, CombatEnchant { public static final String ID = "surprise"; - private ChanceSettingsImpl chanceSettings; - private PotionSettingsImpl potionSettings; - public SurpriseEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to apply random potion effect to enemy on hit."); - this.setMaxLevel(3); - this.setRarity(Rarity.RARE); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.TAIGA_COMMON)); } - @Override - public boolean checkServerRequirements() { - if (Version.isBehind(Version.V1_20_R2)) { - this.error("Enchantment is available for 1.20.2+ only."); - return false; - } - return true; + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to apply random potion effect to enemy on hit.", + EnchantRarity.RARE, + 3, + ItemCategories.WEAPON + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(3, 2, 1)); + this.meta.setProbability(Probability.create(config, Modifier.add(3, 2, 1))); - this.potionSettings = PotionSettingsImpl.create(this, config, PotionEffectType.BLINDNESS, false, + this.meta.setPotionEffects(PotionEffects.create(this, config, PotionEffectType.BLINDNESS, false, Modifier.add(4, 1, 1, 900), Modifier.add(0, 1, 1, 10) - ); + )); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @NotNull - @Override - public PotionSettings getPotionSettings() { - return potionSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - @NotNull @Override public EventPriority getAttackPriority() { @@ -106,7 +76,7 @@ public class SurpriseEnchant extends AbstractEnchantmentData implements ChanceDa if (this.hasVisualEffects()) { Color color = Color.fromRGB(Rnd.nextInt(256), Rnd.nextInt(256), Rnd.nextInt(256)); Particle.DustOptions dustOptions = new Particle.DustOptions(color, 2f); - UniParticle.of(Particle.REDSTONE, dustOptions).play(victim.getEyeLocation(), 0.25, 0.1, 25); + UniParticle.of(Particle.DUST, dustOptions).play(victim.getEyeLocation(), 0.25, 0.1, 25); } return true; } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/SwiperEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/SwiperEnchant.java index 77c8656..0638ddc 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/SwiperEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/SwiperEnchant.java @@ -7,14 +7,15 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.NumberUtil; @@ -22,25 +23,31 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; -public class SwiperEnchant extends AbstractEnchantmentData implements CombatEnchant, ChanceData { +public class SwiperEnchant extends GameEnchantment implements CombatEnchant, ChanceMeta { public static final String ID = "swiper"; public static final String PLACEHOLER_XP_AMOUNT = "%xp_amount%"; - private ChanceSettingsImpl chanceSettings; - private Modifier xpAmount; + private Modifier xpAmount; public SwiperEnchant(@NotNull EnchantsPlugin plugin, File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to steal " + PLACEHOLER_XP_AMOUNT + " XP from players."); - this.setMaxLevel(3); - this.setRarity(Rarity.RARE); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.JUNGLE_SPECIAL)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to steal " + PLACEHOLER_XP_AMOUNT + " XP from players.", + EnchantRarity.LEGENDARY, + 3, + ItemCategories.WEAPON + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(5, 2.5, 1)); + this.meta.setProbability(Probability.create(config, Modifier.add(5, 2.5, 1))); this.xpAmount = Modifier.read(config, "Settings.XP_Amount", Modifier.add(0, 1, 1), @@ -49,24 +56,6 @@ public class SwiperEnchant extends AbstractEnchantmentData implements CombatEnch this.addPlaceholder(PLACEHOLER_XP_AMOUNT, level -> NumberUtil.format(this.getXPAmount(level))); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return this.chanceSettings; - } - public int getXPAmount(int level) { return (int) this.xpAmount.getValue(level); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/TemperEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/TemperEnchant.java index 3773ad8..383a540 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/TemperEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/TemperEnchant.java @@ -7,11 +7,13 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.EntityUtil; import su.nightexpress.nightcore.util.NumberUtil; @@ -21,7 +23,7 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_AMOUNT; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_RADIUS; -public class TemperEnchant extends AbstractEnchantmentData implements CombatEnchant { +public class TemperEnchant extends GameEnchantment implements CombatEnchant { public static final String ID = "temper"; @@ -29,10 +31,17 @@ public class TemperEnchant extends AbstractEnchantmentData implements CombatEnch private Modifier damageStep; public TemperEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription("Inflicts " + GENERIC_AMOUNT + "% more damage for each " + GENERIC_RADIUS + "❤ missing."); - this.setMaxLevel(5); - this.setRarity(Rarity.UNCOMMON); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.SNOW_SPECIAL)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Inflicts " + GENERIC_AMOUNT + "% more damage for each " + GENERIC_RADIUS + "❤ missing.", + EnchantRarity.MYTHIC, + 5, + ItemCategories.WEAPON + ); } @Override @@ -59,18 +68,6 @@ public class TemperEnchant extends AbstractEnchantmentData implements CombatEnch return this.damageStep.getValue(level); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } -// -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - @Override public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { double health = damager.getHealth(); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/ThriftyEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/ThriftyEnchant.java index 63df3dc..df05417 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/ThriftyEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/ThriftyEnchant.java @@ -10,15 +10,16 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.util.EnchantUtils; import su.nightexpress.excellentenchants.hook.HookPlugin; import su.nightexpress.excellentenchants.hook.impl.MythicMobsHook; import su.nightexpress.nightcore.config.ConfigValue; @@ -34,7 +35,7 @@ import java.util.Set; import static org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; -public class ThriftyEnchant extends AbstractEnchantmentData implements ChanceData, DeathEnchant { +public class ThriftyEnchant extends GameEnchantment implements ChanceMeta, DeathEnchant { public static final String ID = "thrifty"; @@ -42,13 +43,18 @@ public class ThriftyEnchant extends AbstractEnchantmentData implements ChanceDat private Set ignoredSpawnReasons; private boolean ignoreMythicMobs; - private ChanceSettingsImpl chanceSettings; - public ThriftyEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance for mobs to drop spawn egg."); - this.setMaxLevel(3); - this.setRarity(Rarity.RARE); + super(plugin, file, definition(), EnchantDistribution.treasure(TradeType.SWAMP_SPECIAL)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance for mobs to drop spawn egg.", + EnchantRarity.LEGENDARY, + 3, + ItemCategories.WEAPON + ); } @Override @@ -62,7 +68,7 @@ public class ThriftyEnchant extends AbstractEnchantmentData implements ChanceDat @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(1, 1, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(1, 1, 1, 100))); this.ignoredEntityTypes = ConfigValue.forSet("Settings.Ignored_Mobs", BukkitThing::getEntityType, @@ -89,24 +95,6 @@ public class ThriftyEnchant extends AbstractEnchantmentData implements ChanceDat ).read(config); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - @Override public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, ItemStack weapon, int level) { if (this.ignoredEntityTypes.contains(entity.getType())) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/ThunderEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/ThunderEnchant.java index d5d546d..2aef07e 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/ThunderEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/ThunderEnchant.java @@ -10,14 +10,15 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.ConfigValue; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.LocationUtil; @@ -29,24 +30,30 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_DAMAGE; -public class ThunderEnchant extends AbstractEnchantmentData implements ChanceData, CombatEnchant { +public class ThunderEnchant extends GameEnchantment implements ChanceMeta, CombatEnchant { public static final String ID = "thunder"; - private boolean thunderstormOnly; - private ChanceSettingsImpl chanceSettings; - private Modifier damageModifier; + private boolean thunderstormOnly; + private Modifier damageModifier; public ThunderEnchant(@NotNull EnchantsPlugin plugin, File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to strike lightning with " + GENERIC_DAMAGE + "❤ extra damage."); - this.setMaxLevel(5); - this.setRarity(Rarity.UNCOMMON); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.TAIGA_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to strike lightning with " + GENERIC_DAMAGE + "❤ extra damage.", + EnchantRarity.RARE, + 5, + ItemCategories.WEAPON + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(5, 2, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(5, 2, 1, 100))); this.thunderstormOnly = ConfigValue.create("Settings.During_Thunderstorm_Only", false, @@ -61,12 +68,6 @@ public class ThunderEnchant extends AbstractEnchantmentData implements ChanceDat this.addPlaceholder(GENERIC_DAMAGE, level -> NumberUtil.format(this.getDamage(level))); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - public boolean isDuringThunderstormOnly() { return thunderstormOnly; } @@ -75,18 +76,6 @@ public class ThunderEnchant extends AbstractEnchantmentData implements ChanceDat return this.damageModifier.getValue(level); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - @Override public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { if (this.isDuringThunderstormOnly() && !victim.getWorld().isThundering()) return false; @@ -100,7 +89,7 @@ public class ThunderEnchant extends AbstractEnchantmentData implements ChanceDat Block block = location.getBlock().getRelative(BlockFace.DOWN); Location center = LocationUtil.getCenter(location); UniParticle.blockCrack(block.getType()).play(center, 0.5, 0.1, 100); - UniParticle.of(Particle.FIREWORKS_SPARK).play(center, 0.75, 0.05, 120); + UniParticle.of(Particle.ELECTRIC_SPARK).play(center, 0.75, 0.05, 120); } event.setDamage(event.getDamage() + this.getDamage(level)); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/VampireEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/VampireEnchant.java index 2b10f68..587ddfc 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/VampireEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/VampireEnchant.java @@ -10,14 +10,15 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.ConfigValue; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.EntityUtil; @@ -29,24 +30,30 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.ENCHANTMENT_CHANCE; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_AMOUNT; -public class VampireEnchant extends AbstractEnchantmentData implements ChanceData, CombatEnchant { +public class VampireEnchant extends GameEnchantment implements ChanceMeta, CombatEnchant { public static final String ID = "vampire"; - private Modifier healAmount; - private boolean healMultiplier; - private ChanceSettingsImpl chanceSettings; + private Modifier healAmount; + private boolean healMultiplier; public VampireEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to heal for " + GENERIC_AMOUNT + "❤ on hit."); - this.setMaxLevel(4); - this.setRarity(Rarity.RARE); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.PLAINS_SPECIAL)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to heal for " + GENERIC_AMOUNT + "❤ on hit.", + EnchantRarity.LEGENDARY, + 4, + ItemCategories.WEAPON + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(5, 2.5, 1)); + this.meta.setProbability(Probability.create(config, Modifier.add(5, 2.5, 1))); this.healAmount = Modifier.read(config, "Settings.Heal.Amount", Modifier.add(0, 0.25, 1, 100), @@ -60,12 +67,6 @@ public class VampireEnchant extends AbstractEnchantmentData implements ChanceDat this.addPlaceholder(GENERIC_AMOUNT, level -> NumberUtil.format(this.isHealMultiplier() ? getHealAmount(level) * 100D : getHealAmount(level))); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - public double getHealAmount(int level) { return this.healAmount.getValue(level); } @@ -74,18 +75,6 @@ public class VampireEnchant extends AbstractEnchantmentData implements ChanceDat return healMultiplier; } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - @NotNull @Override public EventPriority getAttackPriority() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/VenomEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/VenomEnchant.java index e899ff7..27d0812 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/VenomEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/VenomEnchant.java @@ -9,17 +9,17 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionData; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionEffects; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.data.PotionSettingsImpl; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.wrapper.UniParticle; @@ -27,54 +27,34 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.*; -public class VenomEnchant extends AbstractEnchantmentData implements ChanceData, PotionData, CombatEnchant { +public class VenomEnchant extends GameEnchantment implements ChanceMeta, PotionMeta, CombatEnchant { public static final String ID = "venom"; - private ChanceSettingsImpl chanceSettings; - private PotionSettingsImpl potionSettings; - public VenomEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to apply " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.) on hit."); - this.setMaxLevel(3); - this.setRarity(Rarity.UNCOMMON); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.SWAMP_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to apply " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.) on hit.", + EnchantRarity.RARE, + 3, + ItemCategories.WEAPON + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(5, 5, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(5, 5, 1, 100))); - this.potionSettings = PotionSettingsImpl.create(this, config, PotionEffectType.POISON, false, + this.meta.setPotionEffects(PotionEffects.create(this, config, PotionEffectType.POISON, false, Modifier.add(3, 1, 1, 300), Modifier.add(0, 1, 1, 10) - ); + )); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @NotNull - @Override - public PotionSettings getPotionSettings() { - return potionSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - @NotNull @Override public EventPriority getAttackPriority() { @@ -87,7 +67,7 @@ public class VenomEnchant extends AbstractEnchantmentData implements ChanceData, if (!this.addEffect(victim, level)) return false; if (this.hasVisualEffects()) { - UniParticle.of(Particle.SLIME).play(victim.getEyeLocation(), 0.25, 0.1, 30); + UniParticle.of(Particle.ITEM_SLIME).play(victim.getEyeLocation(), 0.25, 0.1, 30); } return true; } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/VillageDefenderEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/VillageDefenderEnchant.java index 35660d4..f9730e0 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/VillageDefenderEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/VillageDefenderEnchant.java @@ -8,11 +8,13 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.ConfigValue; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.NumberUtil; @@ -22,7 +24,7 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_AMOUNT; -public class VillageDefenderEnchant extends AbstractEnchantmentData implements CombatEnchant { +public class VillageDefenderEnchant extends GameEnchantment implements CombatEnchant { public static final String ID = "village_defender"; @@ -30,10 +32,17 @@ public class VillageDefenderEnchant extends AbstractEnchantmentData implements C private Modifier damageAmount; public VillageDefenderEnchant(@NotNull EnchantsPlugin plugin, File file) { - super(plugin, file); - this.setDescription("Inflicts " + GENERIC_AMOUNT + "❤ more damage to all pillagers."); - this.setMaxLevel(5); - this.setRarity(Rarity.COMMON); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.SAVANNA_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Inflicts " + GENERIC_AMOUNT + "❤ more damage to all pillagers.", + EnchantRarity.COMMON, + 5, + ItemCategories.WEAPON + ); } @Override @@ -58,18 +67,6 @@ public class VillageDefenderEnchant extends AbstractEnchantmentData implements C return damageMultiplier; } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - @Override public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { if (!(victim instanceof Illager)) return false; @@ -81,7 +78,7 @@ public class VillageDefenderEnchant extends AbstractEnchantmentData implements C event.setDamage(damageFinal); if (this.hasVisualEffects()) { - UniParticle.of(Particle.VILLAGER_ANGRY).play(victim.getEyeLocation(), 0.25, 0.1, 30); + UniParticle.of(Particle.ANGRY_VILLAGER).play(victim.getEyeLocation(), 0.25, 0.1, 30); } return true; } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/WisdomEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/WisdomEnchant.java index 5e9c183..35acc8b 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/WisdomEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/WisdomEnchant.java @@ -8,11 +8,13 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; +import su.nightexpress.excellentenchants.util.ItemCategories; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.NumberUtil; @@ -21,17 +23,24 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_AMOUNT; import static su.nightexpress.excellentenchants.Placeholders.GENERIC_MODIFIER; -public class WisdomEnchant extends AbstractEnchantmentData implements DeathEnchant { +public class WisdomEnchant extends GameEnchantment implements DeathEnchant { public static final String ID = "exp_hunter"; private Modifier xpModifier; public WisdomEnchant(@NotNull EnchantsPlugin plugin, File file) { - super(plugin, file); - this.setDescription("Mobs drops x" + GENERIC_MODIFIER + " more XP."); - this.setMaxLevel(5); - this.setRarity(Rarity.UNCOMMON); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.JUNGLE_SPECIAL)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + "Mobs drops x" + GENERIC_MODIFIER + " more XP.", + EnchantRarity.RARE, + 5, + ItemCategories.WEAPON + ); } @Override @@ -48,18 +57,6 @@ public class WisdomEnchant extends AbstractEnchantmentData implements DeathEncha return this.xpModifier.getValue(level); } - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } - -// @Override -// @NotNull -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - @Override public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, ItemStack weapon, int level) { double xpModifier = this.getXPModifier(level); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/WitherEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/WitherEnchant.java index 3b71280..82025eb 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/WitherEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/WitherEnchant.java @@ -9,17 +9,17 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.api.Modifier; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData; -import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionData; -import su.nightexpress.excellentenchants.api.enchantment.data.PotionSettings; +import su.nightexpress.excellentenchants.api.enchantment.TradeType; +import su.nightexpress.excellentenchants.api.enchantment.meta.ChanceMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionMeta; +import su.nightexpress.excellentenchants.api.enchantment.meta.Probability; +import su.nightexpress.excellentenchants.api.enchantment.meta.PotionEffects; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; -import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl; -import su.nightexpress.excellentenchants.enchantment.data.ItemCategories; -import su.nightexpress.excellentenchants.enchantment.data.PotionSettingsImpl; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDefinition; +import su.nightexpress.excellentenchants.enchantment.impl.EnchantDistribution; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.util.ItemCategories; +import su.nightexpress.excellentenchants.rarity.EnchantRarity; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.util.wrapper.UniParticle; @@ -27,54 +27,34 @@ import java.io.File; import static su.nightexpress.excellentenchants.Placeholders.*; -public class WitherEnchant extends AbstractEnchantmentData implements ChanceData, PotionData, CombatEnchant { +public class WitherEnchant extends GameEnchantment implements ChanceMeta, PotionMeta, CombatEnchant { public static final String ID = "wither"; - private ChanceSettingsImpl chanceSettings; - private PotionSettingsImpl potionSettings; - public WitherEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { - super(plugin, file); - this.setDescription(ENCHANTMENT_CHANCE + "% chance to apply " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.) on hit."); - this.setMaxLevel(3); - this.setRarity(Rarity.UNCOMMON); + super(plugin, file, definition(), EnchantDistribution.regular(TradeType.SNOW_COMMON)); + } + + @NotNull + private static EnchantDefinition definition() { + return EnchantDefinition.create( + ENCHANTMENT_CHANCE + "% chance to apply " + ENCHANTMENT_POTION_TYPE + " " + ENCHANTMENT_POTION_LEVEL + " (" + ENCHANTMENT_POTION_DURATION + "s.) on hit.", + EnchantRarity.RARE, + 3, + ItemCategories.WEAPON + ); } @Override protected void loadAdditional(@NotNull FileConfig config) { - this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(3, 3, 1, 100)); + this.meta.setProbability(Probability.create(config, Modifier.add(3, 3, 1, 100))); - this.potionSettings = PotionSettingsImpl.create(this, config, PotionEffectType.WITHER, false, + this.meta.setPotionEffects(PotionEffects.create(this, config, PotionEffectType.WITHER, false, Modifier.add(4, 1, 1, 300), Modifier.add(0, 1, 1, 5) - ); + )); } - @NotNull - @Override - public ChanceSettings getChanceSettings() { - return chanceSettings; - } - - @NotNull - @Override - public PotionSettings getPotionSettings() { - return potionSettings; - } - - @Override - @NotNull - public ItemsCategory getSupportedItems() { - return ItemCategories.WEAPON; - } - -// @NotNull -// @Override -// public EnchantmentTarget getCategory() { -// return EnchantmentTarget.WEAPON; -// } - @NotNull @Override public EventPriority getAttackPriority() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantAnvilListener.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/AnvilListener.java similarity index 87% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantAnvilListener.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/AnvilListener.java index a6606b1..e6920fa 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantAnvilListener.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/AnvilListener.java @@ -10,12 +10,13 @@ import org.bukkit.event.inventory.PrepareAnvilEvent; import org.bukkit.inventory.AnvilInventory; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.view.AnvilView; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; import su.nightexpress.excellentenchants.config.Config; import su.nightexpress.excellentenchants.config.Keys; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; +import su.nightexpress.excellentenchants.util.EnchantUtils; import su.nightexpress.nightcore.manager.AbstractListener; import su.nightexpress.nightcore.util.PDCUtil; import su.nightexpress.nightcore.util.wrapper.UniSound; @@ -23,9 +24,9 @@ import su.nightexpress.nightcore.util.wrapper.UniSound; import java.util.HashMap; import java.util.Map; -public class EnchantAnvilListener extends AbstractListener { +public class AnvilListener extends AbstractListener { - public EnchantAnvilListener(@NotNull EnchantsPlugin plugin) { + public AnvilListener(@NotNull EnchantsPlugin plugin) { super(plugin); } @@ -47,14 +48,6 @@ public class EnchantAnvilListener extends AbstractListener { if (this.handleRecharge(event, first, second)) return; this.handleCombine(event, first, second, result); - - /*this.plugin.runTask(task -> { - ItemStack updated = event.getResult(); - if (updated == null || updated.getType().isAir()) return; - - EnchantUtils.updateDisplay(updated); - inventory.setItem(2, updated); - });*/ } /*private boolean handleRename(@NotNull PrepareAnvilEvent event, @NotNull ItemStack first, @NotNull ItemStack second, @NotNull ItemStack result) { @@ -69,12 +62,14 @@ public class EnchantAnvilListener extends AbstractListener { return true; }*/ + @SuppressWarnings("UnstableApiUsage") private boolean handleRecharge(@NotNull PrepareAnvilEvent event, @NotNull ItemStack first, @NotNull ItemStack second) { + if (!Config.isChargesEnabled()) return false; if (second.getType().isAir()) return false; - Map chargable = new HashMap<>(); + Map chargable = new HashMap<>(); EnchantUtils.getCustomEnchantments(first).forEach((data, level) -> { - if (data.isChargesEnabled() && data.isChargesFuel(second) && !data.isFullOfCharges(first)) { + if (data.isChargesFuel(second) && !data.isFullOfCharges(first)) { chargable.put(data, level); } }); @@ -90,7 +85,7 @@ public class EnchantAnvilListener extends AbstractListener { //EnchantUtils.updateDisplay(recharged); event.setResult(recharged); - this.plugin.runTask(task -> event.getInventory().setRepairCost(chargable.size())); + this.plugin.runTask(task -> event.getView().setRepairCost(chargable.size())); return true; } @@ -109,10 +104,8 @@ public class EnchantAnvilListener extends AbstractListener { return false; } - Map chargesMap = new HashMap<>(); + Map chargesMap = new HashMap<>(); EnchantUtils.getCustomEnchantments(result).forEach((data, level) -> { - if (!data.isChargesEnabled()) return; - int chargesFirst = data.getCharges(first); int chargesSecond = data.getCharges(second); @@ -161,10 +154,12 @@ public class EnchantAnvilListener extends AbstractListener { return true;*/ } + @SuppressWarnings("UnstableApiUsage") @EventHandler(priority = EventPriority.NORMAL) public void onClickAnvil(InventoryClickEvent event) { Inventory inventory = event.getInventory(); if (!(inventory instanceof AnvilInventory anvilInventory)) return; + if (!(event.getView() instanceof AnvilView anvilView)) return; if (event.getRawSlot() != 2) return; ItemStack item = event.getCurrentItem(); @@ -174,9 +169,9 @@ public class EnchantAnvilListener extends AbstractListener { if (count == 0) return; Player player = (Player) event.getWhoClicked(); - if (player.getLevel() < anvilInventory.getRepairCost()) return; + if (player.getLevel() < anvilView.getRepairCost()) return; - player.setLevel(player.getLevel() - anvilInventory.getRepairCost()); + player.setLevel(player.getLevel() - anvilView.getRepairCost()); PDCUtil.remove(item, Keys.itemRecharged); event.getView().setCursor(item); event.setCancelled(false); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantGenericListener.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantGenericListener.java deleted file mode 100644 index ec8d192..0000000 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantGenericListener.java +++ /dev/null @@ -1,169 +0,0 @@ -package su.nightexpress.excellentenchants.enchantment.listener; - -import org.bukkit.GameMode; -import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.enchantment.EnchantItemEvent; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.bukkit.event.entity.EntityShootBowEvent; -import org.bukkit.event.entity.ProjectileHitEvent; -import org.bukkit.event.player.PlayerGameModeChangeEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; -import su.nightexpress.excellentenchants.enchantment.EnchantManager; -import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; -import su.nightexpress.nightcore.manager.AbstractListener; - -public class EnchantGenericListener extends AbstractListener { - - //private final EnchantManager enchantManager; - - public EnchantGenericListener(@NotNull EnchantsPlugin plugin, @NotNull EnchantManager enchantManager) { - super(plugin); - //this.enchantManager = enchantManager; - } - - @SuppressWarnings("UnstableApiUsage") - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onDisplayGameMode(PlayerGameModeChangeEvent event) { - Player player = event.getPlayer(); - GameMode current = player.getGameMode(); - GameMode changed = event.getNewGameMode(); - - // When enter Creative gamemode, force update all inventory to flush item's lore so they don't have enchant descriptions. - if (changed == GameMode.CREATIVE) { - EnchantUtils.doIgnoreDisplayUpdate(player, player::updateInventory); - } - else if (current == GameMode.CREATIVE) { - this.plugin.runTask(task -> player.updateInventory()); - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onDisplayQuit(PlayerQuitEvent event) { - EnchantUtils.removeIgnoreDisplayUpdate(event.getPlayer()); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onCreatureSpawn(CreatureSpawnEvent event) { - EnchantUtils.setSpawnReason(event.getEntity(), event.getSpawnReason()); - } - - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void onEnchantedProjectileShoot(EntityShootBowEvent event) { - if (event.getProjectile() instanceof Projectile projectile) { - EnchantUtils.addEnchantedProjectile(projectile, event.getBow()); - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onEnchantedProjectileLand(ProjectileHitEvent event) { - this.plugin.runTask(task -> { - EnchantUtils.removeEnchantedProjectile(event.getEntity()); - }); - } - - /*@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEnchantDisplayUpdateGrindstoneClick(InventoryClickEvent event) { - Inventory inventory = event.getInventory(); - if (inventory.getType() != InventoryType.GRINDSTONE) return; - if (event.getRawSlot() == 2) return; - - this.updateGrindstone(inventory); - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEnchantDisplayUpdateGrindstoneDrag(InventoryDragEvent event) { - Inventory inventory = event.getInventory(); - if (inventory.getType() != InventoryType.GRINDSTONE) return; - - this.updateGrindstone(inventory); - } - - private void updateGrindstone(@NotNull Inventory inventory) { - this.plugin.runTask(task -> { - ItemStack result = inventory.getItem(2); - if (result == null || result.getType().isAir()) return; - - EnchantUtils.updateDisplay(result); - }); - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEnchantDisplayUpdatePickup(EntityPickupItemEvent event) { - if (!(event.getEntity() instanceof Player)) return; - - Item item = event.getItem(); - ItemStack itemStack = item.getItemStack(); - if (EnchantUtils.updateDisplay(itemStack)) { - item.setItemStack(itemStack); - } - }*/ - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEnchantDisplayUpdateEnchanting(EnchantItemEvent event) { - this.plugin.runTask(task -> { - Inventory inventory = event.getInventory(); - - ItemStack result = inventory.getItem(0); - if (result == null) return; - - event.getEnchantsToAdd().forEach((enchantment, level) -> { - EnchantmentData enchant = EnchantRegistry.getByKey(enchantment.getKey()); - if (enchant != null) { - enchant.restoreCharges(result, level); - } - }); - //EnchantUtils.updateDisplay(result); - - inventory.setItem(0, result); - }); - } - - /*@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onEnchantDisplayUpdateVillagerAcquire(VillagerAcquireTradeEvent event) { - if (Config.isCustomDistribution()) return; - - MerchantRecipe origin = event.getRecipe(); - ItemStack result = origin.getResult(); - if (!EnchantUtils.isEnchantable(result)) return; - - int uses = origin.getUses(); - int maxUses = origin.getMaxUses(); - boolean expReward = origin.hasExperienceReward(); - int villagerExperience = origin.getVillagerExperience(); - float priceMultiplier = origin.getPriceMultiplier(); - int demand = origin.getDemand(); - int specialPrice = origin.getSpecialPrice(); - - EnchantUtils.updateDisplay(result); - - MerchantRecipe recipe = new MerchantRecipe(result, uses, maxUses, expReward, villagerExperience, - priceMultiplier, demand, specialPrice); - recipe.setIngredients(origin.getIngredients()); - event.setRecipe(recipe); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onEnchantDisplayUpdateLoot(LootGenerateEvent event) { - if (Config.isCustomDistribution()) return; - - Entity entity = event.getEntity(); - InventoryHolder holder = event.getInventoryHolder(); - - if (entity instanceof Minecart || holder instanceof Chest) { - event.getLoot().forEach(item -> { - if (item != null && EnchantUtils.isEnchantable(item)) { - EnchantUtils.updateDisplay(item); - } - }); - } - }*/ -} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantPopulationListener.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantPopulationListener.java deleted file mode 100644 index 287459f..0000000 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantPopulationListener.java +++ /dev/null @@ -1,132 +0,0 @@ -package su.nightexpress.excellentenchants.enchantment.listener; - -import org.bukkit.World; -import org.bukkit.block.Chest; -import org.bukkit.entity.*; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.enchantment.EnchantItemEvent; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.bukkit.event.entity.VillagerAcquireTradeEvent; -import org.bukkit.event.player.PlayerFishEvent; -import org.bukkit.event.world.LootGenerateEvent; -import org.bukkit.inventory.*; -import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.DistributionWay; -import su.nightexpress.excellentenchants.config.Config; -import su.nightexpress.excellentenchants.enchantment.EnchantPopulator; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; -import su.nightexpress.excellentenchants.hook.HookPlugin; -import su.nightexpress.excellentenchants.hook.impl.MythicMobsHook; -import su.nightexpress.nightcore.manager.AbstractListener; -import su.nightexpress.nightcore.util.EntityUtil; -import su.nightexpress.nightcore.util.Plugins; - -public class EnchantPopulationListener extends AbstractListener { - - public EnchantPopulationListener(@NotNull EnchantsPlugin plugin) { - super(plugin); - } - - @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public void onPopulateEnchantingTable(EnchantItemEvent event) { - ItemStack target = event.getItem(); - World world = event.getEnchanter().getWorld(); - - EnchantPopulator populator = this.plugin.createPopulator(target, DistributionWay.ENCHANTING) - .withWorld(world) - .withLevelGenerator((data, distribution) -> distribution.getLevelByEnchantCost(event.getExpLevelCost())) - .withDefaultPopulation(event.getEnchantsToAdd()); - - event.getEnchantsToAdd().putAll(populator.createPopulation()); - } - - @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public void onPopulateVillagerAcquire(VillagerAcquireTradeEvent event) { - if (Config.getDistributionWaySettings(DistributionWay.VILLAGER).isEmpty()) return; - - MerchantRecipe origin = event.getRecipe(); - ItemStack result = origin.getResult(); - if (!EnchantUtils.isEnchantable(result)) return; - - EnchantPopulator populator = this.plugin.createPopulator(result, DistributionWay.VILLAGER) - .withWorld(event.getEntity().getWorld()); - if (!populator.populate()) return; - - int uses = origin.getUses(); - int maxUses = origin.getMaxUses(); - boolean expReward = origin.hasExperienceReward(); - int villagerExperience = origin.getVillagerExperience(); - float priceMultiplier = origin.getPriceMultiplier(); - int demand = origin.getDemand(); - int specialPrice = origin.getSpecialPrice(); - - MerchantRecipe recipe = new MerchantRecipe(result, uses, maxUses, expReward, villagerExperience, - priceMultiplier, demand, specialPrice); - recipe.setIngredients(origin.getIngredients()); - event.setRecipe(recipe); - } - - @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public void onPopulateLoot(LootGenerateEvent event) { - if (Config.getDistributionWaySettings(DistributionWay.LOOT_GENERATION).isEmpty()) return; - - Entity entity = event.getEntity(); - InventoryHolder holder = event.getInventoryHolder(); - World world = event.getWorld(); - - if (entity instanceof Minecart || holder instanceof Chest) { - event.getLoot().forEach(item -> { - if (item != null && EnchantUtils.isEnchantable(item)) { - this.plugin.createPopulator(item, DistributionWay.LOOT_GENERATION) - .withWorld(world) - .withCondition((data, customDistribution) -> customDistribution.isGoodLootTable(event.getLootTable())) - .populate(); - } - }); - } - } - - @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public void onPopulateFishing(PlayerFishEvent event) { - if (Config.getDistributionWaySettings(DistributionWay.FISHING).isEmpty()) return; - if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) return; - if (!(event.getCaught() instanceof Item item)) return; - - ItemStack itemStack = item.getItemStack(); - World world = item.getWorld(); - if (EnchantUtils.isEnchantable(itemStack)) { - this.plugin.createPopulator(itemStack, DistributionWay.FISHING).withWorld(world).populate(); - } - } - - @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public void onPopulateSpawn(CreatureSpawnEvent event) { - LivingEntity entity = event.getEntity(); - if (entity.getType() == EntityType.ARMOR_STAND) return; - if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.DISPENSE_EGG) return; - if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.SPAWNER_EGG) return; - if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.SPAWNER) return; - - this.plugin.runTaskLater(task -> { - EntityEquipment equipment = entity.getEquipment(); - if (equipment == null) return; - - World world = entity.getWorld(); - boolean isMythic = Plugins.isLoaded(HookPlugin.MYTHIC_MOBS) && MythicMobsHook.isMythicMob(entity); - boolean doPopulation = Config.getDistributionWaySettings(DistributionWay.MOB_EQUIPMENT).isPresent() && !isMythic; - - for (EquipmentSlot slot : EntityUtil.EQUIPMENT_SLOTS) { - ItemStack item = equipment.getItem(slot); - if (EnchantUtils.isEnchantable(item)) { - if (doPopulation) { - this.plugin.createPopulator(item, DistributionWay.MOB_EQUIPMENT).withWorld(world).populate(); - } - EnchantUtils.getCustomEnchantments(item).forEach((enchant, level) -> enchant.restoreCharges(item, level)); - equipment.setItem(slot, item); - } - } - }, 40L); // меньше недостаточно - } -} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantVanillaListener.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantVanillaListener.java deleted file mode 100644 index af4671d..0000000 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantVanillaListener.java +++ /dev/null @@ -1,91 +0,0 @@ -package su.nightexpress.excellentenchants.enchantment.listener; - -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.enchantment.EnchantItemEvent; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryCloseEvent; -import org.bukkit.event.inventory.InventoryType; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.EnchantingBridge; -import su.nightexpress.nightcore.manager.AbstractListener; - -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -public class EnchantVanillaListener extends AbstractListener { - - private final Map>> finedEnchants; - - public EnchantVanillaListener(@NotNull EnchantsPlugin plugin) { - super(plugin); - this.finedEnchants = new HashMap<>(); - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onQuit(PlayerQuitEvent event) { - this.finedEnchants.remove(event.getPlayer().getUniqueId()); - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onEnchantTableBridgePurge(InventoryCloseEvent event) { - Inventory inventory = event.getInventory(); - if (inventory.getType() != InventoryType.ENCHANTING) return; - - this.finedEnchants.remove(event.getPlayer().getUniqueId()); - } - - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void onEnchantTableBridgeSet(InventoryClickEvent event) { - Inventory inventory = event.getInventory(); - if (inventory.getType() != InventoryType.ENCHANTING) return; - - // ======== NOT VALID FOR 1.20.5+ ======== - // I don't know if Mojang is stupid or something - // they use "enchantment.category.canEnchant(item) instead of enchantment.canEnchant(item) - // which fuck ups all custom changes in that overridden method. - // Problem here: EnchantingMenu -> getEnchantmentList -> EnchantmentHelper.selectEnchantment -> getAvailableEnchantmentResults - // We store enchanting item in EnchantingBridge and adjust custom enchantment's 'isDiscoverable' result depends on the item. - // Then only proper enchantments will appear from 'getEnchantsList' method of EnchantmentMenu. - // We store them in a map here and change offers in NMS for best visual result. - // In EnchantItemEven prepared enchantments are used to replace the result. - - this.plugin.runTask(task -> { - Player player = (Player) event.getWhoClicked(); - ItemStack target = inventory.getItem(0); - EnchantingBridge.setEnchantingItem(target); - - if (target != null) { - Map> map = plugin.getEnchantNMS().getEnchantLists(inventory, target); - this.finedEnchants.put(player.getUniqueId(), map); - - EnchantingBridge.clear(); - } - else { - this.finedEnchants.remove(player.getUniqueId()); - } - }); - } - - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void onEnchantTableFixResult(EnchantItemEvent event) { - Player player = event.getEnchanter(); - int button = event.whichButton(); - - Map> indexMap = this.finedEnchants.remove(player.getUniqueId()); - if (indexMap == null) return; - - Map enchantmentMap = indexMap.get(button); - if (enchantmentMap == null) return; - - event.getEnchantsToAdd().clear(); - event.getEnchantsToAdd().putAll(enchantmentMap); - } -} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/GenericListener.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/GenericListener.java new file mode 100644 index 0000000..b262be9 --- /dev/null +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/GenericListener.java @@ -0,0 +1,94 @@ +package su.nightexpress.excellentenchants.enchantment.listener; + +import org.bukkit.GameMode; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.enchantment.EnchantItemEvent; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityShootBowEvent; +import org.bukkit.event.entity.ProjectileHitEvent; +import org.bukkit.event.player.PlayerGameModeChangeEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import su.nightexpress.excellentenchants.EnchantsPlugin; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; +import su.nightexpress.excellentenchants.config.Config; +import su.nightexpress.excellentenchants.enchantment.EnchantManager; +import su.nightexpress.excellentenchants.registry.EnchantRegistry; +import su.nightexpress.excellentenchants.util.EnchantUtils; +import su.nightexpress.nightcore.manager.AbstractListener; + +public class GenericListener extends AbstractListener { + + //private final EnchantManager enchantManager; + + public GenericListener(@NotNull EnchantsPlugin plugin, @NotNull EnchantManager enchantManager) { + super(plugin); + //this.enchantManager = enchantManager; + } + + @SuppressWarnings("UnstableApiUsage") + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onDisplayGameMode(PlayerGameModeChangeEvent event) { + Player player = event.getPlayer(); + GameMode current = player.getGameMode(); + GameMode changed = event.getNewGameMode(); + + // When enter Creative gamemode, force update all inventory to flush item's lore so they don't have enchant descriptions. + if (changed == GameMode.CREATIVE) { + EnchantUtils.runInDisabledDisplayUpdate(player, player::updateInventory); + } + else if (current == GameMode.CREATIVE) { + this.plugin.runTask(task -> player.updateInventory()); + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onDisplayQuit(PlayerQuitEvent event) { + EnchantUtils.allowDisplayUpdate(event.getPlayer()); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onCreatureSpawn(CreatureSpawnEvent event) { + EnchantUtils.setSpawnReason(event.getEntity(), event.getSpawnReason()); + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onEnchantedProjectileShoot(EntityShootBowEvent event) { + if (event.getProjectile() instanceof Projectile projectile) { + EnchantUtils.addEnchantedProjectile(projectile, event.getBow()); + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onEnchantedProjectileLand(ProjectileHitEvent event) { + this.plugin.runTask(task -> { + EnchantUtils.removeEnchantedProjectile(event.getEntity()); + }); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onChargesFillOnEnchant(EnchantItemEvent event) { + if (!Config.isChargesEnabled()) return; + + this.plugin.runTask(task -> { + Inventory inventory = event.getInventory(); + + ItemStack result = inventory.getItem(0); + if (result == null) return; + + event.getEnchantsToAdd().forEach((enchantment, level) -> { + CustomEnchantment customEnchantment = EnchantRegistry.getByKey(enchantment.getKey()); + if (customEnchantment != null) { + customEnchantment.restoreCharges(result, level); + } + }); + + inventory.setItem(0, result); + }); + } +} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/menu/EnchantmentsListMenu.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/menu/EnchantsMenu.java similarity index 68% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/menu/EnchantmentsListMenu.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/menu/EnchantsMenu.java index 04c2251..67854cb 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/menu/EnchantmentsListMenu.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/menu/EnchantsMenu.java @@ -2,21 +2,19 @@ package su.nightexpress.excellentenchants.enchantment.menu; import org.bukkit.Material; import org.bukkit.NamespacedKey; -import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; -import su.nightexpress.excellentenchants.api.DistributionWay; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; import su.nightexpress.excellentenchants.config.Config; -import su.nightexpress.excellentenchants.enchantment.data.CustomDistribution; -import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; +import su.nightexpress.excellentenchants.registry.EnchantRegistry; +import su.nightexpress.excellentenchants.util.EnchantUtils; import su.nightexpress.nightcore.config.ConfigValue; import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.core.CoreLang; import su.nightexpress.nightcore.menu.MenuOptions; +import su.nightexpress.nightcore.menu.MenuSize; import su.nightexpress.nightcore.menu.MenuViewer; import su.nightexpress.nightcore.menu.api.AutoFill; import su.nightexpress.nightcore.menu.api.AutoFilled; @@ -24,6 +22,7 @@ import su.nightexpress.nightcore.menu.impl.ConfigMenu; import su.nightexpress.nightcore.menu.item.ItemHandler; import su.nightexpress.nightcore.menu.item.MenuItem; import su.nightexpress.nightcore.util.*; +import su.nightexpress.nightcore.util.text.NightMessage; import java.util.*; import java.util.function.Predicate; @@ -32,26 +31,24 @@ import java.util.stream.IntStream; import static su.nightexpress.excellentenchants.Placeholders.*; import static su.nightexpress.nightcore.util.text.tag.Tags.*; -public class EnchantmentsListMenu extends ConfigMenu implements AutoFilled { +public class EnchantsMenu extends ConfigMenu implements AutoFilled { private static final String FILE_NAME = "enchants.yml"; - private static final String PLACEHOLDER_CONFLICTS = "%conflicts%"; - private static final String PLACEHOLDER_CHARGES = "%charges%"; - private static final String PLACEHOLDER_OBTAINING = "%obtaining%"; + private static final String CONFLICTS = "%conflicts%"; + private static final String CHARGES = "%charges%"; private final NamespacedKey keyLevel; private final Map> iconCache; - private ItemStack enchantIcon; - private String enchantName; + private ItemStack enchantIcon; + private String enchantName; private List enchantLoreMain; private List enchantLoreConflicts; private List enchantLoreCharges; - private List enchantLoreObtaining; - private int[] enchantSlots; + private int[] enchantSlots; - public EnchantmentsListMenu(@NotNull EnchantsPlugin plugin) { + public EnchantsMenu(@NotNull EnchantsPlugin plugin) { super(plugin, FileConfig.loadOrExtract(plugin, Config.DIR_MENU, FILE_NAME)); this.keyLevel = new NamespacedKey(plugin, "list_display_level"); this.iconCache = new HashMap<>(); @@ -68,10 +65,12 @@ public class EnchantmentsListMenu extends ConfigMenu implements protected void loadAdditional() { this.enchantIcon = ConfigValue.create("Enchantment.Icon", new ItemStack(Material.ENCHANTED_BOOK)).read(this.cfg); - this.enchantName = ConfigValue.create("Enchantment.Name", ENCHANTMENT_NAME_FORMATTED).read(this.cfg); + this.enchantName = ConfigValue.create("Enchantment.Name", + LIGHT_YELLOW.enclose(BOLD.enclose(ENCHANTMENT_NAME + " " + ENCHANTMENT_LEVEL)) + ).read(this.cfg); this.enchantLoreMain = ConfigValue.create("Enchantment.Lore.Main", - Arrays.asList( + Lists.newList( ENCHANTMENT_RARITY, "", ENCHANTMENT_DESCRIPTION_REPLACED, @@ -80,36 +79,28 @@ public class EnchantmentsListMenu extends ConfigMenu implements LIGHT_YELLOW.enclose(BOLD.enclose("Info:")), LIGHT_YELLOW.enclose("▪ " + LIGHT_GRAY.enclose("Applies to: ") + ENCHANTMENT_FIT_ITEM_TYPES), LIGHT_YELLOW.enclose("▪ " + LIGHT_GRAY.enclose("Levels: ") + ENCHANTMENT_LEVEL_MIN + LIGHT_GRAY.enclose(" - ") + ENCHANTMENT_LEVEL_MAX), - PLACEHOLDER_CHARGES, - PLACEHOLDER_CONFLICTS, - PLACEHOLDER_OBTAINING + CHARGES, + CONFLICTS )).read(this.cfg); this.enchantLoreConflicts = ConfigValue.create("Enchantment.Lore.Conflicts", - List.of( + Lists.newList( "", LIGHT_RED.enclose(BOLD.enclose("Conflicts:")), LIGHT_RED.enclose("✘ ") + LIGHT_GRAY.enclose(GENERIC_NAME) )).read(this.cfg); this.enchantLoreCharges = ConfigValue.create("Enchantment.Lore.Charges", - List.of( + Lists.newList( LIGHT_YELLOW.enclose("▪ " + LIGHT_GRAY.enclose("Charges: ") + GENERIC_AMOUNT + "⚡" + LIGHT_GRAY.enclose(" (" + WHITE.enclose(GENERIC_ITEM) + ")"))) ).read(this.cfg); - this.enchantLoreObtaining = ConfigValue.create("Enchantment.Lore.Obtaining", - List.of( - "", - LIGHT_GREEN.enclose(BOLD.enclose("Obtaining:")), - LIGHT_GREEN.enclose("✔ ") + LIGHT_GRAY.enclose(GENERIC_TYPE)) - ).read(this.cfg); - this.enchantSlots = ConfigValue.create("Enchantment.Slots", IntStream.range(0, 27).toArray()).read(this.cfg); } @NotNull protected MenuOptions createDefaultOptions() { - return new MenuOptions(BLACK.enclose("Custom Enchantments"), 36, InventoryType.CHEST); + return new MenuOptions(BLACK.enclose("Custom Enchantments"), MenuSize.CHEST_36); } @NotNull @@ -139,11 +130,11 @@ public class EnchantmentsListMenu extends ConfigMenu implements } @Override - public void onAutoFill(@NotNull MenuViewer viewer, @NotNull AutoFill autoFill) { + public void onAutoFill(@NotNull MenuViewer viewer, @NotNull AutoFill autoFill) { autoFill.setSlots(this.enchantSlots); autoFill.setItems(EnchantRegistry.getRegistered().stream() - .filter(Predicate.not(EnchantmentData::isHiddenFromList)) - .sorted(Comparator.comparing(data -> Colorizer.restrip(data.getName()))) + .filter(Predicate.not(CustomEnchantment::isHiddenFromList)) + .sorted(Comparator.comparing(data -> NightMessage.stripAll(data.getDisplayName()))) .toList() ); autoFill.setItemCreator(enchantmentData -> this.getEnchantIcon(enchantmentData, 1)); @@ -154,7 +145,7 @@ public class EnchantmentsListMenu extends ConfigMenu implements if (currentItem == null) return; int levelHas = PDCUtil.getInt(currentItem, this.keyLevel).orElse(1); - if (++levelHas > enchantmentData.getMaxLevel()) { + if (++levelHas > enchantmentData.getDefinition().getMaxLevel()) { levelHas = 1; } currentItem = this.getEnchantIcon(enchantmentData, levelHas); @@ -163,19 +154,19 @@ public class EnchantmentsListMenu extends ConfigMenu implements }); } - private ItemStack getEnchantIcon(@NotNull EnchantmentData enchant, int level) { + private ItemStack getEnchantIcon(@NotNull CustomEnchantment enchant, int level) { return this.iconCache.computeIfAbsent(enchant.getId(), k -> new HashMap<>()).computeIfAbsent(level, k -> this.buildEnchantIcon(enchant, level)); } @NotNull - private ItemStack buildEnchantIcon(@NotNull EnchantmentData enchant, int level) { + private ItemStack buildEnchantIcon(@NotNull CustomEnchantment enchant, int level) { ItemStack icon = new ItemStack(this.enchantIcon); List conflicts = new ArrayList<>(); - if (enchant.hasConflicts()) { + if (enchant.getDefinition().hasConflicts()) { for (String line : this.enchantLoreConflicts) { if (line.contains(GENERIC_NAME)) { - enchant.getConflicts().stream() + enchant.getDefinition().getConflicts().stream() .map(EnchantUtils::getLocalized).filter(Objects::nonNull) .forEach(conf -> conflicts.add(line.replace(GENERIC_NAME, conf))); continue; @@ -184,29 +175,12 @@ public class EnchantmentsListMenu extends ConfigMenu implements } } - List obtaining = new ArrayList<>(); - if (Config.isCustomDistribution()) { - for (String line : this.enchantLoreObtaining) { - if (line.contains(GENERIC_TYPE)) { - for (DistributionWay distributionWay : DistributionWay.values()) { - if (enchant.getDistributionOptions() instanceof CustomDistribution distribution) { - if (!distribution.isDistributable(distributionWay)) continue; - } - - obtaining.add(line.replace(GENERIC_TYPE, this.plugin.getLangManager().getEnum(distributionWay))); - } - continue; - } - obtaining.add(line); - } - } - List charges = new ArrayList<>(); - if (enchant.isChargesEnabled()) { + if (enchant.hasCharges()) { for (String line : this.enchantLoreCharges) { charges.add(line - .replace(GENERIC_AMOUNT, NumberUtil.format(enchant.getChargesMax(level))) - .replace(GENERIC_ITEM, ItemUtil.getItemName(enchant.getChargesFuel())) + .replace(GENERIC_AMOUNT, NumberUtil.format(enchant.getCharges().getMaxAmount(level))) + .replace(GENERIC_ITEM, ItemUtil.getItemName(enchant.getCharges().getFuel())) ); } } @@ -214,9 +188,8 @@ public class EnchantmentsListMenu extends ConfigMenu implements ItemReplacer.create(icon).hideFlags().trimmed() .setDisplayName(this.enchantName) .setLore(this.enchantLoreMain) - .replaceLoreExact(PLACEHOLDER_CHARGES, charges) - .replaceLoreExact(PLACEHOLDER_CONFLICTS, conflicts) - .replaceLoreExact(PLACEHOLDER_OBTAINING, obtaining) + .replace(CHARGES, charges) + .replace(CONFLICTS, conflicts) .replace(enchant.getPlaceholders(level)) .writeMeta(); return icon; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/hook/impl/PlaceholderHook.java b/Core/src/main/java/su/nightexpress/excellentenchants/hook/impl/PlaceholderHook.java index 159475a..c4b72ce 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/hook/impl/PlaceholderHook.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/hook/impl/PlaceholderHook.java @@ -8,8 +8,8 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; -import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; +import su.nightexpress.excellentenchants.registry.EnchantRegistry; import su.nightexpress.nightcore.util.NumberUtil; import su.nightexpress.nightcore.util.StringUtil; @@ -48,7 +48,7 @@ public class PlaceholderHook { @Override @NotNull public String getAuthor() { - return this.plugin.getDescription().getAuthors().get(0); + return this.plugin.getDescription().getAuthors().getFirst(); } @Override @@ -75,7 +75,7 @@ public class PlaceholderHook { ItemStack item = player.getInventory().getItem(slot); if (item == null || item.getType().isAir()) return "-"; - EnchantmentData enchant = EnchantRegistry.getByKey(NamespacedKey.minecraft(chargesSplit[1].toLowerCase())); + CustomEnchantment enchant = EnchantRegistry.getByKey(NamespacedKey.minecraft(chargesSplit[1].toLowerCase())); if (enchant == null) return null; return String.valueOf(enchant.getCharges(item)); @@ -85,12 +85,12 @@ public class PlaceholderHook { String[] chargesSplit = params.substring("charges_maximum_".length()).split(":"); if (chargesSplit.length < 2) return null; - EnchantmentData enchant = EnchantRegistry.getByKey(NamespacedKey.minecraft(chargesSplit[0].toLowerCase())); + CustomEnchantment enchant = EnchantRegistry.getByKey(NamespacedKey.minecraft(chargesSplit[0].toLowerCase())); if (enchant == null) return null; int level = NumberUtil.getInteger(chargesSplit[1], 1); - return String.valueOf(enchant.getChargesMax(level)); + return String.valueOf(enchant.getCharges().getMaxAmount(level)); } return super.onPlaceholderRequest(player, params); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/hook/impl/ProtocolLibHook.java b/Core/src/main/java/su/nightexpress/excellentenchants/hook/impl/ProtocolLibHook.java index d523ee3..4670638 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/hook/impl/ProtocolLibHook.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/hook/impl/ProtocolLibHook.java @@ -13,20 +13,20 @@ import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; -import su.nightexpress.nightcore.util.Version; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; +import su.nightexpress.excellentenchants.util.EnchantUtils; import su.nightexpress.nightcore.util.text.NightMessage; -import java.util.*; -import java.util.stream.Collectors; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; public class ProtocolLibHook { - private static boolean isRegistered = false; + private static boolean registered = false; public static void setup(@NotNull EnchantsPlugin plugin) { - if (isRegistered) return; + if (registered) return; ProtocolManager manager = ProtocolLibrary.getProtocolManager(); @@ -34,7 +34,7 @@ public class ProtocolLibHook { @Override public void onPacketSending(PacketEvent event) { PacketContainer packet = event.getPacket(); - if (EnchantUtils.isIgnoringDisplayUpdate(event.getPlayer())) return; + if (!EnchantUtils.canUpdateDisplay(event.getPlayer())) return; ItemStack item = packet.getItemModifier().read(0); packet.getItemModifier().write(0, update(item)); @@ -45,7 +45,7 @@ public class ProtocolLibHook { @Override public void onPacketSending(PacketEvent event) { PacketContainer packet = event.getPacket(); - if (EnchantUtils.isIgnoringDisplayUpdate(event.getPlayer())) return; + if (!EnchantUtils.canUpdateDisplay(event.getPlayer())) return; List items = packet.getItemListModifier().readSafely(0); items.replaceAll(ProtocolLibHook::update); @@ -58,7 +58,7 @@ public class ProtocolLibHook { @Override public void onPacketSending(PacketEvent event) { PacketContainer packet = event.getPacket(); - if (EnchantUtils.isIgnoringDisplayUpdate(event.getPlayer())) return; + if (!EnchantUtils.canUpdateDisplay(event.getPlayer())) return; List list = new ArrayList<>(); packet.getMerchantRecipeLists().read(0).forEach(recipe -> { @@ -74,39 +74,27 @@ public class ProtocolLibHook { } }); - isRegistered = true; + registered = true; } @Nullable public static ItemStack update(@Nullable ItemStack item) { - if (item == null || item.getType().isAir()) return item; + if (item == null || item.getType().isAir() || !EnchantUtils.canHaveDescription(item)) return item; ItemStack copy = new ItemStack(item); ItemMeta meta = copy.getItemMeta(); if (meta == null || meta.hasItemFlag(ItemFlag.HIDE_ENCHANTS)) return item; - Map enchants = EnchantUtils.getCustomEnchantments(meta) - .entrySet().stream() - .sorted(Comparator.comparing((Map.Entry entry) -> entry.getKey().getRarity().getWeight()) - .thenComparing(entry -> entry.getKey().getName())) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (old,nev) -> nev, LinkedHashMap::new)); + Map enchants = EnchantUtils.getCustomEnchantments(meta); if (enchants.isEmpty()) return item; - List lore = meta.getLore() == null ? new ArrayList<>() : meta.getLore(); + List metaLore = meta.getLore(); + List lore = metaLore == null ? new ArrayList<>() : metaLore; - if (EnchantUtils.canHaveDescription(item)) { - enchants.forEach((enchant, level) -> { - int charges = enchant.getCharges(meta); - lore.addAll(0, NightMessage.asLegacy(enchant.getDescriptionReplaced(level, charges))); - }); - } - - if (Version.isBehind(Version.MC_1_21)) { - enchants.forEach((enchant, level) -> { - int charges = enchant.getCharges(meta); - lore.addFirst(NightMessage.asLegacy(enchant.getNameFormatted(level, charges))); - }); - } + enchants.forEach((enchant, level) -> { + int chargesAmount = enchant.getCharges(meta); + lore.addAll(NightMessage.asLegacy(enchant.getDescription(level, chargesAmount))); + }); meta.setLore(lore); copy.setItemMeta(meta); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/rarity/EnchantRarity.java b/Core/src/main/java/su/nightexpress/excellentenchants/rarity/EnchantRarity.java new file mode 100644 index 0000000..49d79d7 --- /dev/null +++ b/Core/src/main/java/su/nightexpress/excellentenchants/rarity/EnchantRarity.java @@ -0,0 +1,98 @@ +package su.nightexpress.excellentenchants.rarity; + +import org.jetbrains.annotations.NotNull; +import su.nightexpress.excellentenchants.Placeholders; +import su.nightexpress.excellentenchants.api.enchantment.Rarity; +import su.nightexpress.nightcore.config.ConfigValue; +import su.nightexpress.nightcore.config.FileConfig; +import su.nightexpress.nightcore.util.Lists; +import su.nightexpress.nightcore.util.StringUtil; + +import java.util.List; + +import static su.nightexpress.nightcore.util.text.tag.Tags.*; +import static su.nightexpress.excellentenchants.Placeholders.*; + +public class EnchantRarity implements Rarity { + + public static final String COMMON = "common"; + public static final String RARE = "uncommon"; + public static final String LEGENDARY = "rare"; + public static final String MYTHIC = "very_rare"; + + public static final Rarity DUMMY = new EnchantRarity("dummy", "Default", ENCHANTMENT_NAME, 5); + + private final String id; + private final String name; + private final String nameFormat; + private final int weight; + + public EnchantRarity(@NotNull String id, @NotNull String name, @NotNull String nameFormat, int weight) { + this.id = id; + this.name = name; + this.nameFormat = nameFormat; + this.weight = weight; + } + + @NotNull + public static EnchantRarity read(@NotNull FileConfig config, @NotNull String path, @NotNull String id) { + String name = ConfigValue.create(path + ".Name", StringUtil.capitalizeUnderscored(id)).read(config); + + String nameFormat = ConfigValue.create(path + ".Name_Format", + Placeholders.ENCHANTMENT_NAME, + "Sets general name format for all enchantments of this rarity.", + "You can use 'Enchantment' placeholders: " + Placeholders.WIKI_PLACEHOLDERS, + "Use only 'static' placeholders! Level-dependant and charges placeholders will not update their values.", + "Text formations: " + Placeholders.WIKI_TEXT_URL, + "[*] Reboot required when changed!" + ).read(config); + + int weight = ConfigValue.create(path + ".Weight", + 10, + "Controls the probability of enchantment with this rarity when enchanting", + "The probability is determined 'weight / total weight * 100%', where 'total_weight' is the sum of the weights of all available enchantments.", + "[*] Reboot required when changed!" + ).read(config); + + return new EnchantRarity(id, name, nameFormat, weight); + } + + public void write(@NotNull FileConfig config, @NotNull String path) { + config.set(path + ".Name", this.getName()); + config.set(path + ".Name_Format", this.getNameFormat()); + config.set(path + ".Weight", this.getWeight()); + } + + @NotNull + public static List getDefaults() { + return Lists.newList( + new EnchantRarity(COMMON, LIGHT_GRAY.enclose("Common"), LIGHT_GRAY.enclose(ENCHANTMENT_NAME), 10), + new EnchantRarity(RARE, LIGHT_GREEN.enclose("Rare"), LIGHT_GREEN.enclose(ENCHANTMENT_NAME), 5), + new EnchantRarity(LEGENDARY, LIGHT_YELLOW.enclose("Legendary"), LIGHT_YELLOW.enclose(ENCHANTMENT_NAME), 2), + new EnchantRarity(MYTHIC, LIGHT_PURPLE.enclose("Mythic"), LIGHT_PURPLE.enclose(ENCHANTMENT_NAME), 1) + ); + } + + @NotNull + @Override + public String getId() { + return id; + } + + @NotNull + @Override + public String getName() { + return name; + } + + @NotNull + @Override + public String getNameFormat() { + return nameFormat; + } + + @Override + public int getWeight() { + return weight; + } +} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/rarity/RarityManager.java b/Core/src/main/java/su/nightexpress/excellentenchants/rarity/RarityManager.java new file mode 100644 index 0000000..3d47273 --- /dev/null +++ b/Core/src/main/java/su/nightexpress/excellentenchants/rarity/RarityManager.java @@ -0,0 +1,78 @@ +package su.nightexpress.excellentenchants.rarity; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import su.nightexpress.excellentenchants.EnchantsPlugin; +import su.nightexpress.excellentenchants.api.enchantment.Rarity; +import su.nightexpress.nightcore.config.FileConfig; +import su.nightexpress.nightcore.manager.SimpleManager; +import su.nightexpress.nightcore.util.random.Rnd; + +import java.util.*; + +public class RarityManager extends SimpleManager { + + private final Map rarityMap; + + public RarityManager(@NotNull EnchantsPlugin plugin) { + super(plugin); + this.rarityMap = new HashMap<>(); + } + + @Override + protected void onLoad() { + this.loadRarities(); + } + + @Override + protected void onShutdown() { + this.rarityMap.clear(); + } + + private void loadRarities() { + FileConfig config = this.plugin.getConfig(); + if (!config.contains("Rarity")) { + EnchantRarity.getDefaults().forEach(rarity -> rarity.write(config, "Rarity." + rarity.getId())); + } + + config.getSection("Rarity").forEach(sId -> { + Rarity rarity = EnchantRarity.read(config, "Rarity." + sId, sId); + this.rarityMap.put(rarity.getId(), rarity); + }); + + if (this.rarityMap.isEmpty()) { + this.plugin.warn("No rarities are defined in the config! Adding dummy one for the plugin to work."); + this.plugin.warn("You MUST FIX this issue for the plugin to work properly."); + Rarity rarity = EnchantRarity.DUMMY; + this.rarityMap.put(rarity.getId(), rarity); + } + + this.plugin.info("Loaded " + this.rarityMap.size() + " rarities."); + } + + @NotNull + public Rarity getRarityByWeight() { + Map map = new HashMap<>(); + + for (Rarity rarity : this.getRarities()) { + map.put(rarity, (double) rarity.getWeight()); + } + + return Rnd.getByWeight(map); + } + + @NotNull + public Set getRarities() { + return new HashSet<>(this.rarityMap.values()); + } + + @NotNull + public List getRarityNames() { + return new ArrayList<>(this.rarityMap.keySet()); + } + + @Nullable + public Rarity getRarity(@NotNull String id) { + return this.rarityMap.get(id.toLowerCase()); + } +} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/EnchantRegistry.java b/Core/src/main/java/su/nightexpress/excellentenchants/registry/EnchantRegistry.java similarity index 78% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/EnchantRegistry.java rename to Core/src/main/java/su/nightexpress/excellentenchants/registry/EnchantRegistry.java index 3c9acec..5fa3aa3 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/EnchantRegistry.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/registry/EnchantRegistry.java @@ -1,6 +1,7 @@ -package su.nightexpress.excellentenchants.enchantment.registry; +package su.nightexpress.excellentenchants.registry; import org.bukkit.NamespacedKey; +import org.bukkit.enchantments.Enchantment; import org.bukkit.event.Event; import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockBreakEvent; @@ -11,10 +12,12 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; +import su.nightexpress.excellentenchants.api.EnchantmentID; import su.nightexpress.excellentenchants.api.enchantment.Rarity; import su.nightexpress.excellentenchants.api.enchantment.type.*; import su.nightexpress.excellentenchants.config.Config; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; import su.nightexpress.excellentenchants.enchantment.impl.armor.*; import su.nightexpress.excellentenchants.enchantment.impl.bow.*; import su.nightexpress.excellentenchants.enchantment.impl.fishing.*; @@ -23,9 +26,9 @@ import su.nightexpress.excellentenchants.enchantment.impl.universal.CurseOfFragi import su.nightexpress.excellentenchants.enchantment.impl.universal.RestoreEnchant; import su.nightexpress.excellentenchants.enchantment.impl.universal.SoulboundEnchant; import su.nightexpress.excellentenchants.enchantment.impl.weapon.*; -import su.nightexpress.excellentenchants.enchantment.registry.wrapper.DataGather; -import su.nightexpress.excellentenchants.enchantment.registry.wrapper.DataGathers; -import su.nightexpress.excellentenchants.enchantment.registry.wrapper.WrappedEvent; +import su.nightexpress.excellentenchants.registry.wrapper.DataGather; +import su.nightexpress.excellentenchants.registry.wrapper.DataGathers; +import su.nightexpress.excellentenchants.registry.wrapper.WrappedEvent; import su.nightexpress.nightcore.manager.SimpleManager; import su.nightexpress.nightcore.util.BukkitThing; import su.nightexpress.nightcore.util.FileUtil; @@ -37,12 +40,12 @@ import java.util.stream.Collectors; public class EnchantRegistry extends SimpleManager { - public static final Map BY_KEY = new HashMap<>(); - public static final Map BY_ID = new HashMap<>(); + public static final Map BY_KEY = new HashMap<>(); + public static final Map BY_ID = new HashMap<>(); - private static final Map, Set> ENCHANTS_MAP = new HashMap<>(); + private static final Map, Set> ENCHANTS_MAP = new HashMap<>(); - private boolean isLocked; + private boolean freezed; public EnchantRegistry(@NotNull EnchantsPlugin plugin) { super(plugin); @@ -50,6 +53,7 @@ public class EnchantRegistry extends SimpleManager { @Override protected void onLoad() { + // Register types that don't have any event wrappers. this.registerType(GenericEnchant.class); this.registerType(PassiveEnchant.class); @@ -67,10 +71,10 @@ public class EnchantRegistry extends SimpleManager { this.registerWrapper(PlayerInteractEvent.class, InteractEnchant.class, DataGathers.INTERACT); // Prevent to register enchantments during the runtime. - if (this.isLocked) { - getRegistered().forEach(data -> { - data.clear(); - this.load(data); + if (this.freezed) { + getRegistered().forEach(enchantment -> { + enchantment.clear(); + this.load(enchantment); }); return; } @@ -135,7 +139,7 @@ public class EnchantRegistry extends SimpleManager { this.register(IceShieldEnchant.ID, file -> new IceShieldEnchant(plugin, file)); this.register(ElementalProtectionEnchant.ID, file -> new ElementalProtectionEnchant(plugin, file)); this.register(FireShieldEnchant.ID, file -> new FireShieldEnchant(plugin, file)); - this.register(FlameWalkerEnchant.ID, file -> new FlameWalkerEnchant(plugin, file)); + this.register(EnchantmentID.FLAME_WALKER, file -> new FlameWalkerEnchant(plugin, file)); this.register(HardenedEnchant.ID, file -> new HardenedEnchant(plugin, file)); this.register(NightVisionEnchant.ID, file -> new NightVisionEnchant(plugin, file)); this.register(RegrowthEnchant.ID, file -> new RegrowthEnchant(plugin, file)); @@ -167,30 +171,30 @@ public class EnchantRegistry extends SimpleManager { this.register(SoulboundEnchant.ID, file -> new SoulboundEnchant(plugin, file)); this.register(RestoreEnchant.ID, file -> new RestoreEnchant(plugin, file)); - getRegistered().forEach(data -> { - plugin.getEnchantNMS().addExclusives(data); + getRegistered().forEach(enchantment -> { + this.plugin.getEnchantNMS().addExclusives(enchantment); }); this.plugin.getEnchantNMS().freezeRegistry(); this.plugin.info("Enchantments Registered: " + BY_ID.size()); - this.isLocked = true; + this.freezed = true; } @Override protected void onShutdown() { - if (!isLocked) { - getRegistered().forEach(EnchantmentData::clear); + if (!freezed) { + getRegistered().forEach(CustomEnchantment::clear); ENCHANTS_MAP.clear(); } } - public void registerType(@NotNull Class enchantClass) { + private void registerType(@NotNull Class enchantClass) { ENCHANTS_MAP.computeIfAbsent(enchantClass, k -> new HashSet<>()); } - public void registerWrapper(@NotNull Class eventClass, - @NotNull Class enchantClass, - @NotNull DataGather dataGather) { + private void registerWrapper(@NotNull Class eventClass, + @NotNull Class enchantClass, + @NotNull DataGather dataGather) { for (EventPriority priority : EventPriority.values()) { WrappedEvent event = new WrappedEvent<>(plugin, priority, eventClass, enchantClass, dataGather); @@ -200,8 +204,8 @@ public class EnchantRegistry extends SimpleManager { this.registerType(enchantClass); } - private boolean registerEnchantType(@NotNull T enchant) { - Class enchantClass = enchant.getClass(); + private boolean registerEnchantType(@NotNull T enchant) { + Class enchantClass = enchant.getClass(); Set> assignables = ENCHANTS_MAP.keySet().stream().filter(clazz -> clazz.isAssignableFrom(enchantClass)).collect(Collectors.toSet()); if (assignables.isEmpty()) { @@ -213,43 +217,44 @@ public class EnchantRegistry extends SimpleManager { return true; } - private void register(@NotNull String id, @NotNull Function supplier) { + private void register(@NotNull String id, @NotNull Function supplier) { if (Config.ENCHANTMENTS_DISABLED_LIST.get().contains(id)) return; File file = new File(plugin.getDataFolder() + Config.DIR_ENCHANTS, id + ".yml"); FileUtil.create(file); - EnchantmentData enchantmentData = supplier.apply(file); - if (BukkitThing.getEnchantment(enchantmentData.getId()) != null) { - this.plugin.error("Could not register '" + enchantmentData.getId() + "': Such enchantment already registered."); + GameEnchantment enchantment = supplier.apply(file); + if (BukkitThing.getEnchantment(enchantment.getId()) != null) { + this.plugin.error("Could not register '" + enchantment.getId() + "': Such enchantment already registered."); return; } - if (!this.registerEnchantType(enchantmentData) || !enchantmentData.checkServerRequirements()) { + if (!this.registerEnchantType(enchantment) || !enchantment.checkServerRequirements()) { return; } - this.load(enchantmentData); + this.load(enchantment); - this.plugin.getEnchantNMS().registerEnchantment(enchantmentData); + Enchantment registered = this.plugin.getEnchantNMS().registerEnchantment(enchantment); + enchantment.onRegister(registered); - BY_KEY.put(NamespacedKey.minecraft(enchantmentData.getId()), enchantmentData); - BY_ID.put(enchantmentData.getId(), enchantmentData); + BY_KEY.put(NamespacedKey.minecraft(enchantment.getId()), enchantment); + BY_ID.put(enchantment.getId(), enchantment); - this.plugin.info("Registered enchantment: " + enchantmentData.getId()); + this.plugin.info("Registered enchantment: " + enchantment.getId()); } - private void load(@NotNull EnchantmentData enchantmentData) { - enchantmentData.load(); + private void load(@NotNull CustomEnchantment enchantment) { + enchantment.load(); } @NotNull - public static Set getPeriodicEnchants() { - return getEnchantments(PassiveEnchant.class); + public static List getRegisteredNames() { + return new ArrayList<>(BY_ID.keySet()); } @NotNull - public static Set getEnchantments(@NotNull Class clazz) { + public static Set getEnchantments(@NotNull Class clazz) { Set enchants = new HashSet<>(); ENCHANTS_MAP.getOrDefault(clazz, Collections.emptySet()).forEach(talent -> { @@ -259,9 +264,9 @@ public class EnchantRegistry extends SimpleManager { } @NotNull - public static Set getEnchantments(@NotNull Rarity rarity) { + public static Set getEnchantments(@NotNull Rarity rarity) { return BY_ID.values().stream() - .filter(enchantmentData -> enchantmentData.getRarity() == rarity) + .filter(enchantment -> enchantment.getDefinition().getRarity() == rarity) .collect(Collectors.toCollection(HashSet::new)); } @@ -270,22 +275,22 @@ public class EnchantRegistry extends SimpleManager { } @Nullable - public static EnchantmentData getById(@NotNull String id) { + public static CustomEnchantment getById(@NotNull String id) { return BY_ID.get(id.toLowerCase()); } @Nullable - public static EnchantmentData getByKey(@NotNull NamespacedKey key) { + public static CustomEnchantment getByKey(@NotNull NamespacedKey key) { return BY_KEY.get(key); } @NotNull - public static Set getByRarity(@NotNull Rarity rarity) { - return getRegistered().stream().filter(data -> data.getRarity() == rarity).collect(Collectors.toSet()); + public static Set getByRarity(@NotNull Rarity rarity) { + return getRegistered().stream().filter(enchantment -> enchantment.getDefinition().getRarity() == rarity).collect(Collectors.toSet()); } @NotNull - public static Collection getRegistered() { + public static Collection getRegistered() { return new HashSet<>(BY_ID.values()); } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/wrapper/DataGather.java b/Core/src/main/java/su/nightexpress/excellentenchants/registry/wrapper/DataGather.java similarity index 76% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/wrapper/DataGather.java rename to Core/src/main/java/su/nightexpress/excellentenchants/registry/wrapper/DataGather.java index bd775d2..b741518 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/wrapper/DataGather.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/registry/wrapper/DataGather.java @@ -1,4 +1,4 @@ -package su.nightexpress.excellentenchants.enchantment.registry.wrapper; +package su.nightexpress.excellentenchants.registry.wrapper; import org.bukkit.entity.LivingEntity; import org.bukkit.event.Event; @@ -7,12 +7,12 @@ import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; +import su.nightexpress.excellentenchants.util.EnchantUtils; import java.util.Map; -public abstract class DataGather { +public abstract class DataGather { @Nullable public abstract LivingEntity getEntity(@NotNull E event); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/wrapper/DataGathers.java b/Core/src/main/java/su/nightexpress/excellentenchants/registry/wrapper/DataGathers.java similarity index 97% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/wrapper/DataGathers.java rename to Core/src/main/java/su/nightexpress/excellentenchants/registry/wrapper/DataGathers.java index 177f86b..847f10f 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/wrapper/DataGathers.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/registry/wrapper/DataGathers.java @@ -1,4 +1,4 @@ -package su.nightexpress.excellentenchants.enchantment.registry.wrapper; +package su.nightexpress.excellentenchants.registry.wrapper; import org.bukkit.Material; import org.bukkit.entity.Entity; @@ -15,10 +15,10 @@ import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import su.nightexpress.excellentenchants.api.enchantment.data.ArrowData; +import su.nightexpress.excellentenchants.api.enchantment.meta.ArrowMeta; import su.nightexpress.excellentenchants.api.enchantment.type.*; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; -import su.nightexpress.excellentenchants.enchantment.util.EnchantedProjectile; +import su.nightexpress.excellentenchants.util.EnchantUtils; +import su.nightexpress.excellentenchants.util.EnchantedProjectile; import su.nightexpress.nightcore.util.EntityUtil; import java.util.Collections; @@ -104,8 +104,8 @@ public class DataGathers { EnchantedProjectile enchantedProjectile = EnchantUtils.getEnchantedProjectile(projectile); if (enchantedProjectile != null && onShoot) { enchantedProjectile.getEnchantments().put(enchant, level); - if (enchant.hasVisualEffects() && enchant instanceof ArrowData arrowData && !arrowData.getProjectileTrail().isEmpty()) { - enchantedProjectile.getParticles().add(arrowData.getProjectileTrail()); + if (enchant.hasVisualEffects() && enchant instanceof ArrowMeta arrowMeta && !arrowMeta.getProjectileTrail().isEmpty()) { + enchantedProjectile.getParticles().add(arrowMeta.getProjectileTrail()); } } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/wrapper/WrappedEvent.java b/Core/src/main/java/su/nightexpress/excellentenchants/registry/wrapper/WrappedEvent.java similarity index 78% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/wrapper/WrappedEvent.java rename to Core/src/main/java/su/nightexpress/excellentenchants/registry/wrapper/WrappedEvent.java index e21ac67..ea318cb 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/wrapper/WrappedEvent.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/registry/wrapper/WrappedEvent.java @@ -1,4 +1,4 @@ -package su.nightexpress.excellentenchants.enchantment.registry.wrapper; +package su.nightexpress.excellentenchants.registry.wrapper; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -8,9 +8,9 @@ import org.bukkit.event.Listener; import org.bukkit.plugin.EventExecutor; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; -public class WrappedEvent implements Listener, EventExecutor { +public class WrappedEvent implements Listener, EventExecutor { //private final ExcellentEnchants plugin; private final EventPriority priority; @@ -39,12 +39,9 @@ public class WrappedEvent implements if (entity == null) return; Player player = entity instanceof Player user ? user : null; - //AtomicBoolean needUpdate = new AtomicBoolean(false); this.dataGather.getEnchants(event, this.enchantClass, entity).forEach((item, enchants) -> { enchants.forEach((enchant, level) -> { - //if (enchant.isChargesEnabled() && this.priority == EventPriority.MONITOR) needUpdate.set(true); - if (!this.dataGather.checkPriority(enchant, this.priority)) return; if (!enchant.isAvailableToUse(entity)) return; if (enchant.isOutOfCharges(item)) return; @@ -52,10 +49,6 @@ public class WrappedEvent implements enchant.consumeChargesNoUpdate(item, level); } }); - - /*if (needUpdate.get() && player != null) { - EnchantUtils.updateDisplay(item); - }*/ }); } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantPlaceholders.java b/Core/src/main/java/su/nightexpress/excellentenchants/util/EnchantPlaceholders.java similarity index 97% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantPlaceholders.java rename to Core/src/main/java/su/nightexpress/excellentenchants/util/EnchantPlaceholders.java index 721e7cb..d4c19f1 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantPlaceholders.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/util/EnchantPlaceholders.java @@ -1,4 +1,4 @@ -package su.nightexpress.excellentenchants.enchantment.util; +package su.nightexpress.excellentenchants.util; import org.jetbrains.annotations.NotNull; import su.nightexpress.nightcore.util.Pair; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantUtils.java b/Core/src/main/java/su/nightexpress/excellentenchants/util/EnchantUtils.java similarity index 61% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantUtils.java rename to Core/src/main/java/su/nightexpress/excellentenchants/util/EnchantUtils.java index 77a3232..e957c26 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantUtils.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/util/EnchantUtils.java @@ -1,4 +1,4 @@ -package su.nightexpress.excellentenchants.enchantment.util; +package su.nightexpress.excellentenchants.util; import org.bukkit.GameMode; import org.bukkit.Material; @@ -15,32 +15,31 @@ import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import su.nightexpress.excellentenchants.EnchantsPlugin; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; import su.nightexpress.excellentenchants.config.Config; import su.nightexpress.excellentenchants.config.Keys; -import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry; +import su.nightexpress.excellentenchants.enchantment.impl.GameEnchantment; +import su.nightexpress.excellentenchants.registry.EnchantRegistry; import su.nightexpress.nightcore.language.LangAssets; import su.nightexpress.nightcore.util.*; +import su.nightexpress.nightcore.util.random.Rnd; import java.util.*; import java.util.concurrent.ConcurrentHashMap; -public class EnchantUtils { +import static su.nightexpress.excellentenchants.Placeholders.*; +import static su.nightexpress.excellentenchants.Placeholders.GENERIC_CHARGES; +import static su.nightexpress.nightcore.util.Placeholders.GENERIC_VALUE; - //@Deprecated - //public static final EquipmentSlot[] EQUIPMENT_SLOTS = {EquipmentSlot.HAND, EquipmentSlot.OFF_HAND, EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET}; +public class EnchantUtils { private static final Set IGNORE_DISPLAY_UPDATE = new HashSet<>(); private static final Map ENCHANTED_PROJECTILE_MAP = new ConcurrentHashMap<>(); - private static EnchantsPlugin plugin; - private static boolean busyBreak; + public static final int LEVEL_CAP = 255; + public static final int WEIGHT_CAP = 1024; - public static void hook(@NotNull EnchantsPlugin plugin) { - EnchantUtils.plugin = plugin; - EnchantUtils.busyBreak = false; - } + private static boolean busyBreak; public static boolean isBusyByOthers() { return false; @@ -66,29 +65,24 @@ public class EnchantUtils { } } - public static boolean isIgnoringDisplayUpdate(@NotNull Player player) { - return IGNORE_DISPLAY_UPDATE.contains(player.getUniqueId()) || player.getGameMode() == GameMode.CREATIVE; + public static boolean canUpdateDisplay(@NotNull Player player) { + return !IGNORE_DISPLAY_UPDATE.contains(player.getUniqueId()) && player.getGameMode() != GameMode.CREATIVE; } - public static void doIgnoreDisplayUpdate(@NotNull Player player, @NotNull Runnable runnable) { - addIgnoreDisplayUpdate(player); + public static void runInDisabledDisplayUpdate(@NotNull Player player, @NotNull Runnable runnable) { + stopDisplayUpdate(player); runnable.run(); - removeIgnoreDisplayUpdate(player); + allowDisplayUpdate(player); } - public static void addIgnoreDisplayUpdate(@NotNull Player player) { + public static void stopDisplayUpdate(@NotNull Player player) { IGNORE_DISPLAY_UPDATE.add(player.getUniqueId()); } - public static void removeIgnoreDisplayUpdate(@NotNull Player player) { + public static void allowDisplayUpdate(@NotNull Player player) { IGNORE_DISPLAY_UPDATE.remove(player.getUniqueId()); } - /*@NotNull - public static NamespacedKey createKey(@NotNull String id) { - return NamespacedKey.minecraft(id.toLowerCase()); - }*/ - @Nullable public static String getLocalized(@NotNull String keyRaw) { Enchantment enchantment = BukkitThing.getEnchantment(keyRaw); @@ -97,29 +91,49 @@ public class EnchantUtils { @NotNull public static String getLocalized(@NotNull Enchantment enchantment) { - EnchantmentData enchant = EnchantRegistry.getByKey(enchantment.getKey()); + CustomEnchantment enchant = EnchantRegistry.getByKey(enchantment.getKey()); if (enchant != null) { - return enchant.getName(); + return enchant.getDisplayName(); } return LangAssets.get(enchantment); } - public static boolean isEnchantable(@NotNull ItemStack item) { - return plugin.getEnchantNMS().isEnchantable(item); -// if (item.getType().isAir()) return false; -// -// return item.getType() == Material.ENCHANTED_BOOK || Stream.of(EnchantmentTarget.values()).anyMatch(target -> target.includes(item)); + @NotNull + public static String replaceComponents(@NotNull GameEnchantment enchantment, @NotNull String string, int level, int charges) { + String chargesFormat = ""; + boolean showLevel = enchantment.getDefinition().getMaxLevel() > 1; + boolean showCharges = enchantment.hasCharges() && charges >= 0; + + if (showCharges) { + int chargesMax = enchantment.getCharges().getMaxAmount(level); + int percent = (int) Math.ceil((double) charges / (double) chargesMax * 100D); + Map.Entry entry = Config.ENCHANTMENTS_CHARGES_FORMAT.get().floorEntry(percent); + if (entry != null) { + chargesFormat = entry.getValue().replace(GENERIC_AMOUNT, String.valueOf(charges)); + } + } + + String compName = Config.ENCHANTMENTS_DISPLAY_NAME_COMPONENT.get().replace(GENERIC_VALUE, enchantment.getDisplayName()); + String compLevel = showLevel ? Config.ENCHANTMENTS_DISPLAY_LEVEL_COMPONENT.get().replace(GENERIC_VALUE, NumberUtil.toRoman(level)) : ""; + String compChrages = showCharges ? Config.ENCHANTMENTS_DISPLAY_CHARGES_COMPONENT.get().replace(GENERIC_VALUE, chargesFormat) : ""; + + return string + .replace(GENERIC_NAME, compName) + .replace(GENERIC_LEVEL, compLevel) + .replace(GENERIC_CHARGES, compChrages); } public static boolean isEnchantedBook(@NotNull ItemStack item) { - return /*item.getType() == Material.BOOK || */item.getType() == Material.ENCHANTED_BOOK; + return item.getType() == Material.ENCHANTED_BOOK; + } + + public static int randomLevel(@NotNull Enchantment enchantment) { + return Rnd.get(1, enchantment.getMaxLevel()); } public static boolean add(@NotNull ItemStack item, @NotNull Enchantment enchantment, int level, boolean force) { if (!force && (!enchantment.canEnchantItem(item) && !isEnchantedBook(item))) return false; - //remove(item, enchantment); - ItemMeta meta = item.getItemMeta(); if (meta == null) return false; @@ -134,21 +148,6 @@ public class EnchantUtils { return true; } - public static void removeAll(@NotNull ItemStack item) { - //ItemMeta meta = item.getItemMeta(); - //if (meta == null) return; - - ItemUtil.editMeta(item, meta -> { - getEnchantments(meta).keySet().forEach(enchantment -> remove(meta, enchantment)); - }); -// if (Version.isAtLeast(Version.V1_20_R3)) { -// item.removeEnchantments(); -// } -// else { - //getEnchantments(meta).keySet().forEach(enchantment -> remove(meta, enchantment)); -// } - } - public static void remove(@NotNull ItemStack item, @NotNull Enchantment enchantment) { ItemUtil.editMeta(item, meta -> { remove(meta, enchantment); @@ -164,88 +163,19 @@ public class EnchantUtils { } } - /*public static void updateChargesDisplay(@NotNull ItemStack item) { - if (Config.ENCHANTMENTS_CHARGES_ENABLED.get()) { - updateDisplay(item); - } - }*/ + public static void removeAll(@NotNull ItemStack item) { + ItemUtil.editMeta(item, meta -> { + getEnchantments(meta).keySet().forEach(enchantment -> remove(meta, enchantment)); + }); + } public static boolean canHaveDescription(@NotNull ItemStack item) { - if (!Config.ENCHANTMENTS_DISPLAY_DESCRIPTION_ENABLED.get()) return false; - if (Config.ENCHANTMENTS_DISPLAY_DESCRIPTION_BOOKS_ONLY.get()) { return isEnchantedBook(item); } - return true; } - @Deprecated - public static boolean updateDisplay(@NotNull ItemStack item) { - /*if (Config.ENCHANTMENTS_DISPLAY_MODE.get() != 1) return false; - - ItemMeta meta = item.getItemMeta(); - if (meta == null) return false; - - if (!isEnchantable(item)) { - PDCUtil.remove(item, Keys.loreSize); - return false; - } - - Map enchantDataMap = Lists.sort(getCustomEnchantments(item), - Comparator.comparing( - (Map.Entry entry) -> entry.getKey().getRarity().getWeight() - ) - .thenComparing(entry -> entry.getKey().getName()) - ); - - int sizeCached = PDCUtil.getInt(item, Keys.loreSize).orElse(0); - int sizeReal = enchantDataMap.size(); - if (sizeCached == 0 && sizeReal == 0) return false; - - List lore = meta.getLore() == null ? new ArrayList<>() : meta.getLore(); - for (int index = 0; index < sizeCached && !lore.isEmpty(); index++) { - lore.remove(0); - } - - if (!meta.hasItemFlag(ItemFlag.HIDE_ENCHANTS)) { - if (canHaveDescription(item)) { - for (var entry : enchantDataMap.entrySet()) { - List description = entry.getKey().getDescriptionReplaced(entry.getValue()); - - lore.addAll(0, NightMessage.asLegacy(description)); - sizeReal += description.size(); - } - } - enchantDataMap.forEach((enchant, level) -> { - lore.add(0, NightMessage.asLegacy(enchant.getNameFormatted(level, enchant.getCharges(meta)))); - }); - } - else sizeReal = 0; - - meta.setLore(lore); - - if (sizeReal > 0) { - PDCUtil.set(meta, Keys.loreSize, sizeReal); - } - else PDCUtil.remove(meta, Keys.loreSize); - - item.setItemMeta(meta);*/ - return true; - } - - @Nullable - public static ItemStack getHandItem(@NotNull Player player, @NotNull Material material) { - for (EquipmentSlot slot : new EquipmentSlot[]{EquipmentSlot.HAND, EquipmentSlot.OFF_HAND}) { - ItemStack itemStack = player.getInventory().getItem(slot); - if (itemStack != null && itemStack.getType() == material) { - return itemStack; - } - } - - return null; - } - @Nullable public static EquipmentSlot getItemHand(@NotNull Player player, @NotNull Material material) { for (EquipmentSlot slot : new EquipmentSlot[]{EquipmentSlot.HAND, EquipmentSlot.OFF_HAND}) { @@ -270,10 +200,10 @@ public class EnchantUtils { } public static boolean contains(@NotNull ItemStack item, @NotNull String id) { - EnchantmentData enchant = EnchantRegistry.getById(id); + CustomEnchantment enchant = EnchantRegistry.getById(id); if (enchant == null) return false; - return contains(item, enchant.getEnchantment()); + return contains(item, enchant.getBukkitEnchantment()); } public static boolean contains(@NotNull ItemStack item, @NotNull Enchantment enchantment) { @@ -285,10 +215,6 @@ public class EnchantUtils { return (meta instanceof EnchantmentStorageMeta storageMeta) ? storageMeta.hasStoredEnchant(enchantment) : meta.hasEnchant(enchantment); } - public static boolean hasMaximumEnchants(@NotNull ItemStack item) { - return countCustomEnchantments(item) >= Config.CORE_ITEM_ENCHANT_LIMIT.get(); - } - public static int getLevel(@NotNull ItemStack item, @NotNull Enchantment enchant) { ItemMeta meta = item.getItemMeta(); return meta == null ? 0 : getLevel(meta, enchant); @@ -307,20 +233,20 @@ public class EnchantUtils { } @NotNull - public static Map getCustomEnchantments(@NotNull ItemStack item) { + public static Map getCustomEnchantments(@NotNull ItemStack item) { return toCustomEnchantments(getEnchantments(item)); } @NotNull - public static Map getCustomEnchantments(@NotNull ItemMeta meta) { + public static Map getCustomEnchantments(@NotNull ItemMeta meta) { return toCustomEnchantments(getEnchantments(meta)); } @NotNull - private static Map toCustomEnchantments(@NotNull Map enchants) { - Map map = new HashMap<>(); + private static Map toCustomEnchantments(@NotNull Map enchants) { + Map map = new LinkedHashMap<>(); enchants.forEach((enchantment, level) -> { - EnchantmentData excellent = EnchantRegistry.getByKey(enchantment.getKey()); + CustomEnchantment excellent = EnchantRegistry.getByKey(enchantment.getKey()); if (excellent != null) { map.put(excellent, level); } @@ -329,10 +255,10 @@ public class EnchantUtils { } @NotNull - public static Map getCustomEnchantments(@NotNull ItemStack item, @NotNull Class clazz) { + public static Map getCustomEnchantments(@NotNull ItemStack item, @NotNull Class clazz) { Map map = new HashMap<>(); getEnchantments(item).forEach((enchantment, level) -> { - EnchantmentData enchantmentData = EnchantRegistry.getByKey(enchantment.getKey()); + CustomEnchantment enchantmentData = EnchantRegistry.getByKey(enchantment.getKey()); if (enchantmentData == null || !clazz.isAssignableFrom(enchantmentData.getClass())) return; map.put(clazz.cast(enchantmentData), level); @@ -340,11 +266,6 @@ public class EnchantUtils { return map; } - /*@NotNull - private static Map getEnchantedEquipment(@NotNull LivingEntity entity) { - return getEnchantedEquipment(entity, EQUIPMENT_SLOTS); - }*/ - @NotNull private static Map getEnchantedEquipment(@NotNull LivingEntity entity, @NotNull EquipmentSlot... slots) { Map equipment = EntityUtil.getEquippedItems(entity, slots); @@ -375,9 +296,9 @@ public class EnchantUtils { }*/ @NotNull - public static Map> getEquipped(@NotNull LivingEntity entity, - @NotNull Class clazz, - @NotNull EquipmentSlot... slots) { + public static Map> getEquipped(@NotNull LivingEntity entity, + @NotNull Class clazz, + @NotNull EquipmentSlot... slots) { Map> map = new HashMap<>(); getEnchantedEquipment(entity, slots).values().forEach(item -> { map.computeIfAbsent(item, k -> new LinkedHashMap<>()).putAll(getCustomEnchantments(item, clazz)); @@ -386,10 +307,10 @@ public class EnchantUtils { } @NotNull - public static Map getEquipped(@NotNull LivingEntity entity, @NotNull EnchantmentData data) { + public static Map getEquipped(@NotNull LivingEntity entity, @NotNull CustomEnchantment enchantment) { Map map = new HashMap<>(); - getEnchantedEquipment(entity, data.getSupportedItems().getSlots()).values().forEach(item -> { - int level = getLevel(item, data.getEnchantment()); + getEnchantedEquipment(entity, enchantment.getDefinition().getSupportedItems().getSlots()).values().forEach(item -> { + int level = getLevel(item, enchantment.getBukkitEnchantment()); if (level > 0) { map.put(item, level); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantedProjectile.java b/Core/src/main/java/su/nightexpress/excellentenchants/util/EnchantedProjectile.java similarity index 96% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantedProjectile.java rename to Core/src/main/java/su/nightexpress/excellentenchants/util/EnchantedProjectile.java index f292ea8..82f5cc6 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantedProjectile.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/util/EnchantedProjectile.java @@ -1,4 +1,4 @@ -package su.nightexpress.excellentenchants.enchantment.util; +package su.nightexpress.excellentenchants.util; import org.bukkit.entity.Projectile; import org.bukkit.inventory.ItemStack; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/ItemCategories.java b/Core/src/main/java/su/nightexpress/excellentenchants/util/ItemCategories.java similarity index 76% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/ItemCategories.java rename to Core/src/main/java/su/nightexpress/excellentenchants/util/ItemCategories.java index a9a977f..c41c110 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/data/ItemCategories.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/util/ItemCategories.java @@ -1,8 +1,7 @@ -package su.nightexpress.excellentenchants.enchantment.data; +package su.nightexpress.excellentenchants.util; import org.bukkit.Material; import org.bukkit.Tag; -import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.inventory.EquipmentSlot; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; @@ -17,67 +16,81 @@ public class ItemCategories { public static final ItemsCategory HELMET = ItemsCategory.buildDirect(getItemsBySlot(EquipmentSlot.HEAD)).slots(EquipmentSlot.HEAD) .localized(Lang.ITEM_CATEGORY_HELMET) - .target(EnchantmentTarget.ARMOR_HEAD).build(); + /*.target(EnchantmentTarget.ARMOR_HEAD)*/.build(); public static final ItemsCategory CHESTPLATE = ItemsCategory.buildDirect(getItemsBySlot(EquipmentSlot.CHEST)).slots(EquipmentSlot.CHEST) .localized(Lang.ITEM_CATEGORY_CHESTPLATE) - .target(EnchantmentTarget.ARMOR_TORSO).build(); + /*.target(EnchantmentTarget.ARMOR_TORSO)*/.build(); public static final ItemsCategory LEGGINGS = ItemsCategory.buildDirect(getItemsBySlot(EquipmentSlot.LEGS)).slots(EquipmentSlot.LEGS) .localized(Lang.ITEM_CATEGORY_LEGGINGS) - .target(EnchantmentTarget.ARMOR_LEGS).build(); + //.target(EnchantmentTarget.ARMOR_LEGS) + .build(); public static final ItemsCategory BOOTS = ItemsCategory.buildDirect(getItemsBySlot(EquipmentSlot.FEET)).slots(EquipmentSlot.FEET) .localized(Lang.ITEM_CATEGORY_BOOTS) - .target(EnchantmentTarget.ARMOR_FEET).build(); + //.target(EnchantmentTarget.ARMOR_FEET) + .build(); public static final ItemsCategory ELYTRA = ItemsCategory.buildDirect(Material.ELYTRA).slots(EquipmentSlot.CHEST) .localized(Lang.ITEM_CATEGORY_ELYTRA) - .target(EnchantmentTarget.ARMOR_TORSO).build(); + //.target(EnchantmentTarget.ARMOR_TORSO) + .build(); public static final ItemsCategory SWORD = ItemsCategory.buildDirect(Tag.ITEMS_SWORDS).slots(EquipmentSlot.HAND) .localized(Lang.ITEM_CATEGORY_SWORD) - .target(EnchantmentTarget.WEAPON).build(); + //.target(EnchantmentTarget.WEAPON) + .build(); public static final ItemsCategory AXE = ItemsCategory.buildDirect(Tag.ITEMS_AXES).slots(EquipmentSlot.HAND) .localized(Lang.ITEM_CATEGORY_AXE) - .target(EnchantmentTarget.TOOL).build(); + //.target(EnchantmentTarget.TOOL) + .build(); public static final ItemsCategory HOE = ItemsCategory.buildDirect(Tag.ITEMS_HOES).slots(EquipmentSlot.HAND) .localized(Lang.ITEM_CATEGORY_HOE) - .target(EnchantmentTarget.TOOL).build(); + //.target(EnchantmentTarget.TOOL) + .build(); public static final ItemsCategory PICKAXE = ItemsCategory.buildDirect(Tag.ITEMS_PICKAXES).slots(EquipmentSlot.HAND) .localized(Lang.ITEM_CATEGORY_PICKAXE) - .target(EnchantmentTarget.TOOL).build(); + //.target(EnchantmentTarget.TOOL) + .build(); public static final ItemsCategory SHOVEL = ItemsCategory.buildDirect(Tag.ITEMS_SHOVELS).slots(EquipmentSlot.HAND) .localized(Lang.ITEM_CATEGORY_SHOVEL) - .target(EnchantmentTarget.TOOL).build(); + //.target(EnchantmentTarget.TOOL) + .build(); public static final ItemsCategory TRIDENT = ItemsCategory.buildDirect(Material.TRIDENT).slots(EquipmentSlot.HAND, EquipmentSlot.OFF_HAND) .localized(Lang.ITEM_CATEGORY_TRIDENT) - .target(EnchantmentTarget.TRIDENT).build(); + //.target(EnchantmentTarget.TRIDENT) + .build(); public static final ItemsCategory BOW = ItemsCategory.buildDirect(Material.BOW).slots(EquipmentSlot.HAND, EquipmentSlot.OFF_HAND) .localized(Lang.ITEM_CATEGORY_BOW) - .target(EnchantmentTarget.BOW).build(); + //.target(EnchantmentTarget.BOW) + .build(); public static final ItemsCategory CROSSBOW = ItemsCategory.buildDirect(Material.CROSSBOW).slots(EquipmentSlot.HAND, EquipmentSlot.OFF_HAND) .localized(Lang.ITEM_CATEGORY_CROSSBOW) - .target(EnchantmentTarget.CROSSBOW).build(); + //.target(EnchantmentTarget.CROSSBOW) + .build(); public static final ItemsCategory FISHING_ROD = ItemsCategory.buildDirect(Material.FISHING_ROD).slots(EquipmentSlot.HAND, EquipmentSlot.OFF_HAND) .localized(Lang.ITEM_CATEGORY_FISHING_ROD) - .target(EnchantmentTarget.FISHING_ROD).build(); + //.target(EnchantmentTarget.FISHING_ROD) + .build(); public static final ItemsCategory SHIELD = ItemsCategory.buildDirect(Material.SHIELD).slots(EquipmentSlot.OFF_HAND) .localized(Lang.ITEM_CATEGORY_SHIELD) - .target(EnchantmentTarget.BREAKABLE).build(); + //.target(EnchantmentTarget.BREAKABLE) + .build(); public static final ItemsCategory BREAKABLE = ItemsCategory.buildDirect(getItemsWithDurability()).slots(EquipmentSlot.values()) .localized(Lang.ITEM_CATEGORY_BREAKABLE) - .target(EnchantmentTarget.BREAKABLE).build(); + //.target(EnchantmentTarget.BREAKABLE) + .build(); public static final ItemsCategory ARMOR = ItemsCategory.buildRef(() -> { Set materials = new HashSet<>(); @@ -86,14 +99,14 @@ public class ItemCategories { materials.addAll(getItemsBySlot(EquipmentSlot.LEGS)); materials.addAll(getItemsBySlot(EquipmentSlot.FEET)); return materials; - }).slots(EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET).target(EnchantmentTarget.ARMOR).localized(Lang.ITEM_CATEGORY_ARMOR).build(); + }).slots(EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET)./*target(EnchantmentTarget.ARMOR).*/localized(Lang.ITEM_CATEGORY_ARMOR).build(); public static final ItemsCategory TOOL = ItemsCategory.buildDirect( Tag.ITEMS_AXES, Tag.ITEMS_HOES, Tag.ITEMS_PICKAXES, Tag.ITEMS_SHOVELS - ).slots(EquipmentSlot.HAND).target(EnchantmentTarget.TOOL).localized(Lang.ITEM_CATEGORY_TOOL).build(); + ).slots(EquipmentSlot.HAND)/*.target(EnchantmentTarget.TOOL)*/.localized(Lang.ITEM_CATEGORY_TOOL).build(); public static final ItemsCategory WEAPON = ItemsCategory.buildRef(() -> { @@ -104,7 +117,7 @@ public class ItemCategories { } return materials; - }).slots(EquipmentSlot.HAND).target(EnchantmentTarget.WEAPON).localized(Lang.ITEM_CATEGORY_WEAPON).build(); + }).slots(EquipmentSlot.HAND)./*target(EnchantmentTarget.WEAPON).*/localized(Lang.ITEM_CATEGORY_WEAPON).build(); public static final ItemsCategory BOWS = ItemsCategory.buildRef(() -> { @@ -115,7 +128,7 @@ public class ItemCategories { } return materials; - }).slots(EquipmentSlot.HAND, EquipmentSlot.OFF_HAND).target(EnchantmentTarget.BOW).localized(Lang.ITEM_CATEGORY_BOWS).build(); + }).slots(EquipmentSlot.HAND, EquipmentSlot.OFF_HAND)./*target(EnchantmentTarget.BOW).*/localized(Lang.ITEM_CATEGORY_BOWS).build(); public static final ItemsCategory TORSO = ItemsCategory.buildRef(() -> { @@ -126,7 +139,7 @@ public class ItemCategories { } return materials; - }).slots(EquipmentSlot.CHEST).target(EnchantmentTarget.ARMOR_TORSO).localized(Lang.ITEM_CATEGORY_TORSO).build(); + }).slots(EquipmentSlot.CHEST)./*target(EnchantmentTarget.ARMOR_TORSO).*/localized(Lang.ITEM_CATEGORY_TORSO).build(); public static final ItemsCategory ALL_RANGE_WEAPON = ItemsCategory.buildRef(() -> { @@ -136,7 +149,7 @@ public class ItemCategories { materials.addAll(TRIDENT.getMaterials()); materials.addAll(TOOL.getMaterials()); return materials; - }).slots(EquipmentSlot.HAND).target(EnchantmentTarget.BREAKABLE).localized(Lang.ITEM_CATEGORY_ALL_WEAPON).build(); + }).slots(EquipmentSlot.HAND)./*target(EnchantmentTarget.BREAKABLE).*/localized(Lang.ITEM_CATEGORY_ALL_WEAPON).build(); public static final ItemsCategory MINING_TOOLS = ItemsCategory.buildRef(() -> { Set materials = new HashSet<>(); @@ -144,7 +157,7 @@ public class ItemCategories { materials.addAll(PICKAXE.getMaterials()); materials.addAll(SHOVEL.getMaterials()); return materials; - }).slots(EquipmentSlot.HAND).target(EnchantmentTarget.TOOL).localized(Lang.ITEM_CATEGORY_MINING_TOOLS).build(); + }).slots(EquipmentSlot.HAND)./*target(EnchantmentTarget.TOOL).*/localized(Lang.ITEM_CATEGORY_MINING_TOOLS).build(); @NotNull diff --git a/Core/src/main/resources/lang/messages_ru.yml b/Core/src/main/resources/lang/messages_ru.yml deleted file mode 100644 index b216be8..0000000 --- a/Core/src/main/resources/lang/messages_ru.yml +++ /dev/null @@ -1,36 +0,0 @@ -Command: - List: - Desc: 'Меню дополнительных зачарований.' - Enchant: - Usage: '<зачарование> <уровень> [игрок] [слот]' - Desc: 'Зачарование предмета в руке.' - Book: - Usage: '<игрок> <зачарование> <уровень>' - Desc: 'Выдача книги с указанным зачарованием.' - Done: 'Выдана книга с зачарованием &6%enchant%&7 игроку &6%player_name%&7.' - TierBook: - Usage: '<игрок> <ранг> <уровень>' - Desc: 'Выдача книги с произвольным зачарованием указанного ранга.' - Error: '&cТакого ранга не существует!' - Done: 'Выдана книга с зачарованием ранга &6%tier_name%&7 игроку &6%player_name%&7.' -Error: - NoEnchant: '&cТакого зачарования не существует.' -FitItemType: - HELMET: 'Шлем' - CHESTPLATE: 'Нагрудник' - LEGGINGS: 'Поножи' - BOOTS: 'Ботинки' - ELYTRA: 'Элитры' - WEAPON: 'Оружие' - TOOL: 'Инструмент' - ARMOR: 'Броня' - SWORD: 'Меч' - TRIDENT: 'Трезубец' - AXE: 'Топор' - BOW: 'Лук' - CROSSBOW: 'Арбалет' - HOE: 'Мотыга' - PICKAXE: 'Кирка' - SHOVEL: 'Лопата' - FISHING_ROD: 'Удочка' - UNIVERSAL: 'Универсально' \ No newline at end of file diff --git a/Core/src/main/resources/plugin.yml b/Core/src/main/resources/plugin.yml index 2a368f7..cb70f5a 100644 --- a/Core/src/main/resources/plugin.yml +++ b/Core/src/main/resources/plugin.yml @@ -2,8 +2,8 @@ main: su.nightexpress.excellentenchants.EnchantsPlugin version: '${project.version}' name: ExcellentEnchants author: NightExpress -desciption: Amazing enchantments with seamless integration. +desciption: A lot of new enchantments properly integrated into the server! depend: [ nightcore ] softdepend: [ ProtocolLib, PlaceholderAPI, MythicMobs ] -api-version: 1.19 +api-version: 1.21 load: STARTUP \ No newline at end of file diff --git a/MC_1_20_6/pom.xml b/MC_1_20_6/pom.xml deleted file mode 100644 index 9c91da9..0000000 --- a/MC_1_20_6/pom.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - 4.0.0 - - su.nightexpress.excellentenchants - ExcellentEnchants - 4.1.0 - - - MC_1_20_6 - - - 21 - 21 - UTF-8 - - - - - org.spigotmc - spigot - 1.20.6-R0.1-SNAPSHOT - remapped-mojang - - - - su.nightexpress.excellentenchants - API - 4.1.0 - - - - su.nightexpress.excellentenchants - NMS - 4.1.0 - - - - - - - net.md-5 - specialsource-maven-plugin - 2.0.3 - - - package - - remap - - remap-obf - - org.spigotmc:minecraft-server:1.20.6-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:1.20.6-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:1.20.6-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.20.6-R0.1-SNAPSHOT:jar:remapped-obf - - - - - - - - \ No newline at end of file diff --git a/MC_1_20_6/pom.xml.versionsBackup b/MC_1_20_6/pom.xml.versionsBackup deleted file mode 100644 index c3d8843..0000000 --- a/MC_1_20_6/pom.xml.versionsBackup +++ /dev/null @@ -1,79 +0,0 @@ - - - 4.0.0 - - su.nightexpress.excellentenchants - ExcellentEnchants - 4.0.4 - - - MC_1_20_6 - - - 21 - 21 - UTF-8 - - - - - org.spigotmc - spigot - 1.20.6-R0.1-SNAPSHOT - remapped-mojang - - - - su.nightexpress.excellentenchants - API - 4.0.4 - - - - su.nightexpress.excellentenchants - NMS - 4.0.4 - - - - - - - net.md-5 - specialsource-maven-plugin - 2.0.3 - - - package - - remap - - remap-obf - - org.spigotmc:minecraft-server:1.20.6-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:1.20.6-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:1.20.6-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.20.6-R0.1-SNAPSHOT:jar:remapped-obf - - - - - - - - \ No newline at end of file diff --git a/MC_1_20_6/src/main/java/su/nightexpress/excellentenchants/CustomEnchantment.java b/MC_1_20_6/src/main/java/su/nightexpress/excellentenchants/CustomEnchantment.java deleted file mode 100644 index 4d1b85d..0000000 --- a/MC_1_20_6/src/main/java/su/nightexpress/excellentenchants/CustomEnchantment.java +++ /dev/null @@ -1,149 +0,0 @@ -package su.nightexpress.excellentenchants; - -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.ItemTags; -import net.minecraft.tags.TagKey; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.enchantment.Enchantment; -import org.bukkit.NamespacedKey; -import org.bukkit.craftbukkit.v1_20_R4.CraftEquipmentSlot; -import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_20_R4.util.CraftNamespacedKey; -import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.EnchantingBridge; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; -import su.nightexpress.excellentenchants.api.enchantment.Rarity; -import su.nightexpress.excellentenchants.api.enchantment.distribution.VanillaOptions; - -public class CustomEnchantment extends Enchantment { - - private final EnchantmentData enchantmentData; - - private VanillaOptions vanillaOptions; - - @NotNull - public static CustomEnchantment from(@NotNull EnchantmentData enchantmentData) { - TagKey category = nmsCategory(enchantmentData); - int weight = enchantmentData.getRarity().getWeight(); - int maxLevel = enchantmentData.getMaxLevel(); - Cost minCost = new Cost(enchantmentData.getMinCost().base(), enchantmentData.getMinCost().perLevel()); - Cost maxCost = new Cost(enchantmentData.getMaxCost().base(), enchantmentData.getMaxCost().perLevel()); - int anvilCost = enchantmentData.getAnvilCost(); - EquipmentSlot[] slots = nmsSlots(enchantmentData); - - EnchantmentDefinition definition = Enchantment.definition(category, weight, maxLevel, minCost, maxCost, anvilCost, slots); - return new CustomEnchantment(enchantmentData, definition); - } - - public CustomEnchantment(@NotNull EnchantmentData enchantmentData, @NotNull EnchantmentDefinition definition) { - super(definition); - this.enchantmentData = enchantmentData; - - if (enchantmentData.getDistributionOptions() instanceof VanillaOptions options) { - this.vanillaOptions = options; - } - } - - @Override - protected boolean checkCompatibility(Enchantment other) { - ResourceLocation location = BuiltInRegistries.ENCHANTMENT.getKey(other); - if (location == null) return false; - - NamespacedKey key = CraftNamespacedKey.fromMinecraft(location); - String id = key.getKey(); - - // Expensive probably. - //org.bukkit.enchantments.Enchantment bukkit = CraftEnchantment.minecraftToBukkit(other); - //String id = bukkit.getKey().getKey(); - - return !this.enchantmentData.getConflicts().contains(id); - } - - @Override - public boolean canEnchant(ItemStack item) { - if (!super.canEnchant(item)) return false; - - return this.canEnchant(CraftItemStack.asBukkitCopy(item)); - } - - public boolean canEnchant(@NotNull org.bukkit.inventory.ItemStack bukkitItem) { - if (!this.enchantmentData.checkEnchantLimit(bukkitItem)) return false; - - /*if (!this.enchantmentData.hasItemCategory()) { - if (this.enchantmentData.checkEnchantCategory(bukkitItem)) return true; - } - - return this.enchantmentData.checkItemCategory(bukkitItem);*/ - return this.enchantmentData.isSupportedItem(bukkitItem); - } - - @Override - public boolean isTreasureOnly() { - return this.enchantmentData.isTreasure() || this.isCurse(); - } - - @Override - public boolean isCurse() { - return this.enchantmentData.isCurse(); - } - - @Override - public boolean isTradeable() { - return this.vanillaOptions != null && this.vanillaOptions.isTradeable(); - } - - @Override - public boolean isDiscoverable() { - org.bukkit.inventory.ItemStack bukkitItem = EnchantingBridge.getEnchantingItem(); - if (bukkitItem != null && !this.enchantmentData.isPrimaryItem(bukkitItem)) { - return false; - } - - return this.vanillaOptions != null && this.vanillaOptions.isDiscoverable(); - } - - public static Rarity nmsRarity(@NotNull EnchantmentData data) { - return switch (data.getRarity()) { - case RARE -> Rarity.RARE; - case COMMON -> Rarity.COMMON; - case UNCOMMON -> Rarity.UNCOMMON; - case VERY_RARE -> Rarity.VERY_RARE; - }; - } - - @NotNull - public static TagKey nmsCategory(@NotNull EnchantmentData data) { - return switch (data.getSupportedItems().getTarget()) { - case WEAPON -> ItemTags.WEAPON_ENCHANTABLE; - case TOOL -> ItemTags.MINING_ENCHANTABLE; - case ARMOR -> ItemTags.ARMOR_ENCHANTABLE; - case BOW -> ItemTags.BOW_ENCHANTABLE; - case TRIDENT -> ItemTags.TRIDENT_ENCHANTABLE; - case CROSSBOW -> ItemTags.CROSSBOW_ENCHANTABLE; - case WEARABLE -> ItemTags.EQUIPPABLE_ENCHANTABLE; - case BREAKABLE -> ItemTags.DURABILITY_ENCHANTABLE; - case ARMOR_FEET -> ItemTags.FOOT_ARMOR_ENCHANTABLE; - case ARMOR_HEAD -> ItemTags.HEAD_ARMOR_ENCHANTABLE; - case ARMOR_LEGS -> ItemTags.LEG_ARMOR_ENCHANTABLE; - case ARMOR_TORSO -> ItemTags.CHEST_ARMOR_ENCHANTABLE; - case VANISHABLE -> ItemTags.VANISHING_ENCHANTABLE; - case FISHING_ROD -> ItemTags.FISHING_ENCHANTABLE; - default -> throw new IllegalStateException("Unexpected value: " + data.getSupportedItems().getTarget()); - }; - } - - public static EquipmentSlot[] nmsSlots(@NotNull EnchantmentData data) { - org.bukkit.inventory.EquipmentSlot[] slots = data.getSupportedItems().getSlots(); - EquipmentSlot[] nmsSlots = new EquipmentSlot[slots.length]; - - for (int index = 0; index < nmsSlots.length; index++) { - org.bukkit.inventory.EquipmentSlot bukkitSlot = slots[index]; - nmsSlots[index] = CraftEquipmentSlot.getNMS(bukkitSlot); - } - - return nmsSlots; - } -} diff --git a/MC_1_20_6/src/main/java/su/nightexpress/excellentenchants/Internal1_20_6.java b/MC_1_20_6/src/main/java/su/nightexpress/excellentenchants/Internal1_20_6.java deleted file mode 100644 index 689e2db..0000000 --- a/MC_1_20_6/src/main/java/su/nightexpress/excellentenchants/Internal1_20_6.java +++ /dev/null @@ -1,239 +0,0 @@ -package su.nightexpress.excellentenchants; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Registry; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.network.protocol.game.ClientboundAnimatePacket; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.util.Mth; -import net.minecraft.world.Container; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.item.ItemEntity; -import net.minecraft.world.entity.projectile.FishingHook; -import net.minecraft.world.inventory.EnchantmentMenu; -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.enchantment.EnchantmentInstance; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.LiquidBlock; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.shapes.CollisionContext; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_20_R4.CraftWorld; -import org.bukkit.craftbukkit.v1_20_R4.block.CraftBlock; -import org.bukkit.craftbukkit.v1_20_R4.block.CraftBlockType; -import org.bukkit.craftbukkit.v1_20_R4.enchantments.CraftEnchantment; -import org.bukkit.craftbukkit.v1_20_R4.entity.CraftFishHook; -import org.bukkit.craftbukkit.v1_20_R4.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_20_R4.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_20_R4.event.CraftEventFactory; -import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_20_R4.util.CraftNamespacedKey; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.FishHook; -import org.bukkit.entity.Item; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; -import su.nightexpress.excellentenchants.nms.EnchantNMS; -import su.nightexpress.nightcore.util.BukkitThing; -import su.nightexpress.nightcore.util.Reflex; -import su.nightexpress.nightcore.util.random.Rnd; - -import java.lang.reflect.Method; -import java.util.*; - -public class Internal1_20_6 implements EnchantNMS { - - @Override - public void unfreezeRegistry() { - Reflex.setFieldValue(BuiltInRegistries.ENCHANTMENT, "l", false); // MappedRegistry#frozen - Reflex.setFieldValue(BuiltInRegistries.ENCHANTMENT, "m", new IdentityHashMap<>()); // MappedRegistry#unregisteredIntrusiveHolders - } - - @Override - public void freezeRegistry() { - BuiltInRegistries.ENCHANTMENT.freeze(); - } - - @Override - public boolean isEnchantable(@NotNull ItemStack bukkitItem) { - net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(bukkitItem); - return nmsItem.getItem().isEnchantable(nmsItem); - } - - public void registerEnchantment(@NotNull EnchantmentData data) { - CustomEnchantment enchantment = CustomEnchantment.from(data); - Registry.register(BuiltInRegistries.ENCHANTMENT, data.getId(), enchantment); - - Enchantment bukkitEnchant = CraftEnchantment.minecraftToBukkit(enchantment); - data.setEnchantment(bukkitEnchant); - } - - private static final Method GET_ENCHANTS_LIST = Reflex.getMethod(EnchantmentMenu.class, "a", net.minecraft.world.item.ItemStack.class, Integer.TYPE, Integer.TYPE); - - @SuppressWarnings("unchecked") - @NotNull - @Override - public Map> getEnchantLists(@NotNull Inventory inventory, @NotNull ItemStack bukkitItem) { - Map> map = new HashMap<>(); - - // Returns SimpleContainer class assigned to 'enchantSlots' field. - Container container = ((CraftInventory) inventory).getInventory(); - - // Get parent (real EnchantmentMenu) object from SimpleContainer obtained above. - EnchantmentMenu enchantmentMenu = (EnchantmentMenu) Reflex.getFieldValue(container, "this$0"); - - net.minecraft.world.item.ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem); - - for (int button = 0; button < 3; button++) { - int cost = enchantmentMenu.costs[button]; - List list = (List) Reflex.invokeMethod(GET_ENCHANTS_LIST, enchantmentMenu, itemStack, button, cost); - - Map enchantments = new HashMap<>(); - - if (list != null && !list.isEmpty()) { - EnchantmentInstance random = Rnd.get(list); - enchantmentMenu.enchantClue[button] = BuiltInRegistries.ENCHANTMENT.getId(random.enchantment); - enchantmentMenu.levelClue[button] = random.level; - - for (EnchantmentInstance instance : list) { - ResourceLocation location = BuiltInRegistries.ENCHANTMENT.getKey(instance.enchantment); - if (location == null) continue; - - enchantments.put(BukkitThing.getEnchantment(CraftNamespacedKey.fromMinecraft(location).getKey()), instance.level); - } - } - - map.put(button, enchantments); - } - - return map; - } - - @Override - public void sendAttackPacket(@NotNull Player player, int id) { - CraftPlayer craftPlayer = (CraftPlayer) player; - ServerPlayer entity = craftPlayer.getHandle(); - ClientboundAnimatePacket packet = new ClientboundAnimatePacket(entity, id); - craftPlayer.getHandle().connection.send(packet); - - player.spigot().sendMessage(); - } - - /*@NotNull - public ItemStack setItemLore(@NotNull ItemStack item, @NotNull List lore) { - CraftItemStack craftItem = ensureCraftItemStack(item); - net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(craftItem); - - CompoundTag tag = nmsItem.getTag() == null ? new CompoundTag() : nmsItem.getTag(); - if (!tag.contains(net.minecraft.world.item.ItemStack.TAG_DISPLAY)) { - tag.put(net.minecraft.world.item.ItemStack.TAG_DISPLAY, new CompoundTag()); - } - - CompoundTag displayTag = tag.getCompound(net.minecraft.world.item.ItemStack.TAG_DISPLAY); - ListTag loreTag = new ListTag(); - for (int index = 0; index < lore.size(); index++) { - String text = lore.get(index); - String json = ComponentSerializer.toString(NightMessage.asComponent(text)); - loreTag.add(index, StringTag.valueOf(json)); - } - - displayTag.put(net.minecraft.world.item.ItemStack.TAG_LORE, loreTag); - return CraftItemStack.asBukkitCopy(nmsItem); - }*/ - - @NotNull - private static CraftItemStack ensureCraftItemStack(ItemStack item) { - return item instanceof CraftItemStack craftItem ? craftItem : CraftItemStack.asCraftCopy(item); - } - - @Override - public void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item, @NotNull EquipmentSlot slot) { - CraftFishHook craftFishHook = (CraftFishHook) hook; - FishingHook handle = craftFishHook.getHandle(); - - net.minecraft.world.entity.player.Player owner = handle.getPlayerOwner(); - if (owner == null) return; - - int result = handle.retrieve(CraftItemStack.asNMSCopy(item)); - - net.minecraft.world.entity.EquipmentSlot hand = slot == EquipmentSlot.HAND ? net.minecraft.world.entity.EquipmentSlot.MAINHAND : net.minecraft.world.entity.EquipmentSlot.OFFHAND; - - net.minecraft.world.item.ItemStack itemStack = owner.getItemBySlot(hand); - if (itemStack == null) return; - - itemStack.hurtAndBreak(result, handle.getPlayerOwner(), hand); - } - - @NotNull - @Override - public Material getItemBlockVariant(@NotNull Material material) { - ItemStack itemStack = new ItemStack(material); - net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - if (nmsStack.getItem() instanceof BlockItem blockItem) { - return CraftBlockType.minecraftToBukkit(blockItem.getBlock()); - } - return material; - } - - @Override - @NotNull - public Set handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) { - Entity entity = ((CraftLivingEntity) bukkitEntity).getHandle(); - BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()); - ServerLevel world = ((CraftWorld) bukkitEntity.getWorld()).getHandle(); - - int radius = Math.min(16, 2 + level); - BlockState bStone = Blocks.MAGMA_BLOCK.defaultBlockState(); - BlockPos.MutableBlockPos posAbove = new BlockPos.MutableBlockPos(); - - Set blocks = new HashSet<>(); - for (BlockPos posNear : BlockPos.betweenClosed(pos.offset(-radius, -1, -radius), pos.offset(radius, -1, radius))) { - if (!posNear.closerThan(entity.blockPosition(), radius)) continue; - - posAbove.set(posNear.getX(), posNear.getY() + 1, posNear.getZ()); - - BlockState bLavaAbove = world.getBlockState(posAbove); - BlockState bLava = world.getBlockState(posNear); - - if (!bLavaAbove.isAir()) continue; - if (!bLava.getBlock().equals(Blocks.LAVA)) continue; - if (bLava.getValue(LiquidBlock.LEVEL) != 0) continue; - if (!bStone.canSurvive(world, posNear)) continue; - if (!world.isUnobstructed(bStone, posNear, CollisionContext.empty())) continue; - if (!CraftEventFactory.handleBlockFormEvent(world, posNear, bStone, entity)) continue; - //world.scheduleTick(posNear, Blocks.STONE, Rnd.get(60, 120)); - - Location bukkitLoc = new Location(world.getWorld(), posNear.getX(), posNear.getY(), posNear.getZ()); - blocks.add(bukkitLoc.getBlock()); - } - return blocks; - } - - @NotNull - public Item popResource(@NotNull Block block, @NotNull ItemStack item) { - Level world = ((CraftWorld)block.getWorld()).getHandle(); - BlockPos pos = ((CraftBlock)block).getPosition(); - net.minecraft.world.item.ItemStack itemstack = CraftItemStack.asNMSCopy(item); - - float yMod = EntityType.ITEM.getHeight() / 2.0F; - double x = (pos.getX() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D); - double y = (pos.getY() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D) - yMod; - double z = (pos.getZ() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D); - - ItemEntity itemEntity = new ItemEntity(world, x, y, z, itemstack); - itemEntity.setDefaultPickUpDelay(); - return (Item) itemEntity.getBukkitEntity(); - } -} diff --git a/MC_1_21/pom.xml b/MC_1_21/pom.xml index 08ae9b0..8a49aa1 100644 --- a/MC_1_21/pom.xml +++ b/MC_1_21/pom.xml @@ -6,7 +6,7 @@ su.nightexpress.excellentenchants ExcellentEnchants - 4.1.0 + 4.2.0 MC_1_21 @@ -21,20 +21,20 @@ org.spigotmc spigot - 1.21-R0.1-SNAPSHOT + 1.21.1-R0.1-SNAPSHOT remapped-mojang su.nightexpress.excellentenchants API - 4.1.0 + 4.2.0 su.nightexpress.excellentenchants NMS - 4.1.0 + 4.2.0 @@ -52,9 +52,9 @@ remap-obf - org.spigotmc:minecraft-server:1.21-R0.1-SNAPSHOT:txt:maps-mojang + org.spigotmc:minecraft-server:1.21.1-R0.1-SNAPSHOT:txt:maps-mojang true - org.spigotmc:spigot:1.21-R0.1-SNAPSHOT:jar:remapped-mojang + org.spigotmc:spigot:1.21.1-R0.1-SNAPSHOT:jar:remapped-mojang true remapped-obf @@ -67,8 +67,8 @@ remap-spigot ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:1.21-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.21-R0.1-SNAPSHOT:jar:remapped-obf + org.spigotmc:minecraft-server:1.21.1-R0.1-SNAPSHOT:csrg:maps-spigot + org.spigotmc:spigot:1.21.1-R0.1-SNAPSHOT:jar:remapped-obf diff --git a/MC_1_21/src/main/java/su/nightexpress/excellentenchants/Internal_1_21.java b/MC_1_21/src/main/java/su/nightexpress/excellentenchants/Internal_1_21.java index df09c9b..07b4f5f 100644 --- a/MC_1_21/src/main/java/su/nightexpress/excellentenchants/Internal_1_21.java +++ b/MC_1_21/src/main/java/su/nightexpress/excellentenchants/Internal_1_21.java @@ -11,17 +11,16 @@ import net.minecraft.network.protocol.game.ClientboundAnimatePacket; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.tags.EnchantmentTags; import net.minecraft.tags.TagKey; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.EquipmentSlotGroup; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.projectile.FishingHook; import net.minecraft.world.flag.FeatureFlags; -import net.minecraft.world.inventory.EnchantmentMenu; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.Item; import net.minecraft.world.item.enchantment.Enchantment; @@ -31,7 +30,6 @@ import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.shapes.CollisionContext; import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_21_R1.CraftEquipmentSlot; @@ -51,33 +49,36 @@ import org.bukkit.entity.FishHook; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; -import su.nightexpress.excellentenchants.api.enchantment.ItemsCategory; -import su.nightexpress.excellentenchants.api.enchantment.distribution.VanillaOptions; +import su.nightexpress.excellentenchants.api.enchantment.*; +import su.nightexpress.excellentenchants.api.enchantment.bridge.FlameWalker; import su.nightexpress.excellentenchants.nms.EnchantNMS; import su.nightexpress.nightcore.NightPlugin; import su.nightexpress.nightcore.util.Reflex; +import su.nightexpress.nightcore.util.random.Rnd; import su.nightexpress.nightcore.util.text.NightMessage; -import java.lang.reflect.Method; import java.util.*; import java.util.function.BiConsumer; public class Internal_1_21 implements EnchantNMS { - private static final MinecraftServer SERVER; + private static final MinecraftServer SERVER; private static final Registry ENCHANTMENT_REGISTRY; + private static final Registry ITEM_REGISTRY; - private static final String HOLDER_SET_NAMED_CONTENTS_FIELD = "c"; // 'contents' field of the HolderSet.Named +// private static final String NETTY_NAME = "excellent_enchants_handler"; +// private static final String HANDLER_NAME = "EEPackets"; + + private static final String HOLDER_SET_NAMED_CONTENTS_FIELD = "c"; // 'contents' field of the HolderSet.Named private static final String HOLDER_SET_DIRECT_CONTENTS_FIELD = "b"; // 'contents' field of the HolderSet.Direct - private static final String HOLDER_REFERENCE_TAGS_FIELD = "b"; // 'tags' field of the Holder.Reference + private static final String HOLDER_REFERENCE_TAGS_FIELD = "b"; // 'tags' field of the Holder.Reference static { SERVER = ((CraftServer)Bukkit.getServer()).getServer(); ENCHANTMENT_REGISTRY = SERVER.registryAccess().registry(Registries.ENCHANTMENT).orElse(null); + ITEM_REGISTRY = SERVER.registryAccess().registry(Registries.ITEM).orElseThrow(); } private final NightPlugin plugin; @@ -97,29 +98,32 @@ public class Internal_1_21 implements EnchantNMS { ENCHANTMENT_REGISTRY.freeze(); } - @Override - public boolean isEnchantable(@NotNull ItemStack bukkitItem) { - net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(bukkitItem); - return nmsItem.getItem().isEnchantable(nmsItem); - } - - //HolderGetter itemRegistry = SERVER.registryAccess().lookupOrThrow(Registries.ITEM); //HolderLookup.RegistryLookup enchantRegistry = minecraftServer.registryAccess().lookupOrThrow(Registries.ENCHANTMENT); //VanillaRegistries.createLookup().lookup(Registries.ENCHANTMENT).get(); + // Create Enchantment reference. + //Holder.Reference reference = Holder.Reference.createStandAlone(ENCHANTMENT_REGISTRY.holderOwner(), key); + // Bind enchantment value to the reference (or it will be null). + //Reflex.setFieldValue(reference, "e", enchantment); + + @NotNull + private static ResourceKey createKey(@NotNull String name) { + return ResourceKey.create(Registries.ENCHANTMENT, ResourceLocation.withDefaultNamespace(name)); + } + @Override - public void addExclusives(@NotNull EnchantmentData data) { - Enchantment enchantment = ENCHANTMENT_REGISTRY.get(key(data.getId())); + public void addExclusives(@NotNull CustomEnchantment customEnchantment) { + Enchantment enchantment = ENCHANTMENT_REGISTRY.get(createKey(customEnchantment.getId())); if (enchantment == null) { - this.plugin.error(data.getId() + ": Could not set exclusive item list. Enchantment is not registered."); + this.plugin.error(customEnchantment.getId() + ": Could not set exclusive item list. Enchantment is not registered."); return; } HolderSet exclusiveSet = enchantment.exclusiveSet(); List> contents = new ArrayList<>(); - data.getConflicts().forEach(enchantId -> { - ResourceKey key = key(enchantId); + customEnchantment.getDefinition().getConflicts().forEach(enchantId -> { + ResourceKey key = createKey(enchantId); Holder.Reference reference = ENCHANTMENT_REGISTRY.getHolder(key).orElse(null); if (reference == null) return; @@ -129,122 +133,154 @@ public class Internal_1_21 implements EnchantNMS { Reflex.setFieldValue(exclusiveSet, HOLDER_SET_DIRECT_CONTENTS_FIELD, contents); } - public void registerEnchantment(@NotNull EnchantmentData data) { - ResourceKey key = key(data.getId()); + @Override + @NotNull + public org.bukkit.enchantments.Enchantment registerEnchantment(@NotNull CustomEnchantment customEnchantment) { + Definition customDefinition = customEnchantment.getDefinition(); - Component component = CraftChatMessage.fromJSON(NightMessage.asJson(data.getName())); - HolderSet.Named supportedItems = createItemSet("enchant_supported", data, data.getSupportedItems()); - HolderSet.Named primaryItems = createItemSet("enchant_primary", data, data.getPrimaryItems()); - int weight = data.getRarity().getWeight(); - int maxLevel = data.getMaxLevel(); - Enchantment.Cost minCost = new Enchantment.Cost(data.getMinCost().base(), data.getMinCost().perLevel()); - Enchantment.Cost maxCost = new Enchantment.Cost(data.getMaxCost().base(), data.getMaxCost().perLevel()); - int anvilCost = data.getAnvilCost(); - net.minecraft.world.entity.EquipmentSlotGroup[] slots = nmsSlots(data); + Component display = CraftChatMessage.fromJSON(NightMessage.asJson(customEnchantment.getFormattedName())); + HolderSet.Named supportedItems = createItemSet("enchant_supported", customEnchantment, customDefinition.getSupportedItems()); + HolderSet.Named primaryItems = createItemSet("enchant_primary", customEnchantment, customDefinition.getPrimaryItems()); + int weight = customDefinition.getRarity().getWeight(); + int maxLevel = customDefinition.getMaxLevel(); + Enchantment.Cost minCost = nmsCost(customDefinition.getMinCost()); + Enchantment.Cost maxCost = nmsCost(customDefinition.getMaxCost()); + int anvilCost = customDefinition.getAnvilCost(); + EquipmentSlotGroup[] slots = nmsSlots(customDefinition); Enchantment.EnchantmentDefinition definition = Enchantment.definition(supportedItems, primaryItems, weight, maxLevel, minCost, maxCost, anvilCost, slots); HolderSet exclusiveSet = HolderSet.direct(); + DataComponentMap.Builder builder = DataComponentMap.builder(); - Enchantment enchantment = new Enchantment(component, definition, exclusiveSet, DataComponentMap.builder().build()); + Enchantment enchantment = new Enchantment(display, definition, exclusiveSet, builder.build()); + // Create a new Holder for the custom enchantment. Holder.Reference reference = ENCHANTMENT_REGISTRY.createIntrusiveHolder(enchantment); - Registry.register(ENCHANTMENT_REGISTRY, data.getId(), enchantment); + // Add it into Registry. + Registry.register(ENCHANTMENT_REGISTRY, customEnchantment.getId(), enchantment); + + // Now it's possible to add/remove it from vanilla tags since we have a valid, registered Reference. + this.setupDistribution(customEnchantment, reference); + + // Return the bukkit mirror. + return CraftEnchantment.minecraftToBukkit(enchantment); + } + +// public void displayTags() { +// displayTag(EnchantmentTags.CURSE); +// displayTag(EnchantmentTags.TREASURE); +// displayTag(EnchantmentTags.NON_TREASURE); +// displayTag(EnchantmentTags.IN_ENCHANTING_TABLE); +// displayTag(EnchantmentTags.DOUBLE_TRADE_PRICE); +// displayTag(EnchantmentTags.ON_TRADED_EQUIPMENT); +// displayTag(EnchantmentTags.ON_MOB_SPAWN_EQUIPMENT); +// displayTag(EnchantmentTags.ON_RANDOM_LOOT); +// displayTag(EnchantmentTags.ARMOR_EXCLUSIVE); +// displayTag(EnchantmentTags.TRADEABLE); +// } +// +// public void displayTag(TagKey tagKey) { +// ENCHANTMENT_REGISTRY.getTag(tagKey).ifPresent(holders -> { +// System.out.println(tagKey + ": " + holders.stream().map(Holder::value).toList()); +// }); +// System.out.println(" "); +// } + + private void setupDistribution(@NotNull CustomEnchantment enchantment, @NotNull Holder.Reference reference) { boolean experimentalTrades = SERVER.getWorldData().enabledFeatures().contains(FeatureFlags.TRADE_REBALANCE); - // TODO More tags Random Loot, Mob Equipment, etc. - if (data.isCurse()) { + Distribution distribution = enchantment.getDistribution(); + + // Any enchantment can be treasure. + if (distribution.isTreasure()) { + addInTag(EnchantmentTags.TREASURE, reference); + addInTag(EnchantmentTags.DOUBLE_TRADE_PRICE, reference); + } + else addInTag(EnchantmentTags.NON_TREASURE, reference); + + // Any enchantment can be on random loot. + if (distribution.isOnRandomLoot()) { + addInTag(EnchantmentTags.ON_RANDOM_LOOT, reference); + } + + // Only non-treasure enchantments should be on mob equipment, traded equipment and non-rebalanced trades. + if (!distribution.isTreasure()) { + if (distribution.isOnMobSpawnEquipment()) { + addInTag(EnchantmentTags.ON_MOB_SPAWN_EQUIPMENT, reference); + } + + if (distribution.isOnTradedEquipment()) { + addInTag(EnchantmentTags.ON_TRADED_EQUIPMENT, reference); + } + + if (!experimentalTrades) { + if (distribution.isTradable()) { + addInTag(EnchantmentTags.TRADEABLE, reference); + } + else removeFromTag(EnchantmentTags.TRADEABLE, reference); + } + } + + // Any enchantment can be on rebalanced trades. + if (experimentalTrades && distribution.isTradable()) { + distribution.getTrades().forEach(tradeType -> { + addInTag(getTradeKey(tradeType), reference); + }); + } + + if (enchantment.isCurse()) { addInTag(EnchantmentTags.CURSE, reference); } else { - if (data.isTreasure()) { - addInTag(EnchantmentTags.TREASURE, reference); - } - else addInTag(EnchantmentTags.NON_TREASURE, reference); - - if (data.getDistributionOptions() instanceof VanillaOptions vanillaOptions) { - if (vanillaOptions.isTradeable()) { - if (experimentalTrades) { - addInTag(EnchantmentTags.TRADES_DESERT_COMMON, reference); - addInTag(EnchantmentTags.TRADES_JUNGLE_COMMON, reference); - addInTag(EnchantmentTags.TRADES_PLAINS_COMMON, reference); - addInTag(EnchantmentTags.TRADES_SAVANNA_COMMON, reference); - addInTag(EnchantmentTags.TRADES_SNOW_COMMON, reference); - addInTag(EnchantmentTags.TRADES_SWAMP_COMMON, reference); - addInTag(EnchantmentTags.TRADES_TAIGA_COMMON, reference); - addInTag(EnchantmentTags.TRADES_DESERT_SPECIAL, reference); - addInTag(EnchantmentTags.TRADES_JUNGLE_SPECIAL, reference); - addInTag(EnchantmentTags.TRADES_PLAINS_SPECIAL, reference); - addInTag(EnchantmentTags.TRADES_SAVANNA_SPECIAL, reference); - addInTag(EnchantmentTags.TRADES_SNOW_SPECIAL, reference); - addInTag(EnchantmentTags.TRADES_SWAMP_SPECIAL, reference); - addInTag(EnchantmentTags.TRADES_TAIGA_SPECIAL, reference); - } - else { - addInTag(EnchantmentTags.TRADEABLE, reference); - } - } - else removeFromTag(EnchantmentTags.TRADEABLE, reference); - - if (vanillaOptions.isDiscoverable()) { + // Only non-curse and non-treasure enchantments should go in enchanting table. + if (!distribution.isTreasure()) { + if (distribution.isDiscoverable()) { addInTag(EnchantmentTags.IN_ENCHANTING_TABLE, reference); } else removeFromTag(EnchantmentTags.IN_ENCHANTING_TABLE, reference); } } - - org.bukkit.enchantments.Enchantment bukkitEnchant = CraftEnchantment.minecraftToBukkit(enchantment); - data.setEnchantment(bukkitEnchant); } private void addInTag(@NotNull TagKey tagKey, @NotNull Holder.Reference reference) { - modfiyTag(tagKey, reference, List::add); + modfiyTag(ENCHANTMENT_REGISTRY, tagKey, reference, List::add); } private void removeFromTag(@NotNull TagKey tagKey, @NotNull Holder.Reference reference) { - modfiyTag(tagKey, reference, List::remove); + modfiyTag(ENCHANTMENT_REGISTRY, tagKey, reference, List::remove); } - private void modfiyTag(@NotNull TagKey tagKey, - @NotNull Holder.Reference reference, - @NotNull BiConsumer>, Holder.Reference> consumer) { - // Get HolderSet of the TagKey - HolderSet.Named holders = ENCHANTMENT_REGISTRY.getTag(tagKey).orElse(null); + @SuppressWarnings("unchecked") + private void modfiyTag(@NotNull Registry registry, + @NotNull TagKey tagKey, + @NotNull Holder.Reference reference, + @NotNull BiConsumer>, Holder.Reference> consumer) { + + HolderSet.Named holders = registry.getTag(tagKey).orElse(null); if (holders == null) { this.plugin.warn(tagKey + ": Could not modify HolderSet. HolderSet is NULL."); return; } - // Create Enchantment reference. - //Holder.Reference reference = Holder.Reference.createStandAlone(ENCHANTMENT_REGISTRY.holderOwner(), key); - // Bind enchantment value to the reference (or it will be null). - //Reflex.setFieldValue(reference, "e", enchantment); - - modfiyHolderSetContents(holders, reference, consumer); - } - - @SuppressWarnings("unchecked") - private static void modfiyHolderSetContents(@NotNull HolderSet.Named holders, - @NotNull Holder.Reference reference, - @NotNull BiConsumer>, Holder.Reference> consumer) { - - // We must use reflection to get a mutable Holder list from the HolderSet. + // We must use reflection to get a Holder list from the HolderSet and make it mutable. List> contents = new ArrayList<>((List>) Reflex.getFieldValue(holders, HOLDER_SET_NAMED_CONTENTS_FIELD)); + // Do something with it. consumer.accept(contents, reference); + // Assign it back to the HolderSet. Reflex.setFieldValue(holders, HOLDER_SET_NAMED_CONTENTS_FIELD, contents); } @SuppressWarnings("unchecked") - private static HolderSet.Named createItemSet(@NotNull String prefix, @NotNull EnchantmentData data, @NotNull ItemsCategory category) { - Registry items = SERVER.registryAccess().registry(Registries.ITEM).orElseThrow(); + private static HolderSet.Named createItemSet(@NotNull String prefix, @NotNull CustomEnchantment data, @NotNull ItemsCategory category) { TagKey customKey = TagKey.create(Registries.ITEM, ResourceLocation.withDefaultNamespace(prefix + "/" + data.getId())); - HolderSet.Named customItems = items.getOrCreateTag(customKey); + HolderSet.Named customItems = ITEM_REGISTRY.getOrCreateTag(customKey); List> holders = new ArrayList<>(); category.getMaterials().forEach(material -> { ResourceLocation location = CraftNamespacedKey.toMinecraft(material.getKey()); - Holder.Reference holder = items.getHolder(location).orElse(null); + Holder.Reference holder = ITEM_REGISTRY.getHolder(location).orElse(null); if (holder == null) return; // We must reassign the 'tags' field value because of the HolderSet#contains(Holder holder) behavior. @@ -262,31 +298,47 @@ public class Internal_1_21 implements EnchantNMS { return customItems; } - private static ResourceKey key(String name) { - return ResourceKey.create(Registries.ENCHANTMENT, ResourceLocation.withDefaultNamespace(name)); + + + + @NotNull + private static TagKey getTradeKey(@NotNull TradeType tradeType) { + return switch (tradeType) { + case DESERT_COMMON -> EnchantmentTags.TRADES_DESERT_COMMON; + case DESERT_SPECIAL -> EnchantmentTags.TRADES_DESERT_SPECIAL; + case PLAINS_COMMON -> EnchantmentTags.TRADES_PLAINS_COMMON; + case PLAINS_SPECIAL -> EnchantmentTags.TRADES_PLAINS_SPECIAL; + case SAVANNA_COMMON -> EnchantmentTags.TRADES_SAVANNA_COMMON; + case SAVANNA_SPECIAL -> EnchantmentTags.TRADES_SAVANNA_SPECIAL; + case JUNGLE_COMMON -> EnchantmentTags.TRADES_JUNGLE_COMMON; + case JUNGLE_SPECIAL -> EnchantmentTags.TRADES_JUNGLE_SPECIAL; + case SNOW_COMMON -> EnchantmentTags.TRADES_SNOW_COMMON; + case SNOW_SPECIAL -> EnchantmentTags.TRADES_SNOW_SPECIAL; + case SWAMP_COMMON -> EnchantmentTags.TRADES_SWAMP_COMMON; + case SWAMP_SPECIAL -> EnchantmentTags.TRADES_SWAMP_SPECIAL; + case TAIGA_COMMON -> EnchantmentTags.TRADES_TAIGA_COMMON; + case TAIGA_SPECIAL -> EnchantmentTags.TRADES_TAIGA_SPECIAL; + }; + } + + @NotNull + private static Enchantment.Cost nmsCost(@NotNull Cost cost) { + return new Enchantment.Cost(cost.base(), cost.perLevel()); } @SuppressWarnings("UnstableApiUsage") - public static net.minecraft.world.entity.EquipmentSlotGroup[] nmsSlots(@NotNull EnchantmentData data) { - org.bukkit.inventory.EquipmentSlot[] slots = data.getSupportedItems().getSlots(); - net.minecraft.world.entity.EquipmentSlotGroup[] nmsSlots = new net.minecraft.world.entity.EquipmentSlotGroup[slots.length]; + private static EquipmentSlotGroup[] nmsSlots(@NotNull Definition definition) { + EquipmentSlot[] slots = definition.getSupportedItems().getSlots(); + EquipmentSlotGroup[] nmsSlots = new EquipmentSlotGroup[slots.length]; for (int index = 0; index < nmsSlots.length; index++) { - org.bukkit.inventory.EquipmentSlot bukkitSlot = slots[index]; + EquipmentSlot bukkitSlot = slots[index]; nmsSlots[index] = CraftEquipmentSlot.getNMSGroup(bukkitSlot.getGroup()); } return nmsSlots; } - private static final Method GET_ENCHANTS_LIST = Reflex.getMethod(EnchantmentMenu.class, "a", net.minecraft.world.item.ItemStack.class, Integer.TYPE, Integer.TYPE); - - @NotNull - @Override - public Map> getEnchantLists(@NotNull Inventory inventory, @NotNull ItemStack bukkitItem) { - return Collections.emptyMap(); - } - @Override public void sendAttackPacket(@NotNull Player player, int id) { CraftPlayer craftPlayer = (CraftPlayer) player; @@ -327,14 +379,13 @@ public class Internal_1_21 implements EnchantNMS { } @Override - @NotNull - public Set handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) { + public boolean handleFlameWalker(@NotNull FlameWalker flameWalker, @NotNull LivingEntity bukkitEntity, int level) { Entity entity = ((CraftLivingEntity) bukkitEntity).getHandle(); - BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()); - ServerLevel world = ((CraftWorld) bukkitEntity.getWorld()).getHandle(); + BlockPos pos = entity.blockPosition(); + Level world = entity.level(); - int radius = Math.min(16, 2 + level); - BlockState bStone = Blocks.MAGMA_BLOCK.defaultBlockState(); + int radius = (int) flameWalker.getRadius().getValue(level); + BlockState magmaState = Blocks.MAGMA_BLOCK.defaultBlockState(); BlockPos.MutableBlockPos posAbove = new BlockPos.MutableBlockPos(); Set blocks = new HashSet<>(); @@ -343,21 +394,22 @@ public class Internal_1_21 implements EnchantNMS { posAbove.set(posNear.getX(), posNear.getY() + 1, posNear.getZ()); - BlockState bLavaAbove = world.getBlockState(posAbove); - BlockState bLava = world.getBlockState(posNear); + BlockState aboveLava = world.getBlockState(posAbove); + BlockState lavaState = world.getBlockState(posNear); - if (!bLavaAbove.isAir()) continue; - if (!bLava.getBlock().equals(Blocks.LAVA)) continue; - if (bLava.getValue(LiquidBlock.LEVEL) != 0) continue; - if (!bStone.canSurvive(world, posNear)) continue; - if (!world.isUnobstructed(bStone, posNear, CollisionContext.empty())) continue; - if (!CraftEventFactory.handleBlockFormEvent(world, posNear, bStone, entity)) continue; - //world.scheduleTick(posNear, Blocks.STONE, Rnd.get(60, 120)); + if (!aboveLava.isAir()) continue; + if (!lavaState.getBlock().equals(Blocks.LAVA)) continue; + if (lavaState.getValue(LiquidBlock.LEVEL) != 0) continue; + if (!magmaState.canSurvive(world, posNear)) continue; + if (!world.isUnobstructed(magmaState, posNear, CollisionContext.empty())) continue; + if (!CraftEventFactory.handleBlockFormEvent(world, posNear, magmaState, entity)) continue; - Location bukkitLoc = new Location(world.getWorld(), posNear.getX(), posNear.getY(), posNear.getZ()); - blocks.add(bukkitLoc.getBlock()); + blocks.add(CraftBlock.at(world, posNear)); } - return blocks; + + blocks.forEach(block -> FlameWalker.addBlock(block, Rnd.getDouble(flameWalker.getBlockDecayTime(level)) + 1)); + + return !blocks.isEmpty(); } @NotNull @@ -375,4 +427,34 @@ public class Internal_1_21 implements EnchantNMS { itemEntity.setDefaultPickUpDelay(); return (org.bukkit.entity.Item) itemEntity.getBukkitEntity(); } + +// public void addPacketListener(@NotNull Player player) { +// ServerPlayer serverPlayer = ((CraftPlayer)player).getHandle(); +// Connection connection = (Connection) Reflex.getFieldValue(serverPlayer.connection, "connection"); +// +// connection.channel.pipeline().addBefore(NETTY_NAME, HANDLER_NAME, new ChannelDuplexHandler() { +// @Override +// public void write(ChannelHandlerContext context, Object packet, ChannelPromise promise) throws Exception { +// if (packet instanceof ClientboundContainerSetSlotPacket slotPacket) { +// +// } +// super.write(context, packet, promise); +// } +// +// @Override +// public void channelRead(ChannelHandlerContext context, Object packet) throws Exception { +// super.channelRead(context, packet); +// } +// }); +// } +// +// public void removePacketListener(@NotNull Player player) { +// ServerPlayer serverPlayer = ((CraftPlayer)player).getHandle(); +// Connection connection = (Connection) Reflex.getFieldValue(serverPlayer.connection, "connection"); +// +// ChannelPipeline pipeline = connection.channel.pipeline(); +// if (pipeline.get(HANDLER_NAME) != null) { +// pipeline.remove(HANDLER_NAME); +// } +// } } \ No newline at end of file diff --git a/NMS/pom.xml b/NMS/pom.xml index 2c4352d..fa25e67 100644 --- a/NMS/pom.xml +++ b/NMS/pom.xml @@ -5,7 +5,7 @@ ExcellentEnchants su.nightexpress.excellentenchants - 4.1.0 + 4.2.0 4.0.0 @@ -28,12 +28,13 @@ org.spigotmc spigot-api - 1.20.4-R0.1-SNAPSHOT + 1.21.1-R0.1-SNAPSHOT + su.nightexpress.excellentenchants API - 4.1.0 + 4.2.0 diff --git a/NMS/src/main/java/su/nightexpress/excellentenchants/nms/EnchantNMS.java b/NMS/src/main/java/su/nightexpress/excellentenchants/nms/EnchantNMS.java index c397bb2..be2a200 100644 --- a/NMS/src/main/java/su/nightexpress/excellentenchants/nms/EnchantNMS.java +++ b/NMS/src/main/java/su/nightexpress/excellentenchants/nms/EnchantNMS.java @@ -1,6 +1,5 @@ package su.nightexpress.excellentenchants.nms; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.enchantments.Enchantment; @@ -9,14 +8,10 @@ import org.bukkit.entity.Item; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; - -import java.util.List; -import java.util.Map; -import java.util.Set; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.bridge.FlameWalker; public interface EnchantNMS { @@ -24,25 +19,17 @@ public interface EnchantNMS { void freezeRegistry(); - //void registerEnchantments(@NotNull List list); + void addExclusives(@NotNull CustomEnchantment data); - boolean isEnchantable(@NotNull ItemStack bukkitItem); - - default void addExclusives(@NotNull EnchantmentData data) { - - } - - void registerEnchantment(@NotNull EnchantmentData enchantment); + @NotNull Enchantment registerEnchantment(@NotNull CustomEnchantment enchantment); void sendAttackPacket(@NotNull Player player, int id); void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item, @NotNull EquipmentSlot slot); - @NotNull Map> getEnchantLists(@NotNull Inventory inventory, @NotNull ItemStack bukkitItem); - @NotNull Material getItemBlockVariant(@NotNull Material material); - @NotNull Set handleFlameWalker(@NotNull LivingEntity entity, @NotNull Location location, int level); + boolean handleFlameWalker(@NotNull FlameWalker flameWalker, @NotNull LivingEntity entity, int level); @NotNull Item popResource(@NotNull Block block, @NotNull ItemStack item); } diff --git a/V1_19_R3/pom.xml b/V1_19_R3/pom.xml deleted file mode 100644 index 1ccd5ae..0000000 --- a/V1_19_R3/pom.xml +++ /dev/null @@ -1,72 +0,0 @@ - - - - ExcellentEnchants - su.nightexpress.excellentenchants - 4.1.0 - - 4.0.0 - - V1_19_R3 - - - 21 - 21 - UTF-8 - - - - - org.spigotmc - spigot - 1.19.4-R0.1-SNAPSHOT - remapped-mojang - - - su.nightexpress.excellentenchants - NMS - 4.1.0 - - - - - - - net.md-5 - specialsource-maven-plugin - 2.0.3 - - - package - - remap - - remap-obf - - org.spigotmc:minecraft-server:1.19.4-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:1.19.4-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:1.19.4-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.19.4-R0.1-SNAPSHOT:jar:remapped-obf - - - - - - - - \ No newline at end of file diff --git a/V1_19_R3/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R3/CustomEnchantment.java b/V1_19_R3/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R3/CustomEnchantment.java deleted file mode 100644 index 9ca2efa..0000000 --- a/V1_19_R3/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R3/CustomEnchantment.java +++ /dev/null @@ -1,147 +0,0 @@ -package su.nightexpress.excellentenchants.nms.v1_19_R3; - -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.enchantment.Enchantment; -import net.minecraft.world.item.enchantment.EnchantmentCategory; -import org.bukkit.NamespacedKey; -import org.bukkit.craftbukkit.v1_19_R3.CraftEquipmentSlot; -import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_19_R3.util.CraftNamespacedKey; -import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.EnchantingBridge; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; -import su.nightexpress.excellentenchants.api.enchantment.distribution.VanillaOptions; - -public class CustomEnchantment extends Enchantment { - - private final EnchantmentData enchantmentData; - - private VanillaOptions vanillaOptions; - - public CustomEnchantment(@NotNull EnchantmentData enchantmentData) { - super(nmsRarity(enchantmentData), nmsCategory(enchantmentData), nmsSlots(enchantmentData)); - this.enchantmentData = enchantmentData; - - if (enchantmentData.getDistributionOptions() instanceof VanillaOptions options) { - this.vanillaOptions = options; - } - } - - @Override - public int getMaxLevel() { - return this.enchantmentData.getMaxLevel(); - } - - @Override - public int getMinCost(int level) { - return this.enchantmentData.getMinCost(level); - } - - @Override - public int getMaxCost(int level) { - return this.enchantmentData.getMaxCost(level); - } - - @Override - protected boolean checkCompatibility(Enchantment other) { - ResourceLocation location = BuiltInRegistries.ENCHANTMENT.getKey(other); - if (location == null) return false; - - NamespacedKey key = CraftNamespacedKey.fromMinecraft(location); - String id = key.getKey(); - - // Expensive probably. - //org.bukkit.enchantments.Enchantment bukkit = CraftEnchantment.minecraftToBukkit(other); - //String id = bukkit.getKey().getKey(); - - return !this.enchantmentData.getConflicts().contains(id); - } - - @Override - public boolean canEnchant(ItemStack item) { - if (!super.canEnchant(item)) return false; - - return this.canEnchant(CraftItemStack.asBukkitCopy(item)); - } - - public boolean canEnchant(@NotNull org.bukkit.inventory.ItemStack bukkitItem) { - if (!this.enchantmentData.checkEnchantLimit(bukkitItem)) return false; - - /*if (!this.enchantmentData.hasItemCategory()) { - if (this.enchantmentData.checkEnchantCategory(bukkitItem)) return true; - } - - return this.enchantmentData.checkItemCategory(bukkitItem);*/ - return this.enchantmentData.isSupportedItem(bukkitItem); - } - - @Override - public boolean isTreasureOnly() { - return this.enchantmentData.isTreasure() || this.isCurse(); - } - - @Override - public boolean isCurse() { - return this.enchantmentData.isCurse(); - } - - @Override - public boolean isTradeable() { - return this.vanillaOptions != null && this.vanillaOptions.isTradeable(); - } - - @Override - public boolean isDiscoverable() { - org.bukkit.inventory.ItemStack bukkitItem = EnchantingBridge.getEnchantingItem(); - if (bukkitItem != null && !this.enchantmentData.isPrimaryItem(bukkitItem)) { - return false; - } - - return this.vanillaOptions != null && this.vanillaOptions.isDiscoverable(); - } - - public static Rarity nmsRarity(@NotNull EnchantmentData data) { - return switch (data.getRarity()) { - case RARE -> Rarity.RARE; - case COMMON -> Rarity.COMMON; - case UNCOMMON -> Rarity.UNCOMMON; - case VERY_RARE -> Rarity.VERY_RARE; - }; - } - - @NotNull - public static EnchantmentCategory nmsCategory(@NotNull EnchantmentData data) { - return switch (data.getSupportedItems().getTarget()) { - case WEAPON -> EnchantmentCategory.WEAPON; - case TOOL -> EnchantmentCategory.DIGGER; - case ARMOR -> EnchantmentCategory.ARMOR; - case BOW -> EnchantmentCategory.BOW; - case TRIDENT -> EnchantmentCategory.TRIDENT; - case CROSSBOW -> EnchantmentCategory.CROSSBOW; - case WEARABLE -> EnchantmentCategory.WEARABLE; - case BREAKABLE -> EnchantmentCategory.BREAKABLE; - case ARMOR_FEET -> EnchantmentCategory.ARMOR_FEET; - case ARMOR_HEAD -> EnchantmentCategory.ARMOR_HEAD; - case ARMOR_LEGS -> EnchantmentCategory.ARMOR_LEGS; - case ARMOR_TORSO -> EnchantmentCategory.ARMOR_CHEST; - case VANISHABLE -> EnchantmentCategory.VANISHABLE; - case FISHING_ROD -> EnchantmentCategory.FISHING_ROD; - default -> throw new IllegalStateException("Unexpected value: " + data.getSupportedItems().getTarget()); - }; - } - - public static EquipmentSlot[] nmsSlots(@NotNull EnchantmentData data) { - org.bukkit.inventory.EquipmentSlot[] slots = data.getSupportedItems().getSlots(); - EquipmentSlot[] nmsSlots = new EquipmentSlot[slots.length]; - - for (int index = 0; index < nmsSlots.length; index++) { - org.bukkit.inventory.EquipmentSlot bukkitSlot = slots[index]; - nmsSlots[index] = CraftEquipmentSlot.getNMS(bukkitSlot); - } - - return nmsSlots; - } -} diff --git a/V1_19_R3/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R3/V1_19_R3.java b/V1_19_R3/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R3/V1_19_R3.java deleted file mode 100644 index dcb97f4..0000000 --- a/V1_19_R3/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R3/V1_19_R3.java +++ /dev/null @@ -1,216 +0,0 @@ -package su.nightexpress.excellentenchants.nms.v1_19_R3; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Registry; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.network.protocol.game.ClientboundAnimatePacket; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.util.Mth; -import net.minecraft.world.Container; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.item.ItemEntity; -import net.minecraft.world.entity.projectile.FishingHook; -import net.minecraft.world.inventory.EnchantmentMenu; -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.enchantment.EnchantmentInstance; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.LiquidBlock; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.shapes.CollisionContext; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_19_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_19_R3.block.CraftBlock; -import org.bukkit.craftbukkit.v1_19_R3.enchantments.CraftEnchantment; -import org.bukkit.craftbukkit.v1_19_R3.entity.CraftFishHook; -import org.bukkit.craftbukkit.v1_19_R3.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_19_R3.event.CraftEventFactory; -import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_19_R3.util.CraftMagicNumbers; -import org.bukkit.craftbukkit.v1_19_R3.util.CraftNamespacedKey; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.FishHook; -import org.bukkit.entity.Item; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; -import su.nightexpress.excellentenchants.nms.EnchantNMS; -import su.nightexpress.nightcore.util.BukkitThing; -import su.nightexpress.nightcore.util.Reflex; -import su.nightexpress.nightcore.util.random.Rnd; - -import java.lang.reflect.Method; -import java.util.*; - -public class V1_19_R3 implements EnchantNMS { - - @Override - public void unfreezeRegistry() { - Reflex.setFieldValue(BuiltInRegistries.ENCHANTMENT, "l", false); - Reflex.setFieldValue(BuiltInRegistries.ENCHANTMENT, "m", new IdentityHashMap<>()); - Reflex.setFieldValue(Enchantment.class, "acceptingNew", true); - } - - @Override - public void freezeRegistry() { - Enchantment.stopAcceptingRegistrations(); - BuiltInRegistries.ENCHANTMENT.freeze(); - } - - @Override - public boolean isEnchantable(@NotNull ItemStack bukkitItem) { - net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(bukkitItem); - return nmsItem.getItem().isEnchantable(nmsItem); - } - - @Override - public void registerEnchantment(@NotNull EnchantmentData data) { - CustomEnchantment customEnchantment = new CustomEnchantment(data); - BuiltInRegistries.ENCHANTMENT.createIntrusiveHolder(customEnchantment); - Registry.register(BuiltInRegistries.ENCHANTMENT, data.getId(), customEnchantment); - - CraftEnchantment craftEnchantment = new CraftEnchantment(customEnchantment); - Enchantment.registerEnchantment(craftEnchantment); - data.setEnchantment(craftEnchantment); - } - - private static final Method GET_ENCHANTS_LIST = Reflex.getMethod(EnchantmentMenu.class, "a", net.minecraft.world.item.ItemStack.class, Integer.TYPE, Integer.TYPE); - - @SuppressWarnings("unchecked") - @NotNull - @Override - public Map> getEnchantLists(@NotNull Inventory inventory, @NotNull ItemStack bukkitItem) { - Map> map = new HashMap<>(); - - // Returns SimpleContainer class assigned to 'enchantSlots' field. - Container container = ((CraftInventory) inventory).getInventory(); - - // Get parent (real EnchantmentMenu) object from SimpleContainer obtained above. - EnchantmentMenu enchantmentMenu = (EnchantmentMenu) Reflex.getFieldValue(container, "this$0"); - - net.minecraft.world.item.ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem); - - for (int button = 0; button < 3; button++) { - int cost = enchantmentMenu.costs[button]; - List list = (List) Reflex.invokeMethod(GET_ENCHANTS_LIST, enchantmentMenu, itemStack, button, cost); - - Map enchantments = new HashMap<>(); - - if (list != null && !list.isEmpty()) { - EnchantmentInstance random = Rnd.get(list); - enchantmentMenu.enchantClue[button] = BuiltInRegistries.ENCHANTMENT.getId(random.enchantment); - enchantmentMenu.levelClue[button] = random.level; - - for (EnchantmentInstance instance : list) { - ResourceLocation location = BuiltInRegistries.ENCHANTMENT.getKey(instance.enchantment); - if (location == null) continue; - - enchantments.put(BukkitThing.getEnchantment(CraftNamespacedKey.fromMinecraft(location).getKey()), instance.level); - } - } - - map.put(button, enchantments); - } - - return map; - } - - @Override - public void sendAttackPacket(@NotNull Player player, int id) { - CraftPlayer craftPlayer = (CraftPlayer) player; - Entity entity = craftPlayer.getHandle(); - ClientboundAnimatePacket packet = new ClientboundAnimatePacket(entity, id); - craftPlayer.getHandle().connection.send(packet); - } - - @Override - public void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item, @NotNull EquipmentSlot slot) { - CraftFishHook craftFishHook = (CraftFishHook) hook; - FishingHook handle = craftFishHook.getHandle(); - - net.minecraft.world.entity.player.Player owner = handle.getPlayerOwner(); - if (owner == null) return; - - int result = handle.retrieve(CraftItemStack.asNMSCopy(item)); - - net.minecraft.world.entity.EquipmentSlot hand = slot == EquipmentSlot.HAND ? net.minecraft.world.entity.EquipmentSlot.MAINHAND : net.minecraft.world.entity.EquipmentSlot.OFFHAND; - - net.minecraft.world.item.ItemStack itemStack = owner.getItemBySlot(hand); - if (itemStack == null) return; - - itemStack.hurtAndBreak(result, handle.getPlayerOwner(), player -> { - player.broadcastBreakEvent(hand); - }); - } - - @NotNull - @Override - public Material getItemBlockVariant(@NotNull Material material) { - ItemStack itemStack = new ItemStack(material); - net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - if (nmsStack.getItem() instanceof BlockItem blockItem) { - return CraftMagicNumbers.getMaterial(blockItem.getBlock()); - } - return material; - } - - @Override - @NotNull - public Set handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) { - Entity entity = ((CraftLivingEntity) bukkitEntity).getHandle(); - BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()); - ServerLevel world = ((CraftWorld) bukkitEntity.getWorld()).getHandle(); - - int radius = Math.min(16, 2 + level); - BlockState bStone = Blocks.MAGMA_BLOCK.defaultBlockState(); - BlockPos.MutableBlockPos posAbove = new BlockPos.MutableBlockPos(); - - Set blocks = new HashSet<>(); - for (BlockPos posNear : BlockPos.betweenClosed(pos.offset(-radius, -1, -radius), pos.offset(radius, -1, radius))) { - if (!posNear.closerThan(entity.blockPosition(), radius)) continue; - - posAbove.set(posNear.getX(), posNear.getY() + 1, posNear.getZ()); - - BlockState bLavaAbove = world.getBlockState(posAbove); - BlockState bLava = world.getBlockState(posNear); - - if (!bLavaAbove.isAir()) continue; - if (!bLava.getBlock().equals(Blocks.LAVA)) continue; - if (bLava.getValue(LiquidBlock.LEVEL) != 0) continue; - if (!bStone.canSurvive(world, posNear)) continue; - if (!world.isUnobstructed(bStone, posNear, CollisionContext.empty())) continue; - if (!CraftEventFactory.handleBlockFormEvent(world, posNear, bStone, entity)) continue; - //world.scheduleTick(posNear, Blocks.STONE, Rnd.get(60, 120)); - - Location bukkitLoc = new Location(world.getWorld(), posNear.getX(), posNear.getY(), posNear.getZ()); - blocks.add(bukkitLoc.getBlock()); - } - return blocks; - } - - @NotNull - public Item popResource(@NotNull Block block, @NotNull ItemStack item) { - Level world = ((CraftWorld)block.getWorld()).getHandle(); - BlockPos pos = ((CraftBlock)block).getPosition(); - net.minecraft.world.item.ItemStack itemstack = CraftItemStack.asNMSCopy(item); - - float yMod = EntityType.ITEM.getHeight() / 2.0F; - double x = (pos.getX() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D); - double y = (pos.getY() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D) - yMod; - double z = (pos.getZ() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D); - - ItemEntity itemEntity = new ItemEntity(world, x, y, z, itemstack); - itemEntity.setDefaultPickUpDelay(); - return (Item) itemEntity.getBukkitEntity(); - } -} diff --git a/V1_20_R1/pom.xml b/V1_20_R1/pom.xml deleted file mode 100644 index 2676e54..0000000 --- a/V1_20_R1/pom.xml +++ /dev/null @@ -1,72 +0,0 @@ - - - - ExcellentEnchants - su.nightexpress.excellentenchants - 4.1.0 - - 4.0.0 - - V1_20_R1 - - - 21 - 21 - UTF-8 - - - - - org.spigotmc - spigot - 1.20.1-R0.1-SNAPSHOT - remapped-mojang - - - su.nightexpress.excellentenchants - NMS - 4.1.0 - - - - - - - net.md-5 - specialsource-maven-plugin - 2.0.3 - - - package - - remap - - remap-obf - - org.spigotmc:minecraft-server:1.20.1-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:1.20.1-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:1.20.1-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.20.1-R0.1-SNAPSHOT:jar:remapped-obf - - - - - - - - \ No newline at end of file diff --git a/V1_20_R1/src/main/java/su/nightexpress/excellentenchants/nms/v1_20_R1/CustomEnchantment.java b/V1_20_R1/src/main/java/su/nightexpress/excellentenchants/nms/v1_20_R1/CustomEnchantment.java deleted file mode 100644 index 554fc51..0000000 --- a/V1_20_R1/src/main/java/su/nightexpress/excellentenchants/nms/v1_20_R1/CustomEnchantment.java +++ /dev/null @@ -1,147 +0,0 @@ -package su.nightexpress.excellentenchants.nms.v1_20_R1; - -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.enchantment.Enchantment; -import net.minecraft.world.item.enchantment.EnchantmentCategory; -import org.bukkit.NamespacedKey; -import org.bukkit.craftbukkit.v1_20_R1.CraftEquipmentSlot; -import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_20_R1.util.CraftNamespacedKey; -import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.EnchantingBridge; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; -import su.nightexpress.excellentenchants.api.enchantment.distribution.VanillaOptions; - -public class CustomEnchantment extends Enchantment { - - private final EnchantmentData enchantmentData; - - private VanillaOptions vanillaOptions; - - public CustomEnchantment(@NotNull EnchantmentData enchantmentData) { - super(nmsRarity(enchantmentData), nmsCategory(enchantmentData), nmsSlots(enchantmentData)); - this.enchantmentData = enchantmentData; - - if (enchantmentData.getDistributionOptions() instanceof VanillaOptions options) { - this.vanillaOptions = options; - } - } - - @Override - public int getMaxLevel() { - return this.enchantmentData.getMaxLevel(); - } - - @Override - public int getMinCost(int level) { - return this.enchantmentData.getMinCost(level); - } - - @Override - public int getMaxCost(int level) { - return this.enchantmentData.getMaxCost(level); - } - - @Override - protected boolean checkCompatibility(Enchantment other) { - ResourceLocation location = BuiltInRegistries.ENCHANTMENT.getKey(other); - if (location == null) return false; - - NamespacedKey key = CraftNamespacedKey.fromMinecraft(location); - String id = key.getKey(); - - // Expensive probably. - //org.bukkit.enchantments.Enchantment bukkit = CraftEnchantment.minecraftToBukkit(other); - //String id = bukkit.getKey().getKey(); - - return !this.enchantmentData.getConflicts().contains(id); - } - - @Override - public boolean canEnchant(ItemStack item) { - if (!super.canEnchant(item)) return false; - - return this.canEnchant(CraftItemStack.asBukkitCopy(item)); - } - - public boolean canEnchant(@NotNull org.bukkit.inventory.ItemStack bukkitItem) { - if (!this.enchantmentData.checkEnchantLimit(bukkitItem)) return false; - - /*if (!this.enchantmentData.hasItemCategory()) { - if (this.enchantmentData.checkEnchantCategory(bukkitItem)) return true; - } - - return this.enchantmentData.checkItemCategory(bukkitItem);*/ - return this.enchantmentData.isSupportedItem(bukkitItem); - } - - @Override - public boolean isTreasureOnly() { - return this.enchantmentData.isTreasure() || this.isCurse(); - } - - @Override - public boolean isCurse() { - return this.enchantmentData.isCurse(); - } - - @Override - public boolean isTradeable() { - return this.vanillaOptions != null && this.vanillaOptions.isTradeable(); - } - - @Override - public boolean isDiscoverable() { - org.bukkit.inventory.ItemStack bukkitItem = EnchantingBridge.getEnchantingItem(); - if (bukkitItem != null && !this.enchantmentData.isPrimaryItem(bukkitItem)) { - return false; - } - - return this.vanillaOptions != null && this.vanillaOptions.isDiscoverable(); - } - - public static Rarity nmsRarity(@NotNull EnchantmentData data) { - return switch (data.getRarity()) { - case RARE -> Rarity.RARE; - case COMMON -> Rarity.COMMON; - case UNCOMMON -> Rarity.UNCOMMON; - case VERY_RARE -> Rarity.VERY_RARE; - }; - } - - @NotNull - public static EnchantmentCategory nmsCategory(@NotNull EnchantmentData data) { - return switch (data.getSupportedItems().getTarget()) { - case WEAPON -> EnchantmentCategory.WEAPON; - case TOOL -> EnchantmentCategory.DIGGER; - case ARMOR -> EnchantmentCategory.ARMOR; - case BOW -> EnchantmentCategory.BOW; - case TRIDENT -> EnchantmentCategory.TRIDENT; - case CROSSBOW -> EnchantmentCategory.CROSSBOW; - case WEARABLE -> EnchantmentCategory.WEARABLE; - case BREAKABLE -> EnchantmentCategory.BREAKABLE; - case ARMOR_FEET -> EnchantmentCategory.ARMOR_FEET; - case ARMOR_HEAD -> EnchantmentCategory.ARMOR_HEAD; - case ARMOR_LEGS -> EnchantmentCategory.ARMOR_LEGS; - case ARMOR_TORSO -> EnchantmentCategory.ARMOR_CHEST; - case VANISHABLE -> EnchantmentCategory.VANISHABLE; - case FISHING_ROD -> EnchantmentCategory.FISHING_ROD; - default -> throw new IllegalStateException("Unexpected value: " + data.getSupportedItems().getTarget()); - }; - } - - public static EquipmentSlot[] nmsSlots(@NotNull EnchantmentData data) { - org.bukkit.inventory.EquipmentSlot[] slots = data.getSupportedItems().getSlots(); - EquipmentSlot[] nmsSlots = new EquipmentSlot[slots.length]; - - for (int index = 0; index < nmsSlots.length; index++) { - org.bukkit.inventory.EquipmentSlot bukkitSlot = slots[index]; - nmsSlots[index] = CraftEquipmentSlot.getNMS(bukkitSlot); - } - - return nmsSlots; - } -} diff --git a/V1_20_R1/src/main/java/su/nightexpress/excellentenchants/nms/v1_20_R1/V1_20_R1.java b/V1_20_R1/src/main/java/su/nightexpress/excellentenchants/nms/v1_20_R1/V1_20_R1.java deleted file mode 100644 index 15b3f4f..0000000 --- a/V1_20_R1/src/main/java/su/nightexpress/excellentenchants/nms/v1_20_R1/V1_20_R1.java +++ /dev/null @@ -1,247 +0,0 @@ -package su.nightexpress.excellentenchants.nms.v1_20_R1; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Registry; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.network.protocol.game.ClientboundAnimatePacket; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.util.Mth; -import net.minecraft.world.Container; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.item.ItemEntity; -import net.minecraft.world.entity.projectile.FishingHook; -import net.minecraft.world.inventory.EnchantmentMenu; -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.enchantment.EnchantmentInstance; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.LiquidBlock; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.shapes.CollisionContext; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_20_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_20_R1.block.CraftBlock; -import org.bukkit.craftbukkit.v1_20_R1.enchantments.CraftEnchantment; -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftFishHook; -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_20_R1.event.CraftEventFactory; -import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_20_R1.util.CraftMagicNumbers; -import org.bukkit.craftbukkit.v1_20_R1.util.CraftNamespacedKey; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.FishHook; -import org.bukkit.entity.Item; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; -import su.nightexpress.excellentenchants.nms.EnchantNMS; -import su.nightexpress.nightcore.util.BukkitThing; -import su.nightexpress.nightcore.util.Reflex; -import su.nightexpress.nightcore.util.random.Rnd; - -import java.lang.reflect.Method; -import java.util.*; - -public class V1_20_R1 implements EnchantNMS { - - @Override - public void unfreezeRegistry() { - Reflex.setFieldValue(BuiltInRegistries.ENCHANTMENT, "l", false); - Reflex.setFieldValue(BuiltInRegistries.ENCHANTMENT, "m", new IdentityHashMap<>()); - Reflex.setFieldValue(Enchantment.class, "acceptingNew", true); - } - - @Override - public void freezeRegistry() { - Enchantment.stopAcceptingRegistrations(); - BuiltInRegistries.ENCHANTMENT.freeze(); - } - - @Override - public boolean isEnchantable(@NotNull ItemStack bukkitItem) { - net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(bukkitItem); - return nmsItem.getItem().isEnchantable(nmsItem); - } - - @Override - public void registerEnchantment(@NotNull EnchantmentData data) { - CustomEnchantment customEnchantment = new CustomEnchantment(data); - BuiltInRegistries.ENCHANTMENT.createIntrusiveHolder(customEnchantment); - Registry.register(BuiltInRegistries.ENCHANTMENT, data.getId(), customEnchantment); - - CraftEnchantment craftEnchantment = new CraftEnchantment(customEnchantment); - Enchantment.registerEnchantment(craftEnchantment); - data.setEnchantment(craftEnchantment); - } - - private static final Method GET_ENCHANTS_LIST = Reflex.getMethod(EnchantmentMenu.class, "a", net.minecraft.world.item.ItemStack.class, Integer.TYPE, Integer.TYPE); - - @SuppressWarnings("unchecked") - @NotNull - @Override - public Map> getEnchantLists(@NotNull Inventory inventory, @NotNull ItemStack bukkitItem) { - Map> map = new HashMap<>(); - - // Returns SimpleContainer class assigned to 'enchantSlots' field. - Container container = ((CraftInventory) inventory).getInventory(); - - // Get parent (real EnchantmentMenu) object from SimpleContainer obtained above. - EnchantmentMenu enchantmentMenu = (EnchantmentMenu) Reflex.getFieldValue(container, "this$0"); - - net.minecraft.world.item.ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem); - - for (int button = 0; button < 3; button++) { - int cost = enchantmentMenu.costs[button]; - List list = (List) Reflex.invokeMethod(GET_ENCHANTS_LIST, enchantmentMenu, itemStack, button, cost); - - Map enchantments = new HashMap<>(); - - if (list != null && !list.isEmpty()) { - EnchantmentInstance random = Rnd.get(list); - enchantmentMenu.enchantClue[button] = BuiltInRegistries.ENCHANTMENT.getId(random.enchantment); - enchantmentMenu.levelClue[button] = random.level; - - for (EnchantmentInstance instance : list) { - ResourceLocation location = BuiltInRegistries.ENCHANTMENT.getKey(instance.enchantment); - if (location == null) continue; - - enchantments.put(BukkitThing.getEnchantment(CraftNamespacedKey.fromMinecraft(location).getKey()), instance.level); - } - } - - map.put(button, enchantments); - } - - return map; - } - - @Override - public void sendAttackPacket(@NotNull Player player, int id) { - CraftPlayer craftPlayer = (CraftPlayer) player; - ServerPlayer entity = craftPlayer.getHandle(); - ClientboundAnimatePacket packet = new ClientboundAnimatePacket(entity, id); - craftPlayer.getHandle().connection.send(packet); - } - - @Override - public void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item, @NotNull EquipmentSlot slot) { - CraftFishHook craftFishHook = (CraftFishHook) hook; - FishingHook handle = craftFishHook.getHandle(); - - net.minecraft.world.entity.player.Player owner = handle.getPlayerOwner(); - if (owner == null) return; - - int result = handle.retrieve(CraftItemStack.asNMSCopy(item)); - - net.minecraft.world.entity.EquipmentSlot hand = slot == EquipmentSlot.HAND ? net.minecraft.world.entity.EquipmentSlot.MAINHAND : net.minecraft.world.entity.EquipmentSlot.OFFHAND; - - net.minecraft.world.item.ItemStack itemStack = owner.getItemBySlot(hand); - if (itemStack == null) return; - - itemStack.hurtAndBreak(result, handle.getPlayerOwner(), player -> { - player.broadcastBreakEvent(hand); - }); - } - - @NotNull - @Override - public Material getItemBlockVariant(@NotNull Material material) { - ItemStack itemStack = new ItemStack(material); - net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - if (nmsStack.getItem() instanceof BlockItem blockItem) { - return CraftMagicNumbers.getMaterial(blockItem.getBlock()); - } - return material; - } - - @Override - @NotNull - public Set handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) { - Entity entity = ((CraftLivingEntity) bukkitEntity).getHandle(); - BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()); - ServerLevel world = ((CraftWorld) bukkitEntity.getWorld()).getHandle(); - - int radius = Math.min(16, 2 + level); - BlockState bStone = Blocks.MAGMA_BLOCK.defaultBlockState(); - BlockPos.MutableBlockPos posAbove = new BlockPos.MutableBlockPos(); - - Set blocks = new HashSet<>(); - for (BlockPos posNear : BlockPos.betweenClosed(pos.offset(-radius, -1, -radius), pos.offset(radius, -1, radius))) { - if (!posNear.closerThan(entity.blockPosition(), radius)) continue; - - posAbove.set(posNear.getX(), posNear.getY() + 1, posNear.getZ()); - - BlockState bLavaAbove = world.getBlockState(posAbove); - BlockState bLava = world.getBlockState(posNear); - - if (!bLavaAbove.isAir()) continue; - if (!bLava.getBlock().equals(Blocks.LAVA)) continue; - if (bLava.getValue(LiquidBlock.LEVEL) != 0) continue; - if (!bStone.canSurvive(world, posNear)) continue; - if (!world.isUnobstructed(bStone, posNear, CollisionContext.empty())) continue; - if (!CraftEventFactory.handleBlockFormEvent(world, posNear, bStone, entity)) continue; - //world.scheduleTick(posNear, Blocks.STONE, Rnd.get(60, 120)); - - Location bukkitLoc = new Location(world.getWorld(), posNear.getX(), posNear.getY(), posNear.getZ()); - blocks.add(bukkitLoc.getBlock()); - } - return blocks; - } - - @NotNull - public Item popResource(@NotNull Block block, @NotNull ItemStack item) { - Level world = ((CraftWorld)block.getWorld()).getHandle(); - BlockPos pos = ((CraftBlock)block).getPosition(); - net.minecraft.world.item.ItemStack itemstack = CraftItemStack.asNMSCopy(item); - - float yMod = EntityType.ITEM.getHeight() / 2.0F; - double x = (pos.getX() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D); - double y = (pos.getY() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D) - yMod; - double z = (pos.getZ() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D); - - ItemEntity itemEntity = new ItemEntity(world, x, y, z, itemstack); - itemEntity.setDefaultPickUpDelay(); - return (Item) itemEntity.getBukkitEntity(); - } - - /*public static void popResourceFromFace(Level world, BlockPos blockposition, Direction enumdirection, ItemStack itemstack) { - int i = enumdirection.getStepX(); - int j = enumdirection.getStepY(); - int k = enumdirection.getStepZ(); - float f = EntityType.ITEM.getWidth() / 2.0F; - float f1 = EntityType.ITEM.getHeight() / 2.0F; - double d0 = (double)((float)blockposition.getX() + 0.5F) + (i == 0 ? Mth.nextDouble(world.random, -0.25D, 0.25D) : (double)((float)i * (0.5F + f))); - double d1 = (double)((float)blockposition.getY() + 0.5F) + (j == 0 ? Mth.nextDouble(world.random, -0.25D, 0.25D) : (double)((float)j * (0.5F + f1))) - (double)f1; - double d2 = (double)((float)blockposition.getZ() + 0.5F) + (k == 0 ? Mth.nextDouble(world.random, -0.25D, 0.25D) : (double)((float)k * (0.5F + f))); - double d3 = i == 0 ? Mth.nextDouble(world.random, -0.1D, 0.1D) : (double)i * 0.1D; - double d4 = j == 0 ? Mth.nextDouble(world.random, 0.0D, 0.1D) : (double)j * 0.1D + 0.1D; - double d5 = k == 0 ? Mth.nextDouble(world.random, -0.1D, 0.1D) : (double)k * 0.1D; - popResource(world, () -> { - return new ItemEntity(world, d0, d1, d2, itemstack, d3, d4, d5); - }, itemstack); - } - - private static void popResource(Level world, Supplier supplier, ItemStack itemstack) { - if (!world.isClientSide && !itemstack.isEmpty() && world.getGameRules().getBoolean(GameRules.RULE_DOBLOCKDROPS)) { - ItemEntity entityitem = (ItemEntity)supplier.get(); - entityitem.setDefaultPickUpDelay(); - if (world.captureDrops != null) { - world.captureDrops.add(entityitem); - } else { - world.addFreshEntity(entityitem); - } - } - - }*/ -} diff --git a/V1_20_R2/pom.xml b/V1_20_R2/pom.xml deleted file mode 100644 index 23c0354..0000000 --- a/V1_20_R2/pom.xml +++ /dev/null @@ -1,72 +0,0 @@ - - - - ExcellentEnchants - su.nightexpress.excellentenchants - 4.1.0 - - 4.0.0 - - V1_20_R2 - - - 21 - 21 - UTF-8 - - - - - org.spigotmc - spigot - 1.20.2-R0.1-SNAPSHOT - remapped-mojang - - - su.nightexpress.excellentenchants - NMS - 4.1.0 - - - - - - - net.md-5 - specialsource-maven-plugin - 2.0.3 - - - package - - remap - - remap-obf - - org.spigotmc:minecraft-server:1.20.2-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:1.20.2-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:1.20.2-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.20.2-R0.1-SNAPSHOT:jar:remapped-obf - - - - - - - - \ No newline at end of file diff --git a/V1_20_R2/src/main/java/su/nightexpress/excellentenchants/nms/v1_20_R2/CustomEnchantment.java b/V1_20_R2/src/main/java/su/nightexpress/excellentenchants/nms/v1_20_R2/CustomEnchantment.java deleted file mode 100644 index b157c23..0000000 --- a/V1_20_R2/src/main/java/su/nightexpress/excellentenchants/nms/v1_20_R2/CustomEnchantment.java +++ /dev/null @@ -1,147 +0,0 @@ -package su.nightexpress.excellentenchants.nms.v1_20_R2; - -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.enchantment.Enchantment; -import net.minecraft.world.item.enchantment.EnchantmentCategory; -import org.bukkit.NamespacedKey; -import org.bukkit.craftbukkit.v1_20_R2.CraftEquipmentSlot; -import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_20_R2.util.CraftNamespacedKey; -import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.EnchantingBridge; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; -import su.nightexpress.excellentenchants.api.enchantment.distribution.VanillaOptions; - -public class CustomEnchantment extends Enchantment { - - private final EnchantmentData enchantmentData; - - private VanillaOptions vanillaOptions; - - public CustomEnchantment(@NotNull EnchantmentData enchantmentData) { - super(nmsRarity(enchantmentData), nmsCategory(enchantmentData), nmsSlots(enchantmentData)); - this.enchantmentData = enchantmentData; - - if (enchantmentData.getDistributionOptions() instanceof VanillaOptions options) { - this.vanillaOptions = options; - } - } - - @Override - public int getMaxLevel() { - return this.enchantmentData.getMaxLevel(); - } - - @Override - public int getMinCost(int level) { - return this.enchantmentData.getMinCost(level); - } - - @Override - public int getMaxCost(int level) { - return this.enchantmentData.getMaxCost(level); - } - - @Override - protected boolean checkCompatibility(Enchantment other) { - ResourceLocation location = BuiltInRegistries.ENCHANTMENT.getKey(other); - if (location == null) return false; - - NamespacedKey key = CraftNamespacedKey.fromMinecraft(location); - String id = key.getKey(); - - // Expensive probably. - //org.bukkit.enchantments.Enchantment bukkit = CraftEnchantment.minecraftToBukkit(other); - //String id = bukkit.getKey().getKey(); - - return !this.enchantmentData.getConflicts().contains(id); - } - - @Override - public boolean canEnchant(ItemStack item) { - if (!super.canEnchant(item)) return false; - - return this.canEnchant(CraftItemStack.asBukkitCopy(item)); - } - - public boolean canEnchant(@NotNull org.bukkit.inventory.ItemStack bukkitItem) { - if (!this.enchantmentData.checkEnchantLimit(bukkitItem)) return false; - - /*if (!this.enchantmentData.hasItemCategory()) { - if (this.enchantmentData.checkEnchantCategory(bukkitItem)) return true; - } - - return this.enchantmentData.checkItemCategory(bukkitItem);*/ - return this.enchantmentData.isSupportedItem(bukkitItem); - } - - @Override - public boolean isTreasureOnly() { - return this.enchantmentData.isTreasure() || this.isCurse(); - } - - @Override - public boolean isCurse() { - return this.enchantmentData.isCurse(); - } - - @Override - public boolean isTradeable() { - return this.vanillaOptions != null && this.vanillaOptions.isTradeable(); - } - - @Override - public boolean isDiscoverable() { - org.bukkit.inventory.ItemStack bukkitItem = EnchantingBridge.getEnchantingItem(); - if (bukkitItem != null && !this.enchantmentData.isPrimaryItem(bukkitItem)) { - return false; - } - - return this.vanillaOptions != null && this.vanillaOptions.isDiscoverable(); - } - - public static Rarity nmsRarity(@NotNull EnchantmentData data) { - return switch (data.getRarity()) { - case RARE -> Rarity.RARE; - case COMMON -> Rarity.COMMON; - case UNCOMMON -> Rarity.UNCOMMON; - case VERY_RARE -> Rarity.VERY_RARE; - }; - } - - @NotNull - public static EnchantmentCategory nmsCategory(@NotNull EnchantmentData data) { - return switch (data.getSupportedItems().getTarget()) { - case WEAPON -> EnchantmentCategory.WEAPON; - case TOOL -> EnchantmentCategory.DIGGER; - case ARMOR -> EnchantmentCategory.ARMOR; - case BOW -> EnchantmentCategory.BOW; - case TRIDENT -> EnchantmentCategory.TRIDENT; - case CROSSBOW -> EnchantmentCategory.CROSSBOW; - case WEARABLE -> EnchantmentCategory.WEARABLE; - case BREAKABLE -> EnchantmentCategory.BREAKABLE; - case ARMOR_FEET -> EnchantmentCategory.ARMOR_FEET; - case ARMOR_HEAD -> EnchantmentCategory.ARMOR_HEAD; - case ARMOR_LEGS -> EnchantmentCategory.ARMOR_LEGS; - case ARMOR_TORSO -> EnchantmentCategory.ARMOR_CHEST; - case VANISHABLE -> EnchantmentCategory.VANISHABLE; - case FISHING_ROD -> EnchantmentCategory.FISHING_ROD; - default -> throw new IllegalStateException("Unexpected value: " + data.getSupportedItems().getTarget()); - }; - } - - public static EquipmentSlot[] nmsSlots(@NotNull EnchantmentData data) { - org.bukkit.inventory.EquipmentSlot[] slots = data.getSupportedItems().getSlots(); - EquipmentSlot[] nmsSlots = new EquipmentSlot[slots.length]; - - for (int index = 0; index < nmsSlots.length; index++) { - org.bukkit.inventory.EquipmentSlot bukkitSlot = slots[index]; - nmsSlots[index] = CraftEquipmentSlot.getNMS(bukkitSlot); - } - - return nmsSlots; - } -} diff --git a/V1_20_R2/src/main/java/su/nightexpress/excellentenchants/nms/v1_20_R2/V1_20_R2.java b/V1_20_R2/src/main/java/su/nightexpress/excellentenchants/nms/v1_20_R2/V1_20_R2.java deleted file mode 100644 index 5a95063..0000000 --- a/V1_20_R2/src/main/java/su/nightexpress/excellentenchants/nms/v1_20_R2/V1_20_R2.java +++ /dev/null @@ -1,216 +0,0 @@ -package su.nightexpress.excellentenchants.nms.v1_20_R2; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Registry; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.network.protocol.game.ClientboundAnimatePacket; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.util.Mth; -import net.minecraft.world.Container; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.item.ItemEntity; -import net.minecraft.world.entity.projectile.FishingHook; -import net.minecraft.world.inventory.EnchantmentMenu; -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.enchantment.EnchantmentInstance; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.LiquidBlock; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.shapes.CollisionContext; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_20_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_20_R2.block.CraftBlock; -import org.bukkit.craftbukkit.v1_20_R2.enchantments.CraftEnchantment; -import org.bukkit.craftbukkit.v1_20_R2.entity.CraftFishHook; -import org.bukkit.craftbukkit.v1_20_R2.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_20_R2.event.CraftEventFactory; -import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_20_R2.util.CraftMagicNumbers; -import org.bukkit.craftbukkit.v1_20_R2.util.CraftNamespacedKey; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.FishHook; -import org.bukkit.entity.Item; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; -import su.nightexpress.excellentenchants.nms.EnchantNMS; -import su.nightexpress.nightcore.util.BukkitThing; -import su.nightexpress.nightcore.util.Reflex; -import su.nightexpress.nightcore.util.random.Rnd; - -import java.lang.reflect.Method; -import java.util.*; - -public class V1_20_R2 implements EnchantNMS { - - @Override - public void unfreezeRegistry() { - Reflex.setFieldValue(BuiltInRegistries.ENCHANTMENT, "l", false); - Reflex.setFieldValue(BuiltInRegistries.ENCHANTMENT, "m", new IdentityHashMap<>()); - Reflex.setFieldValue(Enchantment.class, "acceptingNew", true); - } - - @Override - public void freezeRegistry() { - Enchantment.stopAcceptingRegistrations(); - BuiltInRegistries.ENCHANTMENT.freeze(); - } - - @Override - public boolean isEnchantable(@NotNull ItemStack bukkitItem) { - net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(bukkitItem); - return nmsItem.getItem().isEnchantable(nmsItem); - } - - @Override - public void registerEnchantment(@NotNull EnchantmentData data) { - CustomEnchantment customEnchantment = new CustomEnchantment(data); - Registry.register(BuiltInRegistries.ENCHANTMENT, data.getId(), customEnchantment); - - CraftEnchantment craftEnchantment = new CraftEnchantment(customEnchantment); - Enchantment.registerEnchantment(craftEnchantment); - data.setEnchantment(craftEnchantment); - } - - private static final Method GET_ENCHANTS_LIST = Reflex.getMethod(EnchantmentMenu.class, "a", net.minecraft.world.item.ItemStack.class, Integer.TYPE, Integer.TYPE); - - @SuppressWarnings("unchecked") - @NotNull - @Override - public Map> getEnchantLists(@NotNull Inventory inventory, @NotNull ItemStack bukkitItem) { - Map> map = new HashMap<>(); - - // Returns SimpleContainer class assigned to 'enchantSlots' field. - Container container = ((CraftInventory) inventory).getInventory(); - - // Get parent (real EnchantmentMenu) object from SimpleContainer obtained above. - EnchantmentMenu enchantmentMenu = (EnchantmentMenu) Reflex.getFieldValue(container, "this$0"); - - net.minecraft.world.item.ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem); - - for (int button = 0; button < 3; button++) { - int cost = enchantmentMenu.costs[button]; - List list = (List) Reflex.invokeMethod(GET_ENCHANTS_LIST, enchantmentMenu, itemStack, button, cost); - - Map enchantments = new HashMap<>(); - - if (list != null && !list.isEmpty()) { - EnchantmentInstance random = Rnd.get(list); - enchantmentMenu.enchantClue[button] = BuiltInRegistries.ENCHANTMENT.getId(random.enchantment); - enchantmentMenu.levelClue[button] = random.level; - - for (EnchantmentInstance instance : list) { - ResourceLocation location = BuiltInRegistries.ENCHANTMENT.getKey(instance.enchantment); - if (location == null) continue; - - enchantments.put(BukkitThing.getEnchantment(CraftNamespacedKey.fromMinecraft(location).getKey()), instance.level); - } - } - - map.put(button, enchantments); - } - - return map; - } - - @Override - public void sendAttackPacket(@NotNull Player player, int id) { - CraftPlayer craftPlayer = (CraftPlayer) player; - ServerPlayer entity = craftPlayer.getHandle(); - ClientboundAnimatePacket packet = new ClientboundAnimatePacket(entity, id); - craftPlayer.getHandle().connection.send(packet); - } - - @Override - public void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item, @NotNull EquipmentSlot slot) { - CraftFishHook craftFishHook = (CraftFishHook) hook; - FishingHook handle = craftFishHook.getHandle(); - - net.minecraft.world.entity.player.Player owner = handle.getPlayerOwner(); - if (owner == null) return; - - int result = handle.retrieve(CraftItemStack.asNMSCopy(item)); - - net.minecraft.world.entity.EquipmentSlot hand = slot == EquipmentSlot.HAND ? net.minecraft.world.entity.EquipmentSlot.MAINHAND : net.minecraft.world.entity.EquipmentSlot.OFFHAND; - - net.minecraft.world.item.ItemStack itemStack = owner.getItemBySlot(hand); - if (itemStack == null) return; - - itemStack.hurtAndBreak(result, handle.getPlayerOwner(), player -> { - player.broadcastBreakEvent(hand); - }); - } - - @NotNull - @Override - public Material getItemBlockVariant(@NotNull Material material) { - ItemStack itemStack = new ItemStack(material); - net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - if (nmsStack.getItem() instanceof BlockItem blockItem) { - return CraftMagicNumbers.getMaterial(blockItem.getBlock()); - } - return material; - } - - @Override - @NotNull - public Set handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) { - Entity entity = ((CraftLivingEntity) bukkitEntity).getHandle(); - BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()); - ServerLevel world = ((CraftWorld) bukkitEntity.getWorld()).getHandle(); - - int radius = Math.min(16, 2 + level); - BlockState bStone = Blocks.MAGMA_BLOCK.defaultBlockState(); - BlockPos.MutableBlockPos posAbove = new BlockPos.MutableBlockPos(); - - Set blocks = new HashSet<>(); - for (BlockPos posNear : BlockPos.betweenClosed(pos.offset(-radius, -1, -radius), pos.offset(radius, -1, radius))) { - if (!posNear.closerThan(entity.blockPosition(), radius)) continue; - - posAbove.set(posNear.getX(), posNear.getY() + 1, posNear.getZ()); - - BlockState bLavaAbove = world.getBlockState(posAbove); - BlockState bLava = world.getBlockState(posNear); - - if (!bLavaAbove.isAir()) continue; - if (!bLava.getBlock().equals(Blocks.LAVA)) continue; - if (bLava.getValue(LiquidBlock.LEVEL) != 0) continue; - if (!bStone.canSurvive(world, posNear)) continue; - if (!world.isUnobstructed(bStone, posNear, CollisionContext.empty())) continue; - if (!CraftEventFactory.handleBlockFormEvent(world, posNear, bStone, entity)) continue; - //world.scheduleTick(posNear, Blocks.STONE, Rnd.get(60, 120)); - - Location bukkitLoc = new Location(world.getWorld(), posNear.getX(), posNear.getY(), posNear.getZ()); - blocks.add(bukkitLoc.getBlock()); - } - return blocks; - } - - @NotNull - public Item popResource(@NotNull Block block, @NotNull ItemStack item) { - Level world = ((CraftWorld)block.getWorld()).getHandle(); - BlockPos pos = ((CraftBlock)block).getPosition(); - net.minecraft.world.item.ItemStack itemstack = CraftItemStack.asNMSCopy(item); - - float yMod = EntityType.ITEM.getHeight() / 2.0F; - double x = (pos.getX() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D); - double y = (pos.getY() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D) - yMod; - double z = (pos.getZ() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D); - - ItemEntity itemEntity = new ItemEntity(world, x, y, z, itemstack); - itemEntity.setDefaultPickUpDelay(); - return (Item) itemEntity.getBukkitEntity(); - } -} diff --git a/V1_20_R3/pom.xml b/V1_20_R3/pom.xml deleted file mode 100644 index 917fe2c..0000000 --- a/V1_20_R3/pom.xml +++ /dev/null @@ -1,77 +0,0 @@ - - - - ExcellentEnchants - su.nightexpress.excellentenchants - 4.1.0 - - 4.0.0 - - V1_20_R3 - - - 21 - 21 - UTF-8 - - - - - org.spigotmc - spigot - 1.20.4-R0.1-SNAPSHOT - remapped-mojang - - - su.nightexpress.excellentenchants - API - 4.1.0 - - - su.nightexpress.excellentenchants - NMS - 4.1.0 - - - - - - - net.md-5 - specialsource-maven-plugin - 2.0.3 - - - package - - remap - - remap-obf - - org.spigotmc:minecraft-server:1.20.4-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:1.20.4-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:1.20.4-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.20.4-R0.1-SNAPSHOT:jar:remapped-obf - - - - - - - - \ No newline at end of file diff --git a/V1_20_R3/src/main/java/su/nightexpress/excellentenchants/nms/v1_20_R3/CustomEnchantment.java b/V1_20_R3/src/main/java/su/nightexpress/excellentenchants/nms/v1_20_R3/CustomEnchantment.java deleted file mode 100644 index 4606514..0000000 --- a/V1_20_R3/src/main/java/su/nightexpress/excellentenchants/nms/v1_20_R3/CustomEnchantment.java +++ /dev/null @@ -1,148 +0,0 @@ -package su.nightexpress.excellentenchants.nms.v1_20_R3; - -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.enchantment.Enchantment; -import net.minecraft.world.item.enchantment.EnchantmentCategory; -import org.bukkit.NamespacedKey; -import org.bukkit.craftbukkit.v1_20_R3.CraftEquipmentSlot; -import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_20_R3.util.CraftNamespacedKey; -import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.EnchantingBridge; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; -import su.nightexpress.excellentenchants.api.enchantment.distribution.VanillaOptions; - -public class CustomEnchantment extends Enchantment { - - private final EnchantmentData enchantmentData; - - private VanillaOptions vanillaOptions; - - public CustomEnchantment(@NotNull EnchantmentData enchantmentData) { - super(nmsRarity(enchantmentData), nmsCategory(enchantmentData), nmsSlots(enchantmentData)); - this.enchantmentData = enchantmentData; - - if (enchantmentData.getDistributionOptions() instanceof VanillaOptions options) { - this.vanillaOptions = options; - } - } - - @Override - public int getMaxLevel() { - return this.enchantmentData.getMaxLevel(); - } - - @Override - public int getMinCost(int level) { - return this.enchantmentData.getMinCost(level); - } - - @Override - public int getMaxCost(int level) { - return this.enchantmentData.getMaxCost(level); - } - - @Override - protected boolean checkCompatibility(Enchantment other) { - ResourceLocation location = BuiltInRegistries.ENCHANTMENT.getKey(other); - if (location == null) return false; - - NamespacedKey key = CraftNamespacedKey.fromMinecraft(location); - String id = key.getKey(); - - // Expensive probably. - //org.bukkit.enchantments.Enchantment bukkit = CraftEnchantment.minecraftToBukkit(other); - //String id = bukkit.getKey().getKey(); - - return !this.enchantmentData.getConflicts().contains(id); - } - - @Override - public boolean canEnchant(ItemStack item) { - if (!super.canEnchant(item)) return false; - - return this.canEnchant(CraftItemStack.asBukkitCopy(item)); - } - - public boolean canEnchant(@NotNull org.bukkit.inventory.ItemStack bukkitItem) { - if (!this.enchantmentData.checkEnchantLimit(bukkitItem)) return false; - - /*if (!this.enchantmentData.hasItemCategory()) { - if (this.enchantmentData.checkEnchantCategory(bukkitItem)) return true; - } - - return this.enchantmentData.checkItemCategory(bukkitItem);*/ - - return this.enchantmentData.isSupportedItem(bukkitItem); - } - - @Override - public boolean isTreasureOnly() { - return this.enchantmentData.isTreasure() || this.isCurse(); - } - - @Override - public boolean isCurse() { - return this.enchantmentData.isCurse(); - } - - @Override - public boolean isTradeable() { - return this.vanillaOptions != null && this.vanillaOptions.isTradeable(); - } - - @Override - public boolean isDiscoverable() { - org.bukkit.inventory.ItemStack bukkitItem = EnchantingBridge.getEnchantingItem(); - if (bukkitItem != null && !this.enchantmentData.isPrimaryItem(bukkitItem)) { - return false; - } - - return this.vanillaOptions != null && this.vanillaOptions.isDiscoverable(); - } - - public static Rarity nmsRarity(@NotNull EnchantmentData data) { - return switch (data.getRarity()) { - case RARE -> Rarity.RARE; - case COMMON -> Rarity.COMMON; - case UNCOMMON -> Rarity.UNCOMMON; - case VERY_RARE -> Rarity.VERY_RARE; - }; - } - - @NotNull - public static EnchantmentCategory nmsCategory(@NotNull EnchantmentData data) { - return switch (data.getSupportedItems().getTarget()) { - case WEAPON -> EnchantmentCategory.WEAPON; - case TOOL -> EnchantmentCategory.DIGGER; - case ARMOR -> EnchantmentCategory.ARMOR; - case BOW -> EnchantmentCategory.BOW; - case TRIDENT -> EnchantmentCategory.TRIDENT; - case CROSSBOW -> EnchantmentCategory.CROSSBOW; - case WEARABLE -> EnchantmentCategory.WEARABLE; - case BREAKABLE -> EnchantmentCategory.BREAKABLE; - case ARMOR_FEET -> EnchantmentCategory.ARMOR_FEET; - case ARMOR_HEAD -> EnchantmentCategory.ARMOR_HEAD; - case ARMOR_LEGS -> EnchantmentCategory.ARMOR_LEGS; - case ARMOR_TORSO -> EnchantmentCategory.ARMOR_CHEST; - case VANISHABLE -> EnchantmentCategory.VANISHABLE; - case FISHING_ROD -> EnchantmentCategory.FISHING_ROD; - default -> throw new IllegalStateException("Unexpected value: " + data.getSupportedItems().getTarget()); - }; - } - - public static EquipmentSlot[] nmsSlots(@NotNull EnchantmentData data) { - org.bukkit.inventory.EquipmentSlot[] slots = data.getSupportedItems().getSlots(); - EquipmentSlot[] nmsSlots = new EquipmentSlot[slots.length]; - - for (int index = 0; index < nmsSlots.length; index++) { - org.bukkit.inventory.EquipmentSlot bukkitSlot = slots[index]; - nmsSlots[index] = CraftEquipmentSlot.getNMS(bukkitSlot); - } - - return nmsSlots; - } -} diff --git a/V1_20_R3/src/main/java/su/nightexpress/excellentenchants/nms/v1_20_R3/V1_20_R3.java b/V1_20_R3/src/main/java/su/nightexpress/excellentenchants/nms/v1_20_R3/V1_20_R3.java deleted file mode 100644 index e276435..0000000 --- a/V1_20_R3/src/main/java/su/nightexpress/excellentenchants/nms/v1_20_R3/V1_20_R3.java +++ /dev/null @@ -1,233 +0,0 @@ -package su.nightexpress.excellentenchants.nms.v1_20_R3; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Registry; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.network.protocol.game.ClientboundAnimatePacket; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.util.Mth; -import net.minecraft.world.Container; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.item.ItemEntity; -import net.minecraft.world.entity.projectile.FishingHook; -import net.minecraft.world.inventory.EnchantmentMenu; -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.Items; -import net.minecraft.world.item.enchantment.EnchantmentInstance; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.LiquidBlock; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.shapes.CollisionContext; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_20_R3.block.CraftBlock; -import org.bukkit.craftbukkit.v1_20_R3.block.CraftBlockType; -import org.bukkit.craftbukkit.v1_20_R3.enchantments.CraftEnchantment; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftFishHook; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_20_R3.event.CraftEventFactory; -import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_20_R3.util.CraftNamespacedKey; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.FishHook; -import org.bukkit.entity.Item; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; -import su.nightexpress.excellentenchants.nms.EnchantNMS; -import su.nightexpress.nightcore.util.BukkitThing; -import su.nightexpress.nightcore.util.Reflex; -import su.nightexpress.nightcore.util.random.Rnd; - -import java.lang.reflect.Method; -import java.util.*; - -public class V1_20_R3 implements EnchantNMS { - - @Override - public void unfreezeRegistry() { - Reflex.setFieldValue(BuiltInRegistries.ENCHANTMENT, "l", false); // MappedRegistry#frozen - Reflex.setFieldValue(BuiltInRegistries.ENCHANTMENT, "m", new IdentityHashMap<>()); // MappedRegistry#unregisteredIntrusiveHolders - } - - @Override - public void freezeRegistry() { - BuiltInRegistries.ENCHANTMENT.freeze(); - } - - @Override - public boolean isEnchantable(@NotNull ItemStack bukkitItem) { - net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(bukkitItem); - return nmsItem.getItem().isEnchantable(nmsItem); - } - - public void registerEnchantment(@NotNull EnchantmentData data) { - CustomEnchantment enchantment = new CustomEnchantment(data); - Registry.register(BuiltInRegistries.ENCHANTMENT, data.getId(), enchantment); - - Enchantment bukkitEnchant = CraftEnchantment.minecraftToBukkit(enchantment); - data.setEnchantment(bukkitEnchant); - } - - private static final Method GET_ENCHANTS_LIST = Reflex.getMethod(EnchantmentMenu.class, "a", net.minecraft.world.item.ItemStack.class, Integer.TYPE, Integer.TYPE); - - @SuppressWarnings("unchecked") - @NotNull - @Override - public Map> getEnchantLists(@NotNull Inventory inventory, @NotNull ItemStack bukkitItem) { - Map> map = new HashMap<>(); - - // Returns SimpleContainer class assigned to 'enchantSlots' field. - Container container = ((CraftInventory) inventory).getInventory(); - - // Get parent (real EnchantmentMenu) object from SimpleContainer obtained above. - EnchantmentMenu enchantmentMenu = (EnchantmentMenu) Reflex.getFieldValue(container, "this$0"); - - net.minecraft.world.item.ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem); - - for (int button = 0; button < 3; button++) { - int cost = enchantmentMenu.costs[button]; - List list = (List) Reflex.invokeMethod(GET_ENCHANTS_LIST, enchantmentMenu, itemStack, button, cost); - - Map enchantments = new HashMap<>(); - - if (list != null && !list.isEmpty()) { - EnchantmentInstance random = Rnd.get(list); - enchantmentMenu.enchantClue[button] = BuiltInRegistries.ENCHANTMENT.getId(random.enchantment); - enchantmentMenu.levelClue[button] = random.level; - - for (EnchantmentInstance instance : list) { - ResourceLocation location = BuiltInRegistries.ENCHANTMENT.getKey(instance.enchantment); - if (location == null) continue; - - enchantments.put(BukkitThing.getEnchantment(CraftNamespacedKey.fromMinecraft(location).getKey()), instance.level); - } - } - - map.put(button, enchantments); - } - - return map; - } - - @Override - public void sendAttackPacket(@NotNull Player player, int id) { - CraftPlayer craftPlayer = (CraftPlayer) player; - ServerPlayer entity = craftPlayer.getHandle(); - ClientboundAnimatePacket packet = new ClientboundAnimatePacket(entity, id); - craftPlayer.getHandle().connection.send(packet); - } - - /*@NotNull - public ItemStack setItemLore(@NotNull ItemStack item, @NotNull List lore) { - CraftItemStack craftItem = ensureCraftItemStack(item); - net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(craftItem); - - CompoundTag tag = nmsItem.getTag() == null ? new CompoundTag() : nmsItem.getTag(); - if (!tag.contains(net.minecraft.world.item.ItemStack.TAG_DISPLAY)) { - tag.put(net.minecraft.world.item.ItemStack.TAG_DISPLAY, new CompoundTag()); - } - - CompoundTag displayTag = tag.getCompound(net.minecraft.world.item.ItemStack.TAG_DISPLAY); - ListTag loreTag = new ListTag(); - for (int index = 0; index < lore.size(); index++) { - String text = lore.get(index); - String json = ComponentSerializer.toString(NightMessage.asComponent(text)); - loreTag.add(index, StringTag.valueOf(json)); - } - - displayTag.put(net.minecraft.world.item.ItemStack.TAG_LORE, loreTag); - return CraftItemStack.asBukkitCopy(nmsItem); - }*/ - - @NotNull - private static CraftItemStack ensureCraftItemStack(ItemStack item) { - return item instanceof CraftItemStack craftItem ? craftItem : CraftItemStack.asCraftCopy(item); - } - - @Override - public void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item, @NotNull EquipmentSlot slot) { - CraftFishHook craftFishHook = (CraftFishHook) hook; - FishingHook handle = craftFishHook.getHandle(); - - net.minecraft.world.entity.player.Player owner = handle.getPlayerOwner(); - if (owner == null) return; - - InteractionHand hand = slot == EquipmentSlot.HAND ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND; - Items.FISHING_ROD.use(owner.level(), owner, hand); - } - - @NotNull - @Override - public Material getItemBlockVariant(@NotNull Material material) { - ItemStack itemStack = new ItemStack(material); - net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - if (nmsStack.getItem() instanceof BlockItem blockItem) { - return CraftBlockType.minecraftToBukkit(blockItem.getBlock()); - } - return material; - } - - @Override - @NotNull - public Set handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) { - Entity entity = ((CraftLivingEntity) bukkitEntity).getHandle(); - BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()); - ServerLevel world = ((CraftWorld) bukkitEntity.getWorld()).getHandle(); - - int radius = Math.min(16, 2 + level); - BlockState bStone = Blocks.MAGMA_BLOCK.defaultBlockState(); - BlockPos.MutableBlockPos posAbove = new BlockPos.MutableBlockPos(); - - Set blocks = new HashSet<>(); - for (BlockPos posNear : BlockPos.betweenClosed(pos.offset(-radius, -1, -radius), pos.offset(radius, -1, radius))) { - if (!posNear.closerThan(entity.blockPosition(), radius)) continue; - - posAbove.set(posNear.getX(), posNear.getY() + 1, posNear.getZ()); - - BlockState bLavaAbove = world.getBlockState(posAbove); - BlockState bLava = world.getBlockState(posNear); - - if (!bLavaAbove.isAir()) continue; - if (!bLava.getBlock().equals(Blocks.LAVA)) continue; - if (bLava.getValue(LiquidBlock.LEVEL) != 0) continue; - if (!bStone.canSurvive(world, posNear)) continue; - if (!world.isUnobstructed(bStone, posNear, CollisionContext.empty())) continue; - if (!CraftEventFactory.handleBlockFormEvent(world, posNear, bStone, entity)) continue; - //world.scheduleTick(posNear, Blocks.STONE, Rnd.get(60, 120)); - - Location bukkitLoc = new Location(world.getWorld(), posNear.getX(), posNear.getY(), posNear.getZ()); - blocks.add(bukkitLoc.getBlock()); - } - return blocks; - } - - @NotNull - public Item popResource(@NotNull Block block, @NotNull ItemStack item) { - Level world = ((CraftWorld)block.getWorld()).getHandle(); - BlockPos pos = ((CraftBlock)block).getPosition(); - net.minecraft.world.item.ItemStack itemstack = CraftItemStack.asNMSCopy(item); - - float yMod = EntityType.ITEM.getHeight() / 2.0F; - double x = (pos.getX() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D); - double y = (pos.getY() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D) - yMod; - double z = (pos.getZ() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D); - - ItemEntity itemEntity = new ItemEntity(world, x, y, z, itemstack); - itemEntity.setDefaultPickUpDelay(); - return (Item) itemEntity.getBukkitEntity(); - } -} diff --git a/pom.xml b/pom.xml index 6ef68d9..cd05d99 100644 --- a/pom.xml +++ b/pom.xml @@ -7,16 +7,11 @@ su.nightexpress.excellentenchants ExcellentEnchants pom - 4.1.0 + 4.2.0 API Core NMS - V1_19_R3 - V1_20_R1 - V1_20_R2 - V1_20_R3 - MC_1_20_6 MC_1_21 @@ -30,7 +25,7 @@ su.nightexpress.nightcore nightcore - 2.6.2 + 2.6.3