Code improvements

This commit is contained in:
nulli0n 2023-05-14 02:43:33 +06:00
parent 9c2d0911f1
commit ce07be4c8f
77 changed files with 542 additions and 611 deletions

View File

@ -13,6 +13,7 @@ import su.nightexpress.excellentenchants.command.TierbookCommand;
import su.nightexpress.excellentenchants.config.Config; import su.nightexpress.excellentenchants.config.Config;
import su.nightexpress.excellentenchants.config.Lang; import su.nightexpress.excellentenchants.config.Lang;
import su.nightexpress.excellentenchants.enchantment.EnchantManager; import su.nightexpress.excellentenchants.enchantment.EnchantManager;
import su.nightexpress.excellentenchants.enchantment.EnchantRegistry;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType; import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
import su.nightexpress.excellentenchants.hook.HookId; import su.nightexpress.excellentenchants.hook.HookId;
import su.nightexpress.excellentenchants.hook.impl.PlaceholderHook; import su.nightexpress.excellentenchants.hook.impl.PlaceholderHook;
@ -27,10 +28,9 @@ import su.nightexpress.excellentenchants.tier.TierManager;
public class ExcellentEnchants extends NexPlugin<ExcellentEnchants> { public class ExcellentEnchants extends NexPlugin<ExcellentEnchants> {
public static boolean isLoaded = false; private EnchantRegistry enchantRegistry;
private EnchantNMS enchantNMS;
private EnchantManager enchantManager; private EnchantManager enchantManager;
private EnchantNMS enchantNMS;
private TierManager tierManager; private TierManager tierManager;
@Override @Override
@ -39,6 +39,12 @@ public class ExcellentEnchants extends NexPlugin<ExcellentEnchants> {
return this; return this;
} }
@Override
public void onLoad() {
super.onLoad();
this.enchantRegistry = new EnchantRegistry(this);
}
@Override @Override
public void enable() { public void enable() {
this.setNMS(); this.setNMS();
@ -46,6 +52,8 @@ public class ExcellentEnchants extends NexPlugin<ExcellentEnchants> {
this.tierManager = new TierManager(this); this.tierManager = new TierManager(this);
this.tierManager.setup(); this.tierManager.setup();
this.enchantRegistry.setup();
this.enchantManager = new EnchantManager(this); this.enchantManager = new EnchantManager(this);
this.enchantManager.setup(); this.enchantManager.setup();
} }
@ -61,6 +69,7 @@ public class ExcellentEnchants extends NexPlugin<ExcellentEnchants> {
this.tierManager = null; this.tierManager = null;
} }
PlaceholderHook.shutdown(); PlaceholderHook.shutdown();
//this.enchantRegistry.shutdown(); Do we ever need this at all?
} }
private void setNMS() { private void setNMS() {
@ -120,6 +129,11 @@ public class ExcellentEnchants extends NexPlugin<ExcellentEnchants> {
return tierManager; return tierManager;
} }
@NotNull
public EnchantRegistry getEnchantRegistry() {
return this.enchantRegistry;
}
@NotNull @NotNull
public EnchantManager getEnchantManager() { public EnchantManager getEnchantManager() {
return this.enchantManager; return this.enchantManager;

View File

@ -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);
}

View File

@ -25,8 +25,6 @@ public class EnchantManager extends AbstractManager<ExcellentEnchants> {
@Override @Override
protected void onLoad() { protected void onLoad() {
EnchantRegistry.setup();
this.enchantmentsListMenu = new EnchantmentsListMenu(this.plugin); this.enchantmentsListMenu = new EnchantmentsListMenu(this.plugin);
this.addListener(new EnchantHandlerListener(this)); this.addListener(new EnchantHandlerListener(this));
this.addListener(new EnchantGenericListener(this)); this.addListener(new EnchantGenericListener(this));
@ -53,7 +51,6 @@ public class EnchantManager extends AbstractManager<ExcellentEnchants> {
this.potionEffectsTask.stop(); this.potionEffectsTask.stop();
this.potionEffectsTask = null; this.potionEffectsTask = null;
} }
EnchantRegistry.shutdown();
} }
@NotNull @NotNull

View File

@ -4,197 +4,125 @@ import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import su.nexmedia.engine.api.manager.ICleanable;
import su.nexmedia.engine.utils.Reflex; import su.nexmedia.engine.utils.Reflex;
import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.config.Config; import su.nightexpress.excellentenchants.config.Config;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.armor.*; import su.nightexpress.excellentenchants.enchantment.impl.armor.*;
import su.nightexpress.excellentenchants.enchantment.impl.bow.*; 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.tool.*;
import su.nightexpress.excellentenchants.enchantment.impl.universal.EnchantCurseOfFragility; import su.nightexpress.excellentenchants.enchantment.impl.universal.EnchantCurseOfFragility;
import su.nightexpress.excellentenchants.enchantment.impl.weapon.*; import su.nightexpress.excellentenchants.enchantment.impl.weapon.*;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import su.nightexpress.excellentenchants.tier.Tier; import su.nightexpress.excellentenchants.tier.Tier;
import java.lang.reflect.Field;
import java.util.*; import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class EnchantRegistry { public class EnchantRegistry {
private static final ExcellentEnchants PLUGIN; public static final Map<NamespacedKey, ExcellentEnchant> REGISTRY_MAP = new HashMap<>();
public static final Map<NamespacedKey, ExcellentEnchant> REGISTRY_MAP;
public static final EnchantBlastMining BLAST_MINING; private final ExcellentEnchants plugin;
public static final EnchantCurseOfBreaking CURSE_OF_BREAKING; private boolean isLocked;
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;
public static final EnchantBaneOfNetherspawn BANE_OF_NETHERSPAWN; public EnchantRegistry(@NotNull ExcellentEnchants plugin) {
public static final EnchantIceAspect ICE_ASPECT; this.plugin = plugin;
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 static void setup() { public void setup() {
// Prevent to register enchantments during the runtime. // Prevent to register enchantments during the runtime.
if (ExcellentEnchants.isLoaded) { if (this.isLocked) {
REGISTRY_MAP.values().forEach(ExcellentEnchant::loadConfig); REGISTRY_MAP.values().forEach(ExcellentEnchant::loadSettings);
return; return;
} }
Reflex.setFieldValue(Enchantment.class, "acceptingNew", true); Reflex.setFieldValue(Enchantment.class, "acceptingNew", true);
for (Field field : EnchantRegistry.class.getFields()) {
if (!ExcellentEnchant.class.isAssignableFrom(field.getType())) continue;
try { // Fising Enchants
ExcellentEnchant enchant = (ExcellentEnchant) field.get(null); this.register(AutoFishEnchant.ID,() -> new AutoFishEnchant(plugin));
EnchantRegistry.register(enchant);
} // Tool enchants
catch (Exception e) { this.register(EnchantBlastMining.ID, () -> new EnchantBlastMining(plugin));
e.printStackTrace(); 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(); Enchantment.stopAcceptingRegistrations();
PLUGIN.info("Enchantments Registered: " + REGISTRY_MAP.size()); this.plugin.info("Enchantments Registered: " + getRegistered().size());
ExcellentEnchants.isLoaded = true; this.isLocked = true;
} }
@SuppressWarnings("unchecked") /*@SuppressWarnings("unchecked")
public static void shutdown() { public void shutdown() {
if (PLUGIN.isEnabled()) return; // Prevent to unregister enchantments during the runtime. if (this.plugin.isEnabled()) return; // Prevent to unregister enchantments during the runtime.
Map<NamespacedKey, Enchantment> byKey = (Map<NamespacedKey, Enchantment>) Reflex.getFieldValue(Enchantment.class, "byKey"); Map<NamespacedKey, Enchantment> byKey = (Map<NamespacedKey, Enchantment>) Reflex.getFieldValue(Enchantment.class, "byKey");
Map<String, Enchantment> byName = (Map<String, Enchantment>) Reflex.getFieldValue(Enchantment.class, "byName"); Map<String, Enchantment> byName = (Map<String, Enchantment>) Reflex.getFieldValue(Enchantment.class, "byName");
@ -211,35 +139,28 @@ public class EnchantRegistry {
enchant.unregisterListeners(); enchant.unregisterListeners();
} }
REGISTRY_MAP.clear(); REGISTRY_MAP.clear();
PLUGIN.info("All enchants are unregistered."); this.plugin.info("All enchants are unregistered.");
} }*/
@Nullable private void register(@NotNull String id, @NotNull Supplier<ExcellentEnchant> supplier) {
private static <T extends ExcellentEnchant> T init(@NotNull Class<T> clazz, @NotNull String id) { if (Config.ENCHANTMENTS_DISABLED.get().contains(id)) return;
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;
ExcellentEnchant enchant = supplier.get();
Enchantment.registerEnchantment(enchant); Enchantment.registerEnchantment(enchant);
REGISTRY_MAP.put(enchant.getKey(), enchant); REGISTRY_MAP.put(enchant.getKey(), enchant);
enchant.loadConfig(); enchant.loadSettings();
enchant.getConfig().saveChanges(); enchant.getConfig().saveChanges();
enchant.registerListeners(); enchant.registerListeners();
PLUGIN.info("Registered enchantment: " + enchant.getId()); this.plugin.info("Registered enchantment: " + enchant.getId());
} }
@Nullable @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); return REGISTRY_MAP.get(key);
} }

View File

@ -10,6 +10,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import su.nexmedia.engine.api.config.JYML; import su.nexmedia.engine.api.config.JYML;
import su.nexmedia.engine.api.manager.IListener; import su.nexmedia.engine.api.manager.IListener;
import su.nexmedia.engine.api.placeholder.PlaceholderMap;
import su.nexmedia.engine.lang.LangManager; import su.nexmedia.engine.lang.LangManager;
import su.nexmedia.engine.utils.ItemUtil; import su.nexmedia.engine.utils.ItemUtil;
import su.nexmedia.engine.utils.NumberUtil; 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.IEnchantment;
import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.meta.Potioned; 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.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.FitItemType;
import su.nightexpress.excellentenchants.enchantment.type.ObtainType; 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.enchantment.util.EnchantUtils;
import su.nightexpress.excellentenchants.tier.Tier; import su.nightexpress.excellentenchants.tier.Tier;
import java.util.*; import java.util.*;
import java.util.function.UnaryOperator; import java.util.function.Function;
import java.util.stream.Stream; import java.util.stream.Stream;
public abstract class ExcellentEnchant extends Enchantment implements IEnchantment, IListener { 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 EnchantPriority priority;
protected final EnchantDefaults defaults; protected final EnchantDefaults defaults;
protected final NamespacedKey chargesKey; protected final NamespacedKey chargesKey;
protected final Map<Integer, PlaceholderMap> placeholdersMap;
public ExcellentEnchant(@NotNull ExcellentEnchants plugin, @NotNull String id, @NotNull EnchantPriority priority) { public ExcellentEnchant(@NotNull ExcellentEnchants plugin, @NotNull String id, @NotNull EnchantPriority priority) {
super(NamespacedKey.minecraft(id.toLowerCase())); super(NamespacedKey.minecraft(id.toLowerCase()));
this.plugin = plugin; this.plugin = plugin;
this.id = this.getKey().getKey(); 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.priority = priority;
this.chargesKey = new NamespacedKey(plugin, this.getId() + ".charges"); this.chargesKey = new NamespacedKey(plugin, this.getId() + ".charges");
this.defaults = new EnchantDefaults(this); this.defaults = new EnchantDefaults(this);
this.placeholdersMap = new HashMap<>();
} }
public void loadConfig() { public void loadSettings() {
this.cfg.reload(); this.cfg.reload();
this.placeholdersMap.clear();
this.getDefaults().load(this); this.getDefaults().load(this);
}
@NotNull for (int i = this.getStartLevel(); i < this.getMaxLevel() + 1; i++) {
public UnaryOperator<String> replaceAllPlaceholders(int level) { int level = i;
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()))
;
}
@NotNull PlaceholderMap map = new PlaceholderMap()
public UnaryOperator<String> replacePlaceholders(int level) { .add(Placeholders.ENCHANTMENT_DESCRIPTION, () -> String.join("\n", this.getDescription()))
return str -> { .add(Placeholders.ENCHANTMENT_NAME, this::getDisplayName)
str = str.replace(Placeholders.ENCHANTMENT_DESCRIPTION, String.join("\n", this.getDescription())); .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) { 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) { if (this instanceof Potioned potioned) {
str = str map.add(Placeholders.ENCHANTMENT_POTION_LEVEL, () -> NumberUtil.toRoman(potioned.getEffectAmplifier(level)));
.replace(Placeholders.ENCHANTMENT_POTION_LEVEL, NumberUtil.toRoman(potioned.getEffectAmplifier(level))) map.add(Placeholders.ENCHANTMENT_POTION_DURATION, () -> NumberUtil.format(potioned.getEffectDuration(level) / 20D));
.replace(Placeholders.ENCHANTMENT_POTION_DURATION, NumberUtil.format((double) potioned.getEffectDuration(level) / 20D)) map.add(Placeholders.ENCHANTMENT_POTION_TYPE, () -> LangManager.getPotionType(potioned.getEffectType()));
.replace(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<Integer, String> replacer) {
for (int level = this.getStartLevel(); level < this.getMaxLevel() + 1; level++) {
this.getPlaceholders(level).add(key, replacer.apply(level));
}
} }
@Override @Override
@ -172,7 +183,7 @@ public abstract class ExcellentEnchant extends Enchantment implements IEnchantme
@NotNull @NotNull
public List<String> getDescription(int level) { public List<String> getDescription(int level) {
List<String> description = new ArrayList<>(this.getDescription()); List<String> description = new ArrayList<>(this.getDescription());
description.replaceAll(this.replacePlaceholders(level)); description.replaceAll(this.getPlaceholders(level).replacer());
return description; return description;
} }

View File

@ -27,8 +27,8 @@ public class EnchantAquaman extends ExcellentEnchant implements Potioned, Passiv
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.potionImplementation = PotionImplementation.create(this, PotionEffectType.WATER_BREATHING, true); this.potionImplementation = PotionImplementation.create(this, PotionEffectType.WATER_BREATHING, true);
} }

View File

@ -27,8 +27,8 @@ public class EnchantBunnyHop extends ExcellentEnchant implements Potioned, Passi
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.potionImplementation = PotionImplementation.create(this, PotionEffectType.JUMP, true); this.potionImplementation = PotionImplementation.create(this, PotionEffectType.JUMP, true);
} }

View File

@ -32,8 +32,8 @@ public class EnchantColdSteel extends ExcellentEnchant implements Chanced, Potio
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"60 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5"); "60 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5");

View File

@ -11,13 +11,12 @@ import su.nexmedia.engine.api.config.JOption;
import su.nexmedia.engine.utils.NumberUtil; import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders; import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import java.util.Set; import java.util.Set;
import java.util.function.UnaryOperator;
public class EnchantElementalProtection extends ExcellentEnchant { public class EnchantElementalProtection extends ExcellentEnchant {
@ -42,17 +41,8 @@ public class EnchantElementalProtection extends ExcellentEnchant {
} }
@Override @Override
@NotNull public void loadSettings() {
public UnaryOperator<String> replacePlaceholders(int level) { super.loadSettings();
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();
this.protectionAmount = EnchantScaler.read(this, "Settings.Protection.Amount", this.protectionAmount = EnchantScaler.read(this, "Settings.Protection.Amount",
"0.05 * " + Placeholders.ENCHANTMENT_LEVEL, "0.05 * " + Placeholders.ENCHANTMENT_LEVEL,
@ -62,6 +52,9 @@ public class EnchantElementalProtection extends ExcellentEnchant {
this.protectionAsModifier = JOption.create("Settings.Protection.As_Modifier", false, this.protectionAsModifier = JOption.create("Settings.Protection.As_Modifier", false,
"When 'true' damage will be reduced by a percent of protection value.", "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); "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 @NotNull

View File

@ -8,14 +8,12 @@ import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.NumberUtil; import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders; 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.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; 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 su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import java.util.function.UnaryOperator; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantFireShield extends ExcellentEnchant implements Chanced, CombatEnchant { public class EnchantFireShield extends ExcellentEnchant implements Chanced, CombatEnchant {
@ -33,16 +31,8 @@ public class EnchantFireShield extends ExcellentEnchant implements Chanced, Comb
} }
@Override @Override
@NotNull public void loadSettings() {
public UnaryOperator<String> replacePlaceholders(int level) { super.loadSettings();
return str -> super.replacePlaceholders(level).apply(str)
.replace(PLACEHOLDER_FIRE_DURATION, NumberUtil.format(this.getFireDuration(level)))
;
}
@Override
public void loadConfig() {
super.loadConfig();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
Placeholders.ENCHANTMENT_LEVEL + " * 15.0"); Placeholders.ENCHANTMENT_LEVEL + " * 15.0");
@ -51,6 +41,8 @@ public class EnchantFireShield extends ExcellentEnchant implements Chanced, Comb
"Sets the fire duration (in seconds).", "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 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."); "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 @NotNull

View File

@ -53,8 +53,8 @@ public class EnchantFlameWalker extends ExcellentEnchant implements ICleanable {
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.blockDecayTime = EnchantScaler.read(this, "Settings.Block_Decay", "12.0", 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."); "Sets up to how long (in seconds) blocks will stay before turn back to lava.");
} }

View File

@ -31,8 +31,8 @@ public class EnchantHardened extends ExcellentEnchant implements Chanced, Potion
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"30.0 * " + Placeholders.ENCHANTMENT_LEVEL); "30.0 * " + Placeholders.ENCHANTMENT_LEVEL);

View File

@ -34,8 +34,8 @@ public class EnchantIceShield extends ExcellentEnchant implements Chanced, Potio
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, "25.0 * " + Placeholders.ENCHANTMENT_LEVEL); this.chanceImplementation = ChanceImplementation.create(this, "25.0 * " + Placeholders.ENCHANTMENT_LEVEL);
this.potionImplementation = PotionImplementation.create(this, PotionEffectType.SLOW, false, this.potionImplementation = PotionImplementation.create(this, PotionEffectType.SLOW, false,
"3.0 + " + Placeholders.ENCHANTMENT_LEVEL, "3.0 + " + Placeholders.ENCHANTMENT_LEVEL,

View File

@ -27,8 +27,8 @@ public class EnchantNightVision extends ExcellentEnchant implements Potioned, Pa
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.potionImplementation = PotionImplementation.create(this, PotionEffectType.NIGHT_VISION, true); this.potionImplementation = PotionImplementation.create(this, PotionEffectType.NIGHT_VISION, true);
} }

View File

@ -22,8 +22,6 @@ import su.nightexpress.excellentenchants.enchantment.task.AbstractEnchantmentTas
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import java.util.function.UnaryOperator;
public class EnchantRegrowth extends ExcellentEnchant implements Chanced, PassiveEnchant, ICleanable { public class EnchantRegrowth extends ExcellentEnchant implements Chanced, PassiveEnchant, ICleanable {
public static final String ID = "regrowth"; public static final String ID = "regrowth";
@ -49,8 +47,8 @@ public class EnchantRegrowth extends ExcellentEnchant implements Chanced, Passiv
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"20.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5"); "20.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5");
this.healInterval = JOption.create("Settings.Heal.Interval", 100, 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", this.healAmount = EnchantScaler.read(this, "Settings.Heal.Amount", "0.25",
"Amount of hearts to be restored."); "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 = new Task(plugin);
this.task.start(); this.task.start();
} }
@ -78,17 +81,6 @@ public class EnchantRegrowth extends ExcellentEnchant implements Chanced, Passiv
} }
} }
@Override
@NotNull
public UnaryOperator<String> 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 @NotNull
@Override @Override
public ChanceImplementation getChanceImplementation() { public ChanceImplementation getChanceImplementation() {

View File

@ -10,15 +10,13 @@ import su.nexmedia.engine.api.manager.ICleanable;
import su.nexmedia.engine.utils.NumberUtil; import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders; import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant; 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.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.task.AbstractEnchantmentTask; import su.nightexpress.excellentenchants.enchantment.task.AbstractEnchantmentTask;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import java.util.function.UnaryOperator;
public class EnchantSaturation extends ExcellentEnchant implements PassiveEnchant, ICleanable { public class EnchantSaturation extends ExcellentEnchant implements PassiveEnchant, ICleanable {
public static final String ID = "saturation"; public static final String ID = "saturation";
@ -41,8 +39,8 @@ public class EnchantSaturation extends ExcellentEnchant implements PassiveEnchan
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.saturationInterval = JOption.create("Settings.Saturation.Interval", 100, this.saturationInterval = JOption.create("Settings.Saturation.Interval", 100,
"How often (in ticks) enchantment will have effect? 1 second = 20 ticks.").read(cfg); "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, 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", this.saturationMaxFoodLevel = EnchantScaler.read(this, "Settings.Saturation.Max_Food_Level", "20",
"Maximal player's food level for the enchantment to stop feeding them."); "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 = new Task(plugin);
this.task.start(); this.task.start();
} }
@ -66,16 +68,6 @@ public class EnchantSaturation extends ExcellentEnchant implements PassiveEnchan
} }
} }
@Override
@NotNull
public UnaryOperator<String> 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 @Override
@NotNull @NotNull
public EnchantmentTarget getItemTarget() { public EnchantmentTarget getItemTarget() {

View File

@ -13,14 +13,12 @@ import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.NumberUtil; import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders; 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.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant; 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 su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import java.util.function.UnaryOperator; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantSelfDestruction extends ExcellentEnchant implements Chanced, DeathEnchant { public class EnchantSelfDestruction extends ExcellentEnchant implements Chanced, DeathEnchant {
@ -40,21 +38,15 @@ public class EnchantSelfDestruction extends ExcellentEnchant implements Chanced,
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"20.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 10"); "20.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 10");
this.explosionSize = EnchantScaler.read(this, "Settings.Explosion.Size", this.explosionSize = EnchantScaler.read(this, "Settings.Explosion.Size",
"1.0" + Placeholders.ENCHANTMENT_LEVEL, "1.0" + Placeholders.ENCHANTMENT_LEVEL,
"A size of the explosion. The more size - the bigger the damage."); "A size of the explosion. The more size - the bigger the damage.");
}
@Override this.addPlaceholder(PLACEHOLDER_EXPLOSION_POWER, level -> NumberUtil.format(this.getExplosionSize(level)));
@NotNull
public UnaryOperator<String> replacePlaceholders(int level) {
return str -> super.replacePlaceholders(level).apply(str)
.replace(PLACEHOLDER_EXPLOSION_POWER, NumberUtil.format(this.getExplosionSize(level)))
;
} }
@NotNull @NotNull

View File

@ -27,8 +27,8 @@ public class EnchantSonic extends ExcellentEnchant implements Potioned, PassiveE
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.potionImplementation = PotionImplementation.create(this, PotionEffectType.SPEED, true); this.potionImplementation = PotionImplementation.create(this, PotionEffectType.SPEED, true);
} }

View File

@ -13,14 +13,12 @@ import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.NumberUtil; import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders; 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.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant; 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 su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import java.util.function.UnaryOperator; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantBomber extends ExcellentEnchant implements Chanced, BowEnchant { public class EnchantBomber extends ExcellentEnchant implements Chanced, BowEnchant {
@ -47,20 +45,15 @@ public class EnchantBomber extends ExcellentEnchant implements Chanced, BowEncha
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"5.0 * " + Placeholders.ENCHANTMENT_LEVEL); "5.0 * " + Placeholders.ENCHANTMENT_LEVEL);
this.fuseTicks = EnchantScaler.read(this, "Settings.Fuse_Ticks", this.fuseTicks = EnchantScaler.read(this, "Settings.Fuse_Ticks",
"100 - " + Placeholders.ENCHANTMENT_LEVEL + " * 10", "100 - " + Placeholders.ENCHANTMENT_LEVEL + " * 10",
"Sets fuse ticks (before it will explode) for the launched TNT."); "Sets fuse ticks (before it will explode) for the launched TNT.");
}
@Override this.addPlaceholder(PLACEHOLDER_FUSE_TICKS, level -> NumberUtil.format((double) this.getFuseTicks(level) / 20D));
@NotNull
public UnaryOperator<String> replacePlaceholders(int level) {
return str -> super.replacePlaceholders(level).apply(str)
.replace(PLACEHOLDER_FUSE_TICKS, NumberUtil.format((double) this.getFuseTicks(level) / 20D));
} }
@NotNull @NotNull

View File

@ -46,8 +46,8 @@ public class EnchantConfusingArrows extends ExcellentEnchant implements Chanced,
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.arrowImplementation = ArrowImplementation.create(this, SimpleParticle.of(Particle.SPELL_MOB)); this.arrowImplementation = ArrowImplementation.create(this, SimpleParticle.of(Particle.SPELL_MOB));
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"20.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5.0"); "20.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5.0");

View File

@ -20,16 +20,14 @@ import su.nexmedia.engine.api.particle.SimpleParticle;
import su.nexmedia.engine.utils.NumberUtil; import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders; 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.Arrowed;
import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant; 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.ArrowImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import java.util.function.UnaryOperator;
public class EnchantDragonfireArrows extends ExcellentEnchant implements Chanced, Arrowed, BowEnchant { public class EnchantDragonfireArrows extends ExcellentEnchant implements Chanced, Arrowed, BowEnchant {
@ -58,8 +56,8 @@ public class EnchantDragonfireArrows extends ExcellentEnchant implements Chanced
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.arrowImplementation = ArrowImplementation.create(this, SimpleParticle.of(Particle.DRAGON_BREATH)); this.arrowImplementation = ArrowImplementation.create(this, SimpleParticle.of(Particle.DRAGON_BREATH));
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"10.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5"); "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", this.fireRadius = EnchantScaler.read(this, "Settings.Fire.Radius",
"2.0 + " + Placeholders.ENCHANTMENT_LEVEL, "2.0 + " + Placeholders.ENCHANTMENT_LEVEL,
"Sets the dragonfire cloud effect radius."); "Sets the dragonfire cloud effect radius.");
}
@Override this.addPlaceholder(PLACEHOLDER_FIRE_DURATION, level -> NumberUtil.format(this.getFireDuration(level) / 20D));
@NotNull this.addPlaceholder(PLACEHOLDER_FIRE_RADIUS, level -> NumberUtil.format(this.getFireRadius(level)));
public UnaryOperator<String> 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)))
;
} }
@NotNull @NotNull

View File

@ -51,8 +51,8 @@ public class EnchantElectrifiedArrows extends ExcellentEnchant implements Chance
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.arrowImplementation = ArrowImplementation.create(this, SimpleParticle.of(Particle.FIREWORKS_SPARK)); this.arrowImplementation = ArrowImplementation.create(this, SimpleParticle.of(Particle.FIREWORKS_SPARK));
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"10.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5"); "10.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5");

View File

@ -41,8 +41,8 @@ public class EnchantEnderBow extends ExcellentEnchant implements BowEnchant, Cha
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, "100"); this.chanceImplementation = ChanceImplementation.create(this, "100");
} }

View File

@ -18,16 +18,14 @@ import su.nexmedia.engine.api.particle.SimpleParticle;
import su.nexmedia.engine.utils.NumberUtil; import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders; 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.Arrowed;
import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant; 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.ArrowImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import java.util.function.UnaryOperator;
public class EnchantExplosiveArrows extends ExcellentEnchant implements Chanced, Arrowed, BowEnchant { public class EnchantExplosiveArrows extends ExcellentEnchant implements Chanced, Arrowed, BowEnchant {
@ -58,8 +56,8 @@ public class EnchantExplosiveArrows extends ExcellentEnchant implements Chanced,
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.arrowImplementation = ArrowImplementation.create(this, SimpleParticle.of(Particle.SMOKE_NORMAL)); this.arrowImplementation = ArrowImplementation.create(this, SimpleParticle.of(Particle.SMOKE_NORMAL));
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"10.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5"); "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", this.explosionSize = EnchantScaler.read(this, "Settings.Explosion.Size",
"2.0 + " + Placeholders.ENCHANTMENT_LEVEL, "2.0 + " + Placeholders.ENCHANTMENT_LEVEL,
"Sets the explosion size. The more size - the bigger explosion."); "Sets the explosion size. The more size - the bigger explosion.");
}
@Override this.addPlaceholder(PLACEHOLDER_EXPLOSION_POWER, level -> NumberUtil.format(this.getExplosionSize(level)));
@NotNull
public UnaryOperator<String> replacePlaceholders(int level) {
return str -> super.replacePlaceholders(level).apply(str)
.replace(PLACEHOLDER_EXPLOSION_POWER, NumberUtil.format(this.getExplosionSize(level)))
;
} }
@NotNull @NotNull

View File

@ -48,8 +48,8 @@ public class EnchantGhast extends ExcellentEnchant implements BowEnchant, Chance
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, "100"); this.chanceImplementation = ChanceImplementation.create(this, "100");
this.fireSpread = JOption.create("Settings.Fire_Spread", true, this.fireSpread = JOption.create("Settings.Fire_Spread", true,
"When 'true' creates fire on nearby blocks.").read(cfg); "When 'true' creates fire on nearby blocks.").read(cfg);

View File

@ -46,8 +46,8 @@ public class EnchantHover extends ExcellentEnchant implements Chanced, Arrowed,
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.arrowImplementation = ArrowImplementation.create(this, SimpleParticle.of(Particle.BUBBLE_POP)); this.arrowImplementation = ArrowImplementation.create(this, SimpleParticle.of(Particle.BUBBLE_POP));
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"10.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5"); "10.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5");

View File

@ -47,8 +47,8 @@ public class EnchantPoisonedArrows extends ExcellentEnchant implements Chanced,
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.arrowImplementation = ArrowImplementation.create(this, SimpleParticle.of(Particle.SLIME)); this.arrowImplementation = ArrowImplementation.create(this, SimpleParticle.of(Particle.SLIME));
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"25.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5"); "25.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5");

View File

@ -47,8 +47,8 @@ public class EnchantWitheredArrows extends ExcellentEnchant implements Chanced,
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.arrowImplementation = ArrowImplementation.create(this, SimpleParticle.of(Particle.SPELL_WITCH)); this.arrowImplementation = ArrowImplementation.create(this, SimpleParticle.of(Particle.SPELL_WITCH));
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"15.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5.0"); "15.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5.0");

View File

@ -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;
}
}

View File

@ -1,5 +0,0 @@
package su.nightexpress.excellentenchants.enchantment.impl.fishing;
public class SpeedFishingEnchant {
}

View File

@ -16,19 +16,17 @@ import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.NumberUtil; import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders; 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.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.BlockBreakEnchant; 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.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.enchantment.util.EnchantUtils;
import su.nightexpress.excellentenchants.hook.impl.NoCheatPlusHook; 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.List;
import java.util.function.UnaryOperator;
public class EnchantBlastMining extends ExcellentEnchant implements Chanced, BlockBreakEnchant { public class EnchantBlastMining extends ExcellentEnchant implements Chanced, BlockBreakEnchant {
@ -52,8 +50,8 @@ public class EnchantBlastMining extends ExcellentEnchant implements Chanced, Blo
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"20.0 * " + Placeholders.ENCHANTMENT_LEVEL); "20.0 * " + Placeholders.ENCHANTMENT_LEVEL);
this.explosionPower = EnchantScaler.read(this, "Settings.Explosion.Power", 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.", "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.", "Block strength value is how long it takes to break the block by a hand.",
"For example, a Stone has 3.0 strength."); "For example, a Stone has 3.0 strength.");
this.addPlaceholder(PLACEHOLDER_EXPLOSION_POWER, level -> NumberUtil.format(this.getExplosionPower(level)));
} }
@NotNull @NotNull
@ -85,13 +85,6 @@ public class EnchantBlastMining extends ExcellentEnchant implements Chanced, Blo
return (strength >= this.getMinBlockStrength(level)); return (strength >= this.getMinBlockStrength(level));
} }
@Override
@NotNull
public UnaryOperator<String> replacePlaceholders(int level) {
return str -> super.replacePlaceholders(level).apply(str)
.replace(PLACEHOLDER_EXPLOSION_POWER, NumberUtil.format(this.getExplosionPower(level)));
}
@Override @Override
@NotNull @NotNull
public FitItemType[] getFitItemTypes() { 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) { public boolean onBreak(@NotNull BlockBreakEvent e, @NotNull Player player, @NotNull ItemStack item, int level) {
if (!this.isAvailableToUse(player)) return false; if (!this.isAvailableToUse(player)) return false;
if (EnchantRegistry.VEINMINER != null && EnchantUtils.contains(item, EnchantRegistry.VEINMINER)) return false; if (EnchantUtils.contains(item, EnchantVeinminer.ID)) return false;
if (EnchantRegistry.TUNNEL != null && EnchantUtils.contains(item, EnchantRegistry.TUNNEL)) return false; if (EnchantUtils.contains(item, EnchantTunnel.ID)) return false;
Block block = e.getBlock(); Block block = e.getBlock();
if (block.hasMetadata(META_EXPLOSION_MINED)) return false; if (block.hasMetadata(META_EXPLOSION_MINED)) return false;

View File

@ -10,15 +10,13 @@ import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.NumberUtil; import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders; 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.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.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 su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import java.util.function.UnaryOperator;
public class EnchantCurseOfBreaking extends ExcellentEnchant implements Chanced { public class EnchantCurseOfBreaking extends ExcellentEnchant implements Chanced {
public static final String ID = "curse_of_breaking"; public static final String ID = "curse_of_breaking";
@ -35,13 +33,15 @@ public class EnchantCurseOfBreaking extends ExcellentEnchant implements Chanced
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"10.0 * " + Placeholders.ENCHANTMENT_LEVEL); "10.0 * " + Placeholders.ENCHANTMENT_LEVEL);
this.durabilityAmount = EnchantScaler.read(this, "Settings.Durability_Amount", this.durabilityAmount = EnchantScaler.read(this, "Settings.Durability_Amount",
Placeholders.ENCHANTMENT_LEVEL, Placeholders.ENCHANTMENT_LEVEL,
"Amount of durability points to be taken from the item."); "Amount of durability points to be taken from the item.");
this.addPlaceholder(PLACEHOLDER_DURABILITY_AMOUNT, level -> NumberUtil.format(this.getDurabilityAmount(level)));
} }
@Override @Override
@ -59,13 +59,6 @@ public class EnchantCurseOfBreaking extends ExcellentEnchant implements Chanced
return (int) this.durabilityAmount.getValue(level); return (int) this.durabilityAmount.getValue(level);
} }
@Override
@NotNull
public UnaryOperator<String> replacePlaceholders(int level) {
return str -> super.replacePlaceholders(level).apply(str)
.replace(PLACEHOLDER_DURABILITY_AMOUNT, NumberUtil.format(this.getDurabilityAmount(level)));
}
@NotNull @NotNull
@Override @Override
public EnchantmentTarget getItemTarget() { public EnchantmentTarget getItemTarget() {

View File

@ -38,8 +38,8 @@ public class EnchantCurseOfMisfortune extends ExcellentEnchant implements Chance
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"20.0 * " + Placeholders.ENCHANTMENT_LEVEL); "20.0 * " + Placeholders.ENCHANTMENT_LEVEL);
this.dropExp = JOption.create("Settings.Drop_Exp", false, this.dropExp = JOption.create("Settings.Drop_Exp", false,

View File

@ -49,8 +49,8 @@ public class EnchantDivineTouch extends ExcellentEnchant implements Chanced, Blo
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"15.0 * " + Placeholders.ENCHANTMENT_LEVEL); "15.0 * " + Placeholders.ENCHANTMENT_LEVEL);
this.spawnerName = JOption.create("Settings.Spawner_Item.Name", this.spawnerName = JOption.create("Settings.Spawner_Item.Name",

View File

@ -27,8 +27,8 @@ public class EnchantHaste extends ExcellentEnchant implements Potioned, PassiveE
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.potionImplementation = PotionImplementation.create(this, PotionEffectType.FAST_DIGGING, true); this.potionImplementation = PotionImplementation.create(this, PotionEffectType.FAST_DIGGING, true);
} }

View File

@ -8,15 +8,13 @@ import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.NumberUtil; import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders; 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.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.BlockBreakEnchant; 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.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.type.FitItemType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import java.util.function.UnaryOperator;
public class EnchantLuckyMiner extends ExcellentEnchant implements Chanced, BlockBreakEnchant { public class EnchantLuckyMiner extends ExcellentEnchant implements Chanced, BlockBreakEnchant {
@ -34,13 +32,15 @@ public class EnchantLuckyMiner extends ExcellentEnchant implements Chanced, Bloc
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"30.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 7.0"); "30.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 7.0");
this.expModifier = EnchantScaler.read(this, "Settings.Exp_Modifier", this.expModifier = EnchantScaler.read(this, "Settings.Exp_Modifier",
"1.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 0.5", "1.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 0.5",
"Exp modifier value. The original exp amount will be multiplied on this value."); "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 @NotNull
@ -53,14 +53,6 @@ public class EnchantLuckyMiner extends ExcellentEnchant implements Chanced, Bloc
return this.expModifier.getValue(level); return this.expModifier.getValue(level);
} }
@Override
@NotNull
public UnaryOperator<String> replacePlaceholders(int level) {
return str -> super.replacePlaceholders(level).apply(str)
.replace(PLACEHOLDER_EXP_MODIFIER, NumberUtil.format(this.getExpModifier(level) * 100D - 100D))
;
}
@Override @Override
@NotNull @NotNull
public FitItemType[] getFitItemTypes() { public FitItemType[] getFitItemTypes() {

View File

@ -49,8 +49,8 @@ public class EnchantReplanter extends ExcellentEnchant implements Chanced, Inter
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, "100"); this.chanceImplementation = ChanceImplementation.create(this, "100");
this.replantOnRightClick = JOption.create("Settings.Replant.On_Right_Click", true, 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); "When 'true', player will be able to replant crops when right-clicking farmland blocks.").read(cfg);

View File

@ -60,8 +60,8 @@ public class EnchantSilkChest extends ExcellentEnchant implements BlockDropEncha
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chestName = JOption.create("Settings.Chest_Item.Name", "Chest &7(" + Placeholders.GENERIC_AMOUNT + " items)", this.chestName = JOption.create("Settings.Chest_Item.Name", "Chest &7(" + Placeholders.GENERIC_AMOUNT + " items)",
"Chest item display name.", "Chest item display name.",
"Use '" + Placeholders.GENERIC_AMOUNT + "' for items amount.").mapReader(Colorizer::apply).read(cfg); "Use '" + Placeholders.GENERIC_AMOUNT + "' for items amount.").mapReader(Colorizer::apply).read(cfg);

View File

@ -27,7 +27,6 @@ import su.nightexpress.excellentenchants.enchantment.util.EnchantDropContainer;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import java.util.Map; import java.util.Map;
import java.util.Objects;
public class EnchantSmelter extends ExcellentEnchant implements Chanced, BlockDropEnchant { public class EnchantSmelter extends ExcellentEnchant implements Chanced, BlockDropEnchant {
@ -49,8 +48,8 @@ public class EnchantSmelter extends ExcellentEnchant implements Chanced, BlockDr
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"25.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 10"); "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); "https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Sound.html").read(cfg);
this.smeltingTable = JOption.forMap("Settings.Smelting_Table", this.smeltingTable = JOption.forMap("Settings.Smelting_Table",
str -> Material.getMaterial(str.toLowerCase()), key -> Material.getMaterial(key.toUpperCase()),
(cfg, path, id) -> Material.getMaterial(cfg.getString(path + "." + id, "").toUpperCase()), (cfg, path, key) -> Material.getMaterial(cfg.getString(path + "." + key, "").toUpperCase()),
Map.of( Map.of(
Material.RAW_IRON, Material.IRON_INGOT, Material.RAW_IRON, Material.IRON_INGOT,
Material.RAW_GOLD, Material.GOLD_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!", "Note: Material source is material name of the dropped item, not the broken block!",
"https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html" "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); ).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 @NotNull

View File

@ -34,8 +34,8 @@ public class EnchantTelekinesis extends ExcellentEnchant implements Chanced, Blo
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, "100"); this.chanceImplementation = ChanceImplementation.create(this, "100");
} }

View File

@ -50,8 +50,8 @@ public class EnchantTreasures extends ExcellentEnchant implements Chanced, Block
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"10.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 4.0"); "10.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 4.0");

View File

@ -13,7 +13,6 @@ import su.nexmedia.engine.api.config.JOption;
import su.nexmedia.engine.utils.LocationUtil; import su.nexmedia.engine.utils.LocationUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.api.enchantment.type.BlockBreakEnchant; 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.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType; import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
@ -47,8 +46,8 @@ public class EnchantTunnel extends ExcellentEnchant implements BlockBreakEnchant
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.disableOnSneak = JOption.create("Settings.Ignore_When_Sneaking", true, this.disableOnSneak = JOption.create("Settings.Ignore_When_Sneaking", true,
"When 'true' the enchantment won't be triggered when sneaking.").read(cfg); "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(); Block block = e.getBlock();
if (!this.isAvailableToUse(player)) return false; if (!this.isAvailableToUse(player)) return false;
if (this.disableOnSneak && player.isSneaking()) return false; if (this.disableOnSneak && player.isSneaking()) return false;
if (EnchantRegistry.VEINMINER != null && EnchantUtils.contains(item, EnchantRegistry.VEINMINER)) return false; if (EnchantUtils.contains(item, EnchantVeinminer.ID)) return false;
if (EnchantRegistry.BLAST_MINING != null && EnchantUtils.contains(item, EnchantRegistry.BLAST_MINING)) return false; if (EnchantUtils.contains(item, EnchantBlastMining.ID)) return false;
if (block.hasMetadata(META_BLOCK_TUNNEL)) return false; if (block.hasMetadata(META_BLOCK_TUNNEL)) return false;
if (block.getType().isInteractable() && !INTERACTABLE_BLOCKS.contains(block.getType())) return false; if (block.getType().isInteractable() && !INTERACTABLE_BLOCKS.contains(block.getType())) return false;
if (block.getDrops(item).isEmpty()) return false; if (block.getDrops(item).isEmpty()) return false;

View File

@ -15,7 +15,6 @@ import su.nexmedia.engine.utils.Scaler;
import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders; import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.api.enchantment.type.BlockBreakEnchant; 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.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType; 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.HashSet;
import java.util.Set; import java.util.Set;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -49,8 +47,8 @@ public class EnchantVeinminer extends ExcellentEnchant implements BlockBreakEnch
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.blocksLimit = EnchantScaler.read(this, "Settings.Blocks.Max_At_Once", this.blocksLimit = EnchantScaler.read(this, "Settings.Blocks.Max_At_Once",
"6 + " + Placeholders.ENCHANTMENT_LEVEL, "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.", "List of blocks, that will be affected by this enchantment.",
"https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html" "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); ).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 @NotNull
@ -86,14 +86,6 @@ public class EnchantVeinminer extends ExcellentEnchant implements BlockBreakEnch
return (int) this.blocksLimit.getValue(level); return (int) this.blocksLimit.getValue(level);
} }
@Override
@NotNull
public UnaryOperator<String> replacePlaceholders(int level) {
return str -> super.replacePlaceholders(level).apply(str)
.replace(PLACEHOLDER_BLOCK_LIMIT, String.valueOf(this.getBlocksLimit(level)))
;
}
@Override @Override
@NotNull @NotNull
public FitItemType[] getFitItemTypes() { public FitItemType[] getFitItemTypes() {
@ -140,8 +132,8 @@ public class EnchantVeinminer extends ExcellentEnchant implements BlockBreakEnch
@Override @Override
public boolean onBreak(@NotNull BlockBreakEvent e, @NotNull Player player, @NotNull ItemStack tool, int level) { public boolean onBreak(@NotNull BlockBreakEvent e, @NotNull Player player, @NotNull ItemStack tool, int level) {
if (!this.isAvailableToUse(player)) return false; if (!this.isAvailableToUse(player)) return false;
if (EnchantRegistry.TUNNEL != null && EnchantUtils.contains(tool, EnchantRegistry.TUNNEL)) return false; if (EnchantUtils.contains(tool, EnchantBlastMining.ID)) return false;
if (EnchantRegistry.BLAST_MINING != null && EnchantUtils.contains(tool, EnchantRegistry.BLAST_MINING)) return false; if (EnchantUtils.contains(tool, EnchantTunnel.ID)) return false;
Block block = e.getBlock(); Block block = e.getBlock();
if (block.hasMetadata(META_BLOCK_VEINED)) return false; if (block.hasMetadata(META_BLOCK_VEINED)) return false;

View File

@ -18,7 +18,6 @@ import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import java.util.Set; import java.util.Set;
import java.util.function.UnaryOperator;
public class EnchantBaneOfNetherspawn extends ExcellentEnchant implements CombatEnchant { public class EnchantBaneOfNetherspawn extends ExcellentEnchant implements CombatEnchant {
@ -44,26 +43,21 @@ public class EnchantBaneOfNetherspawn extends ExcellentEnchant implements Combat
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.damageModifier = JOption.create("Settings.Damage.As_Modifier", false, this.damageModifier = JOption.create("Settings.Damage.As_Modifier", false,
"When 'true' multiplies the damage. When 'false' sums plain values.").read(cfg); "When 'true' multiplies the damage. When 'false' sums plain values.").read(cfg);
this.damageFormula = EnchantScaler.read(this, "Settings.Damage.Amount", this.damageFormula = EnchantScaler.read(this, "Settings.Damage.Amount",
"0.5 * " + Placeholders.ENCHANTMENT_LEVEL, "0.5 * " + Placeholders.ENCHANTMENT_LEVEL,
"Amount of additional damage."); "Amount of additional damage.");
this.addPlaceholder(PLACEHOLDER_DAMAGE, level -> NumberUtil.format(this.getDamageModifier(level)));
} }
public double getDamageModifier(int level) { public double getDamageModifier(int level) {
return this.damageFormula.getValue(level); return this.damageFormula.getValue(level);
} }
@Override
@NotNull
public UnaryOperator<String> replacePlaceholders(int level) {
return str -> super.replacePlaceholders(level).apply(str)
.replace(PLACEHOLDER_DAMAGE, NumberUtil.format(this.getDamageModifier(level)));
}
@Override @Override
@NotNull @NotNull
public EnchantmentTarget getItemTarget() { public EnchantmentTarget getItemTarget() {

View File

@ -33,8 +33,8 @@ public class EnchantBlindness extends ExcellentEnchant implements Chanced, Potio
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"15.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 3"); "15.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 3");
this.potionImplementation = PotionImplementation.create(this, PotionEffectType.BLINDNESS, false, this.potionImplementation = PotionImplementation.create(this, PotionEffectType.BLINDNESS, false,

View File

@ -34,8 +34,8 @@ public class EnchantConfusion extends ExcellentEnchant implements Chanced, Potio
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"15.0 * " + Placeholders.ENCHANTMENT_LEVEL); "15.0 * " + Placeholders.ENCHANTMENT_LEVEL);
this.potionImplementation = PotionImplementation.create(this, PotionEffectType.CONFUSION, false, this.potionImplementation = PotionImplementation.create(this, PotionEffectType.CONFUSION, false,

View File

@ -34,8 +34,8 @@ public class EnchantCure extends ExcellentEnchant implements Chanced, CombatEnch
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"20.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 8"); "20.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 8");
} }

View File

@ -24,8 +24,6 @@ import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import java.util.function.UnaryOperator;
public class EnchantCutter extends ExcellentEnchant implements Chanced, CombatEnchant { public class EnchantCutter extends ExcellentEnchant implements Chanced, CombatEnchant {
public static final String ID = "cutter"; public static final String ID = "cutter";
@ -42,13 +40,15 @@ public class EnchantCutter extends ExcellentEnchant implements Chanced, CombatEn
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"1.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 0.6"); "1.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 0.6");
this.durabilityReduction = EnchantScaler.read(this, "Settings.Item.Durability_Reduction", this.durabilityReduction = EnchantScaler.read(this, "Settings.Item.Durability_Reduction",
Placeholders.ENCHANTMENT_LEVEL + " / 100", Placeholders.ENCHANTMENT_LEVEL + " / 100",
"Amount (in percent) of how much item durability will be reduced."); "Amount (in percent) of how much item durability will be reduced.");
this.addPlaceholder(PLACEHOLDER_DURABILITY_DAMAGE, level -> NumberUtil.format(this.getDurabilityReduction(level) * 100D));
} }
@NotNull @NotNull
@ -61,13 +61,6 @@ public class EnchantCutter extends ExcellentEnchant implements Chanced, CombatEn
return this.durabilityReduction.getValue(level); return this.durabilityReduction.getValue(level);
} }
@Override
@NotNull
public UnaryOperator<String> replacePlaceholders(int level) {
return str -> super.replacePlaceholders(level).apply(str)
.replace(PLACEHOLDER_DURABILITY_DAMAGE, NumberUtil.format(this.getDurabilityReduction(level) * 100D));
}
@Override @Override
@NotNull @NotNull
public EnchantmentTarget getItemTarget() { public EnchantmentTarget getItemTarget() {

View File

@ -20,7 +20,6 @@ import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.config.JOption; import su.nexmedia.engine.api.config.JOption;
import su.nexmedia.engine.api.particle.SimpleParticle; import su.nexmedia.engine.api.particle.SimpleParticle;
import su.nexmedia.engine.lang.LangManager; import su.nexmedia.engine.lang.LangManager;
import su.nexmedia.engine.utils.EffectUtil;
import su.nexmedia.engine.utils.ItemUtil; import su.nexmedia.engine.utils.ItemUtil;
import su.nexmedia.engine.utils.PDCUtil; import su.nexmedia.engine.utils.PDCUtil;
import su.nexmedia.engine.utils.StringUtil; import su.nexmedia.engine.utils.StringUtil;
@ -58,8 +57,8 @@ public class EnchantDecapitator extends ExcellentEnchant implements Chanced, Dea
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"5.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 1.75"); "5.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 1.75");

View File

@ -31,8 +31,8 @@ public class EnchantDoubleStrike extends ExcellentEnchant implements Chanced, Co
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"4.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 0.8"); "4.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 0.8");
} }

View File

@ -34,8 +34,8 @@ public class EnchantExhaust extends ExcellentEnchant implements Chanced, Potione
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"20.0 * " + Placeholders.ENCHANTMENT_LEVEL); "20.0 * " + Placeholders.ENCHANTMENT_LEVEL);
this.potionImplementation = PotionImplementation.create(this, PotionEffectType.HUNGER, false, this.potionImplementation = PotionImplementation.create(this, PotionEffectType.HUNGER, false,

View File

@ -8,12 +8,10 @@ import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.NumberUtil; import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders; import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant; import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import java.util.function.UnaryOperator; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantExpHunter extends ExcellentEnchant implements DeathEnchant { public class EnchantExpHunter extends ExcellentEnchant implements DeathEnchant {
@ -30,25 +28,19 @@ public class EnchantExpHunter extends ExcellentEnchant implements DeathEnchant {
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.expModifier = EnchantScaler.read(this, "Settings.Exp_Modifier", this.expModifier = EnchantScaler.read(this, "Settings.Exp_Modifier",
"1.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 0.5", "1.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 0.5",
"Exp modifier value. The original exp amount will be multiplied on this value."); "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) { public final double getExpModifier(int level) {
return this.expModifier.getValue(level); return this.expModifier.getValue(level);
} }
@Override
@NotNull
public UnaryOperator<String> replacePlaceholders(int level) {
return str -> super.replacePlaceholders(level).apply(str)
.replace(PLACEHOLDER_EXP_MODIFIER, NumberUtil.format(this.getExpModifier(level) * 100D - 100D))
;
}
@Override @Override
@NotNull @NotNull
public EnchantmentTarget getItemTarget() { public EnchantmentTarget getItemTarget() {

View File

@ -34,8 +34,8 @@ public class EnchantIceAspect extends ExcellentEnchant implements Chanced, Potio
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, "100"); this.chanceImplementation = ChanceImplementation.create(this, "100");
this.potionImplementation = PotionImplementation.create(this, PotionEffectType.SLOW, false, this.potionImplementation = PotionImplementation.create(this, PotionEffectType.SLOW, false,
"3.0 + " + Placeholders.ENCHANTMENT_LEVEL, "3.0 + " + Placeholders.ENCHANTMENT_LEVEL,

View File

@ -13,13 +13,11 @@ import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.NumberUtil; import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders; import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import java.util.function.UnaryOperator;
public class EnchantInfernus extends ExcellentEnchant { public class EnchantInfernus extends ExcellentEnchant {
public static final String ID = "infernus"; public static final String ID = "infernus";
@ -35,25 +33,19 @@ public class EnchantInfernus extends ExcellentEnchant {
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.fireTicks = EnchantScaler.read(this, "Settings.Fire_Ticks", this.fireTicks = EnchantScaler.read(this, "Settings.Fire_Ticks",
"60 + " + Placeholders.ENCHANTMENT_LEVEL + " * 20", "60 + " + Placeholders.ENCHANTMENT_LEVEL + " * 20",
"Sets for how long (in ticks) entity will be ignited on hit. 20 ticks = 1 second."); "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) { public int getFireTicks(int level) {
return (int) this.fireTicks.getValue(level); return (int) this.fireTicks.getValue(level);
} }
@Override
@NotNull
public UnaryOperator<String> replacePlaceholders(int level) {
return str -> super.replacePlaceholders(level).apply(str)
.replace(PLACEHOLDER_FIRE_DURATION, NumberUtil.format((double) this.getFireTicks(level) / 20D))
;
}
@Override @Override
@NotNull @NotNull
public EnchantmentTarget getItemTarget() { public EnchantmentTarget getItemTarget() {

View File

@ -27,8 +27,8 @@ public class EnchantNimble extends ExcellentEnchant implements Chanced, DeathEnc
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this); this.chanceImplementation = ChanceImplementation.create(this);
} }

View File

@ -33,8 +33,8 @@ public class EnchantParalyze extends ExcellentEnchant implements Chanced, Potion
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"10.0 * " + Placeholders.ENCHANTMENT_LEVEL); "10.0 * " + Placeholders.ENCHANTMENT_LEVEL);
this.potionImplementation = PotionImplementation.create(this, PotionEffectType.SLOW_DIGGING, false, this.potionImplementation = PotionImplementation.create(this, PotionEffectType.SLOW_DIGGING, false,

View File

@ -33,8 +33,8 @@ public class EnchantRage extends ExcellentEnchant implements Chanced, Potioned,
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"7.0 + " + Placeholders.ENCHANTMENT_LEVEL); "7.0 + " + Placeholders.ENCHANTMENT_LEVEL);
this.potionImplementation = PotionImplementation.create(this, PotionEffectType.INCREASE_DAMAGE, false, this.potionImplementation = PotionImplementation.create(this, PotionEffectType.INCREASE_DAMAGE, false,

View File

@ -35,8 +35,8 @@ public class EnchantRocket extends ExcellentEnchant implements Chanced, CombatEn
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"4.0 + " + Placeholders.ENCHANTMENT_LEVEL); "4.0 + " + Placeholders.ENCHANTMENT_LEVEL);
this.fireworkPower = EnchantScaler.read(this, "Settings.Firework_Power", this.fireworkPower = EnchantScaler.read(this, "Settings.Firework_Power",

View File

@ -38,8 +38,8 @@ public class EnchantScavenger extends ExcellentEnchant implements Chanced, Death
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"15.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 10"); "15.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 10");

View File

@ -36,8 +36,8 @@ public class EnchantSurprise extends ExcellentEnchant implements Chanced, Potion
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"2.25 * " + Placeholders.ENCHANTMENT_LEVEL); "2.25 * " + Placeholders.ENCHANTMENT_LEVEL);
this.potionImplementation = PotionImplementation.create(this, PotionEffectType.BLINDNESS, false, this.potionImplementation = PotionImplementation.create(this, PotionEffectType.BLINDNESS, false,

View File

@ -10,12 +10,10 @@ import su.nexmedia.engine.utils.EntityUtil;
import su.nexmedia.engine.utils.NumberUtil; import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders; import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import java.util.function.UnaryOperator; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantTemper extends ExcellentEnchant implements CombatEnchant { public class EnchantTemper extends ExcellentEnchant implements CombatEnchant {
@ -36,8 +34,8 @@ public class EnchantTemper extends ExcellentEnchant implements CombatEnchant {
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.damageAmount = EnchantScaler.read(this, "Settings.Damage.Amount", this.damageAmount = EnchantScaler.read(this, "Settings.Damage.Amount",
"0.01 * " + Placeholders.ENCHANTMENT_LEVEL, "0.01 * " + Placeholders.ENCHANTMENT_LEVEL,
"On how much (in percent) the damage will be increased per each Health Point?"); "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."); "Maximal possible value for the Damage.Amount.");
this.healthPoint = EnchantScaler.read(this, "Settings.Health.Point", "0.5", this.healthPoint = EnchantScaler.read(this, "Settings.Health.Point", "0.5",
"For how much every missing hearts damage will be increased?"); "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) { public double getDamageAmount(int level) {
@ -59,16 +61,6 @@ public class EnchantTemper extends ExcellentEnchant implements CombatEnchant {
return this.healthPoint.getValue(level); return this.healthPoint.getValue(level);
} }
@Override
@NotNull
public UnaryOperator<String> 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 @NotNull
@Override @Override
public EnchantmentTarget getItemTarget() { public EnchantmentTarget getItemTarget() {

View File

@ -47,8 +47,8 @@ public class EnchantThrifty extends ExcellentEnchant implements Chanced, DeathEn
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"5.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 3"); "5.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 3");

View File

@ -35,8 +35,8 @@ public class EnchantThunder extends ExcellentEnchant implements Chanced, CombatE
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"10.0 * " + Placeholders.ENCHANTMENT_LEVEL); "10.0 * " + Placeholders.ENCHANTMENT_LEVEL);
this.inThunderstormOnly = JOption.create("Settings.During_Thunderstorm_Only", false, this.inThunderstormOnly = JOption.create("Settings.During_Thunderstorm_Only", false,

View File

@ -21,8 +21,6 @@ import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import java.util.function.UnaryOperator;
public class EnchantVampire extends ExcellentEnchant implements Chanced, CombatEnchant { public class EnchantVampire extends ExcellentEnchant implements Chanced, CombatEnchant {
public static final String ID = "vampire"; public static final String ID = "vampire";
@ -40,8 +38,8 @@ public class EnchantVampire extends ExcellentEnchant implements Chanced, CombatE
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"25.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5.0"); "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."); "Amount of health to be restored for attacker.");
this.healMultiplier = JOption.create("Settings.Heal.As_Multiplier", false, 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); "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 @NotNull
@ -72,16 +72,6 @@ public class EnchantVampire extends ExcellentEnchant implements Chanced, CombatE
return EnchantmentTarget.WEAPON; return EnchantmentTarget.WEAPON;
} }
@Override
@NotNull
public UnaryOperator<String> 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 @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(damager)) return false; if (!this.isAvailableToUse(damager)) return false;

View File

@ -33,8 +33,8 @@ public class EnchantVenom extends ExcellentEnchant implements Chanced, Potioned,
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"30.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 10.0"); "30.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 10.0");
this.potionImplementation = PotionImplementation.create(this, PotionEffectType.POISON, false, this.potionImplementation = PotionImplementation.create(this, PotionEffectType.POISON, false,

View File

@ -9,7 +9,6 @@ import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.config.JOption; import su.nexmedia.engine.api.config.JOption;
import su.nexmedia.engine.api.particle.SimpleParticle; import su.nexmedia.engine.api.particle.SimpleParticle;
import su.nexmedia.engine.utils.EffectUtil;
import su.nexmedia.engine.utils.NumberUtil; import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders; 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.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import java.util.function.UnaryOperator;
public class EnchantVillageDefender extends ExcellentEnchant implements CombatEnchant { public class EnchantVillageDefender extends ExcellentEnchant implements CombatEnchant {
public static final String ID = "village_defender"; public static final String ID = "village_defender";
@ -36,8 +33,8 @@ public class EnchantVillageDefender extends ExcellentEnchant implements CombatEn
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.damageAmount = EnchantScaler.read(this, "Settings.Damage.Formula", this.damageAmount = EnchantScaler.read(this, "Settings.Damage.Formula",
"0.5 * " + Placeholders.ENCHANTMENT_LEVEL, "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, 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); "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) { public double getDamageAddict(int level) {
@ -55,14 +54,6 @@ public class EnchantVillageDefender extends ExcellentEnchant implements CombatEn
return damageMultiplier; return damageMultiplier;
} }
@Override
@NotNull
public UnaryOperator<String> replacePlaceholders(int level) {
return str -> super.replacePlaceholders(level).apply(str)
.replace(PLACEHOLDER_DAMAGE_AMOUNT, NumberUtil.format(this.getDamageAddict(level)))
;
}
@Override @Override
@NotNull @NotNull
public EnchantmentTarget getItemTarget() { public EnchantmentTarget getItemTarget() {

View File

@ -8,7 +8,6 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.particle.SimpleParticle; import su.nexmedia.engine.api.particle.SimpleParticle;
import su.nexmedia.engine.utils.EffectUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders; import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
@ -34,8 +33,8 @@ public class EnchantWither extends ExcellentEnchant implements Chanced, Potioned
} }
@Override @Override
public void loadConfig() { public void loadSettings() {
super.loadConfig(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"10.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5"); "10.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5");
this.potionImplementation = PotionImplementation.create(this, PotionEffectType.WITHER, false, this.potionImplementation = PotionImplementation.create(this, PotionEffectType.WITHER, false,

View File

@ -15,8 +15,10 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDropItemEvent; import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.event.entity.*; import org.bukkit.event.entity.*;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EntityEquipment; import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -205,6 +207,25 @@ public class EnchantHandlerListener extends AbstractListener<ExcellentEnchants>
}); });
} }
@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 // Death Related Enchants
// --------------------------------------------------------------- // ---------------------------------------------------------------

View File

@ -4,7 +4,6 @@ import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.config.JYML; import su.nexmedia.engine.api.config.JYML;
import su.nexmedia.engine.api.menu.AutoPaged; import su.nexmedia.engine.api.menu.AutoPaged;
@ -125,28 +124,27 @@ public class EnchantmentsListMenu extends ConfigMenu<ExcellentEnchants> implemen
@NotNull @NotNull
private ItemStack buildEnchantIcon(@NotNull ExcellentEnchant enchant, int level) { private ItemStack buildEnchantIcon(@NotNull ExcellentEnchant enchant, int level) {
ItemStack icon = new ItemStack(this.enchantIcon); ItemStack icon = new ItemStack(this.enchantIcon);
ItemMeta meta = icon.getItemMeta(); ItemUtil.mapMeta(icon, meta -> {
if (meta == null) return icon; List<String> lore = meta.getLore();
if (lore == null) lore = new ArrayList<>();
List<String> lore = meta.getLore(); List<String> conflicts = enchant.getConflicts().isEmpty() ? Collections.emptyList() : new ArrayList<>(this.enchantLoreConflicts);
if (lore == null) lore = new ArrayList<>(); List<String> 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<String> conflicts = enchant.getConflicts().isEmpty() ? Collections.emptyList() : new ArrayList<>(this.enchantLoreConflicts); List<String> charges = enchant.isChargesEnabled() ? new ArrayList<>(this.enchantLoreCharges) : Collections.emptyList();
List<String> conflictNames = enchant.getConflicts().stream().map(key -> Enchantment.getByKey(NamespacedKey.minecraft(key))) List<String> obtaining = new ArrayList<>(this.enchantLoreObtaining);
.filter(Objects::nonNull).map(LangManager::getEnchantment).toList();
conflicts = StringUtil.replace(conflicts, Placeholders.ENCHANTMENT_NAME, true, conflictNames);
List<String> charges = enchant.isChargesEnabled() ? new ArrayList<>(this.enchantLoreCharges) : Collections.emptyList(); lore = StringUtil.replace(lore, PLACEHOLDER_CONFLICTS, false, conflicts);
List<String> obtaining = new ArrayList<>(this.enchantLoreObtaining); 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); meta.setLore(lore);
lore = StringUtil.replace(lore, PLACEHOLDER_CHARGES, false, charges); ItemUtil.replace(meta, enchant.getPlaceholders(level).replacer());
lore = StringUtil.replace(lore, PLACEHOLDER_OBTAINING, false, obtaining); });
meta.setLore(lore);
icon.setItemMeta(meta);
ItemUtil.replace(icon, enchant.replaceAllPlaceholders(level));
return icon; return icon;
} }
} }

View File

@ -38,6 +38,11 @@ public class EnchantUtils {
public static final NamespacedKey KEY_LORE_SIZE = new NamespacedKey(ExcellentEnchantsAPI.PLUGIN, "lore_size"); 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) { public static boolean isEnchantable(@NotNull ItemStack item) {
if (item.getType().isAir()) return false; if (item.getType().isAir()) return false;
@ -212,6 +217,13 @@ public class EnchantUtils {
return getAll(item).size(); 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) { public static boolean contains(@NotNull ItemStack item, @NotNull Enchantment enchantment) {
return getLevel(item, enchantment) > 0; return getLevel(item, enchantment) > 0;
} }
@ -292,7 +304,7 @@ public class EnchantUtils {
private static Map<ExcellentEnchant, Integer> getExcellents(@NotNull Map<Enchantment, Integer> enchants) { private static Map<ExcellentEnchant, Integer> getExcellents(@NotNull Map<Enchantment, Integer> enchants) {
Map<ExcellentEnchant, Integer> map = new HashMap<>(); Map<ExcellentEnchant, Integer> map = new HashMap<>();
enchants.forEach((enchantment, level) -> { enchants.forEach((enchantment, level) -> {
ExcellentEnchant excellent = EnchantRegistry.get(enchantment.getKey()); ExcellentEnchant excellent = EnchantRegistry.getByKey(enchantment.getKey());
if (excellent != null) { if (excellent != null) {
map.put(excellent, level); map.put(excellent, level);
} }
@ -304,7 +316,7 @@ public class EnchantUtils {
public static <T extends IEnchantment> Map<T, Integer> getExcellents(@NotNull ItemStack item, @NotNull Class<T> clazz) { public static <T extends IEnchantment> Map<T, Integer> getExcellents(@NotNull ItemStack item, @NotNull Class<T> clazz) {
Map<T, Integer> map = new HashMap<>(); Map<T, Integer> map = new HashMap<>();
getAll(item).forEach((enchantment, level) -> { 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; if (excellent == null || !clazz.isAssignableFrom(excellent.getClass())) return;
map.put(clazz.cast(excellent), level); map.put(clazz.cast(excellent), level);

View File

@ -63,7 +63,7 @@ public class PlaceholderHook {
ItemStack item = player.getInventory().getItem(slot); ItemStack item = player.getInventory().getItem(slot);
if (item == null || item.getType().isAir()) return "-"; 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; if (enchant == null) return null;
return String.valueOf(enchant.getCharges(item)); return String.valueOf(enchant.getCharges(item));
@ -72,7 +72,7 @@ public class PlaceholderHook {
String[] chargesSplit = params.substring("charges_maximum_".length()).split(":"); String[] chargesSplit = params.substring("charges_maximum_".length()).split(":");
if (chargesSplit.length < 2) return null; 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; if (enchant == null) return null;
int level = StringUtil.getInteger(chargesSplit[1], 1); int level = StringUtil.getInteger(chargesSplit[1], 1);

View File

@ -2,8 +2,10 @@ package su.nightexpress.excellentenchants.nms;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Set; import java.util.Set;
@ -12,5 +14,7 @@ public interface EnchantNMS {
void sendAttackPacket(@NotNull Player player, int id); void sendAttackPacket(@NotNull Player player, int id);
void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item);
@NotNull Set<Block> handleFlameWalker(@NotNull LivingEntity entity, @NotNull Location location, int level); @NotNull Set<Block> handleFlameWalker(@NotNull LivingEntity entity, @NotNull Location location, int level);
} }

View File

@ -4,6 +4,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.network.protocol.game.ClientboundAnimatePacket; import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity; 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.Blocks;
import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.state.BlockState; 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.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld; 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.CraftLivingEntity;
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; 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.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.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import su.nightexpress.excellentenchants.nms.EnchantNMS; import su.nightexpress.excellentenchants.nms.EnchantNMS;
@ -32,6 +37,13 @@ public class V1_17_R1 implements EnchantNMS {
craftPlayer.getHandle().connection.send(packet); 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 @Override
@NotNull @NotNull
public Set<Block> handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) { public Set<Block> handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) {

View File

@ -4,6 +4,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.network.protocol.game.ClientboundAnimatePacket; import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity; 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.Blocks;
import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.state.BlockState; 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.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; 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.CraftLivingEntity;
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; 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.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.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import su.nightexpress.excellentenchants.nms.EnchantNMS; import su.nightexpress.excellentenchants.nms.EnchantNMS;
@ -32,6 +37,13 @@ public class V1_18_R2 implements EnchantNMS {
craftPlayer.getHandle().connection.send(packet); 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 @Override
@NotNull @NotNull
public Set<Block> handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) { public Set<Block> handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) {

View File

@ -4,6 +4,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.network.protocol.game.ClientboundAnimatePacket; import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity; 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.Blocks;
import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.state.BlockState; 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.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; 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.CraftLivingEntity;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; 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.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.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import su.nightexpress.excellentenchants.nms.EnchantNMS; import su.nightexpress.excellentenchants.nms.EnchantNMS;
@ -32,6 +37,13 @@ public class V1_19_R1 implements EnchantNMS {
craftPlayer.getHandle().connection.send(packet); 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 @Override
@NotNull @NotNull
public Set<Block> handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) { public Set<Block> handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) {

View File

@ -4,6 +4,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.network.protocol.game.ClientboundAnimatePacket; import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity; 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.Blocks;
import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.state.BlockState; 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.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_19_R2.CraftWorld; 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.CraftLivingEntity;
import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; 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.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.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import su.nightexpress.excellentenchants.nms.EnchantNMS; import su.nightexpress.excellentenchants.nms.EnchantNMS;
@ -32,6 +37,13 @@ public class V1_19_R2 implements EnchantNMS {
craftPlayer.getHandle().connection.send(packet); 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 @Override
@NotNull @NotNull
public Set<Block> handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) { public Set<Block> handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) {

View File

@ -4,6 +4,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.network.protocol.game.ClientboundAnimatePacket; import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity; 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.Blocks;
import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.state.BlockState; 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.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_19_R3.CraftWorld; 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.CraftLivingEntity;
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer; 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.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.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import su.nightexpress.excellentenchants.nms.EnchantNMS; import su.nightexpress.excellentenchants.nms.EnchantNMS;
@ -32,6 +37,13 @@ public class V1_19_R3 implements EnchantNMS {
craftPlayer.getHandle().connection.send(packet); 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 @Override
@NotNull @NotNull
public Set<Block> handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) { public Set<Block> handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) {