Create a fully functional Java 21 Paper/Spigot plugin named ItemFlip with /icf. Main menu has locked Coinflip, Dice, Wheel icons. /icf <player> selects coinflip opponent; provide an intuitive documented way to select opponents for Dice and invite two players for Wheel, including /icf wheel; GUI mode selection must lead to usable setup flow. Coinflip setup shows target, emerald heads/diamond tails and send request. Both 1v1 modes invite with clickable accept command; Wheel invites two players and starts only after both accept. All invitations expire after 30 seconds with notifications and cleanup. Wager GUIs show mirrored real-time separate player lanes; each can modify only their own input slots and confirm via green pane. Strictly cancel all other GUI interactions, including shift clicks, number keys, double clicks, drag, drop and movement of player inventory during active game/wagering; implement a safe explicit method for transferring wagers from inventory to permitted slots without allowing exploits. Confirm locking, 5-second BukkitRunnable animation, random heads/tails or dice rolls (reroll ties), winner takes pot; Wheel has a 3-second ready countdown with cancellation if readiness changes before a 5-second spin and weighted winner based on configurable per-material item values times stack amount (document default values). Securely refund individual wagers on cancellation, expiry, disconnect, GUI closure, disable and errors; overflow drop safely. Implement durable escrow recovery across abrupt server crashes/restarts without duplicating awarded/refunded items to the extent practical, documenting any unavoidable limitations. Use custom InventoryHolder, main-thread Bukkit APIs and BukkitRunnable timers, disallow conflicting games, protect against races and stale tasks. Include plugin.yml, config and concise usage/permissions documentation, make implementation complete rather than stubs. Do not add tests.

Kodari AI
KodariNov 15 at 7:45 am 3
ItemFlip
ItemFlip is a Paper/Spigot plugin providing a comprehensive gambling and wagering system with three game modes: Coinflip, Dice, and Wheel. The main menu displays locked game icons that unlock through a setup flow. Coinflip and Dice support 1v1 matches where players select opponents and invite them via clickable accept commands. Wheel mode requires two players to accept invitations before a 3-second countdown and 5-second spin with weighted rewards based on configurable per-material item values. All wagers are secured in an escrow system with 30-second invitation expiry, real-time mirrored GUI lanes for each player, strict interaction cancellation, and durable recovery across server crashes to prevent item duplication or loss.

I’ll build the menus, invitations and wager flow around server-side escrow, with recovery and crash limitations documented.

Created ItemFlip with /icf, coinflip, dice, wheel, wager escrow and recovery.

Usage, permissions, wheel values and crash-recovery limitations are documented in README.md.

Fix startup error InvalidPluginException: Unsupported API version 1.21. plugin.yml currently api-version '1.21' and build.gradle uses Paper 1.21.4 API. Lower minimum API to 1.20, and compile dependency to compatible Paper 1.20.4 API; inspect implementation and replace any APIs unavailable in 1.20.4 while preserving functionality. Keep Java 21. Update README to document minimum server and Java requirements. Do not add tests.

Kodari AI
KodariNov 15 at 9:43 am 3

The implementation uses no APIs identified as unavailable in 1.20.4. I’ll lower the API declaration and compile dependency, keep Java 21, and update the requirements.

Updated ItemFlip to compile against Paper 1.20.4 and declare API version 1.20. Java 21 remains required, and the README now documents both requirements.

The implementation inspection found no APIs requiring replacement for 1.20.4.

Make ItemFlip compatible with Paper/Spigot Minecraft 1.19.4: change plugin.yml api-version to '1.19', build.gradle compileOnly dependency to Paper API 1.19.4-R0.1-SNAPSHOT, inspect and replace any APIs unavailable in 1.19.4 while preserving features. Keep Java 21 as originally requested; document Java 21 requirement and 1.19.4 compatibility in README. Do not add tests.

Kodari AI
KodariNov 15 at 9:47 am 1

I’ll update the declared API target and README. The implementation inspection found no post-1.19.4 API calls to replace.

Updated ItemFlip’s API target and dependency for Paper/Spigot 1.19.4. Java 21 remains required and is documented in the README.

The implementation inspection found no APIs needing replacement for 1.19.4.

Fix actual Sakura 1.19.4 runtime error: IncompatibleClassChangeError: Found class org.bukkit.inventory.InventoryView, but interface was expected at ItemFlip.onClick line 279, event.getView().getTopInventory(). Despite 1.19.4 declared Gradle dependency, build environment may compile against newer InventoryView interface. Avoid direct bytecode calls on InventoryView throughout the plugin, including click, drag, close, and any other paths, using a compatibility approach (e.g. reflection to access top inventory, or avoid InventoryView entirely where possible). Ensure click and drag events are safely cancelled for plugin GUIs even on compatibility failure, preserving wagers and normal behavior. Inspect all source occurrences and ensure compatibility with Sakura/Paper 1.19.4 and modern Paper. Do not add tests.

Kodari AI
KodariNov 15 at 9:54 am 2
  • Use the inventory event’s top-inventory accessor for clicks and drags, cancelling safely if it fails.

  • Replace the cleanup path’s direct InventoryView call with a cross-version lookup.

Replaced direct InventoryView calls with cross-version access. Clicks and drags are cancelled if inventory identification fails; cleanup uses reflection without closing an unrelated inventory.

No tests were added.

Investigate and fix invitation acceptance failing on Sakura 1.19.4. Screenshot shows target Notcello repeatedly issuing /icf accept 65dbcd89-151f-4870-b0ed-af439cae8fd0 via clickable link, says 'Cant accept', no error visible in excerpt; creator previously /icf Notcello. Read accept/start/GUI lifecycle, identify potential runtime version incompatibilities, premature cancellation/close events, invalid invitation handling, exceptions and timing. Ensure clicked acceptance reliably opens wagering GUIs for both players and game isn't spuriously cancelled during transitions; defer inventory opens to a safe next tick if appropriate with state checks; provide clear feedback for invalid/expired/already-accepted requests and log actionable exceptions, refund safely on failure. Avoid direct InventoryView bytecode as previous fix requires, preserve 1.19.4 support. No tests.

Kodari AI
KodariNov 15 at 10:01 am 2
  • Defer the wager-screen transition to the next tick and guard it against stale invitations and close events.

  • Add specific acceptance feedback and log startup failures before cancelling and refunding.

Updated invitation acceptance to open wager screens on the next tick, with state checks and protection against stale close events. Startup failures now log the exception and cancel the game with refunds; acceptance feedback distinguishes invalid or expired invitations from already-accepted ones.

The reported failure couldn’t be confirmed from the screenshot alone. The new logging should identify any remaining runtime error. No tests were added.

Update ItemFlip wager layout, animations, and public results as follows. Inspect existing ItemFlip.java rendering, slots, countdowns, escrow, and command flows. Coinflip and dice wager GUI: distinct left/right player chambers with names and real-time items, player 1 confirm top-left and player 2 confirm top-right, each player can only operate their own controls and lane; update slot mapping and instructions accordingly. Coinflip 5-second casino animation visibly cycles green heads and red tails before landing on randomly chosen outcome, matching side selection and actual winner. Dice 5-second simultaneous slot-style animation cycles visibly through all numbers 1–6 for both players, lands on actual random results, and automatically rerolls ties with clear feedback. Wheel supports 2 or 3 participants, including usable setup/invites and acceptance for one or two opponents; update commands/help/README. Show clearly separated player lanes/names and dynamically cycle participant names for the 5-second spin, landing on the actual weighted winning player. Preserve existing wheel weighting, three-second ready countdown, 30-second invite expiry, safe escrow/refunds, GUI protection, and Sakura 1.19.4 compatibility (avoid direct InventoryView bytecode). On completion publicly broadcast game result and winner, including a message that winner 'smoked' the losing player(s), with actual outcome details. Ensure animation result matches awarded winner and avoid double payouts or prematurely closing GUI. Update README for layout and commands. No tests.

Kodari AI
KodariNov 15 at 10:33 am 6
  1. Rework wager lanes and controls for two-player games and wheel participants.

  2. Add visible animations that land on the awarded result, including dice tie rerolls.

  3. Update wheel commands and public results, then document the layout and usage.

Updated ItemFlip with separate wager chambers, visible result-matched animations, dice tie rerolls, and two- or three-player wheel invitations. Completed games now broadcast the outcome and winner publicly.

The README documents the controls and updated commands. No tests were added.

Resume and complete pending ItemFlip changes. Inspect current code first, implement anything missing: coinflip/dice wager GUI separate left/right player chambers with player names, live items, player 1 confirm top-left and player 2 top-right with ownership protection; 5-second casino coin animation cycling green heads/red tails and landing on actual outcome; simultaneous dice animation visibly cycling 1–6 for both players, landing on actual rolls and rerolling ties; wheel supports 2–3 participants via usable commands/invites, separate lanes/names and a 5-second name-cycling slot spin landing on actual weighted winner. Preserve wager safety/refunds, wheel 3-second countdown, invitation expiry and Sakura 1.19.4 compatibility; avoid direct InventoryView bytecode. Publicly broadcast final outcomes and winner, including winner 'smoked' losing players, using modern attractive rich formatting, gold winners, gray/aqua accents and clean separators; avoid plain single-color blocks. Ensure actual displayed outcomes match payouts and no duplicate payouts; document commands in README. No tests.

Kodari AI
KodariNov 15 at 10:50 am 2
  1. Strengthen the lane layout and ownership cues while preserving escrow controls.

  2. Keep animations tied to the settled result and improve the public announcement.

  3. Update the command and layout documentation.

Completed the wager layout and public-result formatting. Player lanes now have colored slots and clearer ownership cues; the README explains their placement.

The existing animations, wheel invitations, escrow flow and cross-version inventory handling were retained. No tests were added.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
README.md
settings.gradle
Code
6 663
src/main/java/com/kodari/itemflip/ItemFlip.java
package com.kodari.itemflip;

import com.cryptomorin.xseries.XMaterial;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;

public final class ItemFlip extends JavaPlugin implements Listener {
    private final Map<UUID, Game> busy = new HashMap<>();
    private final Map<String, Game> invitations = new HashMap<>();
    private final Map<UUID, List<ItemStack>> escrow = new LinkedHashMap<>();
    private final Random random = new Random();
    private File escrowFile;

    private enum Mode { COINFLIP, DICE, WHEEL }
    private enum State { INVITING, STARTING, WAGERING, COUNTDOWN, SPINNING, ENDED }

    private final class Menu implements InventoryHolder {
        private final String type;
        private final UUID target;
        private boolean heads = true;
        private Inventory inventory;
        Menu(String type, UUID target) { this.type = type; this.target = target; }
        @Override public Inventory getInventory() { return inventory; }
    }

    private final class View implements InventoryHolder {
        private final Game game;
        private final UUID viewer;
        private Inventory inventory;
        View(Game game, UUID viewer) { this.game = game; this.viewer = viewer; }
        @Override public Inventory getInventory() { return inventory; }
    }

    private final class Game {
        private final String id = UUID.randomUUID().toString();
        private final Mode mode;
        private final List<UUID> players;
        private final Set<UUID> accepted = new HashSet<>();
        private final Set<UUID> ready = new HashSet<>();
        private final Map<UUID, Inventory> views = new HashMap<>();
        private final boolean heads;
        private State state = State.INVITING;
        private BukkitTask task;
        Game(Mode mode, List<UUID> players, boolean heads) {
            this.mode = mode; this.players = players; this.heads = heads;
            accepted.add(players.get(0));
        }
    }

    @Override public void onEnable() {
        saveDefaultConfig();
        escrowFile = new File(getDataFolder(), "escrow.yml");
        YamlConfiguration data = YamlConfiguration.loadConfiguration(escrowFile);
        for (String key : data.getKeys(false)) {
            try {
                UUID id = UUID.fromString(key);
                List<ItemStack> items = new ArrayList<>();
                for (Object value : data.getList(key, new ArrayList<>())) {
                    if (value instanceof ItemStack) items.add(((ItemStack) value).clone());
                }
                if (!items.isEmpty()) escrow.put(id, items);
            } catch (IllegalArgumentException ex) {
                getLogger().warning("Ignoring invalid escrow key: " + key);
            }
        }
        getServer().getPluginManager().registerEvents(this, this);
        for (Player player : Bukkit.getOnlinePlayers()) claim(player);
    }

    @Override public void onDisable() {
        for (Game game : new HashSet<>(busy.values())) cancel(game, "ItemFlip is shutting down.");
    }

    private void saveEscrow() throws IOException {
        YamlConfiguration data = new YamlConfiguration();
        for (Map.Entry<UUID, List<ItemStack>> entry : escrow.entrySet()) {
            if (!entry.getValue().isEmpty()) data.set(entry.getKey().toString(), entry.getValue());
        }
        File temp = new File(getDataFolder(), "escrow.yml.tmp");
        data.save(temp);
        try {
            java.nio.file.Files.move(temp.toPath(), escrowFile.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING, java.nio.file.StandardCopyOption.ATOMIC_MOVE);
        } catch (java.nio.file.AtomicMoveNotSupportedException ex) {
            java.nio.file.Files.move(temp.toPath(), escrowFile.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
        }
    }

    private boolean persist() {
        try { saveEscrow(); return true; }
        catch (IOException ex) { getLogger().severe("Could not save escrow: " + ex.getMessage()); return false; }
    }

    private void claim(Player player) {
        UUID id = player.getUniqueId();
        List<ItemStack> items = escrow.remove(id);
        if (items == null || items.isEmpty()) return;
        if (!persist()) { escrow.put(id, items); player.sendMessage("§cEscrow could not be saved; contact an administrator."); return; }
        for (ItemStack item : items) give(player, item);
        player.sendMessage("§aYour ItemFlip items have been returned or awarded.");
    }

    private void give(Player player, ItemStack item) {
        for (ItemStack overflow : player.getInventory().addItem(item.clone()).values()) {
            player.getWorld().dropItemNaturally(player.getLocation(), overflow);
        }
    }

    private ItemStack icon(String material, String name, String... lore) {
        ItemStack item = XMaterial.matchXMaterial(material).map(XMaterial::parseItem).orElseThrow(() -> new IllegalStateException("Missing material " + material));
        ItemMeta meta = item.getItemMeta();
        meta.setDisplayName(name);
        meta.setLore(Arrays.asList(lore));
        item.setItemMeta(meta);
        return item;
    }

    private void menu(Player player) {
        Menu menu = new Menu("main", null);
        menu.inventory = Bukkit.createInventory(menu, 27, "ItemFlip - Select mode");
        menu.inventory.setItem(11, icon("EMERALD", "§aCoinflip", "§7Click for opponent selection"));
        menu.inventory.setItem(13, icon("DIAMOND", "§bDice", "§7Click for opponent selection"));
        menu.inventory.setItem(15, icon("GOLD_INGOT", "§6Wheel", "§7Click for opponent selection"));
        player.openInventory(menu.inventory);
    }

    private void setup(Player player, Player target) {
        Menu menu = new Menu("setup", target.getUniqueId());
        menu.inventory = Bukkit.createInventory(menu, 27, "Coinflip setup");
        drawSetup(menu);
        player.openInventory(menu.inventory);
    }

    private void drawSetup(Menu menu) {
        OfflinePlayer target = Bukkit.getOfflinePlayer(menu.target);
        menu.inventory.setItem(4, icon("PLAYER_HEAD", "§eOpponent: " + target.getName()));
        menu.inventory.setItem(11, icon("EMERALD", "§aHeads" + (menu.heads ? " §e✔" : "")));
        menu.inventory.setItem(15, icon("DIAMOND", "§bTails" + (!menu.heads ? " §e✔" : "")));
        menu.inventory.setItem(22, icon("GREEN_STAINED_GLASS_PANE", "§aSend request"));
    }

    @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player)) { sender.sendMessage("Players only."); return true; }
        Player player = (Player) sender;
        if (args.length == 2 && args[0].equalsIgnoreCase("accept")) { accept(player, args[1]); return true; }
        if (args.length == 0) { menu(player); return true; }
        Mode mode;
        int offset;
        if (args[0].equalsIgnoreCase("coinflip")) { mode = Mode.COINFLIP; offset = 1; }
        else if (args[0].equalsIgnoreCase("dice")) { mode = Mode.DICE; offset = 1; }
        else if (args[0].equalsIgnoreCase("wheel")) { mode = Mode.WHEEL; offset = 1; }
        else { mode = Mode.COINFLIP; offset = 0; }
        int needed = args.length - offset;
        if (needed < 1 || needed > (mode == Mode.WHEEL ? 2 : 1)) {
            player.sendMessage("§eUse /icf <player>, /icf dice <player>, or /icf wheel <player1> [player2].");
            return true;
        }
        List<Player> opponents = new ArrayList<>();
        Set<UUID> ids = new HashSet<>();
        ids.add(player.getUniqueId());
        for (int i = 0; i < needed; i++) {
            Player target = Bukkit.getPlayerExact(args[offset + i]);