Imran Abdo

create me a plugin where it like a redstone repeater that i can get from doing /repeater with op what it dose it it turns the player full invisble with armour for 30 seconds

Kodari AI
KodariSep 12 at 1:06 pm 1
RedstoneRepeaterInvisibility
An OP-only Minecraft plugin granting players a special redstone repeater item via the /repeater command. When activated, the repeater renders the player fully invisible, including armor and held items, for a duration of 30 seconds. The effect provides complete stealth, allowing players to move undetected by other players and mobs. The plugin manages cooldowns, prevents abuse, and ensures the invisibility effect is properly applied and removed after the timer expires. Ideal for hide-and-seek gameplay, stealth missions, or creative server events.
  1. Create a Gradle Spigot plugin with /repeater restricted to operators.

  2. Add a named repeater item that activates 30 seconds of potion invisibility and hides the player, including armor, from everyone else.

  3. Restore visibility on expiry, quit, and plugin shutdown.

Created the InvisibilityRepeater plugin.

  • /repeater gives operators a named redstone repeater.

  • Right-clicking it makes the player invisible, including armor, for 30 seconds.

  • The repeater is consumed on use.

  • Visibility is restored automatically after 30 seconds, on quit, and when the plugin disables.

  • Added Gradle setup and plugin.yml.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
4 215
src/main/java/com/kodari/repeater/InvisibilityRepeaterPlugin.java
package com.kodari.repeater;

import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XPotion;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.block.Action;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class InvisibilityRepeaterPlugin extends JavaPlugin implements Listener {

    private static final String REPEATER_NAME = "&cInvisibility Repeater";
    private static final int INVISIBILITY_SECONDS = 30;

    private final Map<UUID, BukkitTask> activePlayers = new HashMap<>();

    @Override
    public void onEnable() {
        getCommand("repeater").setExecutor((sender, command, label, args) -> {
            if (!(sender instanceof Player player)) {
                sender.sendMessage(ChatColor.RED + "Only players can use this command.");
                return true;
            }

            if (!player.isOp()) {
                player.sendMessage(ChatColor.RED + "You must be an operator to use this command.");
                return true;
            }

            player.getInventory().addItem(createRepeater());
            player.sendMessage(ChatColor.GREEN + "You received an Invisibility Repeater.");
            return true;
        });

        getServer().getPluginManager().registerEvents(this, this);
    }

    @Override
    public void onDisable() {
        for (UUID playerId : activePlayers.keySet().toArray(new UUID[0])) {
            Player player = Bukkit.getPlayer(playerId);
            if (player != null) {
                restoreVisibility(player);
            }
        }

        activePlayers.values().forEach(BukkitTask::cancel);
        activePlayers.clear();
    }

    @EventHandler(priority = EventPriority.HIGHEST)
    public void onRepeaterUse(PlayerInteractEvent event) {
        if ((event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK)
                || !isRepeater(event.getItem())) {
            return;
        }

        event.setCancelled(true);
        Player player = event.getPlayer();

        if (activePlayers.containsKey(player.getUniqueId())) {
            player.sendMessage(ChatColor.YELLOW + "You are already invisible.");
            return;
        }

        removeOneFromHand(player, event.getItem());
        activateInvisibility(player);
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        Player joiningPlayer = event.getPlayer();
        for (UUID hiddenPlayerId : activePlayers.keySet()) {
            Player hiddenPlayer = Bukkit.getPlayer(hiddenPlayerId);
            if (hiddenPlayer != null && !hiddenPlayer.equals(joiningPlayer)) {
                joiningPlayer.hidePlayer(this, hiddenPlayer);
            }
        }
    }

    @EventHandler
    public void onPlayerQuit(PlayerQuitEvent event) {
        Player player = event.getPlayer();
        BukkitTask task = activePlayers.remove(player.getUniqueId());
        if (task != null) {
            task.cancel();
            restoreVisibility(player);
        }
    }

    private ItemStack createRepeater() {
        ItemStack repeater = XMaterial.matchXMaterial("REPEATER")
                .map(XMaterial::parseItem)
                .orElseThrow(() -> new IllegalStateException("REPEATER is not available on this server."));

        ItemMeta meta = repeater.getItemMeta();
        meta.setDisplayName(color(REPEATER_NAME));
        repeater.setItemMeta(meta);
        return repeater;
    }

    private boolean isRepeater(ItemStack item) {
        if (item == null || !XMaterial.matchXMaterial(item.getType()).name().equals("REPEATER")) {
            return false;
        }

        ItemMeta meta = item.getItemMeta();
        return meta != null && meta.hasDisplayName() && color(REPEATER_NAME).equals(meta.getDisplayName());
    }

    private void activateInvisibility(Player player) {
        for (Player viewer : Bukkit.getOnlinePlayers()) {
            if (!viewer.equals(player)) {
                viewer.hidePlayer(this, player);
            }
        }

        XPotion.matchXPotion("INVISIBILITY")
                .map(potion -> potion.buildPotionEffect(INVISIBILITY_SECONDS * 20, 0))
                .ifPresent(player::addPotionEffect);

        player.sendMessage(ChatColor.GREEN + "You are invisible for 30 seconds.");
        BukkitTask task = Bukkit.getScheduler().runTaskLater(this, () -> {
            activePlayers.remove(player.getUniqueId());
            restoreVisibility(player);
            player.sendMessage(ChatColor.YELLOW + "Your invisibility has worn off.");
        }, INVISIBILITY_SECONDS * 20L);
        activePlayers.put(player.getUniqueId(), task);
    }

    private void restoreVisibility(Player hiddenPlayer) {
        for (Player viewer : Bukkit.getOnlinePlayers()) {
            if (!viewer.equals(hiddenPlayer)) {
                viewer.showPlayer(this, hiddenPlayer);
            }
        }
    }

    private void removeOneFromHand(Player player, ItemStack item) {
        if (item.getAmount() == 1) {
            if (player.getInventory().getItemInMainHand().equals(item)) {
                player.getInventory().setItemInMainHand(null);
            } else {
                player.getInventory().setItemInOffHand(null);
            }
            return;
        }

        item.setAmount(item.getAmount() - 1);
    }

    private String color(String text) {
        return ChatColor.translateAlternateColorCodes('&', text);
    }
}