Ppp

Create a Minecraft practice plugin similar to mcpvp.com search and fully customise configuration

Kodari AI
KodariOct 15 at 1:23 pm 2
PracticeArena
PracticeArena is a fully customizable Minecraft PvP practice plugin inspired by mcpvp.com. It features configurable arena kits with custom items, armor, and effects, plus a search system that matches players into 1v1 duels. Players can create custom arenas via configuration files, set spawn locations, and define match rules including health, hunger, and potion settings. The plugin includes a GUI-based kit selection menu, duel request system, and comprehensive match management with win/loss tracking. All messages, kits, arenas, and match parameters are configurable through YAML files, allowing server owners to tailor the practice experience without code changes. The search system queues players and automatically matches them based on configurable criteria, while the plugin handles teleportation, inventory restoration, and match cleanup automatically.
  1. Add the plugin entry point with kit queues, match handling, GUI selection, and player state restoration.

  2. Add plugin metadata and a fully editable config for kits, arenas, menu, and messages.

Created a configurable PvP practice plugin with kit-selection menus, per-kit 1v1 queues and arenas, match loadouts, forfeits, and player inventory restoration.

Use /practice or /queue to select a kit, /queue <kit> to join directly, and /leave to exit a queue or forfeit. Customize kits, arena and lobby locations, menu text, match settings, and messages in config.yml. Set the configured world names and spawn coordinates to match your server.

Kodari can make mistakes. Review important code before using.
Files
src
Code
3 614
src/main/java/com/kodari/practice/KodariPractice.java
package com.kodari.practice;

import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabCompleter;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

public final class KodariPractice extends JavaPlugin implements Listener, CommandExecutor, TabCompleter {
    private final Map<String, Deque<UUID>> queues = new HashMap<>();
    private final Map<UUID, String> queuedPlayers = new HashMap<>();
    private final Map<UUID, Match> activeMatches = new HashMap<>();
    private final Map<UUID, PlayerSnapshot> pendingRespawns = new HashMap<>();
    private final Map<Inventory, Map<Integer, String>> kitMenus = new HashMap<>();

    @Override
    public void onEnable() {
        saveDefaultConfig();
        Bukkit.getPluginManager().registerEvents(this, this);
        registerCommand("practice");
        registerCommand("queue");
        registerCommand("leave");
    }

    @Override
    public void onDisable() {
        Set<Match> matches = new HashSet<>(activeMatches.values());
        for (Match match : matches) {
            restoreIfOnline(match.first, match.firstSnapshot);
            restoreIfOnline(match.second, match.secondSnapshot);
        }
        activeMatches.clear();
        queues.clear();
        queuedPlayers.clear();
    }

    private void registerCommand(String name) {
        PluginCommand command = getCommand(name);
        if (command != null) {
            command.setExecutor(this);
            command.setTabCompleter(this);
        }
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player player)) {
            sender.sendMessage(color(getConfig().getString("messages.players-only", "Players only.")));
            return true;
        }

        String commandName = command.getName().toLowerCase();
        if (commandName.equals("leave")) {
            leave(player);
            return true;
        }
        if (commandName.equals("queue")) {
            if (args.length == 0) {
                openKitMenu(player);
            } else {
                joinQueue(player, args[0]);
            }
            return true;
        }

        if (args.length == 0) {
            openKitMenu(player);
            return true;
        }
        if (args[0].equalsIgnoreCase("leave")) {
            leave(player);
        } else if (args[0].equalsIgnoreCase("queue") && args.length > 1) {
            joinQueue(player, args[1]);
        } else if (args[0].equalsIgnoreCase("queue")) {
            openKitMenu(player);
        } else {
            joinQueue(player, args[0]);
        }
        return true;
    }

    @Override
    public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
        if (command.getName().equalsIgnoreCase("leave")) {
            return List.of();
        }
        if (args.length == 1 && command.getName().equalsIgnoreCase("practice")) {
            List<String> options = new ArrayList<>(getKitNames());
            options.add("queue");
            options.add("leave");
            return options.stream().filter(option -> option.toLowerCase().startsWith(args[0].toLowerCase())).collect(Collectors.toList());
        }
        if (args.length == 1) {
            return getKitNames().stream().filter(name -> name.toLowerCase().startsWith(args[0].toLowerCase())).collect(Collectors.toList());
        }
        if (args.length == 2 && args[0].equalsIgnoreCase("queue")) {
            return getKitNames().stream().filter(name -> name.toLowerCase().startsWith(args[1].toLowerCase())).collect(Collectors.toList());
        }
        return List.of();
    }

    private List<String> getKitNames() {
        ConfigurationSection section = getConfig().getConfigurationSection("kits");
        return section == null ? List.of() : new ArrayList<>(section.getKeys(false));
    }

    private void openKitMenu(Player player) {
        ConfigurationSection kits = getConfig().getConfigurationSection("kits");
        if (kits == null || kits.getKeys(false).isEmpty()) {
            send(player, "no-kits");
            return;
        }
        int size = Math.max(9, Math.min(54, getConfig().getInt("menu.size", 27)));
        size = ((size + 8) / 9) * 9;
        String title = color(getConfig().getString("menu.title", "&8Select a kit"));
        Inventory inventory = Bukkit.createInventory(null, size, title);
        Map<Integer, String> buttons = new HashMap<>();
        int slot = 0;
        for (String kitName : kits.getKeys(false)) {
            if (slot >= size) {
                break;
            }
            ConfigurationSection kit = kits.getConfigurationSection(kitName);
            if (kit == null) {
                continue;
            }
            ItemStack icon = createItem(kit.getString("icon", "IRON_SWORD"));
            if (icon == null) {
                slot++;
                continue;
            }
            ItemMeta meta = icon.getItemMeta();
            if (meta != null) {
                meta.setDisplayName(color(kit.getString("display-name", kitName)));
                List<String> lore = kit.getStringList("lore").stream().map(KodariPractice::color).collect(Collectors.toList());
                if (!lore.isEmpty()) {
                    meta.setLore(lore);
                }
                icon.setItemMeta(meta);
            }
            inventory.setItem(slot, icon);
            buttons.put(slot, kitName);
            slot++;
        }
        kitMenus.put(inventory, buttons);
        player.openInventory(inventory);
    }

    private void joinQueue(Player player, String kitName) {
        ConfigurationSection kit = getConfig().getConfigurationSection("kits." + kitName);
        if (kit == null) {
            send(player, "unknown-kit", "%kit%", kitName);
            return;
        }
        if (activeMatches.containsKey(player.getUniqueId())) {
            send(player, "already-in-match");
            return;
        }
        String currentQueue = queuedPlayers.get(player.getUniqueId());
        if (currentQueue != null) {
            if (currentQueue.equalsIgnoreCase(kitName)) {
                send(player, "already-queued", "%kit%", kitName);
                return;
            }
            removeFromQueue(player.getUniqueId());
        }

        Deque<UUID> queue = queues.computeIfAbsent(kitName.toLowerCase(), key -> new ArrayDeque<>());
        UUID opponentId = null;
        while (!queue.isEmpty()) {
            UUID candidate = queue.pollFirst();
            queuedPlayers.remove(candidate);