ShieldWielder

a

Kodari AI
KodariNov 3 at 3:20 am 1

The generation was stopped before any content could be produced.

ShieldWielder

using a wind charge on a cobweb should delete the cobweb. add a /itemlimiter remove hand command aswell. (self explanitory). autoreloadholoster does not work. Reaper clears potion effects fully, I only want it to reduce the timer by 10 seconds. Also when reaper is activated, it should /playsound minecraft:entity.ender_dragon.flap. Also reaper should be 50%. artemis should only give the speed when hit a player, also should get speed 2 not one. AScent does not fling the player up. SHould get them a certain amount of levitation and bring them towards the macer. Volley does not work. Still only shoot one arrow, should shoot 2 at the same time

Kodari AI
KodariNov 3 at 3:36 am 3
  1. Wind-charge cobweb removal.

  2. /itemlimiter remove hand.

  3. Fix autoreload holster.

  4. Correct Reaper behavior, sound, and 50% chance.

  5. Fix Artemis speed trigger/amplifier, Ascent lift, and Volley’s two-arrow shot.

  1. Wind charges now remove cobwebs they hit.

  2. Added /itemlimiter remove hand to remove the held item from the limiter.

  3. Fixed Autoloading Holster to recognize regular arrows as ammunition.

  4. Reaper now reduces positive-effect timers by 10 seconds without removing them, plays the dragon flap sound, and retains its 50% critical-hit chance.

  5. Artemis now grants Speed II when its fully charged arrow hits a player; Ascent gives the target brief Levitation and pulls them toward the mace wielder; Volley fires a visibly offset second arrow alongside the first.

ShieldWielder

when it says the spear is on cooldown, I can still left click to lunge

Kodari AI
KodariNov 3 at 3:41 am 1
  • Check the spear cooldown and lunge event handlers.

  • Make cooldown enforcement block the left-click lunge itself.

Updated the spear cooldown handler to explicitly deny both item use and block interaction when the cooldown is active, preventing the left-click Lunge from triggering.

ShieldWielder

windcharges don't break cobwebs. It should clear what ever cobweb the wind charge land

Kodari AI
KodariNov 3 at 2:47 pm 1
  • Inspect the wind-charge impact handler.

  • Remove the cobweb at the charge’s landing location.

Wind-charge impacts now clear a cobweb at the projectile’s impact position, the hit block, or the block immediately in front of the hit face.

ShieldWielder

make the wind charge max able to break 4 blocks. And add windchargecobweb to itemgui so I can config the amount of blocks it break anytime

Kodari AI
KodariNov 3 at 2:56 pm 1
  1. Raise the wind-charge cobweb break cap to four blocks.

  2. Add windchargecobweb to the item GUI so the break amount is configurable.

Wind charges now remove up to 4 nearby cobweb blocks on impact. Added Wind Charge Cobweb to the Item Settings GUI; operators can adjust the limit from 0 to 4, and it saves as item-settings.windchargecobweb (default: 4).

ShieldWielder

give me access to regular vault loot table like rare vaults. /trialchamber loot regularV

Kodari AI
KodariNov 3 at 3:05 pm 1
  1. Locate the trial chamber loot command and its rare-vault handling.

  2. Add regularV access to the regular vault loot table.

Added /trialchamber loot regularV with the same GUI and list/add/remove/chance controls as rare. Regular vault loot is managed separately under trial-chamber.loot.regular; configured entries affect regular vaults, while ominous vaults keep using the rare table.

ShieldWielder

Frenzy • Rarity: Legendary • Applicable To: Helmet • Effect: Grants Haste III continuously while you are wearing the helmet.

Kodari AI
KodariNov 3 at 3:07 pm 1
  • Find how custom enchants are registered, assigned rarity/applicable items, and applied while equipped.

  • Add Legendary helmet enchant Frenzy for continuous Haste III while worn.

Added Frenzy as a Legendary helmet enchant. While the enchanted helmet is worn, it continuously renews Haste III; it’s included in the existing Legendary enchant roll system.

ShieldWielder

make /netheriteremove clear all ancient deberis naturally generated, any type of netherite from chest in the entire nether

Kodari AI
KodariNov 3 at 3:10 pm 1
  • Add /netheriteremove clear while preserving the existing no-argument form.

  • Scan all existing chunks in every loaded Nether world, clearing ancient-debris blocks and Netherite items in containers/entities/player inventories.

  • Report debris blocks and items removed separately.

/netheriteremove clear now removes ancient-debris blocks and Netherite items from containers, dropped items, and player inventories across existing chunks in loaded Nether worlds. It reports block and item totals separately. It scans generated/saved chunks; unexplored chunks aren’t included.

ShieldWielder

for the spear, I can still left click, but Ican't right click. Make it so i can't do either

Kodari AI
KodariNov 3 at 3:17 pm 1
  • Apply the spear’s active cooldown check to both left- and right-click interactions.

  • Cancel the interaction and deny item/block use while it is active.

Spear cooldown now blocks both left- and right-click interactions, denying item use and block interaction while the cooldown is active.

ShieldWielder

Also for the make the netherite clear from all contaners

Kodari AI
KodariNov 3 at 3:18 pm 1
  • Keep scanning every existing Nether chunk and its block containers.

  • Include inventory-holding entities, such as chest minecarts, in the Netherite removal scan.

/netheriteremove clear now checks inventory-holding entities as well as block containers, so Netherite items in containers such as chest minecarts are removed during the Nether scan.

ShieldWielder

add a 10 second cooldown on ascent and blitz

Kodari AI
KodariNov 3 at 3:59 pm 1
  1. Locate the Ascent and Blitz activation handlers.

  2. Add a 10-second cooldown to each ability.

Added independent 10-second cooldowns to Ascent and Blitz activations.

ShieldWielder

make blitz not go through totems

Kodari AI
KodariNov 3 at 4:01 pm 1
  • Make Blitz deal its damage through the normal damage event instead of directly reducing health, so Totems can activate.

Blitz now applies its 50 damage through the normal damage event instead of directly reducing health, allowing the victim’s Totem of Undying to activate.

ShieldWielder

make blitz and ascent cooldown 30 seconds. Add it to itemgui. Also, make itemgui look clean

Kodari AI
KodariNov 3 at 4:08 pm 2
  1. Set Ascent and Blitz cooldowns to 30 seconds.

  2. Add a configurable cooldown setting to the Item GUI.

  3. Clean up the Item GUI layout.

1. Done: Ascent and Blitz now have 30-second cooldowns. I’ll expose their cooldown settings in the Item GUI next.

2. Done: Added editable Ascent and Blitz cooldowns to Item Settings, both defaulting to 30 seconds. I’ll organize the settings screen into clear sections with a consistent footer.

Ascent and Blitz now default to 30-second cooldowns, and both can be adjusted in Item Settings. I reorganized the GUI into General Settings and Ability Cooldowns sections, with a consistent footer.

ShieldWielder

I can still left click lunge through the spear c ooldown

Kodari AI
KodariNov 3 at 4:41 pm 1
  • Block the spear’s swing animation while its cooldown is active.

  • Enforce the same cooldown check on attack damage, even if another listener already cancelled the event.

Spear swings are now cancelled while the cooldown is active, and the attack handler enforces the cooldown even if another listener cancelled the damage event first.

ShieldWielder

what ever you did to make it not be able to right click, do the same for left click. I can still lunge through cooldown

Kodari AI
KodariNov 3 at 4:55 pm 1

Spear attacks now check both the plugin cooldown and the active item cooldown before allowing a hit, so left-click attacks are cancelled during cooldown.

ShieldWielder

Make right click exactly like left click. I can't use my spear with right click but I can use it with left click. Make it like right click

Kodari AI
KodariNov 3 at 5:04 pm 1

Do you want left-click attacks blocked during the spear cooldown to match the currently blocked right-click, or do you want right-click spear use enabled to match left-click? Those are opposite changes, and your message asks for both.

ShieldWielder

I want it to be disabled like right click

Kodari AI
KodariNov 3 at 5:05 pm 1
  • Check the spear’s left-click and right-click cooldown handlers.

  • Make left-click use the same blocking check as right-click.

Left-click interactions now check the spear cooldown at HIGHEST priority, matching right-click’s cooldown block.

ShieldWielder

forget about it. Instead Make me a custom texturepack.

Kodari AI
KodariNov 3 at 5:07 pm 1

This is a Java Minecraft plugin project, and Kodari can’t create custom texture packs here.

ShieldWielder

add to itemgui. Make me switch between if I want the cooldown to be on left click or right click

Kodari AI
KodariNov 3 at 5:09 pm 2
  • Add a saved Left/Right Click selector to Item Settings for the spear cooldown.

  • Make the selected click start the cooldown, while blocking spear use during an active cooldown.

Added a saved Spear Cooldown Click toggle to Item Settings. It defaults to left-click; operators can click the setting to switch it to right-click. Either way, the spear remains blocked while its cooldown is active.

ShieldWielder

just remove it since you can't fix it

Kodari AI
KodariNov 3 at 5:13 pm 1
  • Remove the spear click selector from Item Settings.

  • Remove its config methods and return to the default left-click cooldown activation. Right-click stays blocked during an active cooldown.

Removed the spear click selector from Item Settings and its configuration methods. The cooldown activates on left-click again; right-click is still blocked while that cooldown is active.

ShieldWielder

Also, remove knockout

Kodari AI
KodariNov 3 at 5:18 pm 1
  • Remove Knockout from the enchant catalog and remove its shield-disabling handler.

  • Remove the Knockout duration control from Item Settings.

Removed Knockout from the enchant catalog and disabled its shield effect. Its duration setting is also gone from Item Settings.

ShieldWielder

list all of the custom item enchantnames so I can make a custom texture pack

Kodari AI
KodariNov 3 at 5:39 pm 1

Current active custom enchantment names (excluding removed enchants):

Adrenaline, Arachnid, Artemis, Ascent, Athletic, Autoloading Holster, Autosmelt, Berserk, Blitz, Bolt, Bulwark, Clapback, Cleaving, Compound, Concuss, Counter, Critical, Deflector, Delusional Strength, Demolitionist, Endurance, Extinguish, Firefly, First Strike, Fling, Frenzy, Frost, Hardhat, Headless, Heavenly, Homing, Hook, Immunity, Impale, Infernal, Lifesteal, Lepus, Low Ground, Necromancer, Ninja, Patient Swing, Planter, Pull, Quarry, Rally, Reaper, Reinforce, Replant, Sand Paper, Shock, Slash, Sustenance, Tank, Timber, Trickster, Unbroken Chain, Underdog, Unstable, Vein Miner, Volley, Vortex, Weightless.

For keys, spaces are replaced with underscores and names are lowercase—for example, Autoloading Holster → autoloading_holster.

ShieldWielder

do it like the actually names. like autoloading_holster. and put the applicable name for example.

autoloading_holster. ---> Crossbow

Kodari AI
KodariNov 3 at 5:41 pm 1
Plain Text
adrenaline ---> Sword
arachnid ---> Boots
artemis ---> Bow
ascent ---> Mace
athletic ---> Boots
autoloading_holster ---> Crossbow
autosmelt ---> Pickaxe
berserk ---> Helmet
blitz ---> Mace
bolt ---> Trident
bulwark ---> Shield
clapback ---> Chestplate
cleaving ---> Axe
compound ---> Bow
concuss ---> Mace
counter ---> Shield
critical ---> Sword
deflector ---> Chestplate
delusional_strength ---> Sword
demolitionist ---> Leggings
endurance ---> Leggings
extinguish ---> Leggings
firefly ---> Sword
first_strike ---> Sword
fling ---> Sword
frenzy ---> Helmet
frost ---> Crossbow
hardhat ---> Helmet
headless ---> Sword
heavenly ---> Helmet
homing ---> Bow
hook ---> Fishing Rod
immunity ---> Boots
impale ---> Spear, Trident
infernal ---> Crossbow
lifesteal ---> Sword
lepus ---> Spear
low_ground ---> Axe
necromancer ---> Leggings
ninja ---> Boots
patient_swing ---> Axe
planter ---> Hoe
pull ---> Fishing Rod
quarry ---> Pickaxe, Shovel
rally ---> Shield
reaper ---> Axe
reinforce ---> Any item
replant ---> Hoe
sand_paper ---> Axe
shock ---> Chestplate
slash ---> Sword
sustenance ---> Helmet
tank ---> Chestplate
timber ---> Axe
trickster ---> Sword
unbroken_chain ---> Sword
underdog ---> Sword
unstable ---> Helmet
vein_miner ---> Pickaxe
volley ---> Bow
vortex ---> Trident
weightless ---> Boots
ShieldWielder

add the color code name aswell. and add the rarity

Kodari AI
KodariNov 3 at 5:45 pm 1
Plain Text
adrenaline ---> Swords | &b Aqua | Rare
arachnid ---> Boots | &6 Gold | Legendary
artemis ---> Bows | &6 Gold | Legendary
ascent ---> Maces | &6 Gold | Legendary
athletic ---> Boots | &b Aqua | Rare
autoloading_holster ---> Crossbows | &b Aqua | Rare
autosmelt ---> Pickaxes | &a Green | Common
berserk ---> Helmets | &6 Gold | Legendary
blitz ---> Maces | &c Red | Exotic
bolt ---> Tridents | &6 Gold | Legendary
bulwark ---> Shields | &a Green | Common
clapback ---> Chestplates | &b Aqua | Rare
cleaving ---> Axes | &b Aqua | Rare
compound ---> Bows | &a Green | Common
concuss ---> Maces | &b Aqua | Rare
counter ---> Shields | &6 Gold | Legendary
critical ---> Swords | &b Aqua | Rare
deflector ---> Chestplates | &b Aqua | Rare
delusional_strength ---> Swords | &c Red | Exotic
demolitionist ---> Leggings | &b Aqua | Rare
endurance ---> Leggings | &a Green | Common
extinguish ---> Leggings | &b Aqua | Rare
firefly ---> Swords | &6 Gold | Legendary
first_strike ---> Swords | &6 Gold | Legendary
fling ---> Swords | &a Green | Common
frenzy ---> Helmets | &6 Gold | Legendary
frost ---> Crossbows | &a Green | Common
hardhat ---> Helmets | &c Red | Exotic
headless ---> Swords | &a Green | Common
heavenly ---> Helmets | &c Red | Exotic
homing ---> Bows | &b Aqua | Rare
hook ---> Fishing Rods | &6 Gold | Legendary
immunity ---> Boots | &b Aqua | Rare
impale ---> Spears & Tridents | &a Green | Common
infernal ---> Crossbows | &6 Gold | Legendary
lifesteal ---> Swords | &a Green | Common
lepus ---> Spears | &c Red | Exotic
low_ground ---> Axes | &6 Gold | Legendary
necromancer ---> Leggings | &a Green | Common
ninja ---> Boots | &a Green | Common
patient_swing ---> Axes | &a Green | Common
planter ---> Hoes | &a Green | Common
pull ---> Fishing Rods | &a Green | Common
quarry ---> Pickaxes & Shovels | &6 Gold | Legendary
rally ---> Shields | &b Aqua | Rare
reaper ---> Axes | &6 Gold | Legendary
reinforce ---> All Items | &a Green | Common
replant ---> Hoes | &b Aqua | Rare
sand_paper ---> Axes | &a Green | Common
shock ---> Chestplates | &b Aqua | Rare
slash ---> Swords | &b Aqua | Rare
sustenance ---> Helmets | &a Green | Common
tank ---> Chestplates | &a Green | Common
timber ---> Axes | &a Green | Common
trickster ---> Swords | &b Aqua | Rare
unbroken_chain ---> Swords | &6 Gold | Legendary
underdog ---> Swords | &6 Gold | Legendary
unstable ---> Helmets | &b Aqua | Rare
vein_miner ---> Pickaxes | &a Green | Common
volley ---> Bows | &a Green | Common
vortex ---> Tridents | &6 Gold | Legendary
weightless ---> Boots | &b Aqua | Rare
ShieldWielder

add the bolt aswell

Kodari AI
KodariNov 3 at 5:46 pm 1

The generation was stopped before any content could be produced.

ShieldWielder

add the bold aswell (&l)

Kodari AI
KodariNov 3 at 5:47 pm 1
Plain Text
adrenaline ---> Swords | &b&l Aqua | Rare
arachnid ---> Boots | &6&l Gold | Legendary
artemis ---> Bows | &6&l Gold | Legendary
ascent ---> Maces | &6&l Gold | Legendary
athletic ---> Boots | &b&l Aqua | Rare
autoloading_holster ---> Crossbows | &b&l Aqua | Rare
autosmelt ---> Pickaxes | &a&l Green | Common
berserk ---> Helmets | &6&l Gold | Legendary
blitz ---> Maces | &c&l Red | Exotic
bolt ---> Tridents | &6&l Gold | Legendary
bulwark ---> Shields | &a&l Green | Common
clapback ---> Chestplates | &b&l Aqua | Rare
cleaving ---> Axes | &b&l Aqua | Rare
compound ---> Bows | &a&l Green | Common
concuss ---> Maces | &b&l Aqua | Rare
counter ---> Shields | &6&l Gold | Legendary
critical ---> Swords | &b&l Aqua | Rare
deflector ---> Chestplates | &b&l Aqua | Rare
delusional_strength ---> Swords | &c&l Red | Exotic
demolitionist ---> Leggings | &b&l Aqua | Rare
endurance ---> Leggings | &a&l Green | Common
extinguish ---> Leggings | &b&l Aqua | Rare
firefly ---> Swords | &6&l Gold | Legendary
first_strike ---> Swords | &6&l Gold | Legendary
fling ---> Swords | &a&l Green | Common
frenzy ---> Helmets | &6&l Gold | Legendary
frost ---> Crossbows | &a&l Green | Common
hardhat ---> Helmets | &c&l Red | Exotic
headless ---> Swords | &a&l Green | Common
heavenly ---> Helmets | &c&l Red | Exotic
homing ---> Bows | &b&l Aqua | Rare
hook ---> Fishing Rods | &6&l Gold | Legendary
immunity ---> Boots | &b&l Aqua | Rare
impale ---> Spears & Tridents | &a&l Green | Common
infernal ---> Crossbows | &6&l Gold | Legendary
lifesteal ---> Swords | &a&l Green | Common
lepus ---> Spears | &c&l Red | Exotic
low_ground ---> Axes | &6&l Gold | Legendary
necromancer ---> Leggings | &a&l Green | Common
ninja ---> Boots | &a&l Green | Common
patient_swing ---> Axes | &a&l Green | Common
planter ---> Hoes | &a&l Green | Common
pull ---> Fishing Rods | &a&l Green | Common
quarry ---> Pickaxes & Shovels | &6&l Gold | Legendary
rally ---> Shields | &b&l Aqua | Rare
reaper ---> Axes | &6&l Gold | Legendary
reinforce ---> All Items | &a&l Green | Common
replant ---> Hoes | &b&l Aqua | Rare
sand_paper ---> Axes | &a&l Green | Common
shock ---> Chestplates | &b&l Aqua | Rare
slash ---> Swords | &b&l Aqua | Rare
sustenance ---> Helmets | &a&l Green | Common
tank ---> Chestplates | &a&l Green | Common
timber ---> Axes | &a&l Green | Common
trickster ---> Swords | &b&l Aqua | Rare
unbroken_chain ---> Swords | &6&l Gold | Legendary
underdog ---> Swords | &6&l Gold | Legendary
unstable ---> Helmets | &b&l Aqua | Rare
vein_miner ---> Pickaxes | &a&l Green | Common
volley ---> Bows | &a&l Green | Common
vortex ---> Tridents | &6&l Gold | Legendary
weightless ---> Boots | &b&l Aqua | Rare
ShieldWielder

make the bloodmoon potion drinakble to trigger the event

Kodari AI
KodariNov 3 at 8:54 pm 1
  • Trace the Bloodmoon potion’s item and event handling.

  • Make drinking it trigger the event, then verify the cooldown/consumption behavior in the handler.

The Blood Moon Potion now has an explicit water-potion base, so it can be drunk; consuming it triggers the Bloodmoon event.

ShieldWielder

make it also say who drank the blood moon potion. Make it so if bloodmoon is active, people can't drink the potion

Kodari AI
KodariNov 3 at 8:54 pm 1
  1. Announce the drinker when the Bloodmoon potion starts the event.

  2. Prevent drinking it while Bloodmoon is already active.

The Bloodmoon announcement now includes the potion drinker’s name. Drinking the potion while the event is active is cancelled, so the potion isn’t consumed.

ShieldWielder

it still won't let me drink the bottle

Kodari AI
KodariNov 3 at 8:58 pm 1
  • Allow the tagged Blood Moon Potion through the custom-item right-click handler so Minecraft can consume it; the active-event consume check remains in place.

Fixed: the custom-item right-click listener was cancelling every tagged item, including the Blood Moon Potion. It now lets that potion reach vanilla consumption; the existing check still blocks drinking while Bloodmoon is active.

ShieldWielder

make bloodmoon broadcast on your screen instead of chat

Kodari AI
KodariNov 3 at 9:09 pm 1
  • Replace Bloodmoon start/end chat broadcasts with on-screen titles.

  • Include the potion drinker’s name in the start title.

Bloodmoon start and end announcements now appear as on-screen titles instead of chat messages. When started by drinking the potion, the title subtitle shows who drank it.

ShieldWielder

make firefly counter clean and not show while firefly is on cooldown

Kodari AI
KodariNov 3 at 9:12 pm 1
  • Clear Firefly hit/target state whenever its cooldown is active.

  • Skip counter updates and action-bar display until the cooldown expires.

Firefly’s hit counter now resets during its cooldown and stays hidden until the cooldown expires.

ShieldWielder

Make it bloodmoon say

&c&lBLOODMOON HAS RISEN &c&l Strength 3. Mobs do 5x damage but greater loot

Kodari AI
KodariNov 3 at 9:16 pm 1
  • Update the Bloodmoon start title and subtitle to the exact wording and colors you provided.

Bloodmoon now displays “BLOODMOON HAS RISEN” with the subtitle “Strength 3. Mobs do 5x damage but greater loot.” When started by a potion, the subtitle also identifies who drank it.

ShieldWielder

&c&lBLOODMOON HAS RISEN &c&lEveryone Has Strength 3. Mobs do 5x damage

&c&lBLOODMOON HAS FALLEN &c&lAll damage is back to normal

Kodari AI
KodariNov 3 at 9:21 pm 1

Updated the Bloodmoon titles:

  • BLOODMOON HAS RISEN — “Everyone Has Strength 3. Mobs do 5x damage” (still includes the potion drinker’s name when applicable).

  • BLOODMOON HAS FALLEN — “All damage is back to normal”.

ShieldWielder

remove the potion drinker's name

Kodari AI
KodariNov 3 at 9:21 pm 1
  • Remove the drinker name from the Bloodmoon start announcement, including the now-unneeded name parameter.

  • Keep potion-triggered and command-triggered starts working the same otherwise.

Removed the potion drinker’s name from the Bloodmoon announcement. Drinking the potion still starts the event when it’s inactive.

ShieldWielder

Heart Market. (/market) you can trade what ever currency (/marketgui currency hand) a admin make for Longer potion effects, better Escroll luck.

First Level. 5% Longer Potion Effect. 5% Escroll Luck.

Second Level. 10% Longer Potion Effect. 10% Escroll Luck.

Third Level. 15% Longer Potion Effect. 15% Escroll Luck.

Fourth Level. 20% Longer Potion Effect. 20% Escroll Luck.

Fifth Level. 25% Longer Potion Effect. 25% Escroll Luck.

Sixth Level. 30% Longer Potion Effect. 30% Escroll Luck. /marketgui currency hand /marketgui /marketgui edit (allows people to edit the percentages, the amount of items for a upgrade)

Kodari AI
KodariNov 3 at 9:31 pm 2
  1. Check existing commands, GUI/config patterns, and potion/scroll effect hooks.

  2. Add /market upgrades and admin /marketgui controls for currency, prices, and percentages.

  3. Connect the six upgrade levels to potion duration and Escroll luck.

Added the Heart Market with six default levels (5%–30% potion duration and Enchant Scroll luck).

  • Players use /market to buy the next level with the configured currency item.

  • Admins hold the currency item and run /marketgui currency hand.

  • /marketgui or /marketgui edit opens the editor. Click a level, then left/right-click its settings to adjust them; shift-click changes values by 5.

  • Upgrade levels and settings persist across restarts.

ShieldWielder

make /market look cleannn

Kodari AI
KodariNov 3 at 9:32 pm 1
  • Refresh /market into a roomy 6-row GUI with clear upgrade cards, ownership/next-level states, currency details, and a close button.

/market now has a cleaner six-row layout with clear upgrade cards, current bonuses, locked/unlocked status, currency info, and a dedicated close button.

Kodari can make mistakes. Review important code before using.
Files
src
Code
11 4,479
src/main/java/com/kodari/lifesteal/LifeStealEnchantsPlugin.java
package com.kodari.lifesteal;

import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XEnchantment;
import com.cryptomorin.xseries.XItemFlag;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionType;

import java.util.ArrayList;
import java.util.List;

public final class LifeStealEnchantsPlugin extends JavaPlugin {
    private NamespacedKey itemTypeKey;
    private NamespacedKey enchantKey;
    private EnchantListener enchantListener;
    private BloodmoonEvent bloodmoonEvent;
    private HeartMarket heartMarket;

    @Override
    public void onEnable() {
        itemTypeKey = new NamespacedKey(this, "custom_item");
        enchantKey = new NamespacedKey(this, "enchant");
        heartMarket = new HeartMarket(this);
        Bukkit.getPluginManager().registerEvents(heartMarket, this);
        getCommand("market").setExecutor(heartMarket);
        getCommand("marketgui").setExecutor(heartMarket);
        bloodmoonEvent = new BloodmoonEvent(this);
        Bukkit.getPluginManager().registerEvents(bloodmoonEvent, this);
        getCommand("bloodmoon").setExecutor(bloodmoonEvent);
        getCommand("bloodmoongui").setExecutor(bloodmoonEvent);
        enchantListener = new EnchantListener(this);
        Bukkit.getPluginManager().registerEvents(enchantListener, this);
        CustomItemsGui gui = new CustomItemsGui(this);
        Bukkit.getPluginManager().registerEvents(gui, this);
        getCommand("lifesteal").setExecutor(new LifestealCommand(this, gui));
        getCommand("gui").setExecutor(gui);
        ItemLimiter itemLimiter = new ItemLimiter(this);
        Bukkit.getPluginManager().registerEvents(itemLimiter, this);
        getCommand("itemlimiter").setExecutor(itemLimiter);
        getCommand("itemlimitergui").setExecutor(itemLimiter);
        getCommand("netheriteremove").setExecutor(new NetheriteRemoveCommand(this));
        TrialChamberLoot trialChamberLoot = new TrialChamberLoot(this);
        Bukkit.getPluginManager().registerEvents(trialChamberLoot, this);
        getCommand("trialchamber").setExecutor(trialChamberLoot);
        Bukkit.getScheduler().runTaskTimer(this, () -> Bukkit.getOnlinePlayers().forEach(enchantListener::applyPassiveEffects), 20L, 20L);
    }

    @Override
    public void onDisable() {
        if (bloodmoonEvent != null) {
            bloodmoonEvent.end(false);
        }
    }

    public boolean isBloodmoonActive() {
        return bloodmoonEvent != null && bloodmoonEvent.isActive();
    }

    public int getMarketScrollLuckPercent(Player player) {
        return heartMarket == null ? 0 : heartMarket.getScrollLuckPercent(player);
    }

    public boolean hasEnchant(ItemStack item, CustomEnchant enchant) {
        if (item == null || item.getType().name().equals("AIR")) {
            return false;
        }
        ItemMeta meta = item.getItemMeta();
        return meta != null && meta.getPersistentDataContainer().has(enchantKey(enchant), PersistentDataType.BYTE);
    }

    public boolean hasAnyEnchant(ItemStack item) {
        for (CustomEnchant enchant : CustomEnchant.values()) {
            if (hasEnchant(item, enchant)) {
                return true;
            }
        }
        return false;
    }

    public CustomEnchant getTomeEnchant(ItemStack item) {
        if (item == null || !item.hasItemMeta()) {
            return null;
        }
        return CustomEnchant.byKey(item.getItemMeta().getPersistentDataContainer().get(enchantKey, PersistentDataType.STRING));
    }

    public String getCustomItemType(ItemStack item) {
        if (item == null || !item.hasItemMeta()) {
            return null;
        }
        return item.getItemMeta().getPersistentDataContainer().get(itemTypeKey, PersistentDataType.STRING);
    }

    public ItemStack createScroll() {
        ItemStack item = item("BOOK", "&b&l✦ Enchant Scroll", List.of("&8&m--------------------", "&7Reveal a random custom enchant.", "", "&fCommon: &a69% chance", "&bRare: &e25% chance", "&6Legendary: &c5% chance", "&cExotic: &c1% chance", "", "&e➤ Right-click to reveal", "&8&m--------------------"));
        if (item != null) {
            ItemMeta meta = item.getItemMeta();
            XEnchantment.matchXEnchantment("MENDING").ifPresent(enchantment -> meta.addEnchant(enchantment.getEnchant(), 1, true));
            XItemFlag.of("HIDE_ENCHANTS").ifPresent(flag -> flag.set(meta));
            item.setItemMeta(meta);
        }
        tag(item, "scroll", null);
        return item;
    }

    public ItemStack createTome(CustomEnchant enchant) {
        ItemStack item = item("ENCHANTED_BOOK", enchant.getRarity().getColor() + "&l✦ " + enchant.getDisplayName() + " &8| " + enchant.getRarity().getColor() + enchant.getRarity().getDisplayName(), List.of("&8&m--------------------", "&7" + enchant.getDescription(), "&7Applies To: &f" + enchant.getApplicableItems(), "", "&8Rarity: " + enchant.getRarity().getColor() + enchant.getRarity().getDisplayName(), "&e➤ Hold this tome on your cursor,", "&e then click an applicable item", "&ein your inventory to apply.", "&8&m--------------------"));
        tag(item, "tome", enchant.getKey());
        return item;
    }

    public ItemStack createBloodmoonPotion() {
        ItemStack item = item("POTION", "&c&lBlood Moon Potion",
                List.of("&8&m--------------------", "&7Drinking this starts a Bloodmoon.", "", "&e➤ Consume to begin the event.", "&8&m--------------------"));
        if (item != null) {
            PotionMeta meta = (PotionMeta) item.getItemMeta();
            meta.setBasePotionType(PotionType.WATER);
            item.setItemMeta(meta);
        }
        tag(item, "bloodmoon_potion", null);
        return item;
    }

    public void give(Player player, ItemStack item) {
        var leftovers = player.getInventory().addItem(item);
        leftovers.values().forEach(leftover -> player.getWorld().dropItemNaturally(player.getLocation(), leftover));
    }

    public int getMaceCooldownSeconds() {
        return Math.max(0, getConfig().getInt("item-settings.mace-cooldown-seconds", 0));
    }

    public void setMaceCooldownSeconds(int seconds) {
        getConfig().set("item-settings.mace-cooldown-seconds", Math.max(0, seconds));
        saveConfig();
    }

    public int getMaceCapHearts() {
        return Math.max(0, getConfig().getInt("item-settings.mace-cap-hearts", 0));
    }

    public void setMaceCapHearts(int hearts) {
        getConfig().set("item-settings.mace-cap-hearts", Math.max(0, hearts));
        saveConfig();
    }

    public int getTntMinecartDamageCapHearts() {
        return Math.max(0, getConfig().getInt("item-settings.tnt-minecart-damage-cap-hearts", 0));
    }

    public void setTntMinecartDamageCapHearts(int hearts) {
        getConfig().set("item-settings.tnt-minecart-damage-cap-hearts", Math.max(0, hearts));
        saveConfig();
    }

    public int getSpearCooldownSeconds() {
        return Math.max(0, getConfig().getInt("item-settings.spear-cooldown-seconds", 15));
    }

    public void setSpearCooldownSeconds(int seconds) {
        getConfig().set("item-settings.spear-cooldown-seconds", Math.max(0, seconds));
        saveConfig();
    }

    public int getHeavenlyDurabilityDamagePercent() {
        return Math.max(0, Math.min(100, getConfig().getInt("item-settings.heavenly-durability-damage-percent", 30)));
    }

    public void setHeavenlyDurabilityDamagePercent(int percent) {
        getConfig().set("item-settings.heavenly-durability-damage-percent", Math.max(0, Math.min(100, percent)));
        saveConfig();
    }

    public int getHeavenlyCooldownSeconds() {
        return Math.max(0, getConfig().getInt("item-settings.heavenly-cooldown-seconds", 300));
    }

    public void setHeavenlyCooldownSeconds(int seconds) {
        getConfig().set("item-settings.heavenly-cooldown-seconds", Math.max(0, seconds));
        saveConfig();
    }

    public int getWindChargeCooldownSeconds() {
        return Math.max(0, getConfig().getInt("item-settings.wind-charge-cooldown-seconds", 0));
    }

    public void setWindChargeCooldownSeconds(int seconds) {
        getConfig().set("item-settings.wind-charge-cooldown-seconds", Math.max(0, seconds));
        saveConfig();
    }

    public int getWindChargeCobwebBlocks() {