nishkarshw375
📎 1 file 3,096 chars
📄
pasted-code-1779470189084.txt
txt 32 lines
▶
Act as an expert Minecraft Java Plugin Developer for the Paper/Spigot API (Version 1.21.11). Write a complete, highly optimized, and bug-free vanilla server plugin with two main operator-only commands: `/nick` and `/silentban`. 

Crucial Context: This server runs other complex gameplay plugins (like a "Reincarnation" plugin that scrambles names upon bans, and an "Immortality" plugin). This new plugin MUST NOT interfere with their logic. You must ensure compatibility by using appropriate `EventPriority` levels (e.g., `HIGHEST` or `MONITOR` depending on the listener) so that it plays nice with other plugins modifying player metadata, and avoids aggressive packet manipulation unless absolutely necessary.

Feature 1: The `/nick` Command
- Syntax: `/nick  `
- Permission: Operator only. (If a non-OP uses it, return a standard permission denied message).
- Functionality: Changes a target player's nickname strictly on the server-side. 
- Visibility: The new nickname must seamlessly replace the player's original IGN across all visible elements: 
  1. The nametag above their head in-game.
  2. The Tab list.
  3. Server chat messages.
  4. System broadcasts (e.g., Death messages, standard ban messages, advancements, etc.).
- Technical constraint: Use persistent data containers (PDC) or efficient UUID hash maps to store these nicknames so they persist during the session, but ensure memory is cleared appropriately when a player leaves to prevent memory leaks. Update the profile/game profile cleanly so it doesn't break skin rendering.

Feature 2: The `/silentban` Command
- Syntax: `/silentban ban-ip `
- Permission: Operator only. 
- Functionality: Executes a silent IP ban on the target player.
- Execution Rules:
  1. It must immediately ban the IP address associated with the target player (identical to the vanilla `/ban-ip` backend logic) and kick them from the server.
  2. It MUST suppress the public ban broadcast message entirely. Nobody else on the server should see that a ban occurred.
  3. It MUST suppress the standard "Player left the game" (PlayerQuitEvent/PlayerKickEvent) message for the banned player. Their departure must be completely silent to the public.
  4. It MUST send a private confirmation message ONLY to the specific Operator who executed the command. Do not broadcast this to all online Operators. 
  5. The private confirmation format must be exactly: "You banned this IP [Target_IP_Address] [Target_IGN]".

Optimization & Code Quality Requirements:
- Write highly optimized Java code with zero redundant loops or heavy tasks on the main server thread. 
- Provide the complete `plugin.yml` file.
- Provide the Main class and any necessary command executor or listener classes.
- Include logic to double-check if an event is already cancelled by another plugin before applying chat/death message modifications.
- Add brief, clear comments explaining the logic, especially around the event priorities used to ensure compatibility with the server's existing Reincarnation/Immortality plugins.
Kodari AI
KodariMay 22 at 5:18 pm 7,742 (v2)
NickAndSilentBan
A lightweight operator-only utility plugin providing two commands: /nick to change a player's visible nickname across nametags, tab list, chat, and death/advancement broadcasts; and /silentban ban-ip to silently IP-ban a player with zero public visibility. Uses PDC for nickname persistence, proper EventPriority ordering for compatibility with other plugins, and sends a private confirmation only to the executing operator.

Planning class dependencies:

  • NickAndSilentBan (main) — holds NickManager, registers commands + listeners

  • NickManager — stores UUID→nickname map, PDC read/write, team management for nametags

  • NickCommand — /nick executor

  • SilentBanCommand — /silentban executor

  • NickListener — chat, death, advancement, quit message interception

  • GUIManager / GUIListener / InventoryGUI / InventoryButton / InventoryHandler — not needed here (no GUI)

Here’s a summary of every design decision:

NickManager

  • Dual storage: a HashMap<UUID, String> for O(1) in-session lookups, plus PDC on the player entity so nicks survive plugin reloads within the same session.

  • Nametag replacement uses a scoreboard Team per player (the only reliable vanilla method without packet manipulation). Team names are nick_ + 11 hex chars of the UUID to stay within the 16-char limit.

  • onQuit() removes the UUID from the map immediately — no leaks.

SilentBanCommand

  • Calls BanList.addBan() directly instead of dispatching /ban-ip, which avoids the vanilla broadcast entirely.

  • Tags the target with a FixedMetadataValue("silentban_kick") before kicking so the listener can identify and suppress the quit/kick messages.

  • Confirmation is sent only to sender, never broadcast.

NickListener

  • onChat — EventPriority.HIGH, checks isCancelled() first to respect mute plugins. Uses Paper’s AsyncChatEvent renderer API to swap the display name component cleanly.

  • onDeath / onAdvancement — EventPriority.HIGH, skips if cancelled (respects the Immortality plugin suppressing death events).

  • onQuit / onKick — MONITOR and HIGH respectively; nulls out the leave/kick message for silently banned players only.

Kodari can make mistakes. Review important code before using.
Files
src
Code
6 482
src/main/java/com/nicksilentban/NickAndSilentBan.java
package com.nicksilentban;

import com.nicksilentban.command.NickCommand;
import com.nicksilentban.command.SilentBanCommand;
import com.nicksilentban.listener.NickListener;
import com.nicksilentban.manager.NickManager;
import org.bukkit.plugin.java.JavaPlugin;

public class NickAndSilentBan extends JavaPlugin {

    private NickManager nickManager;

    @Override
    public void onEnable() {
        nickManager = new NickManager(this);

        getCommand("nick").setExecutor(new NickCommand(nickManager));
        getCommand("silentban").setExecutor(new SilentBanCommand());

        getServer().getPluginManager().registerEvents(new NickListener(nickManager), this);

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

    @Override
    public void onDisable() {
        nickManager.clearAll();
        getLogger().info("NickAndSilentBan disabled.");
    }

    public NickManager getNickManager() {
        return nickManager;
    }
}