davideloo
📎 1 file 2,266 chars
📄
pasted-code-1780291103847.txt
txt 74 lines
▶
Create a Minecraft plugin that adds a custom Netherite Sword called **Invisible Cloak**.

Requirements:

* The sword can only be obtained through an operator-only command.
* It must not be craftable or obtainable through normal gameplay.
* Include the command to give the sword.

Ability Activation:

* The ability only activates when the player is **crouching/sneaking and right-clicks** while holding the sword.
* Right-clicking without sneaking should do nothing.

Ability Effect:

* The player becomes completely invisible for **10 seconds** by default.
* This should work like a vanish system, not a normal invisibility potion effect.
* Other players must not be able to see:

  * The player model
  * Armor
  * Held items
  * Offhand items
  * Nametag
* The player's armor must remain equipped and continue providing full protection, enchantments, and attributes.
* The player should automatically become visible again when the duration ends.

Cooldown:

* Default cooldown is **45 seconds**.
* Cooldowns must be tracked separately for each player.
* The ability cannot be used while on cooldown.

Action Bar:

* While holding the sword, display the cooldown status in the Action Bar.
* Default ready message:

  * `&b&lINVISIBLE CLOAK &fis ready to be used.`
* Default cooldown message:

  * `&b&lINVISIBLE CLOAK &fCooldown: &b{seconds}s`
* Update the cooldown display in real time.
* When the cooldown reaches 0, play a configurable ready sound.

Configuration:
Create a config.yml with editable settings for:

* Ability duration
* Cooldown duration
* Ready Action Bar message
* Cooldown Action Bar message
* Activation message
* Activation sound
* Ready sound
* Sword name
* Sword lore
* Permission node
* Message colors and formatting

Performance:

* Multiplayer compatible.
* Optimized for minimal lag.
* Properly clean up all tasks and data.
* No visual glitches when entering or leaving invisibility.

Output:

* Generate the complete plugin.
* Include all source code, plugin.yml, config.yml, commands, permissions, listeners, and setup instructions.
* Use modern Spigot/Paper API best practices.
* The code should be production-ready, configurable, and compile without errors.
Kodari AI
KodariJun 1 at 5:21 am 16
InvisibleCloakPlugin
A Minecraft plugin that adds a custom Netherite Sword called "Invisible Cloak." Obtained exclusively via an operator command, it grants true vanish-style invisibility (hides model, armor, held items, and nametag) for a configurable duration when activated by sneaking and right-clicking. Features per-player cooldown tracking, real-time Action Bar status display with sound cues, and a fully configurable config.yml for all durations, messages, sounds, and permissions.

Plan:

  1. ConfigManager — typed config accessors for all settings

  2. ItemUtil — creates/identifies the cloak sword via PersistentDataContainer

  3. CooldownManager — per-UUID cooldown tracking with timestamp-based expiry

  4. CloakManager — hide/show players using hidePlayer/showPlayer, schedules auto-reveal tasks

  5. ActionBarTask — global 20-tick repeating task for Action Bar + ready sound on cooldown expiry

  6. SwordListener — sneak + right-click activation logic

  7. PlayerListener — cleanup on quit, hide invisible players from joining players

  8. GiveCloakCommand — op-gated give command


Setup Instructions

  1. Build: Run ./gradlew jar — the output JAR will be in build/libs/.

  2. Install: Drop the JAR into your server’s plugins/ folder and restart.

  3. Get the sword: Use /givecloak (op) or /givecloak <player> to give it to someone.

  4. Use the ability: Hold the sword, sneak + right-click to activate invisibility.

How invisibility works:

  • Uses hidePlayer/showPlayer per-player, not a potion effect — the player model, armor, held items, and nametag are completely hidden from all others.

  • Armor stays equipped in full, providing all protection stats and enchantments normally.

  • Players who join mid-invisibility are also prevented from seeing the hidden player via PlayerJoinEvent.

  • On server shutdown, all active cloaks are automatically deactivated.

Key config values to tune:

Key
Default
Purpose
ability.duration
10
How long invisibility lasts (seconds)
ability.cooldown
45
Cooldown between uses (seconds)
permission
invisiblecloak.use
Who can activate the ability
sounds.activation.sound
ENTITY_ENDERMAN_TELEPORT
Any XSound name
sounds.ready.sound
ENTITY_EXPERIENCE_ORB_PICKUP
Plays when cooldown expires
Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
12 697
src/main/java/com/kodari/invisiblecloak/InvisibleCloakPlugin.java
package com.kodari.invisiblecloak;

import com.kodari.invisiblecloak.command.GiveCloakCommand;
import com.kodari.invisiblecloak.config.ConfigManager;
import com.kodari.invisiblecloak.listener.PlayerListener;
import com.kodari.invisiblecloak.listener.SwordListener;
import com.kodari.invisiblecloak.manager.CloakManager;
import com.kodari.invisiblecloak.manager.CooldownManager;
import com.kodari.invisiblecloak.task.ActionBarTask;
import org.bukkit.plugin.java.JavaPlugin;

public class InvisibleCloakPlugin extends JavaPlugin {

    private static InvisibleCloakPlugin instance;

    private ConfigManager configManager;
    private CloakManager cloakManager;
    private CooldownManager cooldownManager;
    private ActionBarTask actionBarTask;

    @Override
    public void onEnable() {
        instance = this;

        saveDefaultConfig();
        configManager = new ConfigManager(this);
        cloakManager = new CloakManager(this);
        cooldownManager = new CooldownManager(configManager);

        getServer().getPluginManager().registerEvents(new SwordListener(this), this);
        getServer().getPluginManager().registerEvents(new PlayerListener(this), this);

        GiveCloakCommand giveCloakCommand = new GiveCloakCommand(this);
        getCommand("givecloak").setExecutor(giveCloakCommand);
        getCommand("givecloak").setTabCompleter(giveCloakCommand);

        actionBarTask = new ActionBarTask(this);
        actionBarTask.runTaskTimer(this, 0L, 20L);

        getLogger().info("InvisibleCloakPlugin enabled.");
    }

    @Override
    public void onDisable() {
        if (cloakManager != null) {
            cloakManager.deactivateAll();
        }
        getLogger().info("InvisibleCloakPlugin disabled.");
    }

    public static InvisibleCloakPlugin getInstance() {
        return instance;
    }

    public ConfigManager getConfigManager() {
        return configManager;
    }

    public CloakManager getCloakManager() {
        return cloakManager;
    }

    public CooldownManager getCooldownManager() {
        return cooldownManager;
    }

    public ActionBarTask getActionBarTask() {
        return actionBarTask;
    }
}