A
📎 1 file 2,595 chars
📄
pasted-code-1774584921354.txt
txt 79 lines
▶
TASK:
Refactor the entire plugin codebase to REMOVE all dependencies on the XSeries library (including but not limited to XMaterial, XSound, XItemStack, XEnchantment, etc.) and replace them with native Bukkit/Paper API equivalents.

REQUIREMENTS:

1. DEPENDENCY REMOVAL
- Completely remove XSeries from build files (Gradle/Maven).
- Remove all imports like:
  com.cryptomorin.xseries.*

2. MATERIAL REPLACEMENT
- Replace all XMaterial usages with org.bukkit.Material.
- Use Material.matchMaterial(String) for config-based materials.
- Handle legacy names safely:
  - If invalid material → fallback to Material.STONE (or configurable default).
- Example:
  BEFORE:
    XMaterial.matchXMaterial("DIAMOND_SWORD").get().parseMaterial()
  AFTER:
    Material.matchMaterial("DIAMOND_SWORD")

3. SOUND REPLACEMENT
- Replace XSound with org.bukkit.Sound.
- Use Sound.valueOf() safely with try/catch.
- Provide fallback sound if invalid (e.g., ENTITY_PLAYER_LEVELUP).

4. ITEMSTACK HANDLING
- Replace any XItemStack builders with standard Bukkit ItemStack.
- Use:
  - new ItemStack(Material)
  - ItemMeta for name, lore, enchantments
- Ensure null safety when editing ItemMeta.

5. ENCHANTMENTS
- Replace XEnchantment with org.bukkit.enchantments.Enchantment.
- Use Enchantment.getByName() or NamespacedKey if needed.

6. PARTICLES / EFFECTS
- Replace any XSeries particle/effect utilities with:
  - org.bukkit.Particle
  - org.bukkit.World#spawnParticle

7. VERSION COMPATIBILITY
- Target Paper 1.21+ (no legacy support needed).
- Remove all cross-version hacks and simplify logic.

8. CONFIG COMPATIBILITY
- Keep existing config.yml format unchanged.
- When reading config values:
  - Validate material/sound strings
  - Log warnings if invalid
  - Apply fallback values instead of crashing

9. ERROR HANDLING
- Ensure no NullPointerExceptions occur from invalid materials/sounds.
- Add clean logging:
  - "[CloudPractise] Invalid material in config: "

10. CODE QUALITY IMPROVEMENTS
- Simplify utility methods previously used for XSeries.
- Remove unnecessary abstraction layers.
- Keep code clean, readable, and production-ready.

11. TESTING
- Ensure:
  ✔ Items load correctly
  ✔ Sounds play correctly
  ✔ No ClassNotFound errors
  ✔ Plugin runs without XSeries dependency

OUTPUT:
- Provide fully updated Java classes
- Highlight major replaced sections
- Ensure plugin compiles and runs without XSeries

BONUS:
- Create a small utility class:
  `ItemUtil.java`
  to safely parse materials and create ItemStacks.
Kodari AI
KodariMar 27 at 4:27 am 57,299 (v2)

Let me read all the relevant files first.

Now let me check the utils folder and any remaining managers/models.

Now let me read the utils and remaining managers/models.

Now I have a complete picture. The XSeries references are in:

  • EventManager.java — XMaterial in buildEventKit()

  • KitSelectorGUI.java — XMaterial import for kit icon

  • QueueSelectorGUI.java — XMaterial import for kit icon

  • StatsGUI.java — fully qualified XMaterial for kit icon

  • CombatListener.java — XSound for death/kill sounds

build.gradle does not include XSeries, so no change needed there. I’ll:

  • Create ItemUtil.java with safe Material parsing + ItemStack building

  • Remove all XSeries usage in the 5 affected files

Now wire ItemUtil.init() into the plugin startup so the logger is available for warnings:

Here’s a summary of every change made:

  • ItemUtil.java (new) — safe Material.matchMaterial() with fallback + warning logging, Sound.valueOf() with try/catch fallback, and convenience createItem() / playSound() helpers

  • EventManager.java — replaced all XMaterial.matchXMaterial(...).map(XMaterial::parseItem) calls with ItemUtil.createItem(materialName)

  • KitSelectorGUI.java — removed XMaterial import, replaced with ItemUtil.parseMaterial()

  • QueueSelectorGUI.java — same as above

  • StatsGUI.java — removed fully-qualified XMaterial call, replaced with ItemUtil.parseMaterial()

  • CombatListener.java — replaced XSound.matchXSound(...).ifPresent(s -> s.play(...)) with native Sound.valueOf() via ItemUtil.parseSound() + player.playSound()

  • CloudPractise.java — added ItemUtil.init(getLogger()) on enable so warnings include the logger

A

continue and also add plugin reload command and also scoreborads according to worlds

Kodari AI
KodariMar 27 at 4:44 am 78,334 (v2)

Let me read the existing files first.

Now I have a complete picture. Here’s my plan:

  • Complete MatchManager with full lifecycle: countdown, arena assignment, kit giving, win detection, elo updates, stat tracking

  • Full ScoreboardManager rewrite with world-aware, config-driven, per-state (lobby/queue/match/event) scoreboards that update on a task

  • Enhance reload command and add reloadPlugin() to main class

  • Create plugin.yml + config.yml (they don’t exist yet)

  • Patch Match.java to add arena and eliminatedPlayers fields needed by MatchManager

That’s everything. Here’s a summary of what was done:

New files:

  • plugin.yml — registers all commands and permissions (was completely missing)

  • config.yml — full config with settings, messages, and per-state scoreboard definitions including world overrides

MatchManager (full rewrite):

  • createMatch now finds an arena, teleports players, clears inventory, then runs a countdown

  • startCountdown → beginMatch — title-based countdown, kit application at fight time

  • handlePlayerElimination — tracks per-team alive status, triggers endMatch when a team is fully eliminated

  • endMatch → finalizeMatch — broadcasts result, updates elo (Elo K-factor formula), win/loss/kill/death stats, restores players after a configurable delay, releases arena

  • forfeit and handlePlayerQuit properly integrated

ScoreboardManager (full rewrite):

  • Periodic task updates all online players every scoreboards.update-interval ticks

  • State detection: in-match → match board, in-queue → queue board, in-event → event board, else → lobby board

  • World-based overrides: lobby players get a world-specific scoreboard if scoreboards.worlds.<worldName> is configured

  • Rich placeholder replacement: {elo}, {wins}, {losses}, {kdr}, {kit}, {opponent}, {time}, {queue_time}, {event_players}, {online}, {queued}, {matches}, {date}

  • Duplicate-line deduplication using invisible ChatColor suffix padding

  • reload() method cancels the old task, clears boards, restarts cleanly

/cp reload command now calls plugin.reloadPlugin() which reloads config, kits, arenas, spawn, and fully restarts the scoreboard system.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
52 5,088
src/main/java/com/arsec4real/cloudpractise/CloudPractise.java
package com.arsec4real.cloudpractise;

import com.arsec4real.cloudpractise.commands.ArenaCommand;
import com.arsec4real.cloudpractise.commands.CloudPractiseCommand;
import com.arsec4real.cloudpractise.commands.DuelCommand;
import com.arsec4real.cloudpractise.commands.EventCommand;
import com.arsec4real.cloudpractise.commands.KitCommand;
import com.arsec4real.cloudpractise.commands.LeaderboardCommand;
import com.arsec4real.cloudpractise.commands.PartyCommand;
import com.arsec4real.cloudpractise.commands.QueueCommand;
import com.arsec4real.cloudpractise.commands.SpectateCommand;
import com.arsec4real.cloudpractise.commands.StatsCommand;
import com.arsec4real.cloudpractise.gui.ArenaEditorGUI;
import com.arsec4real.cloudpractise.gui.EventGUI;
import com.arsec4real.cloudpractise.gui.KitEditorGUI;
import com.arsec4real.cloudpractise.gui.KitSelectorGUI;
import com.arsec4real.cloudpractise.gui.LeaderboardGUI;
import com.arsec4real.cloudpractise.gui.PartyGUI;
import com.arsec4real.cloudpractise.gui.QueueSelectorGUI;
import com.arsec4real.cloudpractise.gui.SpectatorGUI;
import com.arsec4real.cloudpractise.gui.StatsGUI;
import com.arsec4real.cloudpractise.listeners.CombatListener;
import com.arsec4real.cloudpractise.listeners.InventoryListener;
import com.arsec4real.cloudpractise.listeners.PlayerListener;
import com.arsec4real.cloudpractise.managers.ArenaManager;
import com.arsec4real.cloudpractise.managers.EventManager;
import com.arsec4real.cloudpractise.managers.KitManager;
import com.arsec4real.cloudpractise.managers.MatchManager;
import com.arsec4real.cloudpractise.managers.PartyManager;
import com.arsec4real.cloudpractise.managers.QueueManager;
import com.arsec4real.cloudpractise.managers.ScoreboardManager;
import com.arsec4real.cloudpractise.managers.SpectatorManager;
import com.arsec4real.cloudpractise.managers.StatsManager;
import com.arsec4real.cloudpractise.utils.ColorUtil;
import com.arsec4real.cloudpractise.utils.ItemUtil;
import lombok.Getter;
import org.bukkit.Location;
import org.bukkit.plugin.java.JavaPlugin;

@Getter
public class CloudPractise extends JavaPlugin {

    private ArenaManager arenaManager;
    private KitManager kitManager;
    private MatchManager matchManager;
    private QueueManager queueManager;
    private PartyManager partyManager;
    private StatsManager statsManager;
    private EventManager eventManager;
    private SpectatorManager spectatorManager;
    private ScoreboardManager scoreboardManager;

    private KitSelectorGUI kitSelectorGUI;
    private QueueSelectorGUI queueSelectorGUI;
    private KitEditorGUI kitEditorGUI;
    private SpectatorGUI spectatorGUI;
    private StatsGUI statsGUI;
    private LeaderboardGUI leaderboardGUI;
    private PartyGUI partyGUI;
    private EventGUI eventGUI;
    private ArenaEditorGUI arenaEditorGUI;

    private Location spawn;

    @Override
    public void onEnable() {
        ItemUtil.init(getLogger());
        saveDefaultConfig();
        saveResource("help.txt", false);
        getDataFolder().mkdirs();
        loadSpawn();
        initManagers();
        initGUIs();
        registerCommands();
        registerListeners();
        printStartupBanner();
    }

    public void reloadPlugin() {
        reloadConfig();
        if (kitManager != null) kitManager.loadKits();
        if (arenaManager != null) arenaManager.loadArenas();
        if (scoreboardManager != null) scoreboardManager.reload();
        loadSpawn();
    }

    @Override
    public void onDisable() {
        if (statsManager != null) statsManager.saveAll();
        if (kitManager != null) kitManager.saveKits();
        if (arenaManager != null) arenaManager.saveArenas();
        if (queueManager != null) queueManager.shutdown();
        if (scoreboardManager != null) scoreboardManager.shutdown();
        getLogger().info("CloudPractise has been disabled.");
    }

    private void initManagers() {
        statsManager = new StatsManager(this);
        arenaManager = new ArenaManager(this);
        kitManager = new KitManager(this);
        spectatorManager = new SpectatorManager(this);
        matchManager = new MatchManager(this);
        queueManager = new QueueManager(this);
        partyManager = new PartyManager(this);
        eventManager = new EventManager(this);
        scoreboardManager = new ScoreboardManager(this);
    }

    private void initGUIs() {
        kitSelectorGUI = new KitSelectorGUI(this);
        queueSelectorGUI = new QueueSelectorGUI(this);
        kitEditorGUI = new KitEditorGUI(this);
        spectatorGUI = new SpectatorGUI(this);
        statsGUI = new StatsGUI(this);
        leaderboardGUI = new LeaderboardGUI(this);
        partyGUI = new PartyGUI(this);
        eventGUI = new EventGUI(this);
        arenaEditorGUI = new ArenaEditorGUI(this);
    }

    private void registerCommands() {
        DuelCommand duelCmd = new DuelCommand(this);
        getCommand("duel").setExecutor(duelCmd);
        getCommand("duel").setTabCompleter(duelCmd);
        getCommand("accept").setExecutor(duelCmd);
        getCommand("deny").setExecutor(duelCmd);

        ArenaCommand arenaCmd = new ArenaCommand(this);
        getCommand("arena").setExecutor(arenaCmd);
        getCommand("arena").setTabCompleter(arenaCmd);

        KitCommand kitCmd = new KitCommand(this);
        getCommand("kit").setExecutor(kitCmd);
        getCommand("kit").setTabCompleter(kitCmd);
        getCommand("editkit").setExecutor(kitCmd);
        getCommand("editkit").setTabCompleter(kitCmd);

        QueueCommand queueCmd = new QueueCommand(this);
        getCommand("queue").setExecutor(queueCmd);
        getCommand("queue").setTabCompleter(queueCmd);
        getCommand("leave").setExecutor(queueCmd);

        PartyCommand partyCmd = new PartyCommand(this);
        getCommand("party").setExecutor(partyCmd);
        getCommand("party").setTabCompleter(partyCmd);

        getCommand("stats").setExecutor(new StatsCommand(this));
        getCommand("leaderboard").setExecutor(new LeaderboardCommand(this));
        getCommand("event").setExecutor(new EventCommand(this));
        getCommand("spectate").setExecutor(new SpectateCommand(this));

        CloudPractiseCommand cpCmd = new CloudPractiseCommand(this);
        getCommand("cloudpractise").setExecutor(cpCmd);
        getCommand("cloudpractise").setTabCompleter(cpCmd);
        getCommand("setspawn").setExecutor(cpCmd);
    }

    private void registerListeners() {
        getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
        getServer().getPluginManager().registerEvents(new CombatListener(this), this);
        getServer().getPluginManager().registerEvents(new InventoryListener(this), this);
    }

    private void loadSpawn() {
        String world = getConfig().getString("spawn.world", "world");
        double x = getConfig().getDouble("spawn.x", 0.0);
        double y = getConfig().getDouble("spawn.y", 64.0);
        double z = getConfig().getDouble("spawn.z", 0.0);
        float yaw = (float) getConfig().getDouble("spawn.yaw", 0.0);
        float pitch = (float) getConfig().getDouble("spawn.pitch", 0.0);
        org.bukkit.World w = getServer().getWorld(world);
        if (w != null) spawn = new Location(w, x, y, z, yaw, pitch);
    }

    public void setSpawn(Location location) {
        this.spawn = location;
        getConfig().set("spawn.world", location.getWorld().getName());
        getConfig().set("spawn.x", location.getX());
        getConfig().set("spawn.y", location.getY());
        getConfig().set("spawn.z", location.getZ());
        getConfig().set("spawn.yaw", location.getYaw());
        getConfig().set("spawn.pitch", location.getPitch());
        saveConfig();
    }

    private void printStartupBanner() {
        String[] lines = {
                "&b&l  ___ _             _  ___ ",
                "&b&l / __| |___ _  _ __| ||   \\",
                "&3&l| (__| / _ \\| || / _` || |) |",
                "&3&l \\___|_\\___/\\_,_\\__,_||___/ ",
                "&7       &bPractise Plugin",
                "",
                "&b Author: &3arsec4real",
                "&b Version: &3" + getDescription().getVersion(),
                "&7 Arenas: &e" + arenaManager.getArenaCount() + "  &7Kits: &e" + kitManager.getKitCount(),
                "&a Plugin enabled successfully!"
        };
        for (String line : lines) {
            getLogger().info(ColorUtil.strip(line).replace("  ", " "));