diego alvarez

Create a comprehensive Minecraft Paper/Spigot plugin for Smart AI NPCs.

Requirements:

  1. Implement a custom NPC system. When a player types /npc-create <name> <role_description>, it spawns a named NPC at the player's location.
  2. Listen to player chat messages. If a player mentions the NPC's name within a 5-block radius, cancel the global chat and trigger an asynchronous HTTP request to the Google Gemini API (or a customizable URL endpoint in a config.yml).
  3. Pass a structured prompt to the AI: Include the player's name, their message, and the NPC's custom <role_description>. Instruct the AI to respond in character, short and concise (max 2 sentences).
  4. Run the API call fully asynchronously so it doesn't lag or freeze the main server thread.
  5. Use BukkitScheduler to safely send the AI's final text response back to the player in-game as: [NPC_Name]: <response>.
  6. Create a config.yml file to save the API Key, the endpoint URL, and the data of spawned NPCs so they persist after a server restart.
Kodari AI
KodariOct 1 at 10:46 pm 1
SmartAINPCs
Creates AI-driven NPCs that respond to nearby player chat. Spawn NPCs via /npc-create command with custom role descriptions. Listens for player messages mentioning NPC names within 5 blocks, cancels global chat, and sends asynchronous HTTP requests to Google Gemini API or custom endpoint. Uses BukkitScheduler for non-blocking responses delivered in-character as [NPC_Name]: response. Persists API config and NPC data in config.yml for restart survival.
  1. Set up the Paper/Spigot build, plugin metadata, and API configuration.

  2. Add persistent Villager NPC records and /npc-create.

  3. Intercept nearby NPC mentions, call Gemini asynchronously, and send replies on the server thread.

Created the SmartAINPC plugin with persistent Villager NPCs, /npc-create <name> <role_description>, and nearby name-mention chat handling. AI requests run asynchronously; replies are sent on the server thread as [NPC_Name]: <response>.

Set api.key in config.yml. The endpoint is configurable there; use {api_key} in its URL if the endpoint expects the key as a parameter.

diego alvarez

PARA LA BERSION 1.21.11

Kodari AI
KodariOct 1 at 10:47 pm 1
  1. Revisaré la configuración de compilación y el código del NPC.

  2. Ajustaré el plugin para Paper/Spigot 1.21.11.

Actualizado para Minecraft 1.21.11: el proyecto ahora compila con Java 21, usa Spigot API 1.21.11 y declara api-version: '1.21.11'.

diego alvarez

PARA PAPER?

Kodari AI
KodariOct 1 at 10:47 pm 1

Sí. Ya está configurado para Paper 1.21.11: cambié la dependencia de Spigot API por Paper API y actualicé el repositorio de Maven.

diego alvarez

Create a Minecraft Paper/Spigot plugin for Smart AI NPCs.

CRITICAL FIX FOR GOOGLE GEMINI 404 ERROR:

  1. The plugin must use the official, stable Gemini API endpoint: "https://googleapis.com"
  2. When building the HTTP POST request, append "?key=" + apiKey directly to the end of the URL string dynamically inside the Java code. Do NOT hardcode "{api_key}" in the URL config if the parser cannot replace it properly.
  3. The JSON body payload MUST strictly follow the correct Gemini API structure:

'{"contents": [{"parts": [{"text": "PROMPT_HERE"}]}]}'

  1. Implement a custom NPC system. When a player types /npc-create <name> <role>, it spawns a named NPC.
  2. If a player mentions the NPC's name within 5 blocks, cancel global chat and trigger the HTTP request fully ASYNCHRONOUSLY using CompletableFuture.
  3. Use BukkitScheduler to safely display the final response in the main server thread as: [NPC_Name]: <response>.
  4. Generate a config.yml file that looks exactly like this template:

api: key: ""

Kodari AI
KodariOct 2 at 1:43 pm 1
  1. Corregiré la URL de Gemini: googleapis.com solo no es un endpoint válido de generación.

  2. Simplificaré el JSON al formato requerido y agregaré la clave como ?key= en Java.

  3. Ejecutaré la llamada con CompletableFuture y entregaré la respuesta en el hilo principal; dejaré config.yml con la plantilla exacta.

Actualicé Gemini para enviar el JSON contents → parts → text, agregar la clave dinámicamente con ?key= y realizar la solicitud mediante CompletableFuture; la respuesta se envía al jugador desde el hilo principal. config.yml queda con la plantilla exacta api.key.

Nota: https://googleapis.com no es un endpoint de generación válido por sí solo. Usé el endpoint de Gemini generativelanguage.googleapis.com con la ruta generateContent para evitar el 404.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
10 448
src/main/java/com/kodari/smartnpc/SmartNpcPlugin.java
package com.kodari.smartnpc;

import com.kodari.smartnpc.command.NpcCreateCommand;
import com.kodari.smartnpc.npc.NpcManager;
import com.kodari.smartnpc.service.GeminiClient;
import com.kodari.smartnpc.listener.NpcChatListener;
import org.bukkit.plugin.java.JavaPlugin;

public final class SmartNpcPlugin extends JavaPlugin {
    @Override
    public void onEnable() {
        saveDefaultConfig();

        NpcManager npcManager = new NpcManager(this);
        npcManager.load();

        GeminiClient geminiClient = new GeminiClient(this);
        getServer().getPluginManager().registerEvents(new NpcChatListener(this, npcManager, geminiClient), this);
        getCommand("npc-create").setExecutor(new NpcCreateCommand(npcManager));
    }
}