From ce07be4c8fd15c7dba8b8b5fdbefec32d14ced6a Mon Sep 17 00:00:00 2001 From: nulli0n Date: Sun, 14 May 2023 02:43:33 +0600 Subject: [PATCH] Code improvements --- .../excellentenchants/ExcellentEnchants.java | 20 +- .../api/enchantment/type/FishingEnchant.java | 11 + .../enchantment/EnchantManager.java | 3 - .../enchantment/EnchantRegistry.java | 283 +++++++----------- .../enchantment/impl/ExcellentEnchant.java | 89 +++--- .../impl/armor/EnchantAquaman.java | 4 +- .../impl/armor/EnchantBunnyHop.java | 4 +- .../impl/armor/EnchantColdSteel.java | 4 +- .../armor/EnchantElementalProtection.java | 19 +- .../impl/armor/EnchantFireShield.java | 22 +- .../impl/armor/EnchantFlameWalker.java | 4 +- .../impl/armor/EnchantHardened.java | 4 +- .../impl/armor/EnchantIceShield.java | 4 +- .../impl/armor/EnchantNightVision.java | 4 +- .../impl/armor/EnchantRegrowth.java | 22 +- .../impl/armor/EnchantSaturation.java | 24 +- .../impl/armor/EnchantSelfDestruction.java | 20 +- .../enchantment/impl/armor/EnchantSonic.java | 4 +- .../enchantment/impl/bow/EnchantBomber.java | 19 +- .../impl/bow/EnchantConfusingArrows.java | 4 +- .../impl/bow/EnchantDragonfireArrows.java | 22 +- .../impl/bow/EnchantElectrifiedArrows.java | 4 +- .../enchantment/impl/bow/EnchantEnderBow.java | 4 +- .../impl/bow/EnchantExplosiveArrows.java | 20 +- .../enchantment/impl/bow/EnchantGhast.java | 4 +- .../enchantment/impl/bow/EnchantHover.java | 4 +- .../impl/bow/EnchantPoisonedArrows.java | 4 +- .../impl/bow/EnchantWitheredArrows.java | 4 +- .../impl/fishing/AutoFishEnchant.java | 41 +++ .../impl/fishing/SpeedFishingEnchant.java | 5 - .../impl/tool/EnchantBlastMining.java | 27 +- .../impl/tool/EnchantCurseOfBreaking.java | 21 +- .../impl/tool/EnchantCurseOfMisfortune.java | 4 +- .../impl/tool/EnchantDivineTouch.java | 4 +- .../enchantment/impl/tool/EnchantHaste.java | 4 +- .../impl/tool/EnchantLuckyMiner.java | 22 +- .../impl/tool/EnchantReplanter.java | 4 +- .../impl/tool/EnchantSilkChest.java | 4 +- .../enchantment/impl/tool/EnchantSmelter.java | 11 +- .../impl/tool/EnchantTelekinesis.java | 4 +- .../impl/tool/EnchantTreasures.java | 4 +- .../enchantment/impl/tool/EnchantTunnel.java | 9 +- .../impl/tool/EnchantVeinminer.java | 20 +- .../impl/weapon/EnchantBaneOfNetherspawn.java | 14 +- .../impl/weapon/EnchantBlindness.java | 4 +- .../impl/weapon/EnchantConfusion.java | 4 +- .../enchantment/impl/weapon/EnchantCure.java | 4 +- .../impl/weapon/EnchantCutter.java | 15 +- .../impl/weapon/EnchantDecapitator.java | 5 +- .../impl/weapon/EnchantDoubleStrike.java | 4 +- .../impl/weapon/EnchantExhaust.java | 4 +- .../impl/weapon/EnchantExpHunter.java | 20 +- .../impl/weapon/EnchantIceAspect.java | 4 +- .../impl/weapon/EnchantInfernus.java | 18 +- .../impl/weapon/EnchantNimble.java | 4 +- .../impl/weapon/EnchantParalyze.java | 4 +- .../enchantment/impl/weapon/EnchantRage.java | 4 +- .../impl/weapon/EnchantRocket.java | 4 +- .../impl/weapon/EnchantScavenger.java | 4 +- .../impl/weapon/EnchantSurprise.java | 4 +- .../impl/weapon/EnchantTemper.java | 24 +- .../impl/weapon/EnchantThrifty.java | 4 +- .../impl/weapon/EnchantThunder.java | 4 +- .../impl/weapon/EnchantVampire.java | 18 +- .../enchantment/impl/weapon/EnchantVenom.java | 4 +- .../impl/weapon/EnchantVillageDefender.java | 17 +- .../impl/weapon/EnchantWither.java | 5 +- .../listener/EnchantHandlerListener.java | 21 ++ .../menu/EnchantmentsListMenu.java | 34 +-- .../enchantment/util/EnchantUtils.java | 16 +- .../hook/impl/PlaceholderHook.java | 4 +- .../excellentenchants/nms/EnchantNMS.java | 4 + .../nms/v1_17_R1/V1_17_R1.java | 12 + .../nms/v1_18_R2/V1_18_R2.java | 12 + .../nms/v1_19_R1/V1_19_R1.java | 12 + .../nms/v1_19_R2/V1_19_R2.java | 12 + .../nms/v1_19_R3/V1_19_R3.java | 12 + 77 files changed, 542 insertions(+), 611 deletions(-) create mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/FishingEnchant.java create mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/AutoFishEnchant.java delete mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SpeedFishingEnchant.java diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/ExcellentEnchants.java b/Core/src/main/java/su/nightexpress/excellentenchants/ExcellentEnchants.java index 949eaeb..458eaa6 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/ExcellentEnchants.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/ExcellentEnchants.java @@ -13,6 +13,7 @@ import su.nightexpress.excellentenchants.command.TierbookCommand; import su.nightexpress.excellentenchants.config.Config; import su.nightexpress.excellentenchants.config.Lang; import su.nightexpress.excellentenchants.enchantment.EnchantManager; +import su.nightexpress.excellentenchants.enchantment.EnchantRegistry; import su.nightexpress.excellentenchants.enchantment.type.FitItemType; import su.nightexpress.excellentenchants.hook.HookId; import su.nightexpress.excellentenchants.hook.impl.PlaceholderHook; @@ -27,10 +28,9 @@ import su.nightexpress.excellentenchants.tier.TierManager; public class ExcellentEnchants extends NexPlugin { - public static boolean isLoaded = false; - - private EnchantNMS enchantNMS; + private EnchantRegistry enchantRegistry; private EnchantManager enchantManager; + private EnchantNMS enchantNMS; private TierManager tierManager; @Override @@ -39,6 +39,12 @@ public class ExcellentEnchants extends NexPlugin { return this; } + @Override + public void onLoad() { + super.onLoad(); + this.enchantRegistry = new EnchantRegistry(this); + } + @Override public void enable() { this.setNMS(); @@ -46,6 +52,8 @@ public class ExcellentEnchants extends NexPlugin { this.tierManager = new TierManager(this); this.tierManager.setup(); + this.enchantRegistry.setup(); + this.enchantManager = new EnchantManager(this); this.enchantManager.setup(); } @@ -61,6 +69,7 @@ public class ExcellentEnchants extends NexPlugin { this.tierManager = null; } PlaceholderHook.shutdown(); + //this.enchantRegistry.shutdown(); Do we ever need this at all? } private void setNMS() { @@ -120,6 +129,11 @@ public class ExcellentEnchants extends NexPlugin { return tierManager; } + @NotNull + public EnchantRegistry getEnchantRegistry() { + return this.enchantRegistry; + } + @NotNull public EnchantManager getEnchantManager() { return this.enchantManager; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/FishingEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/FishingEnchant.java new file mode 100644 index 0000000..1665720 --- /dev/null +++ b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/FishingEnchant.java @@ -0,0 +1,11 @@ +package su.nightexpress.excellentenchants.api.enchantment.type; + +import org.bukkit.event.player.PlayerFishEvent; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import su.nightexpress.excellentenchants.api.enchantment.IEnchantment; + +public interface FishingEnchant extends IEnchantment { + + boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level); +} 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 569971f..6e46f73 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantManager.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantManager.java @@ -25,8 +25,6 @@ public class EnchantManager extends AbstractManager { @Override protected void onLoad() { - EnchantRegistry.setup(); - this.enchantmentsListMenu = new EnchantmentsListMenu(this.plugin); this.addListener(new EnchantHandlerListener(this)); this.addListener(new EnchantGenericListener(this)); @@ -53,7 +51,6 @@ public class EnchantManager extends AbstractManager { this.potionEffectsTask.stop(); this.potionEffectsTask = null; } - EnchantRegistry.shutdown(); } @NotNull diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantRegistry.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantRegistry.java index ef6c937..dd8e386 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantRegistry.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantRegistry.java @@ -4,197 +4,125 @@ import org.bukkit.NamespacedKey; import org.bukkit.enchantments.Enchantment; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import su.nexmedia.engine.api.manager.ICleanable; import su.nexmedia.engine.utils.Reflex; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.config.Config; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.armor.*; import su.nightexpress.excellentenchants.enchantment.impl.bow.*; +import su.nightexpress.excellentenchants.enchantment.impl.fishing.AutoFishEnchant; import su.nightexpress.excellentenchants.enchantment.impl.tool.*; import su.nightexpress.excellentenchants.enchantment.impl.universal.EnchantCurseOfFragility; import su.nightexpress.excellentenchants.enchantment.impl.weapon.*; +import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import su.nightexpress.excellentenchants.tier.Tier; -import java.lang.reflect.Field; import java.util.*; +import java.util.function.Supplier; import java.util.stream.Collectors; public class EnchantRegistry { - private static final ExcellentEnchants PLUGIN; - public static final Map REGISTRY_MAP; + public static final Map REGISTRY_MAP = new HashMap<>(); - public static final EnchantBlastMining BLAST_MINING; - public static final EnchantCurseOfBreaking CURSE_OF_BREAKING; - public static final EnchantCurseOfMisfortune CURSE_OF_MISFORTUNE; - public static final EnchantDivineTouch DIVINE_TOUCH; - public static final EnchantHaste HASTE; - public static final EnchantLuckyMiner LUCKY_MINER; - public static final EnchantReplanter REPLANTER; - public static final EnchantSilkChest SILK_CHEST; - public static final EnchantSmelter SMELTER; - public static final EnchantTelekinesis TELEKINESIS; - public static final EnchantTreasures TREASURES; - public static final EnchantTunnel TUNNEL; - public static final EnchantVeinminer VEINMINER; + private final ExcellentEnchants plugin; + private boolean isLocked; - public static final EnchantBaneOfNetherspawn BANE_OF_NETHERSPAWN; - public static final EnchantIceAspect ICE_ASPECT; - public static final EnchantInfernus INFERNUS; - public static final EnchantVenom VENOM; - public static final EnchantExhaust EXHAUST; - public static final EnchantWither WITHER; - public static final EnchantParalyze PARALYZE; - public static final EnchantExpHunter EXP_HUNTER; - public static final EnchantDecapitator DECAPITATOR; - public static final EnchantCutter CUTTER; - public static final EnchantConfusion CONFUSION; - public static final EnchantDoubleStrike DOUBLE_STRIKE; - public static final EnchantNimble NIMBLE; - public static final EnchantBlindness BLINDNESS; - public static final EnchantVampire VAMPIRE; - public static final EnchantCure CURE; - public static final EnchantRage RAGE; - public static final EnchantScavenger SCAVENGER; - public static final EnchantSurprise SURPRISE; - public static final EnchantTemper TEMPER; - public static final EnchantThrifty THRIFTY; - public static final EnchantThunder THUNDER; - public static final EnchantVillageDefender VILLAGE_DEFENDER; - public static final EnchantRocket ROCKET; - - public static final EnchantElementalProtection ELEMENTAL_PROTECTION; - public static final EnchantFireShield FIRE_SHIELD; - public static final EnchantFlameWalker FLAME_WALKER; - public static final EnchantHardened HARDENED; - public static final EnchantIceShield ICE_SHIELD; - public static final EnchantColdSteel COLD_STEEL; - public static final EnchantSelfDestruction SELF_DESTRUCTION; - public static final EnchantSaturation SATURATION; - public static final EnchantAquaman AQUAMAN; - public static final EnchantNightVision NIGHT_VISION; - public static final EnchantBunnyHop BUNNY_HOP; - public static final EnchantSonic SONIC; - public static final EnchantRegrowth REGROWTH; - - public static final EnchantBomber BOMBER; - public static final EnchantConfusingArrows CONFUSING_ARROWS; - public static final EnchantDragonfireArrows DRAGONFIRE_ARROWS; - public static final EnchantElectrifiedArrows ELECTRIFIED_ARROWS; - public static final EnchantEnderBow ENDER_BOW; - public static final EnchantGhast GHAST; - public static final EnchantHover HOVER; - public static final EnchantPoisonedArrows POISONED_ARROWS; - public static final EnchantWitheredArrows WITHERED_ARROWS; - public static final EnchantExplosiveArrows EXPLOSIVE_ARROWS; - - public static final EnchantCurseOfFragility CURSE_OF_FRAGILITY; - - static { - PLUGIN = ExcellentEnchants.getPlugin(ExcellentEnchants.class); - REGISTRY_MAP = new HashMap<>(); - - // Tool enchants - BLAST_MINING = init(EnchantBlastMining.class, EnchantBlastMining.ID); - CURSE_OF_BREAKING = init(EnchantCurseOfBreaking.class, EnchantCurseOfBreaking.ID); - CURSE_OF_MISFORTUNE = init(EnchantCurseOfMisfortune.class, EnchantCurseOfMisfortune.ID); - DIVINE_TOUCH = init(EnchantDivineTouch.class, EnchantDivineTouch.ID); - HASTE = init(EnchantHaste.class, EnchantHaste.ID); - LUCKY_MINER = init(EnchantLuckyMiner.class, EnchantLuckyMiner.ID); - REPLANTER = init(EnchantReplanter.class, EnchantReplanter.ID); - SILK_CHEST = init(EnchantSilkChest.class, EnchantSilkChest.ID); - SMELTER = init(EnchantSmelter.class, EnchantSmelter.ID); - TELEKINESIS = init(EnchantTelekinesis.class, EnchantTelekinesis.ID); - TREASURES = init(EnchantTreasures.class, EnchantTreasures.ID); - TUNNEL = init(EnchantTunnel.class, EnchantTunnel.ID); - VEINMINER = init(EnchantVeinminer.class, EnchantVeinminer.ID); - - // Weapon enchants - BANE_OF_NETHERSPAWN = init(EnchantBaneOfNetherspawn.class, EnchantBaneOfNetherspawn.ID); - BLINDNESS = init(EnchantBlindness.class, EnchantBlindness.ID); - CONFUSION = init(EnchantConfusion.class, EnchantConfusion.ID); - CUTTER = init(EnchantCutter.class, EnchantCutter.ID); - DECAPITATOR = init(EnchantDecapitator.class, EnchantDecapitator.ID); - DOUBLE_STRIKE = init(EnchantDoubleStrike.class, EnchantDoubleStrike.ID); - EXHAUST = init(EnchantExhaust.class, EnchantExhaust.ID); - EXP_HUNTER = init(EnchantExpHunter.class, EnchantExpHunter.ID); - ICE_ASPECT = init(EnchantIceAspect.class, EnchantIceAspect.ID); - INFERNUS = init(EnchantInfernus.class, EnchantInfernus.ID); - NIMBLE = init(EnchantNimble.class, EnchantNimble.ID); - PARALYZE = init(EnchantParalyze.class, EnchantParalyze.ID); - CURE = init(EnchantCure.class, EnchantCure.ID); - RAGE = init(EnchantRage.class, EnchantRage.ID); - ROCKET = init(EnchantRocket.class, EnchantRocket.ID); - SCAVENGER = init(EnchantScavenger.class, EnchantScavenger.ID); - SURPRISE = init(EnchantSurprise.class, EnchantSurprise.ID); - TEMPER = init(EnchantTemper.class, EnchantTemper.ID); - THRIFTY = init(EnchantThrifty.class, EnchantThrifty.ID); - THUNDER = init(EnchantThunder.class, EnchantThunder.ID); - VAMPIRE = init(EnchantVampire.class, EnchantVampire.ID); - VENOM = init(EnchantVenom.class, EnchantVenom.ID); - VILLAGE_DEFENDER = init(EnchantVillageDefender.class, EnchantVillageDefender.ID); - WITHER = init(EnchantWither.class, EnchantWither.ID); - - // Armor enchants - AQUAMAN = init(EnchantAquaman.class, EnchantAquaman.ID); - BUNNY_HOP = init(EnchantBunnyHop.class, EnchantBunnyHop.ID); - COLD_STEEL = init(EnchantColdSteel.class, EnchantColdSteel.ID); - ICE_SHIELD = init(EnchantIceShield.class, EnchantIceShield.ID); - ELEMENTAL_PROTECTION = init(EnchantElementalProtection.class, EnchantElementalProtection.ID); - FIRE_SHIELD = init(EnchantFireShield.class, EnchantFireShield.ID); - FLAME_WALKER = init(EnchantFlameWalker.class, EnchantFlameWalker.ID); - HARDENED = init(EnchantHardened.class, EnchantHardened.ID); - NIGHT_VISION = init(EnchantNightVision.class, EnchantNightVision.ID); - REGROWTH = init(EnchantRegrowth.class, EnchantRegrowth.ID); - SATURATION = init(EnchantSaturation.class, EnchantSaturation.ID); - SELF_DESTRUCTION = init(EnchantSelfDestruction.class, EnchantSelfDestruction.ID); - SONIC = init(EnchantSonic.class, EnchantSonic.ID); - - // Bow enchants - BOMBER = init(EnchantBomber.class, EnchantBomber.ID); - CONFUSING_ARROWS = init(EnchantConfusingArrows.class, EnchantConfusingArrows.ID); - DRAGONFIRE_ARROWS = init(EnchantDragonfireArrows.class, EnchantDragonfireArrows.ID); - ELECTRIFIED_ARROWS = init(EnchantElectrifiedArrows.class, EnchantElectrifiedArrows.ID); - ENDER_BOW = init(EnchantEnderBow.class, EnchantEnderBow.ID); - EXPLOSIVE_ARROWS = init(EnchantExplosiveArrows.class, EnchantExplosiveArrows.ID); - GHAST = init(EnchantGhast.class, EnchantGhast.ID); - HOVER = init(EnchantHover.class, EnchantHover.ID); - POISONED_ARROWS = init(EnchantPoisonedArrows.class, EnchantPoisonedArrows.ID); - WITHERED_ARROWS = init(EnchantWitheredArrows.class, EnchantWitheredArrows.ID); - - // Universal - CURSE_OF_FRAGILITY = init(EnchantCurseOfFragility.class, EnchantCurseOfFragility.ID); + public EnchantRegistry(@NotNull ExcellentEnchants plugin) { + this.plugin = plugin; } - public static void setup() { + public void setup() { // Prevent to register enchantments during the runtime. - if (ExcellentEnchants.isLoaded) { - REGISTRY_MAP.values().forEach(ExcellentEnchant::loadConfig); + if (this.isLocked) { + REGISTRY_MAP.values().forEach(ExcellentEnchant::loadSettings); return; } Reflex.setFieldValue(Enchantment.class, "acceptingNew", true); - for (Field field : EnchantRegistry.class.getFields()) { - if (!ExcellentEnchant.class.isAssignableFrom(field.getType())) continue; - try { - ExcellentEnchant enchant = (ExcellentEnchant) field.get(null); - EnchantRegistry.register(enchant); - } - catch (Exception e) { - e.printStackTrace(); - } - } + // Fising Enchants + this.register(AutoFishEnchant.ID,() -> new AutoFishEnchant(plugin)); + + // Tool enchants + this.register(EnchantBlastMining.ID, () -> new EnchantBlastMining(plugin)); + this.register(EnchantCurseOfBreaking.ID, () -> new EnchantCurseOfBreaking(plugin)); + this.register(EnchantCurseOfMisfortune.ID, () -> new EnchantCurseOfMisfortune(plugin)); + this.register(EnchantDivineTouch.ID, () -> new EnchantDivineTouch(plugin)); + this.register(EnchantHaste.ID, () -> new EnchantHaste(plugin)); + this.register(EnchantLuckyMiner.ID, () -> new EnchantLuckyMiner(plugin)); + this.register(EnchantReplanter.ID, () -> new EnchantReplanter(plugin)); + this.register(EnchantSilkChest.ID, () -> new EnchantSilkChest(plugin)); + this.register(EnchantSmelter.ID, () -> new EnchantSmelter(plugin)); + this.register(EnchantTelekinesis.ID, () -> new EnchantTelekinesis(plugin)); + this.register(EnchantTreasures.ID, () -> new EnchantTreasures(plugin)); + this.register(EnchantTunnel.ID, () -> new EnchantTunnel(plugin)); + this.register(EnchantVeinminer.ID, () -> new EnchantVeinminer(plugin)); + + // Weapon enchants + this.register(EnchantBaneOfNetherspawn.ID, () -> new EnchantBaneOfNetherspawn(plugin)); + this.register(EnchantBlindness.ID, () -> new EnchantBlindness(plugin)); + this.register(EnchantConfusion.ID, () -> new EnchantConfusion(plugin)); + this.register(EnchantCutter.ID, () -> new EnchantCutter(plugin)); + this.register(EnchantDecapitator.ID, () -> new EnchantDecapitator(plugin)); + this.register(EnchantDoubleStrike.ID, () -> new EnchantDoubleStrike(plugin)); + this.register(EnchantExhaust.ID, () -> new EnchantExhaust(plugin)); + this.register(EnchantExpHunter.ID, () -> new EnchantExpHunter(plugin)); + this.register(EnchantIceAspect.ID, () -> new EnchantIceAspect(plugin)); + this.register(EnchantInfernus.ID, () -> new EnchantInfernus(plugin)); + this.register(EnchantNimble.ID, () -> new EnchantNimble(plugin)); + this.register(EnchantParalyze.ID, () -> new EnchantParalyze(plugin)); + this.register(EnchantCure.ID, () -> new EnchantCure(plugin)); + this.register(EnchantRage.ID, () -> new EnchantRage(plugin)); + this.register(EnchantRocket.ID, () -> new EnchantRocket(plugin)); + this.register(EnchantScavenger.ID, () -> new EnchantScavenger(plugin)); + this.register(EnchantSurprise.ID, () -> new EnchantSurprise(plugin)); + this.register(EnchantTemper.ID, () -> new EnchantTemper(plugin)); + this.register(EnchantThrifty.ID, () -> new EnchantThrifty(plugin)); + this.register(EnchantThunder.ID, () -> new EnchantThunder(plugin)); + this.register(EnchantVampire.ID, () -> new EnchantVampire(plugin)); + this.register(EnchantVenom.ID, () -> new EnchantVenom(plugin)); + this.register(EnchantVillageDefender.ID, () -> new EnchantVillageDefender(plugin)); + this.register(EnchantWither.ID, () -> new EnchantWither(plugin)); + + // Armor enchants + this.register(EnchantAquaman.ID, () -> new EnchantAquaman(plugin)); + this.register(EnchantBunnyHop.ID, () -> new EnchantBunnyHop(plugin)); + this.register(EnchantColdSteel.ID, () -> new EnchantColdSteel(plugin)); + this.register(EnchantIceShield.ID, () -> new EnchantIceShield(plugin)); + this.register(EnchantElementalProtection.ID, () -> new EnchantElementalProtection(plugin)); + this.register(EnchantFireShield.ID, () -> new EnchantFireShield(plugin)); + this.register(EnchantFlameWalker.ID, () -> new EnchantFlameWalker(plugin)); + this.register(EnchantHardened.ID, () -> new EnchantHardened(plugin)); + this.register(EnchantNightVision.ID, () -> new EnchantNightVision(plugin)); + this.register(EnchantRegrowth.ID, () -> new EnchantRegrowth(plugin)); + this.register(EnchantSaturation.ID, () -> new EnchantSaturation(plugin)); + this.register(EnchantSelfDestruction.ID, () -> new EnchantSelfDestruction(plugin)); + this.register(EnchantSonic.ID, () -> new EnchantSonic(plugin)); + + // Bow enchants + this.register(EnchantBomber.ID, () -> new EnchantBomber(plugin)); + this.register(EnchantConfusingArrows.ID, () -> new EnchantConfusingArrows(plugin)); + this.register(EnchantDragonfireArrows.ID, () -> new EnchantDragonfireArrows(plugin)); + this.register(EnchantElectrifiedArrows.ID, () -> new EnchantElectrifiedArrows(plugin)); + this.register(EnchantEnderBow.ID, () -> new EnchantEnderBow(plugin)); + this.register(EnchantExplosiveArrows.ID, () -> new EnchantExplosiveArrows(plugin)); + this.register(EnchantGhast.ID, () -> new EnchantGhast(plugin)); + this.register(EnchantHover.ID, () -> new EnchantHover(plugin)); + this.register(EnchantPoisonedArrows.ID, () -> new EnchantPoisonedArrows(plugin)); + this.register(EnchantWitheredArrows.ID, () -> new EnchantWitheredArrows(plugin)); + + // Universal + this.register(EnchantCurseOfFragility.ID, () -> new EnchantCurseOfFragility(plugin)); Enchantment.stopAcceptingRegistrations(); - PLUGIN.info("Enchantments Registered: " + REGISTRY_MAP.size()); - ExcellentEnchants.isLoaded = true; + this.plugin.info("Enchantments Registered: " + getRegistered().size()); + this.isLocked = true; } - @SuppressWarnings("unchecked") - public static void shutdown() { - if (PLUGIN.isEnabled()) return; // Prevent to unregister enchantments during the runtime. + /*@SuppressWarnings("unchecked") + public void shutdown() { + if (this.plugin.isEnabled()) return; // Prevent to unregister enchantments during the runtime. Map byKey = (Map) Reflex.getFieldValue(Enchantment.class, "byKey"); Map byName = (Map) Reflex.getFieldValue(Enchantment.class, "byName"); @@ -211,35 +139,28 @@ public class EnchantRegistry { enchant.unregisterListeners(); } REGISTRY_MAP.clear(); - PLUGIN.info("All enchants are unregistered."); - } + this.plugin.info("All enchants are unregistered."); + }*/ - @Nullable - private static T init(@NotNull Class clazz, @NotNull String id) { - if (Config.ENCHANTMENTS_DISABLED.get().contains(id)) return null; - - try { - return clazz.getConstructor(ExcellentEnchants.class).newInstance(PLUGIN); - } - catch (Exception ex) { - ex.printStackTrace(); - return null; - } - } - - private static void register(@Nullable ExcellentEnchant enchant) { - if (enchant == null) return; + private void register(@NotNull String id, @NotNull Supplier supplier) { + if (Config.ENCHANTMENTS_DISABLED.get().contains(id)) return; + ExcellentEnchant enchant = supplier.get(); Enchantment.registerEnchantment(enchant); REGISTRY_MAP.put(enchant.getKey(), enchant); - enchant.loadConfig(); + enchant.loadSettings(); enchant.getConfig().saveChanges(); enchant.registerListeners(); - PLUGIN.info("Registered enchantment: " + enchant.getId()); + this.plugin.info("Registered enchantment: " + enchant.getId()); } @Nullable - public static ExcellentEnchant get(@NotNull NamespacedKey key) { + public static ExcellentEnchant getById(@NotNull String id) { + return getByKey(EnchantUtils.createKey(id)); + } + + @Nullable + public static ExcellentEnchant getByKey(@NotNull NamespacedKey key) { return REGISTRY_MAP.get(key); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/ExcellentEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/ExcellentEnchant.java index 892310f..e8c6755 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/ExcellentEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/ExcellentEnchant.java @@ -10,6 +10,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import su.nexmedia.engine.api.config.JYML; import su.nexmedia.engine.api.manager.IListener; +import su.nexmedia.engine.api.placeholder.PlaceholderMap; import su.nexmedia.engine.lang.LangManager; import su.nexmedia.engine.utils.ItemUtil; import su.nexmedia.engine.utils.NumberUtil; @@ -19,16 +20,17 @@ import su.nightexpress.excellentenchants.Placeholders; import su.nightexpress.excellentenchants.api.enchantment.IEnchantment; import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; import su.nightexpress.excellentenchants.api.enchantment.meta.Potioned; -import su.nightexpress.excellentenchants.enchantment.config.EnchantDefaults; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.config.Config; +import su.nightexpress.excellentenchants.enchantment.EnchantManager; +import su.nightexpress.excellentenchants.enchantment.config.EnchantDefaults; import su.nightexpress.excellentenchants.enchantment.type.FitItemType; import su.nightexpress.excellentenchants.enchantment.type.ObtainType; +import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import su.nightexpress.excellentenchants.tier.Tier; import java.util.*; -import java.util.function.UnaryOperator; +import java.util.function.Function; import java.util.stream.Stream; public abstract class ExcellentEnchant extends Enchantment implements IEnchantment, IListener { @@ -39,60 +41,69 @@ public abstract class ExcellentEnchant extends Enchantment implements IEnchantme protected final EnchantPriority priority; protected final EnchantDefaults defaults; protected final NamespacedKey chargesKey; + protected final Map placeholdersMap; public ExcellentEnchant(@NotNull ExcellentEnchants plugin, @NotNull String id, @NotNull EnchantPriority priority) { super(NamespacedKey.minecraft(id.toLowerCase())); this.plugin = plugin; this.id = this.getKey().getKey(); - this.cfg = new JYML(plugin.getDataFolder() + "/enchants/", id + ".yml"); + this.cfg = new JYML(plugin.getDataFolder() + EnchantManager.DIR_ENCHANTS, id + ".yml"); this.priority = priority; this.chargesKey = new NamespacedKey(plugin, this.getId() + ".charges"); this.defaults = new EnchantDefaults(this); + this.placeholdersMap = new HashMap<>(); } - public void loadConfig() { + public void loadSettings() { this.cfg.reload(); + this.placeholdersMap.clear(); + this.getDefaults().load(this); - } - @NotNull - public UnaryOperator replaceAllPlaceholders(int level) { - return str -> this.replacePlaceholders(level).apply(str) - .replace(Placeholders.ENCHANTMENT_NAME, this.getDisplayName()) - .replace(Placeholders.ENCHANTMENT_NAME_FORMATTED, this.getNameFormatted(level)) - .replace(Placeholders.ENCHANTMENT_LEVEL, NumberUtil.toRoman(level)) - .replace(Placeholders.ENCHANTMENT_LEVEL_MIN, String.valueOf(this.getStartLevel())) - .replace(Placeholders.ENCHANTMENT_LEVEL_MAX, String.valueOf(this.getMaxLevel())) - .replace(Placeholders.ENCHANTMENT_TIER, this.getTier().getName()) - .replace(Placeholders.ENCHANTMENT_FIT_ITEM_TYPES, String.join(", ", Stream.of(this.getFitItemTypes()).map(type -> plugin.getLangManager().getEnum(type)).toList())) - .replace(Placeholders.ENCHANTMENT_OBTAIN_CHANCE_ENCHANTING, NumberUtil.format(this.getObtainChance(ObtainType.ENCHANTING))) - .replace(Placeholders.ENCHANTMENT_OBTAIN_CHANCE_VILLAGER, NumberUtil.format(this.getObtainChance(ObtainType.VILLAGER))) - .replace(Placeholders.ENCHANTMENT_OBTAIN_CHANCE_LOOT_GENERATION, NumberUtil.format(this.getObtainChance(ObtainType.LOOT_GENERATION))) - .replace(Placeholders.ENCHANTMENT_OBTAIN_CHANCE_FISHING, NumberUtil.format(this.getObtainChance(ObtainType.FISHING))) - .replace(Placeholders.ENCHANTMENT_OBTAIN_CHANCE_MOB_SPAWNING, NumberUtil.format(this.getObtainChance(ObtainType.MOB_SPAWNING))) - .replace(Placeholders.ENCHANTMENT_CHARGES_MAX_AMOUNT, String.valueOf(this.getChargesMax(level))) - .replace(Placeholders.ENCHANTMENT_CHARGES_CONSUME_AMOUNT, String.valueOf(this.getChargesConsumeAmount(level))) - .replace(Placeholders.ENCHANTMENT_CHARGES_RECHARGE_AMOUNT, String.valueOf(this.getChargesRechargeAmount(level))) - .replace(Placeholders.ENCHANTMENT_CHARGES_FUEL_ITEM, ItemUtil.getItemName(this.getChargesFuel())) - ; - } + for (int i = this.getStartLevel(); i < this.getMaxLevel() + 1; i++) { + int level = i; - @NotNull - public UnaryOperator replacePlaceholders(int level) { - return str -> { - str = str.replace(Placeholders.ENCHANTMENT_DESCRIPTION, String.join("\n", this.getDescription())); + PlaceholderMap map = new PlaceholderMap() + .add(Placeholders.ENCHANTMENT_DESCRIPTION, () -> String.join("\n", this.getDescription())) + .add(Placeholders.ENCHANTMENT_NAME, this::getDisplayName) + .add(Placeholders.ENCHANTMENT_NAME_FORMATTED, () -> this.getNameFormatted(level)) + .add(Placeholders.ENCHANTMENT_LEVEL, () -> NumberUtil.toRoman(level)) + .add(Placeholders.ENCHANTMENT_LEVEL_MIN, () -> String.valueOf(this.getStartLevel())) + .add(Placeholders.ENCHANTMENT_LEVEL_MAX, () -> String.valueOf(this.getMaxLevel())) + .add(Placeholders.ENCHANTMENT_TIER, () -> this.getTier().getName()) + .add(Placeholders.ENCHANTMENT_FIT_ITEM_TYPES, () -> String.join(", ", Stream.of(this.getFitItemTypes()).map(type -> plugin.getLangManager().getEnum(type)).toList())) + .add(Placeholders.ENCHANTMENT_OBTAIN_CHANCE_ENCHANTING, () -> NumberUtil.format(this.getObtainChance(ObtainType.ENCHANTING))) + .add(Placeholders.ENCHANTMENT_OBTAIN_CHANCE_VILLAGER, () -> NumberUtil.format(this.getObtainChance(ObtainType.VILLAGER))) + .add(Placeholders.ENCHANTMENT_OBTAIN_CHANCE_LOOT_GENERATION, () -> NumberUtil.format(this.getObtainChance(ObtainType.LOOT_GENERATION))) + .add(Placeholders.ENCHANTMENT_OBTAIN_CHANCE_FISHING, () -> NumberUtil.format(this.getObtainChance(ObtainType.FISHING))) + .add(Placeholders.ENCHANTMENT_OBTAIN_CHANCE_MOB_SPAWNING, () -> NumberUtil.format(this.getObtainChance(ObtainType.MOB_SPAWNING))) + .add(Placeholders.ENCHANTMENT_CHARGES_MAX_AMOUNT, () -> NumberUtil.format(this.getChargesMax(level))) + .add(Placeholders.ENCHANTMENT_CHARGES_CONSUME_AMOUNT, () -> NumberUtil.format(this.getChargesConsumeAmount(level))) + .add(Placeholders.ENCHANTMENT_CHARGES_RECHARGE_AMOUNT, () -> NumberUtil.format(this.getChargesRechargeAmount(level))) + .add(Placeholders.ENCHANTMENT_CHARGES_FUEL_ITEM, () -> ItemUtil.getItemName(this.getChargesFuel())); if (this instanceof Chanced chanced) { - str = str.replace(Placeholders.ENCHANTMENT_CHANCE, NumberUtil.format(chanced.getTriggerChance(level))); + map.add(Placeholders.ENCHANTMENT_CHANCE, () -> NumberUtil.format(chanced.getTriggerChance(level))); } if (this instanceof Potioned potioned) { - str = str - .replace(Placeholders.ENCHANTMENT_POTION_LEVEL, NumberUtil.toRoman(potioned.getEffectAmplifier(level))) - .replace(Placeholders.ENCHANTMENT_POTION_DURATION, NumberUtil.format((double) potioned.getEffectDuration(level) / 20D)) - .replace(Placeholders.ENCHANTMENT_POTION_TYPE, LangManager.getPotionType(potioned.getEffectType())); + map.add(Placeholders.ENCHANTMENT_POTION_LEVEL, () -> NumberUtil.toRoman(potioned.getEffectAmplifier(level))); + map.add(Placeholders.ENCHANTMENT_POTION_DURATION, () -> NumberUtil.format(potioned.getEffectDuration(level) / 20D)); + map.add(Placeholders.ENCHANTMENT_POTION_TYPE, () -> LangManager.getPotionType(potioned.getEffectType())); } - return str; - }; + + this.placeholdersMap.put(level, map); + } + } + + @NotNull + public PlaceholderMap getPlaceholders(int level) { + return this.placeholdersMap.get(level); + } + + public void addPlaceholder(@NotNull String key, @NotNull Function replacer) { + for (int level = this.getStartLevel(); level < this.getMaxLevel() + 1; level++) { + this.getPlaceholders(level).add(key, replacer.apply(level)); + } } @Override @@ -172,7 +183,7 @@ public abstract class ExcellentEnchant extends Enchantment implements IEnchantme @NotNull public List getDescription(int level) { List description = new ArrayList<>(this.getDescription()); - description.replaceAll(this.replacePlaceholders(level)); + description.replaceAll(this.getPlaceholders(level).replacer()); return description; } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantAquaman.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantAquaman.java index 8784a88..67de252 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantAquaman.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantAquaman.java @@ -27,8 +27,8 @@ public class EnchantAquaman extends ExcellentEnchant implements Potioned, Passiv } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.potionImplementation = PotionImplementation.create(this, PotionEffectType.WATER_BREATHING, true); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantBunnyHop.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantBunnyHop.java index 6ed17b8..a08aae3 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantBunnyHop.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantBunnyHop.java @@ -27,8 +27,8 @@ public class EnchantBunnyHop extends ExcellentEnchant implements Potioned, Passi } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.potionImplementation = PotionImplementation.create(this, PotionEffectType.JUMP, true); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantColdSteel.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantColdSteel.java index 548a0cc..712c3d6 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantColdSteel.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantColdSteel.java @@ -32,8 +32,8 @@ public class EnchantColdSteel extends ExcellentEnchant implements Chanced, Potio } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "60 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5"); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantElementalProtection.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantElementalProtection.java index 53518aa..fe02a04 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantElementalProtection.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantElementalProtection.java @@ -11,13 +11,12 @@ import su.nexmedia.engine.api.config.JOption; import su.nexmedia.engine.utils.NumberUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; +import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; -import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import java.util.Set; -import java.util.function.UnaryOperator; public class EnchantElementalProtection extends ExcellentEnchant { @@ -42,17 +41,8 @@ public class EnchantElementalProtection extends ExcellentEnchant { } @Override - @NotNull - public UnaryOperator replacePlaceholders(int level) { - return str -> super.replacePlaceholders(level).apply(str) - .replace(PLACEHOLDER_PROTECTION_AMOUNT, NumberUtil.format(this.getProtectionAmount(level))) - .replace(PLACEHOLDER_PROTECTION_CAPACITY, NumberUtil.format(this.getProtectionCapacity())) - ; - } - - @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.protectionAmount = EnchantScaler.read(this, "Settings.Protection.Amount", "0.05 * " + Placeholders.ENCHANTMENT_LEVEL, @@ -62,6 +52,9 @@ public class EnchantElementalProtection extends ExcellentEnchant { this.protectionAsModifier = JOption.create("Settings.Protection.As_Modifier", false, "When 'true' damage will be reduced by a percent of protection value.", "When 'false' damage will be reduced by a plain protection value.").read(cfg); + + this.addPlaceholder(PLACEHOLDER_PROTECTION_AMOUNT, level -> NumberUtil.format(this.getProtectionAmount(level))); + this.addPlaceholder(PLACEHOLDER_PROTECTION_CAPACITY, level -> NumberUtil.format(this.getProtectionCapacity())); } @NotNull diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantFireShield.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantFireShield.java index fbad30a..db63449 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantFireShield.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantFireShield.java @@ -8,14 +8,12 @@ import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.utils.NumberUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; -import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; - -import java.util.function.UnaryOperator; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; +import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; +import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantFireShield extends ExcellentEnchant implements Chanced, CombatEnchant { @@ -33,16 +31,8 @@ public class EnchantFireShield extends ExcellentEnchant implements Chanced, Comb } @Override - @NotNull - public UnaryOperator replacePlaceholders(int level) { - return str -> super.replacePlaceholders(level).apply(str) - .replace(PLACEHOLDER_FIRE_DURATION, NumberUtil.format(this.getFireDuration(level))) - ; - } - - @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, Placeholders.ENCHANTMENT_LEVEL + " * 15.0"); @@ -51,6 +41,8 @@ public class EnchantFireShield extends ExcellentEnchant implements Chanced, Comb "Sets the fire duration (in seconds).", "If entity's current fire ticks amount is less than this value, it will be set to this value.", "If entity's current fire ticks amount is greater than this value, it won't be changed."); + + this.addPlaceholder(PLACEHOLDER_FIRE_DURATION, level -> NumberUtil.format(this.getFireDuration(level))); } @NotNull diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantFlameWalker.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantFlameWalker.java index a2633f6..5cb4a01 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantFlameWalker.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantFlameWalker.java @@ -53,8 +53,8 @@ public class EnchantFlameWalker extends ExcellentEnchant implements ICleanable { } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.blockDecayTime = EnchantScaler.read(this, "Settings.Block_Decay", "12.0", "Sets up to how long (in seconds) blocks will stay before turn back to lava."); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantHardened.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantHardened.java index 3653fbe..d15c978 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantHardened.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantHardened.java @@ -31,8 +31,8 @@ public class EnchantHardened extends ExcellentEnchant implements Chanced, Potion } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "30.0 * " + Placeholders.ENCHANTMENT_LEVEL); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantIceShield.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantIceShield.java index 0d2b3af..d65bccb 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantIceShield.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantIceShield.java @@ -34,8 +34,8 @@ public class EnchantIceShield extends ExcellentEnchant implements Chanced, Potio } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "25.0 * " + Placeholders.ENCHANTMENT_LEVEL); this.potionImplementation = PotionImplementation.create(this, PotionEffectType.SLOW, false, "3.0 + " + Placeholders.ENCHANTMENT_LEVEL, diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantNightVision.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantNightVision.java index fcf52cf..9ddafa5 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantNightVision.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantNightVision.java @@ -27,8 +27,8 @@ public class EnchantNightVision extends ExcellentEnchant implements Potioned, Pa } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.potionImplementation = PotionImplementation.create(this, PotionEffectType.NIGHT_VISION, true); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantRegrowth.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantRegrowth.java index 3552237..af82685 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantRegrowth.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantRegrowth.java @@ -22,8 +22,6 @@ import su.nightexpress.excellentenchants.enchantment.task.AbstractEnchantmentTas import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; -import java.util.function.UnaryOperator; - public class EnchantRegrowth extends ExcellentEnchant implements Chanced, PassiveEnchant, ICleanable { public static final String ID = "regrowth"; @@ -49,8 +47,8 @@ public class EnchantRegrowth extends ExcellentEnchant implements Chanced, Passiv } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "20.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5"); this.healInterval = JOption.create("Settings.Heal.Interval", 100, @@ -62,6 +60,11 @@ public class EnchantRegrowth extends ExcellentEnchant implements Chanced, Passiv this.healAmount = EnchantScaler.read(this, "Settings.Heal.Amount", "0.25", "Amount of hearts to be restored."); + this.addPlaceholder(PLACEHOLDER_HEAL_AMOUNT, level -> NumberUtil.format(this.getHealAmount(level))); + this.addPlaceholder(PLACEHOLDER_HEAL_MIN_HEALTH, level -> NumberUtil.format(this.getHealMaxHealth(level))); + this.addPlaceholder(PLACEHOLDER_HEAL_MAX_HEALTH, level -> NumberUtil.format(this.getHealMaxHealth(level))); + this.addPlaceholder(PLACEHOLDER_HEAL_INTERVAL, level -> NumberUtil.format((double) this.healInterval / 20D)); + this.task = new Task(plugin); this.task.start(); } @@ -78,17 +81,6 @@ public class EnchantRegrowth extends ExcellentEnchant implements Chanced, Passiv } } - @Override - @NotNull - public UnaryOperator replacePlaceholders(int level) { - return str -> super.replacePlaceholders(level).apply(str) - .replace(PLACEHOLDER_HEAL_AMOUNT, NumberUtil.format(this.getHealAmount(level))) - .replace(PLACEHOLDER_HEAL_MIN_HEALTH, NumberUtil.format(this.getHealMaxHealth(level))) - .replace(PLACEHOLDER_HEAL_MAX_HEALTH, NumberUtil.format(this.getHealMaxHealth(level))) - .replace(PLACEHOLDER_HEAL_INTERVAL, NumberUtil.format((double) this.healInterval / 20D)) - ; - } - @NotNull @Override public ChanceImplementation getChanceImplementation() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantSaturation.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantSaturation.java index d98bae4..a4acd16 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantSaturation.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantSaturation.java @@ -10,15 +10,13 @@ import su.nexmedia.engine.api.manager.ICleanable; import su.nexmedia.engine.utils.NumberUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.task.AbstractEnchantmentTask; +import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; -import java.util.function.UnaryOperator; - public class EnchantSaturation extends ExcellentEnchant implements PassiveEnchant, ICleanable { public static final String ID = "saturation"; @@ -41,8 +39,8 @@ public class EnchantSaturation extends ExcellentEnchant implements PassiveEnchan } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.saturationInterval = JOption.create("Settings.Saturation.Interval", 100, "How often (in ticks) enchantment will have effect? 1 second = 20 ticks.").read(cfg); this.saturationAmount = EnchantScaler.read(this, "Settings.Saturation.Amount", Placeholders.ENCHANTMENT_LEVEL, @@ -50,6 +48,10 @@ public class EnchantSaturation extends ExcellentEnchant implements PassiveEnchan this.saturationMaxFoodLevel = EnchantScaler.read(this, "Settings.Saturation.Max_Food_Level", "20", "Maximal player's food level for the enchantment to stop feeding them."); + this.addPlaceholder(PLACEHOLDER_SATURATION_AMOUNT, level -> NumberUtil.format(this.getSaturationAmount(level))); + this.addPlaceholder(PLACEHOLDER_SATURATION_INTERVAL, level -> NumberUtil.format((double) this.saturationInterval / 20D)); + this.addPlaceholder(PLACEHOLDER_SATURATION_MAX_FOOD_LEVEL, level -> NumberUtil.format(this.getMaxFoodLevel(level))); + this.task = new Task(plugin); this.task.start(); } @@ -66,16 +68,6 @@ public class EnchantSaturation extends ExcellentEnchant implements PassiveEnchan } } - @Override - @NotNull - public UnaryOperator replacePlaceholders(int level) { - return str -> super.replacePlaceholders(level).apply(str) - .replace(PLACEHOLDER_SATURATION_AMOUNT, NumberUtil.format(this.getSaturationAmount(level))) - .replace(PLACEHOLDER_SATURATION_INTERVAL, NumberUtil.format((double) this.saturationInterval / 20D)) - .replace(PLACEHOLDER_SATURATION_MAX_FOOD_LEVEL, NumberUtil.format(this.getMaxFoodLevel(level))) - ; - } - @Override @NotNull public EnchantmentTarget getItemTarget() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantSelfDestruction.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantSelfDestruction.java index 2d836c9..eb6a380 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantSelfDestruction.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantSelfDestruction.java @@ -13,14 +13,12 @@ import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.utils.NumberUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; -import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; - -import java.util.function.UnaryOperator; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; +import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; +import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantSelfDestruction extends ExcellentEnchant implements Chanced, DeathEnchant { @@ -40,21 +38,15 @@ public class EnchantSelfDestruction extends ExcellentEnchant implements Chanced, } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "20.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 10"); this.explosionSize = EnchantScaler.read(this, "Settings.Explosion.Size", "1.0" + Placeholders.ENCHANTMENT_LEVEL, "A size of the explosion. The more size - the bigger the damage."); - } - @Override - @NotNull - public UnaryOperator replacePlaceholders(int level) { - return str -> super.replacePlaceholders(level).apply(str) - .replace(PLACEHOLDER_EXPLOSION_POWER, NumberUtil.format(this.getExplosionSize(level))) - ; + this.addPlaceholder(PLACEHOLDER_EXPLOSION_POWER, level -> NumberUtil.format(this.getExplosionSize(level))); } @NotNull diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantSonic.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantSonic.java index 4be2cda..9e97483 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantSonic.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantSonic.java @@ -27,8 +27,8 @@ public class EnchantSonic extends ExcellentEnchant implements Potioned, PassiveE } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.potionImplementation = PotionImplementation.create(this, PotionEffectType.SPEED, true); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantBomber.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantBomber.java index 9cd1839..a7116ab 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantBomber.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantBomber.java @@ -13,14 +13,12 @@ import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.utils.NumberUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; -import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; - -import java.util.function.UnaryOperator; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; +import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; +import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantBomber extends ExcellentEnchant implements Chanced, BowEnchant { @@ -47,20 +45,15 @@ public class EnchantBomber extends ExcellentEnchant implements Chanced, BowEncha } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "5.0 * " + Placeholders.ENCHANTMENT_LEVEL); this.fuseTicks = EnchantScaler.read(this, "Settings.Fuse_Ticks", "100 - " + Placeholders.ENCHANTMENT_LEVEL + " * 10", "Sets fuse ticks (before it will explode) for the launched TNT."); - } - @Override - @NotNull - public UnaryOperator replacePlaceholders(int level) { - return str -> super.replacePlaceholders(level).apply(str) - .replace(PLACEHOLDER_FUSE_TICKS, NumberUtil.format((double) this.getFuseTicks(level) / 20D)); + this.addPlaceholder(PLACEHOLDER_FUSE_TICKS, level -> NumberUtil.format((double) this.getFuseTicks(level) / 20D)); } @NotNull diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantConfusingArrows.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantConfusingArrows.java index 1061945..f749165 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantConfusingArrows.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantConfusingArrows.java @@ -46,8 +46,8 @@ public class EnchantConfusingArrows extends ExcellentEnchant implements Chanced, } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.arrowImplementation = ArrowImplementation.create(this, SimpleParticle.of(Particle.SPELL_MOB)); this.chanceImplementation = ChanceImplementation.create(this, "20.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5.0"); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantDragonfireArrows.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantDragonfireArrows.java index a14aca5..6aeb214 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantDragonfireArrows.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantDragonfireArrows.java @@ -20,16 +20,14 @@ import su.nexmedia.engine.api.particle.SimpleParticle; import su.nexmedia.engine.utils.NumberUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.api.enchantment.meta.Arrowed; import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; +import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ArrowImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; -import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; - -import java.util.function.UnaryOperator; +import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantDragonfireArrows extends ExcellentEnchant implements Chanced, Arrowed, BowEnchant { @@ -58,8 +56,8 @@ public class EnchantDragonfireArrows extends ExcellentEnchant implements Chanced } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.arrowImplementation = ArrowImplementation.create(this, SimpleParticle.of(Particle.DRAGON_BREATH)); this.chanceImplementation = ChanceImplementation.create(this, "10.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5"); @@ -69,15 +67,9 @@ public class EnchantDragonfireArrows extends ExcellentEnchant implements Chanced this.fireRadius = EnchantScaler.read(this, "Settings.Fire.Radius", "2.0 + " + Placeholders.ENCHANTMENT_LEVEL, "Sets the dragonfire cloud effect radius."); - } - @Override - @NotNull - public UnaryOperator replacePlaceholders(int level) { - return str -> super.replacePlaceholders(level).apply(str) - .replace(PLACEHOLDER_FIRE_DURATION, NumberUtil.format(this.getFireDuration(level) / 20D)) - .replace(PLACEHOLDER_FIRE_RADIUS, NumberUtil.format(this.getFireRadius(level))) - ; + this.addPlaceholder(PLACEHOLDER_FIRE_DURATION, level -> NumberUtil.format(this.getFireDuration(level) / 20D)); + this.addPlaceholder(PLACEHOLDER_FIRE_RADIUS, level -> NumberUtil.format(this.getFireRadius(level))); } @NotNull diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantElectrifiedArrows.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantElectrifiedArrows.java index fed3c1c..8f7dc00 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantElectrifiedArrows.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantElectrifiedArrows.java @@ -51,8 +51,8 @@ public class EnchantElectrifiedArrows extends ExcellentEnchant implements Chance } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.arrowImplementation = ArrowImplementation.create(this, SimpleParticle.of(Particle.FIREWORKS_SPARK)); this.chanceImplementation = ChanceImplementation.create(this, "10.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5"); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantEnderBow.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantEnderBow.java index 9b6f048..e623526 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantEnderBow.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantEnderBow.java @@ -41,8 +41,8 @@ public class EnchantEnderBow extends ExcellentEnchant implements BowEnchant, Cha } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "100"); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantExplosiveArrows.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantExplosiveArrows.java index 2a86755..99ebe9c 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantExplosiveArrows.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantExplosiveArrows.java @@ -18,16 +18,14 @@ import su.nexmedia.engine.api.particle.SimpleParticle; import su.nexmedia.engine.utils.NumberUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.api.enchantment.meta.Arrowed; import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; +import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ArrowImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; -import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; - -import java.util.function.UnaryOperator; +import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantExplosiveArrows extends ExcellentEnchant implements Chanced, Arrowed, BowEnchant { @@ -58,8 +56,8 @@ public class EnchantExplosiveArrows extends ExcellentEnchant implements Chanced, } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.arrowImplementation = ArrowImplementation.create(this, SimpleParticle.of(Particle.SMOKE_NORMAL)); this.chanceImplementation = ChanceImplementation.create(this, "10.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5"); @@ -72,14 +70,8 @@ public class EnchantExplosiveArrows extends ExcellentEnchant implements Chanced, this.explosionSize = EnchantScaler.read(this, "Settings.Explosion.Size", "2.0 + " + Placeholders.ENCHANTMENT_LEVEL, "Sets the explosion size. The more size - the bigger explosion."); - } - @Override - @NotNull - public UnaryOperator replacePlaceholders(int level) { - return str -> super.replacePlaceholders(level).apply(str) - .replace(PLACEHOLDER_EXPLOSION_POWER, NumberUtil.format(this.getExplosionSize(level))) - ; + this.addPlaceholder(PLACEHOLDER_EXPLOSION_POWER, level -> NumberUtil.format(this.getExplosionSize(level))); } @NotNull diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantGhast.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantGhast.java index 96982b3..233a14f 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantGhast.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantGhast.java @@ -48,8 +48,8 @@ public class EnchantGhast extends ExcellentEnchant implements BowEnchant, Chance } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "100"); this.fireSpread = JOption.create("Settings.Fire_Spread", true, "When 'true' creates fire on nearby blocks.").read(cfg); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantHover.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantHover.java index f1ecdec..88d34d5 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantHover.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantHover.java @@ -46,8 +46,8 @@ public class EnchantHover extends ExcellentEnchant implements Chanced, Arrowed, } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.arrowImplementation = ArrowImplementation.create(this, SimpleParticle.of(Particle.BUBBLE_POP)); this.chanceImplementation = ChanceImplementation.create(this, "10.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5"); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantPoisonedArrows.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantPoisonedArrows.java index 78e3a45..d435a1d 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantPoisonedArrows.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantPoisonedArrows.java @@ -47,8 +47,8 @@ public class EnchantPoisonedArrows extends ExcellentEnchant implements Chanced, } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.arrowImplementation = ArrowImplementation.create(this, SimpleParticle.of(Particle.SLIME)); this.chanceImplementation = ChanceImplementation.create(this, "25.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5"); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantWitheredArrows.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantWitheredArrows.java index dd7def6..7facc29 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantWitheredArrows.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantWitheredArrows.java @@ -47,8 +47,8 @@ public class EnchantWitheredArrows extends ExcellentEnchant implements Chanced, } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.arrowImplementation = ArrowImplementation.create(this, SimpleParticle.of(Particle.SPELL_WITCH)); this.chanceImplementation = ChanceImplementation.create(this, "15.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5.0"); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/AutoFishEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/AutoFishEnchant.java new file mode 100644 index 0000000..473469b --- /dev/null +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/AutoFishEnchant.java @@ -0,0 +1,41 @@ +package su.nightexpress.excellentenchants.enchantment.impl.fishing; + +import org.bukkit.enchantments.EnchantmentTarget; +import org.bukkit.event.player.PlayerFishEvent; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import su.nightexpress.excellentenchants.ExcellentEnchants; +import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; +import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; + +public class AutoFishEnchant extends ExcellentEnchant implements FishingEnchant { + + public static final String ID = "auto_fish"; + + public AutoFishEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID, EnchantPriority.MEDIUM); + this.getDefaults().setDescription("Automatically reels in a hook on bite."); + this.getDefaults().setLevelMax(1); + this.getDefaults().setTier(1.0); + } + + @NotNull + @Override + public EnchantmentTarget getItemTarget() { + return EnchantmentTarget.FISHING_ROD; + } + + @Override + public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) { + if (event.getState() != PlayerFishEvent.State.BITE) return false; + + this.plugin.runTask(task -> { + if (event.isCancelled()) return; + + plugin.getEnchantNMS().sendAttackPacket(event.getPlayer(), 0); + plugin.getEnchantNMS().retrieveHook(event.getHook(), item); + }); + return true; + } +} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SpeedFishingEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SpeedFishingEnchant.java deleted file mode 100644 index 50c8b8b..0000000 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SpeedFishingEnchant.java +++ /dev/null @@ -1,5 +0,0 @@ -package su.nightexpress.excellentenchants.enchantment.impl.fishing; - -public class SpeedFishingEnchant { - -} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantBlastMining.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantBlastMining.java index c254b82..6f34627 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantBlastMining.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantBlastMining.java @@ -16,19 +16,17 @@ import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.utils.NumberUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; import su.nightexpress.excellentenchants.api.enchantment.type.BlockBreakEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; +import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; +import su.nightexpress.excellentenchants.enchantment.type.FitItemType; +import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import su.nightexpress.excellentenchants.hook.impl.NoCheatPlusHook; -import su.nightexpress.excellentenchants.enchantment.EnchantRegistry; -import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; -import su.nightexpress.excellentenchants.enchantment.type.FitItemType; import java.util.List; -import java.util.function.UnaryOperator; public class EnchantBlastMining extends ExcellentEnchant implements Chanced, BlockBreakEnchant { @@ -52,8 +50,8 @@ public class EnchantBlastMining extends ExcellentEnchant implements Chanced, Blo } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "20.0 * " + Placeholders.ENCHANTMENT_LEVEL); this.explosionPower = EnchantScaler.read(this, "Settings.Explosion.Power", @@ -64,6 +62,8 @@ public class EnchantBlastMining extends ExcellentEnchant implements Chanced, Blo "Minimal block strength value for the enchantment to have effect.", "Block strength value is how long it takes to break the block by a hand.", "For example, a Stone has 3.0 strength."); + + this.addPlaceholder(PLACEHOLDER_EXPLOSION_POWER, level -> NumberUtil.format(this.getExplosionPower(level))); } @NotNull @@ -85,13 +85,6 @@ public class EnchantBlastMining extends ExcellentEnchant implements Chanced, Blo return (strength >= this.getMinBlockStrength(level)); } - @Override - @NotNull - public UnaryOperator replacePlaceholders(int level) { - return str -> super.replacePlaceholders(level).apply(str) - .replace(PLACEHOLDER_EXPLOSION_POWER, NumberUtil.format(this.getExplosionPower(level))); - } - @Override @NotNull public FitItemType[] getFitItemTypes() { @@ -108,8 +101,8 @@ public class EnchantBlastMining extends ExcellentEnchant implements Chanced, Blo public boolean onBreak(@NotNull BlockBreakEvent e, @NotNull Player player, @NotNull ItemStack item, int level) { if (!this.isAvailableToUse(player)) return false; - if (EnchantRegistry.VEINMINER != null && EnchantUtils.contains(item, EnchantRegistry.VEINMINER)) return false; - if (EnchantRegistry.TUNNEL != null && EnchantUtils.contains(item, EnchantRegistry.TUNNEL)) return false; + if (EnchantUtils.contains(item, EnchantVeinminer.ID)) return false; + if (EnchantUtils.contains(item, EnchantTunnel.ID)) return false; Block block = e.getBlock(); if (block.hasMetadata(META_EXPLOSION_MINED)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantCurseOfBreaking.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantCurseOfBreaking.java index 0261b1f..bc88ee9 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantCurseOfBreaking.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantCurseOfBreaking.java @@ -10,15 +10,13 @@ import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.utils.NumberUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; -import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; +import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; +import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; -import java.util.function.UnaryOperator; - public class EnchantCurseOfBreaking extends ExcellentEnchant implements Chanced { public static final String ID = "curse_of_breaking"; @@ -35,13 +33,15 @@ public class EnchantCurseOfBreaking extends ExcellentEnchant implements Chanced } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "10.0 * " + Placeholders.ENCHANTMENT_LEVEL); this.durabilityAmount = EnchantScaler.read(this, "Settings.Durability_Amount", Placeholders.ENCHANTMENT_LEVEL, "Amount of durability points to be taken from the item."); + + this.addPlaceholder(PLACEHOLDER_DURABILITY_AMOUNT, level -> NumberUtil.format(this.getDurabilityAmount(level))); } @Override @@ -59,13 +59,6 @@ public class EnchantCurseOfBreaking extends ExcellentEnchant implements Chanced return (int) this.durabilityAmount.getValue(level); } - @Override - @NotNull - public UnaryOperator replacePlaceholders(int level) { - return str -> super.replacePlaceholders(level).apply(str) - .replace(PLACEHOLDER_DURABILITY_AMOUNT, NumberUtil.format(this.getDurabilityAmount(level))); - } - @NotNull @Override public EnchantmentTarget getItemTarget() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantCurseOfMisfortune.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantCurseOfMisfortune.java index 9f6d407..6fd9b8a 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantCurseOfMisfortune.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantCurseOfMisfortune.java @@ -38,8 +38,8 @@ public class EnchantCurseOfMisfortune extends ExcellentEnchant implements Chance } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "20.0 * " + Placeholders.ENCHANTMENT_LEVEL); this.dropExp = JOption.create("Settings.Drop_Exp", false, diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantDivineTouch.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantDivineTouch.java index 839e0b1..06735f6 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantDivineTouch.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantDivineTouch.java @@ -49,8 +49,8 @@ public class EnchantDivineTouch extends ExcellentEnchant implements Chanced, Blo } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "15.0 * " + Placeholders.ENCHANTMENT_LEVEL); this.spawnerName = JOption.create("Settings.Spawner_Item.Name", diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantHaste.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantHaste.java index 1e1699e..2ed436e 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantHaste.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantHaste.java @@ -27,8 +27,8 @@ public class EnchantHaste extends ExcellentEnchant implements Potioned, PassiveE } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.potionImplementation = PotionImplementation.create(this, PotionEffectType.FAST_DIGGING, true); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantLuckyMiner.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantLuckyMiner.java index 402c956..6bcecfe 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantLuckyMiner.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantLuckyMiner.java @@ -8,15 +8,13 @@ import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.utils.NumberUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; import su.nightexpress.excellentenchants.api.enchantment.type.BlockBreakEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; -import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; +import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.type.FitItemType; - -import java.util.function.UnaryOperator; +import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantLuckyMiner extends ExcellentEnchant implements Chanced, BlockBreakEnchant { @@ -34,13 +32,15 @@ public class EnchantLuckyMiner extends ExcellentEnchant implements Chanced, Bloc } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "30.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 7.0"); this.expModifier = EnchantScaler.read(this, "Settings.Exp_Modifier", "1.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 0.5", "Exp modifier value. The original exp amount will be multiplied on this value."); + + this.addPlaceholder(PLACEHOLDER_EXP_MODIFIER, level -> NumberUtil.format(this.getExpModifier(level) * 100D - 100D)); } @NotNull @@ -53,14 +53,6 @@ public class EnchantLuckyMiner extends ExcellentEnchant implements Chanced, Bloc return this.expModifier.getValue(level); } - @Override - @NotNull - public UnaryOperator replacePlaceholders(int level) { - return str -> super.replacePlaceholders(level).apply(str) - .replace(PLACEHOLDER_EXP_MODIFIER, NumberUtil.format(this.getExpModifier(level) * 100D - 100D)) - ; - } - @Override @NotNull public FitItemType[] getFitItemTypes() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantReplanter.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantReplanter.java index 826e2e8..ce9d047 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantReplanter.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantReplanter.java @@ -49,8 +49,8 @@ public class EnchantReplanter extends ExcellentEnchant implements Chanced, Inter } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "100"); this.replantOnRightClick = JOption.create("Settings.Replant.On_Right_Click", true, "When 'true', player will be able to replant crops when right-clicking farmland blocks.").read(cfg); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantSilkChest.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantSilkChest.java index 894706a..3356c76 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantSilkChest.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantSilkChest.java @@ -60,8 +60,8 @@ public class EnchantSilkChest extends ExcellentEnchant implements BlockDropEncha } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chestName = JOption.create("Settings.Chest_Item.Name", "Chest &7(" + Placeholders.GENERIC_AMOUNT + " items)", "Chest item display name.", "Use '" + Placeholders.GENERIC_AMOUNT + "' for items amount.").mapReader(Colorizer::apply).read(cfg); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantSmelter.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantSmelter.java index 2cbe021..b8d16cd 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantSmelter.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantSmelter.java @@ -27,7 +27,6 @@ import su.nightexpress.excellentenchants.enchantment.util.EnchantDropContainer; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import java.util.Map; -import java.util.Objects; public class EnchantSmelter extends ExcellentEnchant implements Chanced, BlockDropEnchant { @@ -49,8 +48,8 @@ public class EnchantSmelter extends ExcellentEnchant implements Chanced, BlockDr } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "25.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 10"); @@ -59,8 +58,8 @@ public class EnchantSmelter extends ExcellentEnchant implements Chanced, BlockDr "https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Sound.html").read(cfg); this.smeltingTable = JOption.forMap("Settings.Smelting_Table", - str -> Material.getMaterial(str.toLowerCase()), - (cfg, path, id) -> Material.getMaterial(cfg.getString(path + "." + id, "").toUpperCase()), + key -> Material.getMaterial(key.toUpperCase()), + (cfg, path, key) -> Material.getMaterial(cfg.getString(path + "." + key, "").toUpperCase()), Map.of( Material.RAW_IRON, Material.IRON_INGOT, Material.RAW_GOLD, Material.GOLD_INGOT @@ -70,8 +69,6 @@ public class EnchantSmelter extends ExcellentEnchant implements Chanced, BlockDr "Note: Material source is material name of the dropped item, not the broken block!", "https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html" ).setWriter((cfg, path, map) -> map.forEach((src, to) -> cfg.set(path + "." + src.name(), to.name()))).read(cfg); - this.smeltingTable.keySet().removeIf(Objects::isNull); - this.smeltingTable.values().removeIf(Objects::isNull); } @NotNull diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantTelekinesis.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantTelekinesis.java index 66c1371..73c720f 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantTelekinesis.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantTelekinesis.java @@ -34,8 +34,8 @@ public class EnchantTelekinesis extends ExcellentEnchant implements Chanced, Blo } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "100"); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantTreasures.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantTreasures.java index 70146cd..a9e6078 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantTreasures.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantTreasures.java @@ -50,8 +50,8 @@ public class EnchantTreasures extends ExcellentEnchant implements Chanced, Block } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "10.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 4.0"); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantTunnel.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantTunnel.java index a36946d..fd72c51 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantTunnel.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantTunnel.java @@ -13,7 +13,6 @@ import su.nexmedia.engine.api.config.JOption; import su.nexmedia.engine.utils.LocationUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.api.enchantment.type.BlockBreakEnchant; -import su.nightexpress.excellentenchants.enchantment.EnchantRegistry; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.type.FitItemType; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; @@ -47,8 +46,8 @@ public class EnchantTunnel extends ExcellentEnchant implements BlockBreakEnchant } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.disableOnSneak = JOption.create("Settings.Ignore_When_Sneaking", true, "When 'true' the enchantment won't be triggered when sneaking.").read(cfg); } @@ -70,8 +69,8 @@ public class EnchantTunnel extends ExcellentEnchant implements BlockBreakEnchant Block block = e.getBlock(); if (!this.isAvailableToUse(player)) return false; if (this.disableOnSneak && player.isSneaking()) return false; - if (EnchantRegistry.VEINMINER != null && EnchantUtils.contains(item, EnchantRegistry.VEINMINER)) return false; - if (EnchantRegistry.BLAST_MINING != null && EnchantUtils.contains(item, EnchantRegistry.BLAST_MINING)) return false; + if (EnchantUtils.contains(item, EnchantVeinminer.ID)) return false; + if (EnchantUtils.contains(item, EnchantBlastMining.ID)) return false; if (block.hasMetadata(META_BLOCK_TUNNEL)) return false; if (block.getType().isInteractable() && !INTERACTABLE_BLOCKS.contains(block.getType())) return false; if (block.getDrops(item).isEmpty()) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantVeinminer.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantVeinminer.java index c90f5a3..07fd5e2 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantVeinminer.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantVeinminer.java @@ -15,7 +15,6 @@ import su.nexmedia.engine.utils.Scaler; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; import su.nightexpress.excellentenchants.api.enchantment.type.BlockBreakEnchant; -import su.nightexpress.excellentenchants.enchantment.EnchantRegistry; import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.type.FitItemType; @@ -25,7 +24,6 @@ import su.nightexpress.excellentenchants.hook.impl.NoCheatPlusHook; import java.util.HashSet; import java.util.Set; -import java.util.function.UnaryOperator; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -49,8 +47,8 @@ public class EnchantVeinminer extends ExcellentEnchant implements BlockBreakEnch } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.blocksLimit = EnchantScaler.read(this, "Settings.Blocks.Max_At_Once", "6 + " + Placeholders.ENCHANTMENT_LEVEL, @@ -75,6 +73,8 @@ public class EnchantVeinminer extends ExcellentEnchant implements BlockBreakEnch "List of blocks, that will be affected by this enchantment.", "https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html" ).setWriter((cfg, path, set) -> cfg.set(path, set.stream().map(Enum::name).toList())).read(cfg); + + this.addPlaceholder(PLACEHOLDER_BLOCK_LIMIT, level -> String.valueOf(this.getBlocksLimit(level))); } @NotNull @@ -86,14 +86,6 @@ public class EnchantVeinminer extends ExcellentEnchant implements BlockBreakEnch return (int) this.blocksLimit.getValue(level); } - @Override - @NotNull - public UnaryOperator replacePlaceholders(int level) { - return str -> super.replacePlaceholders(level).apply(str) - .replace(PLACEHOLDER_BLOCK_LIMIT, String.valueOf(this.getBlocksLimit(level))) - ; - } - @Override @NotNull public FitItemType[] getFitItemTypes() { @@ -140,8 +132,8 @@ public class EnchantVeinminer extends ExcellentEnchant implements BlockBreakEnch @Override public boolean onBreak(@NotNull BlockBreakEvent e, @NotNull Player player, @NotNull ItemStack tool, int level) { if (!this.isAvailableToUse(player)) return false; - if (EnchantRegistry.TUNNEL != null && EnchantUtils.contains(tool, EnchantRegistry.TUNNEL)) return false; - if (EnchantRegistry.BLAST_MINING != null && EnchantUtils.contains(tool, EnchantRegistry.BLAST_MINING)) return false; + if (EnchantUtils.contains(tool, EnchantBlastMining.ID)) return false; + if (EnchantUtils.contains(tool, EnchantTunnel.ID)) return false; Block block = e.getBlock(); if (block.hasMetadata(META_BLOCK_VEINED)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantBaneOfNetherspawn.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantBaneOfNetherspawn.java index d452aff..f2538de 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantBaneOfNetherspawn.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantBaneOfNetherspawn.java @@ -18,7 +18,6 @@ import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import java.util.Set; -import java.util.function.UnaryOperator; public class EnchantBaneOfNetherspawn extends ExcellentEnchant implements CombatEnchant { @@ -44,26 +43,21 @@ public class EnchantBaneOfNetherspawn extends ExcellentEnchant implements Combat } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.damageModifier = JOption.create("Settings.Damage.As_Modifier", false, "When 'true' multiplies the damage. When 'false' sums plain values.").read(cfg); this.damageFormula = EnchantScaler.read(this, "Settings.Damage.Amount", "0.5 * " + Placeholders.ENCHANTMENT_LEVEL, "Amount of additional damage."); + + this.addPlaceholder(PLACEHOLDER_DAMAGE, level -> NumberUtil.format(this.getDamageModifier(level))); } public double getDamageModifier(int level) { return this.damageFormula.getValue(level); } - @Override - @NotNull - public UnaryOperator replacePlaceholders(int level) { - return str -> super.replacePlaceholders(level).apply(str) - .replace(PLACEHOLDER_DAMAGE, NumberUtil.format(this.getDamageModifier(level))); - } - @Override @NotNull public EnchantmentTarget getItemTarget() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantBlindness.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantBlindness.java index d11c372..06c54c9 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantBlindness.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantBlindness.java @@ -33,8 +33,8 @@ public class EnchantBlindness extends ExcellentEnchant implements Chanced, Potio } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "15.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 3"); this.potionImplementation = PotionImplementation.create(this, PotionEffectType.BLINDNESS, false, diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantConfusion.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantConfusion.java index b68b89d..a88928e 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantConfusion.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantConfusion.java @@ -34,8 +34,8 @@ public class EnchantConfusion extends ExcellentEnchant implements Chanced, Potio } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "15.0 * " + Placeholders.ENCHANTMENT_LEVEL); this.potionImplementation = PotionImplementation.create(this, PotionEffectType.CONFUSION, false, diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantCure.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantCure.java index 6a5813a..2f760e1 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantCure.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantCure.java @@ -34,8 +34,8 @@ public class EnchantCure extends ExcellentEnchant implements Chanced, CombatEnch } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "20.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 8"); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantCutter.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantCutter.java index 2cb403f..3f9b8c6 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantCutter.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantCutter.java @@ -24,8 +24,6 @@ import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; -import java.util.function.UnaryOperator; - public class EnchantCutter extends ExcellentEnchant implements Chanced, CombatEnchant { public static final String ID = "cutter"; @@ -42,13 +40,15 @@ public class EnchantCutter extends ExcellentEnchant implements Chanced, CombatEn } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "1.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 0.6"); this.durabilityReduction = EnchantScaler.read(this, "Settings.Item.Durability_Reduction", Placeholders.ENCHANTMENT_LEVEL + " / 100", "Amount (in percent) of how much item durability will be reduced."); + + this.addPlaceholder(PLACEHOLDER_DURABILITY_DAMAGE, level -> NumberUtil.format(this.getDurabilityReduction(level) * 100D)); } @NotNull @@ -61,13 +61,6 @@ public class EnchantCutter extends ExcellentEnchant implements Chanced, CombatEn return this.durabilityReduction.getValue(level); } - @Override - @NotNull - public UnaryOperator replacePlaceholders(int level) { - return str -> super.replacePlaceholders(level).apply(str) - .replace(PLACEHOLDER_DURABILITY_DAMAGE, NumberUtil.format(this.getDurabilityReduction(level) * 100D)); - } - @Override @NotNull public EnchantmentTarget getItemTarget() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantDecapitator.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantDecapitator.java index 66e8be4..7937fe2 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantDecapitator.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantDecapitator.java @@ -20,7 +20,6 @@ import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.api.config.JOption; import su.nexmedia.engine.api.particle.SimpleParticle; import su.nexmedia.engine.lang.LangManager; -import su.nexmedia.engine.utils.EffectUtil; import su.nexmedia.engine.utils.ItemUtil; import su.nexmedia.engine.utils.PDCUtil; import su.nexmedia.engine.utils.StringUtil; @@ -58,8 +57,8 @@ public class EnchantDecapitator extends ExcellentEnchant implements Chanced, Dea } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "5.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 1.75"); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantDoubleStrike.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantDoubleStrike.java index dc30d1b..491d70b 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantDoubleStrike.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantDoubleStrike.java @@ -31,8 +31,8 @@ public class EnchantDoubleStrike extends ExcellentEnchant implements Chanced, Co } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "4.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 0.8"); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantExhaust.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantExhaust.java index e611e9d..d0345b8 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantExhaust.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantExhaust.java @@ -34,8 +34,8 @@ public class EnchantExhaust extends ExcellentEnchant implements Chanced, Potione } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "20.0 * " + Placeholders.ENCHANTMENT_LEVEL); this.potionImplementation = PotionImplementation.create(this, PotionEffectType.HUNGER, false, diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantExpHunter.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantExpHunter.java index ce88174..5a7ddce 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantExpHunter.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantExpHunter.java @@ -8,12 +8,10 @@ import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.utils.NumberUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; - -import java.util.function.UnaryOperator; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; +import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantExpHunter extends ExcellentEnchant implements DeathEnchant { @@ -30,25 +28,19 @@ public class EnchantExpHunter extends ExcellentEnchant implements DeathEnchant { } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.expModifier = EnchantScaler.read(this, "Settings.Exp_Modifier", "1.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 0.5", "Exp modifier value. The original exp amount will be multiplied on this value."); + + this.addPlaceholder(PLACEHOLDER_EXP_MODIFIER, level -> NumberUtil.format(this.getExpModifier(level) * 100D - 100D)); } public final double getExpModifier(int level) { return this.expModifier.getValue(level); } - @Override - @NotNull - public UnaryOperator replacePlaceholders(int level) { - return str -> super.replacePlaceholders(level).apply(str) - .replace(PLACEHOLDER_EXP_MODIFIER, NumberUtil.format(this.getExpModifier(level) * 100D - 100D)) - ; - } - @Override @NotNull public EnchantmentTarget getItemTarget() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantIceAspect.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantIceAspect.java index 04b07a1..368790f 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantIceAspect.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantIceAspect.java @@ -34,8 +34,8 @@ public class EnchantIceAspect extends ExcellentEnchant implements Chanced, Potio } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "100"); this.potionImplementation = PotionImplementation.create(this, PotionEffectType.SLOW, false, "3.0 + " + Placeholders.ENCHANTMENT_LEVEL, diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantInfernus.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantInfernus.java index b4bf5dc..b0600c6 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantInfernus.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantInfernus.java @@ -13,13 +13,11 @@ import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.utils.NumberUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; +import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; -import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; -import java.util.function.UnaryOperator; - public class EnchantInfernus extends ExcellentEnchant { public static final String ID = "infernus"; @@ -35,25 +33,19 @@ public class EnchantInfernus extends ExcellentEnchant { } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.fireTicks = EnchantScaler.read(this, "Settings.Fire_Ticks", "60 + " + Placeholders.ENCHANTMENT_LEVEL + " * 20", "Sets for how long (in ticks) entity will be ignited on hit. 20 ticks = 1 second."); + + this.addPlaceholder(PLACEHOLDER_FIRE_DURATION, level -> NumberUtil.format((double) this.getFireTicks(level) / 20D)); } public int getFireTicks(int level) { return (int) this.fireTicks.getValue(level); } - @Override - @NotNull - public UnaryOperator replacePlaceholders(int level) { - return str -> super.replacePlaceholders(level).apply(str) - .replace(PLACEHOLDER_FIRE_DURATION, NumberUtil.format((double) this.getFireTicks(level) / 20D)) - ; - } - @Override @NotNull public EnchantmentTarget getItemTarget() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantNimble.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantNimble.java index 07e5c95..f874c47 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantNimble.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantNimble.java @@ -27,8 +27,8 @@ public class EnchantNimble extends ExcellentEnchant implements Chanced, DeathEnc } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantParalyze.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantParalyze.java index 0f76234..f50ed68 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantParalyze.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantParalyze.java @@ -33,8 +33,8 @@ public class EnchantParalyze extends ExcellentEnchant implements Chanced, Potion } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "10.0 * " + Placeholders.ENCHANTMENT_LEVEL); this.potionImplementation = PotionImplementation.create(this, PotionEffectType.SLOW_DIGGING, false, diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantRage.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantRage.java index 6403677..f83be3d 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantRage.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantRage.java @@ -33,8 +33,8 @@ public class EnchantRage extends ExcellentEnchant implements Chanced, Potioned, } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "7.0 + " + Placeholders.ENCHANTMENT_LEVEL); this.potionImplementation = PotionImplementation.create(this, PotionEffectType.INCREASE_DAMAGE, false, diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantRocket.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantRocket.java index 4f73460..0ef7d67 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantRocket.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantRocket.java @@ -35,8 +35,8 @@ public class EnchantRocket extends ExcellentEnchant implements Chanced, CombatEn } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "4.0 + " + Placeholders.ENCHANTMENT_LEVEL); this.fireworkPower = EnchantScaler.read(this, "Settings.Firework_Power", diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantScavenger.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantScavenger.java index c12d076..e3be45a 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantScavenger.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantScavenger.java @@ -38,8 +38,8 @@ public class EnchantScavenger extends ExcellentEnchant implements Chanced, Death } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "15.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 10"); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantSurprise.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantSurprise.java index 519f1c4..943aaef 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantSurprise.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantSurprise.java @@ -36,8 +36,8 @@ public class EnchantSurprise extends ExcellentEnchant implements Chanced, Potion } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "2.25 * " + Placeholders.ENCHANTMENT_LEVEL); this.potionImplementation = PotionImplementation.create(this, PotionEffectType.BLINDNESS, false, diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantTemper.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantTemper.java index 92b72a0..63a4651 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantTemper.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantTemper.java @@ -10,12 +10,10 @@ import su.nexmedia.engine.utils.EntityUtil; import su.nexmedia.engine.utils.NumberUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; - -import java.util.function.UnaryOperator; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; +import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantTemper extends ExcellentEnchant implements CombatEnchant { @@ -36,8 +34,8 @@ public class EnchantTemper extends ExcellentEnchant implements CombatEnchant { } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.damageAmount = EnchantScaler.read(this, "Settings.Damage.Amount", "0.01 * " + Placeholders.ENCHANTMENT_LEVEL, "On how much (in percent) the damage will be increased per each Health Point?"); @@ -45,6 +43,10 @@ public class EnchantTemper extends ExcellentEnchant implements CombatEnchant { "Maximal possible value for the Damage.Amount."); this.healthPoint = EnchantScaler.read(this, "Settings.Health.Point", "0.5", "For how much every missing hearts damage will be increased?"); + + this.addPlaceholder(PLACEHOLDER_DAMAGE_AMOUNT, level -> NumberUtil.format(this.getDamageAmount(level) * 100D)); + this.addPlaceholder(PLACEHOLDER_DAMAGE_CAPACITY, level -> NumberUtil.format(this.getDamageCapacity(level) * 100D)); + this.addPlaceholder(PLACEHOLDER_HEALTH_POINT, level -> NumberUtil.format(this.getHealthPoint(level))); } public double getDamageAmount(int level) { @@ -59,16 +61,6 @@ public class EnchantTemper extends ExcellentEnchant implements CombatEnchant { return this.healthPoint.getValue(level); } - @Override - @NotNull - public UnaryOperator replacePlaceholders(int level) { - return str -> super.replacePlaceholders(level).apply(str) - .replace(PLACEHOLDER_DAMAGE_AMOUNT, NumberUtil.format(this.getDamageAmount(level) * 100D)) - .replace(PLACEHOLDER_DAMAGE_CAPACITY, NumberUtil.format(this.getDamageCapacity(level) * 100D)) - .replace(PLACEHOLDER_HEALTH_POINT, NumberUtil.format(this.getHealthPoint(level))) - ; - } - @NotNull @Override public EnchantmentTarget getItemTarget() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantThrifty.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantThrifty.java index a3d6269..5a303f2 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantThrifty.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantThrifty.java @@ -47,8 +47,8 @@ public class EnchantThrifty extends ExcellentEnchant implements Chanced, DeathEn } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "5.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 3"); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantThunder.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantThunder.java index e5faaf6..8072c01 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantThunder.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantThunder.java @@ -35,8 +35,8 @@ public class EnchantThunder extends ExcellentEnchant implements Chanced, CombatE } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "10.0 * " + Placeholders.ENCHANTMENT_LEVEL); this.inThunderstormOnly = JOption.create("Settings.During_Thunderstorm_Only", false, diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantVampire.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantVampire.java index abecf76..774fc59 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantVampire.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantVampire.java @@ -21,8 +21,6 @@ import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; -import java.util.function.UnaryOperator; - public class EnchantVampire extends ExcellentEnchant implements Chanced, CombatEnchant { public static final String ID = "vampire"; @@ -40,8 +38,8 @@ public class EnchantVampire extends ExcellentEnchant implements Chanced, CombatE } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "25.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5.0"); @@ -50,6 +48,8 @@ public class EnchantVampire extends ExcellentEnchant implements Chanced, CombatE "Amount of health to be restored for attacker."); this.healMultiplier = JOption.create("Settings.Heal.As_Multiplier", false, "When 'true', the option above will work as a multiplier of the inflicted damage.").read(cfg); + + this.addPlaceholder(PLACEHOLDER_HEAL_AMOUNT, level -> NumberUtil.format(this.isHealMultiplier() ? getHealAmount(level) * 100D : getHealAmount(level))); } @NotNull @@ -72,16 +72,6 @@ public class EnchantVampire extends ExcellentEnchant implements Chanced, CombatE return EnchantmentTarget.WEAPON; } - @Override - @NotNull - public UnaryOperator replacePlaceholders(int level) { - double healAmount = this.getHealAmount(level); - - return str -> super.replacePlaceholders(level).apply(str) - .replace(PLACEHOLDER_HEAL_AMOUNT, NumberUtil.format(this.isHealMultiplier() ? healAmount * 100D : healAmount)) - ; - } - @Override public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { if (!this.isAvailableToUse(damager)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantVenom.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantVenom.java index b8b3e3d..a07b315 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantVenom.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantVenom.java @@ -33,8 +33,8 @@ public class EnchantVenom extends ExcellentEnchant implements Chanced, Potioned, } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "30.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 10.0"); this.potionImplementation = PotionImplementation.create(this, PotionEffectType.POISON, false, diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantVillageDefender.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantVillageDefender.java index 2897fa2..1f1a524 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantVillageDefender.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantVillageDefender.java @@ -9,7 +9,6 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.api.config.JOption; import su.nexmedia.engine.api.particle.SimpleParticle; -import su.nexmedia.engine.utils.EffectUtil; import su.nexmedia.engine.utils.NumberUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; @@ -18,8 +17,6 @@ import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; -import java.util.function.UnaryOperator; - public class EnchantVillageDefender extends ExcellentEnchant implements CombatEnchant { public static final String ID = "village_defender"; @@ -36,8 +33,8 @@ public class EnchantVillageDefender extends ExcellentEnchant implements CombatEn } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.damageAmount = EnchantScaler.read(this, "Settings.Damage.Formula", "0.5 * " + Placeholders.ENCHANTMENT_LEVEL, @@ -45,6 +42,8 @@ public class EnchantVillageDefender extends ExcellentEnchant implements CombatEn this.damageMultiplier = JOption.create("Settings.Damage.As_Modifier", false, "When 'true' the 'Damage.Formula' will work as a multiplier to the original damage.").read(cfg); + + this.addPlaceholder(PLACEHOLDER_DAMAGE_AMOUNT, level -> NumberUtil.format(this.getDamageAddict(level))); } public double getDamageAddict(int level) { @@ -55,14 +54,6 @@ public class EnchantVillageDefender extends ExcellentEnchant implements CombatEn return damageMultiplier; } - @Override - @NotNull - public UnaryOperator replacePlaceholders(int level) { - return str -> super.replacePlaceholders(level).apply(str) - .replace(PLACEHOLDER_DAMAGE_AMOUNT, NumberUtil.format(this.getDamageAddict(level))) - ; - } - @Override @NotNull public EnchantmentTarget getItemTarget() { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantWither.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantWither.java index 0e739f7..e39a6bb 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantWither.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantWither.java @@ -8,7 +8,6 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.api.particle.SimpleParticle; -import su.nexmedia.engine.utils.EffectUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; @@ -34,8 +33,8 @@ public class EnchantWither extends ExcellentEnchant implements Chanced, Potioned } @Override - public void loadConfig() { - super.loadConfig(); + public void loadSettings() { + super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "10.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5"); this.potionImplementation = PotionImplementation.create(this, PotionEffectType.WITHER, false, diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantHandlerListener.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantHandlerListener.java index 2f429cc..da4dc34 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantHandlerListener.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantHandlerListener.java @@ -15,8 +15,10 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockDropItemEvent; import org.bukkit.event.entity.*; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.EntityEquipment; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.metadata.FixedMetadataValue; import org.jetbrains.annotations.NotNull; @@ -205,6 +207,25 @@ public class EnchantHandlerListener extends AbstractListener }); } + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onEnchantFishing(PlayerFishEvent event) { + Player player = event.getPlayer(); + + ItemStack item; + ItemStack main = player.getInventory().getItem(EquipmentSlot.HAND); + ItemStack off = player.getInventory().getItem(EquipmentSlot.OFF_HAND); + if (main != null && main.getType() == Material.FISHING_ROD) item = main; + else if (off != null && off.getType() == Material.FISHING_ROD) item = off; + else return; + + EnchantUtils.getExcellents(item, FishingEnchant.class).forEach((enchant, level) -> { + if (enchant.isOutOfCharges(item)) return; + if (enchant.onFishing(event, item, level)) { + enchant.consumeCharges(item); + } + }); + } + // --------------------------------------------------------------- // Death Related Enchants // --------------------------------------------------------------- diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/menu/EnchantmentsListMenu.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/menu/EnchantmentsListMenu.java index c447a11..82493f1 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/menu/EnchantmentsListMenu.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/menu/EnchantmentsListMenu.java @@ -4,7 +4,6 @@ import org.bukkit.NamespacedKey; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.api.config.JYML; import su.nexmedia.engine.api.menu.AutoPaged; @@ -125,28 +124,27 @@ public class EnchantmentsListMenu extends ConfigMenu implemen @NotNull private ItemStack buildEnchantIcon(@NotNull ExcellentEnchant enchant, int level) { ItemStack icon = new ItemStack(this.enchantIcon); - ItemMeta meta = icon.getItemMeta(); - if (meta == null) return icon; + ItemUtil.mapMeta(icon, meta -> { + List lore = meta.getLore(); + if (lore == null) lore = new ArrayList<>(); - List lore = meta.getLore(); - if (lore == null) lore = new ArrayList<>(); + List conflicts = enchant.getConflicts().isEmpty() ? Collections.emptyList() : new ArrayList<>(this.enchantLoreConflicts); + List conflictNames = enchant.getConflicts().stream().map(key -> Enchantment.getByKey(NamespacedKey.minecraft(key))) + .filter(Objects::nonNull).map(LangManager::getEnchantment).toList(); + conflicts = StringUtil.replace(conflicts, Placeholders.ENCHANTMENT_NAME, true, conflictNames); - List conflicts = enchant.getConflicts().isEmpty() ? Collections.emptyList() : new ArrayList<>(this.enchantLoreConflicts); - List conflictNames = enchant.getConflicts().stream().map(key -> Enchantment.getByKey(NamespacedKey.minecraft(key))) - .filter(Objects::nonNull).map(LangManager::getEnchantment).toList(); - conflicts = StringUtil.replace(conflicts, Placeholders.ENCHANTMENT_NAME, true, conflictNames); + List charges = enchant.isChargesEnabled() ? new ArrayList<>(this.enchantLoreCharges) : Collections.emptyList(); + List obtaining = new ArrayList<>(this.enchantLoreObtaining); - List charges = enchant.isChargesEnabled() ? new ArrayList<>(this.enchantLoreCharges) : Collections.emptyList(); - List obtaining = new ArrayList<>(this.enchantLoreObtaining); + lore = StringUtil.replace(lore, PLACEHOLDER_CONFLICTS, false, conflicts); + lore = StringUtil.replace(lore, PLACEHOLDER_CHARGES, false, charges); + lore = StringUtil.replace(lore, PLACEHOLDER_OBTAINING, false, obtaining); + lore = StringUtil.replace(lore, Placeholders.ENCHANTMENT_DESCRIPTION, true, enchant.getDescription()); - lore = StringUtil.replace(lore, PLACEHOLDER_CONFLICTS, false, conflicts); - lore = StringUtil.replace(lore, PLACEHOLDER_CHARGES, false, charges); - lore = StringUtil.replace(lore, PLACEHOLDER_OBTAINING, false, obtaining); + meta.setLore(lore); + ItemUtil.replace(meta, enchant.getPlaceholders(level).replacer()); + }); - meta.setLore(lore); - icon.setItemMeta(meta); - - ItemUtil.replace(icon, enchant.replaceAllPlaceholders(level)); return icon; } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantUtils.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantUtils.java index d3e8f65..b0fd032 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantUtils.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantUtils.java @@ -38,6 +38,11 @@ public class EnchantUtils { public static final NamespacedKey KEY_LORE_SIZE = new NamespacedKey(ExcellentEnchantsAPI.PLUGIN, "lore_size"); + @NotNull + public static NamespacedKey createKey(@NotNull String id) { + return NamespacedKey.minecraft(id.toLowerCase()); + } + public static boolean isEnchantable(@NotNull ItemStack item) { if (item.getType().isAir()) return false; @@ -212,6 +217,13 @@ public class EnchantUtils { return getAll(item).size(); } + public static boolean contains(@NotNull ItemStack item, @NotNull String id) { + ExcellentEnchant enchant = EnchantRegistry.getById(id); + if (enchant == null) return false; + + return contains(item, enchant); + } + public static boolean contains(@NotNull ItemStack item, @NotNull Enchantment enchantment) { return getLevel(item, enchantment) > 0; } @@ -292,7 +304,7 @@ public class EnchantUtils { private static Map getExcellents(@NotNull Map enchants) { Map map = new HashMap<>(); enchants.forEach((enchantment, level) -> { - ExcellentEnchant excellent = EnchantRegistry.get(enchantment.getKey()); + ExcellentEnchant excellent = EnchantRegistry.getByKey(enchantment.getKey()); if (excellent != null) { map.put(excellent, level); } @@ -304,7 +316,7 @@ public class EnchantUtils { public static Map getExcellents(@NotNull ItemStack item, @NotNull Class clazz) { Map map = new HashMap<>(); getAll(item).forEach((enchantment, level) -> { - ExcellentEnchant excellent = EnchantRegistry.get(enchantment.getKey()); + ExcellentEnchant excellent = EnchantRegistry.getByKey(enchantment.getKey()); if (excellent == null || !clazz.isAssignableFrom(excellent.getClass())) return; map.put(clazz.cast(excellent), level); 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 a8621b6..c20da53 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 @@ -63,7 +63,7 @@ public class PlaceholderHook { ItemStack item = player.getInventory().getItem(slot); if (item == null || item.getType().isAir()) return "-"; - ExcellentEnchant enchant = EnchantRegistry.get(NamespacedKey.minecraft(chargesSplit[1].toLowerCase())); + ExcellentEnchant enchant = EnchantRegistry.getByKey(NamespacedKey.minecraft(chargesSplit[1].toLowerCase())); if (enchant == null) return null; return String.valueOf(enchant.getCharges(item)); @@ -72,7 +72,7 @@ public class PlaceholderHook { String[] chargesSplit = params.substring("charges_maximum_".length()).split(":"); if (chargesSplit.length < 2) return null; - ExcellentEnchant enchant = EnchantRegistry.get(NamespacedKey.minecraft(chargesSplit[0].toLowerCase())); + ExcellentEnchant enchant = EnchantRegistry.getByKey(NamespacedKey.minecraft(chargesSplit[0].toLowerCase())); if (enchant == null) return null; int level = StringUtil.getInteger(chargesSplit[1], 1); 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 cadf840..8bc10ba 100644 --- a/NMS/src/main/java/su/nightexpress/excellentenchants/nms/EnchantNMS.java +++ b/NMS/src/main/java/su/nightexpress/excellentenchants/nms/EnchantNMS.java @@ -2,8 +2,10 @@ package su.nightexpress.excellentenchants.nms; import org.bukkit.Location; import org.bukkit.block.Block; +import org.bukkit.entity.FishHook; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import java.util.Set; @@ -12,5 +14,7 @@ public interface EnchantNMS { void sendAttackPacket(@NotNull Player player, int id); + void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item); + @NotNull Set handleFlameWalker(@NotNull LivingEntity entity, @NotNull Location location, int level); } diff --git a/V1_17_R1/src/main/java/su/nightexpress/excellentenchants/nms/v1_17_R1/V1_17_R1.java b/V1_17_R1/src/main/java/su/nightexpress/excellentenchants/nms/v1_17_R1/V1_17_R1.java index 9e5431d..6d64803 100644 --- a/V1_17_R1/src/main/java/su/nightexpress/excellentenchants/nms/v1_17_R1/V1_17_R1.java +++ b/V1_17_R1/src/main/java/su/nightexpress/excellentenchants/nms/v1_17_R1/V1_17_R1.java @@ -4,6 +4,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.protocol.game.ClientboundAnimatePacket; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.projectile.FishingHook; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.state.BlockState; @@ -11,11 +12,15 @@ import net.minecraft.world.phys.shapes.CollisionContext; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_17_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftFishHook; import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity; import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_17_R1.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; +import org.bukkit.entity.FishHook; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.nms.EnchantNMS; @@ -32,6 +37,13 @@ public class V1_17_R1 implements EnchantNMS { craftPlayer.getHandle().connection.send(packet); } + @Override + public void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item) { + CraftFishHook craftFishHook = (CraftFishHook) hook; + FishingHook handle = craftFishHook.getHandle(); + handle.retrieve(CraftItemStack.asNMSCopy(item)); + } + @Override @NotNull public Set handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) { diff --git a/V1_18_R2/src/main/java/su/nightexpress/excellentenchants/nms/v1_18_R2/V1_18_R2.java b/V1_18_R2/src/main/java/su/nightexpress/excellentenchants/nms/v1_18_R2/V1_18_R2.java index 2fdf6d3..42bd1da 100644 --- a/V1_18_R2/src/main/java/su/nightexpress/excellentenchants/nms/v1_18_R2/V1_18_R2.java +++ b/V1_18_R2/src/main/java/su/nightexpress/excellentenchants/nms/v1_18_R2/V1_18_R2.java @@ -4,6 +4,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.protocol.game.ClientboundAnimatePacket; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.projectile.FishingHook; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.state.BlockState; @@ -11,11 +12,15 @@ import net.minecraft.world.phys.shapes.CollisionContext; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; +import org.bukkit.craftbukkit.v1_18_R2.entity.CraftFishHook; import org.bukkit.craftbukkit.v1_18_R2.entity.CraftLivingEntity; import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_18_R2.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack; +import org.bukkit.entity.FishHook; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.nms.EnchantNMS; @@ -32,6 +37,13 @@ public class V1_18_R2 implements EnchantNMS { craftPlayer.getHandle().connection.send(packet); } + @Override + public void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item) { + CraftFishHook craftFishHook = (CraftFishHook) hook; + FishingHook handle = craftFishHook.getHandle(); + handle.retrieve(CraftItemStack.asNMSCopy(item)); + } + @Override @NotNull public Set handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) { diff --git a/V1_19_R1/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R1/V1_19_R1.java b/V1_19_R1/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R1/V1_19_R1.java index bd5bbca..841aab7 100644 --- a/V1_19_R1/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R1/V1_19_R1.java +++ b/V1_19_R1/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R1/V1_19_R1.java @@ -4,6 +4,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.protocol.game.ClientboundAnimatePacket; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.projectile.FishingHook; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.state.BlockState; @@ -11,11 +12,15 @@ import net.minecraft.world.phys.shapes.CollisionContext; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftFishHook; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftLivingEntity; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_19_R1.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; +import org.bukkit.entity.FishHook; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.nms.EnchantNMS; @@ -32,6 +37,13 @@ public class V1_19_R1 implements EnchantNMS { craftPlayer.getHandle().connection.send(packet); } + @Override + public void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item) { + CraftFishHook craftFishHook = (CraftFishHook) hook; + FishingHook handle = craftFishHook.getHandle(); + handle.retrieve(CraftItemStack.asNMSCopy(item)); + } + @Override @NotNull public Set handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) { diff --git a/V1_19_R2/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R2/V1_19_R2.java b/V1_19_R2/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R2/V1_19_R2.java index c8a1a95..3a1de22 100644 --- a/V1_19_R2/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R2/V1_19_R2.java +++ b/V1_19_R2/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R2/V1_19_R2.java @@ -4,6 +4,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.protocol.game.ClientboundAnimatePacket; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.projectile.FishingHook; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.state.BlockState; @@ -11,11 +12,15 @@ import net.minecraft.world.phys.shapes.CollisionContext; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_19_R2.CraftWorld; +import org.bukkit.craftbukkit.v1_19_R2.entity.CraftFishHook; import org.bukkit.craftbukkit.v1_19_R2.entity.CraftLivingEntity; import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_19_R2.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack; +import org.bukkit.entity.FishHook; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.nms.EnchantNMS; @@ -32,6 +37,13 @@ public class V1_19_R2 implements EnchantNMS { craftPlayer.getHandle().connection.send(packet); } + @Override + public void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item) { + CraftFishHook craftFishHook = (CraftFishHook) hook; + FishingHook handle = craftFishHook.getHandle(); + handle.retrieve(CraftItemStack.asNMSCopy(item)); + } + @Override @NotNull public Set handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) { 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 index 4b4d3a5..5da9592 100644 --- 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 @@ -4,6 +4,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.protocol.game.ClientboundAnimatePacket; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.projectile.FishingHook; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.state.BlockState; @@ -11,11 +12,15 @@ import net.minecraft.world.phys.shapes.CollisionContext; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_19_R3.CraftWorld; +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.CraftItemStack; +import org.bukkit.entity.FishHook; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.nms.EnchantNMS; @@ -32,6 +37,13 @@ public class V1_19_R3 implements EnchantNMS { craftPlayer.getHandle().connection.send(packet); } + @Override + public void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item) { + CraftFishHook craftFishHook = (CraftFishHook) hook; + FishingHook handle = craftFishHook.getHandle(); + handle.retrieve(CraftItemStack.asNMSCopy(item)); + } + @Override @NotNull public Set handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) {