atif0432_87606
📎 1 file 6,202 chars
📄
pasted-code-1795337865513.txt
txt 195 lines
▶
Create a Minecraft plugin for version 1.21.11 that adds 4 unique custom weapons. Each weapon can only be crafted once on the entire server. When crafted, the player receives a Weapon Core (looks like a player head). When the core is placed on the ground, a 5-minute unlock timer starts. After the timer ends, only the player who placed the core can equip that specific weapon.

While the core is placed, a boss bar should appear on the player’s screen showing:
- The coordinates of the placed core
- The name of the player who owns it

There should also be an admin/owner command:
/customweapon give  

All weapons must have an enchantment glint effect.
All enchantments on the weapons must be completely hidden (do not show in the lore or tooltip).

----------------------------------------

1. Crownbreaker (Mace – Legendary Ultimate Weapon)

Hidden Enchantments:
- Breach 29
- Density 70

Abilities:

1. Sky Launcher
- Activation: Shift + Right Click
- Cooldown: 4 seconds
- Effect: Launches the player 15 blocks in the exact direction they are looking (based on pitch and yaw).
- Visuals: Continuous looping totem-pop particles around the player + red and orange star-shaped particles while the ability is active.

IMPORTANT - Direction Logic (must follow exactly):
You must use this exact method for launching the player:
Vector direction = player.getLocation().getDirection().normalize();
player.setVelocity(direction.multiply(1.85));

Do NOT manually calculate yaw/pitch.
Do NOT use getEyeLocation().getDirection() with any modifications.
Do NOT force any Y value unless necessary.
This method must work correctly when looking up, down, or sideways.

2. Water Dash
- Only works while the player is in water.
- Activation: Right Click (in water)
- Cooldown: 5 seconds
- Effect: Dashes the player 15 blocks forward in the direction they are looking.
- Visuals: Continuous looping bubble particles + rocket particles around the player.

IMPORTANT - Direction Logic (must follow exactly):
Use the same correct method:
Vector direction = player.getLocation().getDirection().normalize();
player.setVelocity(direction.multiply(1.9));

This must also work in all directions (up, down, sideways).

3. Soul Reaper (Ultimate Ability)
- Requires 25/25 Ultimate charge.
- When fully charged, a screen popup appears:
  “Soul Reaper Ultimate Ability”
  Shift + Left Click to Unleash
- Effect: Creates a 7x7 AOE blast that forces a totem pop on every player in the area (works even on full Protection 4 Netherite + 500 hearts).
- Ultimate charge increases only when the player performs a smash attack on another player using this mace.
- Maximum charge: 25
- Ultimate progress is displayed as a Boss Bar above the XP bar.

Lore:
§6§lCrownbreaker
§7Legendary Weapon

§bSky Launcher
§7Launch yourself 15 blocks in the
§7direction you're looking
§8(Shift + Right Click) §7| §c4s Cooldown

§bWater Dash
§7Dash 15 blocks forward while in water
§8(Right Click) §7| §c5s Cooldown

§c§lSoul Reaper
§7Unleash a devastating 7x7 AOE
§7that forces every player to pop
§7their totem of undying
§8(Requires 25/25 Ultimate)

----------------------------------------

2. Kn_Dasher (Diamond Sword)

Hidden Enchantments:
- Sharpness 135

Ultimate:
- Charges by hitting players 10 times.
- When ready, activate with Shift + Left Click.
- Cooldown: 150 seconds
- Effect: Deals massive damage to all players in a 7x7 radius.

Lore:
§6§lKn_Dasher
§7Legendary Blade

§bUltimate Ability
§7Hit any player 10 times to charge
§7your ultimate. Once ready, press
§eShift + Left Click §7to unleash
§7devastating damage in a 7x7 radius.
§cCooldown: 150 seconds

§8All enchants are hidden

----------------------------------------

3. Tide_Breaker (Trident)

No extra enchantments.
No cooldown on any ability.

Abilities:
- Normal hit: Strikes the target with lightning that deals 5 hearts of true damage.
- Ultimate charges by hitting players 15 times.
- When fully charged, a screen popup appears:
  “Ultimate God Ability”
  Shift + Right Click to Enable
- Effect: Strikes every player in a 10x10 radius (except the holder) with lightning that deals 7 hearts of damage.
- Ultimate progress is shown as a Boss Bar (same style as Crownbreaker), max charge 15.

Lore:
§6§lTide Breaker
§7God of the Seas

§bLightning Strike
§7Every hit summons a lightning bolt
§7that deals 5 hearts of true damage

§c§lUltimate God Ability
§7Hit any player 15 times to charge.
§7Once ready, press §eShift + Right Click
§7to call down lightning on every
§7player in a 10x10 radius
§7(deals 7 hearts of damage)

----------------------------------------

4. Breaker_Bow (Bow)

Hidden Enchantments:
- Sharpness 245

Ability:
- Any player hit by an arrow from this bow has their entire armor completely destroyed/removed.
- Cooldown: 100 seconds

Lore:
§6§lBreaker Bow
§7Armor Destroyer

§c§lArmor Breaker
§7Any player hit by an arrow from
§7this bow will have their entire
§7armor set completely destroyed.
§cCooldown: 100 seconds

§8All enchants are hidden

----------------------------------------

Crafting Recipes (Crafting Table → Weapon Core)

Crownbreaker Core:
- Center: Mace
- Left side: 2 Shards
- Right side: 2 Shards
- Top row: 3 Totems of Undying

Kn_Dasher Core:
- Center: Diamond Sword
- Left side: 2 Totems of Undying
- Right side: 2 Totems of Undying

Tide_Breaker Core:
- Center: Trident
- Left side: 2 Quartz
- Right side: 2 Quartz
- Top row: 3 Ice

Breaker_Bow Core:
- Center: Bow
- Left side: 2 Blackstone
- Right side: 2 Blackstone
- Top: Deepslate Bricks

----------------------------------------

Make the plugin clean, optimized, and fully functional with proper particle effects, boss bars, cooldowns, and permission handling. All weapons must have glint and completely hidden enchantments.
Target version: Minecraft 1.21.11

Very Important:
For Sky Launcher and Water Dash, strictly follow the direction calculation method mentioned above. The abilities must work correctly in all looking directions (up, down, left, right).
Kodari AI
KodariYesterday at 8:58 am 3
UniqueWeaponForge
A Minecraft 1.21.11 plugin adding four legendary craftable weapons, each craftable only once per server. Players craft a Weapon Core (player head) that, when placed, starts a 5-minute unlock timer with a boss bar showing coordinates and owner name. Weapons include Crownbreaker (mace with Sky Launcher, Water Dash, and Soul Reaper ultimate), Kn_Dasher (sword with charged ultimate), Tide_Breaker (trident with lightning strikes), and Breaker_Bow (armor-destroying arrows). Features hidden enchantments with glint, cooldown systems, ultimate charge boss bars, particle effects, and admin command to give weapons directly.

Created the four weapons, core recipes, unlock timers, boss bars, abilities, and admin command.

Recipe assumption: “Shards” means echo shards. Admin-given weapons bypass the one-time crafting limit.

Ultimate charge and cooldowns reset when the server restarts. The forced-totem effect uses high damage, so it may be affected by other plugins’ damage protections.

Kodari can make mistakes. Review important code before using.
Files
src
Code
2 445
src/main/java/com/kodari/customweapons/CustomWeapons.java
package com.kodari.customweapons;

import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XEnchantment;
import com.cryptomorin.xseries.XItemFlag;
import com.cryptomorin.xseries.particles.XParticle;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.AbstractArrow;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

public final class CustomWeapons extends JavaPlugin implements Listener {
    private NamespacedKey typeKey, ownerKey, coreKey, arrowKey;
    private final Map<String, Core> cores = new HashMap<>();
    private final Set<String> crafted = new HashSet<>();
    private final Map<UUID, Map<String, Integer>> charges = new HashMap<>();
    private final Map<UUID, Map<String, Long>> cooldowns = new HashMap<>();
    private final Map<UUID, BossBar> coreBars = new HashMap<>();
    private final Map<UUID, BossBar> chargeBars = new HashMap<>();
    private File dataFile;
    private YamlConfiguration data;

    private static final class Core {
        final String type;
        final UUID owner;
        final Location location;
        final long unlock;
        Core(String type, UUID owner, Location location, long unlock) {
            this.type = type; this.owner = owner; this.location = location; this.unlock = unlock;
        }
    }

    @Override public void onEnable() {
        typeKey = new NamespacedKey(this, "weapon_type");
        ownerKey = new NamespacedKey(this, "weapon_owner");
        coreKey = new NamespacedKey(this, "weapon_core");
        arrowKey = new NamespacedKey(this, "breaker_arrow");
        dataFile = new File(getDataFolder(), "weapons.yml");
        data = YamlConfiguration.loadConfiguration(dataFile);
        crafted.addAll(data.getStringList("crafted"));
        ConfigurationSection section = data.getConfigurationSection("cores");
        if (section != null) for (String type : section.getKeys(false)) {
            try {
                World world = Bukkit.getWorld(section.getString(type + ".world", ""));
                if (world == null) { getLogger().warning("Core world unavailable for " + type); continue; }
                Location loc = new Location(world, section.getInt(type + ".x"), section.getInt(type + ".y"), section.getInt(type + ".z"));
                cores.put(type, new Core(type, UUID.fromString(section.getString(type + ".owner", "")), loc, section.getLong(type + ".unlock")));
            } catch (IllegalArgumentException ex) { getLogger().warning("Invalid saved core: " + type); }
        }
        registerRecipes();
        Bukkit.getPluginManager().registerEvents(this, this);
        Bukkit.getScheduler().runTaskTimer(this, this::tick, 1L, 20L);
    }

    @Override public void onDisable() {
        saveData();
        coreBars.values().forEach(BossBar::removeAll);
        chargeBars.values().forEach(BossBar::removeAll);
    }

    private void saveData() {
        data.set("crafted", Arrays.asList(crafted.toArray(new String[0])));
        // Preserve entries for worlds that were not loaded during startup.
        for (Core core : cores.values()) {
            String path = "cores." + core.type;
            data.set(path + ".owner", core.owner.toString());
            data.set(path + ".world", core.location.getWorld().getName());
            data.set(path + ".x", core.location.getBlockX());
            data.set(path + ".y", core.location.getBlockY());
            data.set(path + ".z", core.location.getBlockZ());
            data.set(path + ".unlock", core.unlock);
        }
        getDataFolder().mkdirs();
        try { data.save(dataFile); } catch (IOException ex) { getLogger().severe("Could not save weapons.yml: " + ex.getMessage()); }
    }

    private ItemStack material(String name) {
        ItemStack item = XMaterial.matchXMaterial(name).map(XMaterial::parseItem).orElse(null);
        if (item == null) throw new IllegalStateException("Missing material " + name);
        return item;
    }

    private String display(String type) {
        switch (type) {
            case "crownbreaker": return "Crownbreaker";
            case "kn_dasher": return "Kn_Dasher";
            case "tide_breaker": return "Tide Breaker";
            case "breaker_bow": return "Breaker Bow";
            default: return type;
        }
    }

    private boolean validType(String type) {
        return type != null && (type.equals("crownbreaker") || type.equals("kn_dasher") || type.equals("tide_breaker") || type.equals("breaker_bow"));
    }

    private ItemStack coreItem(String type) {
        ItemStack item = material("PLAYER_HEAD");
        ItemMeta meta = item.getItemMeta();
        meta.setDisplayName("§6" + display(type) + " Core");
        meta.setLore(Arrays.asList("§7Place to begin the 5-minute unlock.", "§7Only the placer can wield this weapon."));
        meta.getPersistentDataContainer().set(coreKey, PersistentDataType.STRING, type);
        item.setItemMeta(meta);
        return item;
    }

    private ItemStack weapon(String type, UUID owner) {
        String material = type.equals("crownbreaker") ? "MACE" : type.equals("kn_dasher") ? "DIAMOND_SWORD" : type.equals("tide_breaker") ? "TRIDENT" : "BOW";
        ItemStack item = material(material);
        ItemMeta meta = item.getItemMeta();
        meta.setDisplayName("§6§l" + display(type));
        switch (type) {
            case "crownbreaker":
                meta.setLore(Arrays.asList("§7Legendary Weapon", "", "§bSky Launcher", "§7Launch yourself 15 blocks in the", "§7direction you're looking", "§8(Shift + Right Click) §7| §c4s Cooldown", "", "§bWater Dash", "§7Dash 15 blocks forward while in water", "§8(Right Click) §7| §c5s Cooldown", "", "§c§lSoul Reaper", "§7Unleash a devastating 7x7 AOE", "§7that forces every player to pop", "§7their totem of undying", "§8(Requires 25/25 Ultimate)"));
                enchant(meta, "BREACH", 29); enchant(meta, "DENSITY", 70); break;
            case "kn_dasher":
                meta.setLore(Arrays.asList("§7Legendary Blade", "", "§bUltimate Ability", "§7Hit any player 10 times to charge", "§7your ultimate. Once ready, press", "§eShift + Left Click §7to unleash", "§7devastating damage in a 7x7 radius.", "§cCooldown: 150 seconds", "", "§8All enchants are hidden"));
                enchant(meta, "SHARPNESS", 135); break;
            case "tide_breaker":
                meta.setLore(Arrays.asList("§7God of the Seas", "", "§bLightning Strike", "§7Every hit summons a lightning bolt", "§7that deals 5 hearts of true damage", "", "§c§lUltimate God Ability", "§7Hit any player 15 times to charge.", "§7Once ready, press §eShift + Right Click", "§7to call down lightning on every", "§7player in a 10x10 radius", "§7(deals 7 hearts of damage)")); break;
            case "breaker_bow":
                meta.setLore(Arrays.asList("§7Armor Destroyer", "", "§c§lArmor Breaker", "§7Any player hit by an arrow from", "§7this bow will have their entire", "§7armor set completely destroyed.", "§cCooldown: 100 seconds", "", "§8All enchants are hidden"));
                enchant(meta, "SHARPNESS", 245); break;
        }
        meta.setEnchantmentGlintOverride(true);
        XItemFlag.of("HIDE_ENCHANTS").ifPresent(flag -> flag.set(meta));
        meta.getPersistentDataContainer().set(typeKey, PersistentDataType.STRING, type);
        meta.getPersistentDataContainer().set(ownerKey, PersistentDataType.STRING, owner.toString());
        item.setItemMeta(meta);
        return item;
    }

    private void enchant(ItemMeta meta, String name, int level) {
        XEnchantment.matchXEnchantment(name).ifPresent(e -> meta.addEnchant(e.getEnchant(), level, true));
    }

    private String tag(ItemStack item, NamespacedKey key) {
        return item == null || !item.hasItemMeta() ? null : item.getItemMeta().getPersistentDataContainer().get(key, PersistentDataType.STRING);
    }

    private boolean owned(Player player, ItemStack item) {
        String type = tag(item, typeKey);
        return validType(type) && player.getUniqueId().toString().equals(tag(item, ownerKey));
    }

    private void registerRecipes() {
        recipe("crownbreaker", new String[]{"TTT", "SMS", "S S"}, "TOTEM_OF_UNDYING", "ECHO_SHARD", "MACE");
        recipe("kn_dasher", new String[]{"   ", "TMT", "T T"}, "TOTEM_OF_UNDYING", null, "DIAMOND_SWORD");
        recipe("tide_breaker", new String[]{"TTT", "SMS", "S S"}, "ICE", "QUARTZ", "TRIDENT");
        recipe("breaker_bow", new String[]{" T ", "SMS", "S S"}, "DEEPSLATE_BRICKS", "BLACKSTONE", "BOW");
    }

    private void recipe(String type, String[] shape, String top, String side, String middle) {
        ShapedRecipe recipe = new ShapedRecipe(new NamespacedKey(this, type + "_core"), coreItem(type));