c1oud007
📎 1 file 1,488 chars
📄
pasted-code-1783089502338.txt
txt 46 lines
▶
Create a Minecraft Paper 1.21.11 plugin that provides a INVENTORY GUI-based warp system using a Chest INVENTORY GUI.

Features
/warp
Every player has permission to use this command by default.
Running /warp opens a Chest INVENTORY GUI displaying all configured warps.
Clicking a warp teleports the player to that location.
/setwarp
This command is OP-only.

Usage:

/setwarp   [display name]
 is the internal warp ID.
 specifies the INVENTORY GUI icon (Material).
[display name] is optional and is the name shown in the INVENTORY GUI.
The player's current location is saved as the warp location.

Example:

/setwarp spawn DIAMOND_BLOCK Spawn
/warpeditor
OP-only command.
Opens a Chest INVENTORY GUI listing all existing warps.
Right-clicking a warp opens an editor INVENTORY GUI.
Warp Editor INVENTORY GUI

The editor should include options such as:

Change display name
Change icon/material
Change slot position in the INVENTORY GUI
Rename internal warp ID
Update the warp location to the player's current position
Delete warp
Back button
Save changes
Additional Requirements
Compatible with Paper 1.21.11.
Store all warp data in a YAML configuration file.
Preserve INVENTORY GUI slot positions after server restarts.
Prevent duplicate warp names.
Use clean, modular, and well-documented code.
Handle invalid commands and errors gracefully.
Include tab completion for commands.
INVENTORY GUI should automatically update when warps are added, edited, or removed.
Kodari AI
KodariJul 3 at 2:41 pm 2

I’ll create a warp management plugin with inventory GUI system.

WarpGUI
A Paper 1.21 warp management plugin with a full inventory GUI system. Players use /warp to open a chest GUI of all configured warps and click to teleport. Admins use /setwarp to create warps and /warpeditor to edit them through interactive menus. Warps persist in YAML config with slot positions preserved across restarts. Features chat-based inline editing for display names, icons, slots, and warp renaming.
Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
19 1,224
src/main/java/com/warpgui/WarpGUI.java
package com.warpgui;

import com.warpgui.command.SetWarpCommand;
import com.warpgui.command.WarpCommand;
import com.warpgui.command.WarpEditorCommand;
import com.warpgui.command.WarpTabCompleter;
import com.warpgui.inventory.gui.GUIListener;
import com.warpgui.inventory.gui.GUIManager;
import com.warpgui.inventory.impl.WarpEditorGUI;
import com.warpgui.util.ColorUtil;
import org.bukkit.Bukkit;
import org.bukkit.Material;
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.AsyncPlayerChatEvent;
import org.bukkit.plugin.java.JavaPlugin;

public class WarpGUI extends JavaPlugin implements Listener {
    private WarpManager warpManager;
    private GUIManager guiManager;

    @Override
    public void onEnable() {
        saveDefaultConfig();

        warpManager = new WarpManager(this);
        guiManager = new GUIManager();

        GUIListener guiListener = new GUIListener(guiManager);
        getServer().getPluginManager().registerEvents(guiListener, this);
        getServer().getPluginManager().registerEvents(this, this);

        WarpCommand warpCommand = new WarpCommand(warpManager, guiManager);
        SetWarpCommand setWarpCommand = new SetWarpCommand(warpManager);
        WarpEditorCommand warpEditorCommand = new WarpEditorCommand(warpManager, guiManager);
        WarpTabCompleter tabCompleter = new WarpTabCompleter(warpManager);

        getCommand("warp").setExecutor(warpCommand);
        getCommand("setwarp").setExecutor(setWarpCommand);
        getCommand("warpeditor").setExecutor(warpEditorCommand);
        getCommand("warp").setTabCompleter(tabCompleter);
        getCommand("setwarp").setTabCompleter(tabCompleter);

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

    @Override
    public void onDisable() {
        if (warpManager != null) {
            warpManager.saveWarps();
            warpManager.getPendingEdits().clear();
        }
        getLogger().info("WarpGUI disabled.");
    }

    @EventHandler(priority = EventPriority.LOWEST)
    public void onPlayerChat(AsyncPlayerChatEvent event) {
        Player player = event.getPlayer();
        WarpManager.PendingEdit pending = warpManager.getPendingEdit(player.getUniqueId());
        if (pending == null) return;

        event.setCancelled(true);
        String message = event.getMessage().trim();

        if (message.equalsIgnoreCase("cancel")) {
            warpManager.removePendingEdit(player.getUniqueId());
            player.sendMessage(ColorUtil.colorize("<red>Edit cancelled."));
            Bukkit.getScheduler().runTask(this, () -> {
                WarpEditorGUI gui = new WarpEditorGUI(warpManager, guiManager, pending.getWarpName());
                guiManager.openGUI(gui, player);
            });
            return;
        }

        Warp warp = warpManager.getWarp(pending.getWarpName());
        if (warp == null) {
            warpManager.removePendingEdit(player.getUniqueId());
            player.sendMessage(ColorUtil.colorize("<red>That warp no longer exists."));
            return;
        }

        boolean success = false;

        switch (pending.getType()) {
            case DISPLAY_NAME:
                warp.setDisplayName(message);
                success = true;
                player.sendMessage(ColorUtil.colorize("<green>Display name changed to '<gold>" + message + "<green>'."));
                break;

            case ICON:
                String upper = message.toUpperCase();
                Material mat = Material.getMaterial(upper);
                if (mat == null || !mat.isItem()) {
                    player.sendMessage(ColorUtil.colorize("<red>Invalid material: " + message));
                    player.sendMessage(ColorUtil.colorize("<gray>Type another material name, or 'cancel' to abort."));
                    return;
                }
                warp.setIcon(upper);
                success = true;
                player.sendMessage(ColorUtil.colorize("<green>Icon changed to <white>" + upper + "<green>."));
                break;

            case SLOT:
                try {
                    int slot = Integer.parseInt(message);
                    if (slot < 0 || slot > 53) {
                        player.sendMessage(ColorUtil.colorize("<red>Slot must be between 0 and 53."));
                        player.sendMessage(ColorUtil.colorize("<gray>Type another slot number, or 'cancel' to abort."));
                        return;
                    }
                    warp.setSlot(slot);
                    success = true;
                    player.sendMessage(ColorUtil.colorize("<green>Slot changed to <white>" + slot + "<green>."));
                } catch (NumberFormatException e) {
                    player.sendMessage(ColorUtil.colorize("<red>Invalid number: " + message));
                    player.sendMessage(ColorUtil.colorize("<gray>Type a valid slot number, or 'cancel' to abort."));
                    return;
                }
                break;

            case RENAME:
                String newName = message.toLowerCase().replace(" ", "-");
                if (!newName.matches("[a-z0-9_-]+")) {
                    player.sendMessage(ColorUtil.colorize("<red>Warp ID must be lowercase alphanumeric (hyphens and underscores allowed)."));
                    return;
                }
                if (warpManager.renameWarp(pending.getWarpName(), newName)) {
                    success = true;
                    player.sendMessage(ColorUtil.colorize("<green>Warp ID renamed to '<gold>" + newName + "<green>'."));
                    // Update pending to use the new name
                    warpManager.removePendingEdit(player.getUniqueId());
                    warpManager.setPendingEdit(player.getUniqueId(),
                        new WarpManager.PendingEdit(newName, WarpManager.PendingEdit.EditType.RENAME));
                } else {
                    player.sendMessage(ColorUtil.colorize("<red>A warp with ID '" + newName + "' already exists."));
                    return;
                }
                break;
        }

        if (success) {
            warpManager.saveWarps();
            warpManager.removePendingEdit(player.getUniqueId());
            final String targetWarp = warp.getName();
            Bukkit.getScheduler().runTask(this, () -> {
                WarpEditorGUI gui = new WarpEditorGUI(warpManager, guiManager, targetWarp);
                guiManager.openGUI(gui, player);
            });
        }
    }
}