Skylar
📎 1 file 1,921 chars
📄
pasted-code-1794524060421.txt
txt 27 lines
▶
Act as an expert Minecraft plugin developer specializing in Spigot/Bukkit (using Java and Maven or Gradle). 

I need a complete code architecture and implementation guide for a custom server-side "Doughnut SMP" Gambling and Economy plugin. Ensure all item metadata, inventories, and event listeners use standard Spigot-compatible APIs (such as PersistentDataContainer for custom item data and Inventory views for GUIs).

The plugin must feature the following core systems:

1. Rigged Arrow / Archery Game:
- A custom target tracking system using block break, interact, or projectile hit events.
- Server-side "rigging" configuration (toggled via operator permissions or config files) that overrides hit detection to guarantee wins, losses, or specific ring scores on demand.

2. Contract & Paper Document System:
- Custom paper items representing contracts, debt IOU notes, or casino licenses.
- Utilizing Spigot's PersistentDataContainer to securely store signed player UUIDs, debt values, and contract terms directly inside the paper item's metadata so they cannot be exploited.

3. Interactive Blackjack Table:
- A custom graphical user interface (GUI) opened by interacting with a designated block or NPC/item frame setup.
- A clean visual card layout using renamed items, stained glass, or map arts representing cards and betting chips.
- Built-in administrative rigging logic to secretly manipulate dealer draws or player win rates based on server configurations.

4. Visual & Aesthetic Polish:
- Particle effects and sound cues matching a vibrant "Doughnut SMP" theme upon wins/losses.

Please provide:
- The main `JavaPlugin` entry point class and plugin.yml setup.
- Event listeners for the Arrow target game and the Blackjack GUI interaction.
- Code for storing and reading custom debt data on paper items using PersistentDataContainer.
- Server-side command structure for the hidden "rigging" toggle mechanics.
Kodari AI
KodariNov 12 at 11:03 pm 3
DoughnutGambling
A comprehensive gambling and economy plugin for Doughnut SMP featuring a rigged archery target game with configurable win/loss outcomes, a contract and debt paper system using PersistentDataContainer for secure player data storage, an interactive blackjack GUI with hidden admin rigging capabilities, and vibrant particle/sound effects for wins and losses. Includes admin commands to toggle rigging modes, manage contracts, and control casino operations.

I’ll build the games around a persistent, plugin-managed credit balance, with operator controls for rigging and signed paper documents. Blackjack wagers will be forfeited if a player closes the table before finishing.

Built the casino plugin with archery scoring, a blackjack table, persistent casino credits, signed paper documents, effects, and operator-only rigging commands.

Use /casino help for commands. Operators can designate blocks with /casino settable and /casino settarget. Blackjack rigging controls the settled outcome; archery rigging controls the reported score.

Document signatures detect altered stored data, but they do not prevent copying a valid item. Documents are records only—they don’t automatically collect debts or enforce contracts.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
4 463
src/main/java/com/kodari/casino/DoughnutCasino.java
package com.kodari.casino;

import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XSound;
import com.cryptomorin.xseries.particles.XParticle;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.UUID;

public final class DoughnutCasino extends JavaPlugin implements Listener {
    private File dataFile;
    private YamlConfiguration data;
    private byte[] secret;
    private NamespacedKey documentKey;
    private NamespacedKey signatureKey;
    private final SecureRandom random = new SecureRandom();

    @Override
    public void onEnable() {
        saveDefaultConfig();
        dataFile = new File(getDataFolder(), "data.yml");
        data = YamlConfiguration.loadConfiguration(dataFile);
        String savedSecret = data.getString("document-secret");
        if (savedSecret == null) {
            secret = new byte[32];
            random.nextBytes(secret);
            data.set("document-secret", Base64.getEncoder().encodeToString(secret));
            saveData();
        } else {
            try {
                secret = Base64.getDecoder().decode(savedSecret);
            } catch (IllegalArgumentException ex) {
                getLogger().severe("Invalid document secret; refusing to start.");
                getServer().getPluginManager().disablePlugin(this);
                return;
            }
        }
        documentKey = new NamespacedKey(this, "document");
        signatureKey = new NamespacedKey(this, "signature");
        getServer().getPluginManager().registerEvents(this, this);
    }

    @Override
    public void onDisable() {
        if (data != null) saveData();
    }

    private void saveData() {
        try {
            data.save(dataFile);
        } catch (IOException ex) {
            getLogger().severe("Could not save casino data: " + ex.getMessage());
        }
    }

    private long balance(UUID id) {
        return Math.max(0, data.getLong("balances." + id, 0));
    }

    private void setBalance(UUID id, long value) {
        data.set("balances." + id, value);
        saveData();
    }

    private String color(String text) {
        return ChatColor.translateAlternateColorCodes('&', text);
    }

    private ItemStack icon(String material, String name, String... lore) {
        ItemStack item = XMaterial.matchXMaterial(material).map(XMaterial::parseItem).orElse(null);
        if (item == null) item = XMaterial.matchXMaterial("PAPER").map(XMaterial::parseItem).orElseThrow(IllegalStateException::new);
        ItemMeta meta = item.getItemMeta();
        meta.setDisplayName(color(name));
        List<String> lines = new ArrayList<>();
        for (String line : lore) lines.add(color(line));
        meta.setLore(lines);
        item.setItemMeta(meta);
        return item;
    }

    private String sign(String payload) {
        try {
            Mac mac = Mac.getInstance("HmacSHA256");
            mac.init(new SecretKeySpec(secret, "HmacSHA256"));
            return Base64.getEncoder().encodeToString(mac.doFinal(payload.getBytes(StandardCharsets.UTF_8)));
        } catch (Exception ex) {
            throw new IllegalStateException("Cannot sign document", ex);
        }
    }

    private ItemStack document(UUID issuer, UUID subject, long debt, String type, String terms) {
        String encodedTerms = Base64.getEncoder().encodeToString(terms.getBytes(StandardCharsets.UTF_8));
        String payload = "1|" + UUID.randomUUID() + "|" + issuer + "|" + subject + "|" + debt + "|" + type + "|" + encodedTerms;
        ItemStack item = icon("PAPER", "&dCasino " + type, "&7Subject: &f" + subject, "&7Debt: &e" + debt + " credits", "&7Terms: &f" + terms, "&8Use /casino inspect to verify.");
        ItemMeta meta = item.getItemMeta();
        meta.getPersistentDataContainer().set(documentKey, PersistentDataType.STRING, payload);
        meta.getPersistentDataContainer().set(signatureKey, PersistentDataType.STRING, sign(payload));
        item.setItemMeta(meta);
        return item;
    }

    private void inspect(Player player) {
        ItemStack item = player.getInventory().getItemInMainHand();
        if (!item.hasItemMeta()) {
            player.sendMessage(color("&cHold a signed casino document."));
            return;
        }
        PersistentDataContainer pdc = item.getItemMeta().getPersistentDataContainer();
        String payload = pdc.get(documentKey, PersistentDataType.STRING);
        String signature = pdc.get(signatureKey, PersistentDataType.STRING);
        if (payload == null || signature == null || !MessageDigest.isEqual(sign(payload).getBytes(StandardCharsets.UTF_8), signature.getBytes(StandardCharsets.UTF_8))) {
            player.sendMessage(color("&cInvalid or altered casino document."));
            return;
        }
        try {
            String[] parts = payload.split("\\|", -1);
            if (parts.length != 7 || !parts[0].equals("1")) throw new IllegalArgumentException();
            UUID.fromString(parts[1]);
            UUID.fromString(parts[2]);
            UUID.fromString(parts[3]);
            Long.parseLong(parts[4]);
            String terms = new String(Base64.getDecoder().decode(parts[6]), StandardCharsets.UTF_8);
            player.sendMessage(color("&aVerified " + parts[5] + " &7#" + parts[1]));
            player.sendMessage(color("&7Issuer: &f" + parts[2] + " &7Subject: &f" + parts[3]));
            player.sendMessage(color("&7Debt: &e" + parts[4] + " &7Terms: &f" + terms));
        } catch (IllegalArgumentException ex) {
            player.sendMessage(color("&cMalformed casino document."));
        }
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (args.length == 0 || args[0].equalsIgnoreCase("help")) {
            sender.sendMessage(color("&d/casino balance &7| &d/casino inspect &7| Right-click a casino table to play."));
            if (sender.hasPermission("doughnutcasino.admin")) {
                sender.sendMessage(color("&7Admin: /casino settable|settarget|grant|document|rig"));
                sender.sendMessage(color("&7/ casino rig blackjack normal|win|lose; archery normal|win|lose|score [0-10]".replace("/ casino", "/casino")));
            }
            return true;
        }
        String sub = args[0].toLowerCase(Locale.ROOT);
        if (sub.equals("balance") && sender instanceof Player) {
            sender.sendMessage(color("&dCasino balance: &e" + balance(((Player) sender).getUniqueId()) + " credits"));
            return true;
        }
        if (sub.equals("inspect") && sender instanceof Player) {
            inspect((Player) sender);
            return true;
        }
        if (!sender.hasPermission("doughnutcasino.admin")) {
            sender.sendMessage(color("&cYou don't have permission."));
            return true;
        }
        if ((sub.equals("settable") || sub.equals("settarget")) && sender instanceof Player) {
            Block block = ((Player) sender).getTargetBlockExact(5);
            if (block == null) sender.sendMessage(color("&cLook at a block within five blocks."));
            else {
                data.set(sub.equals("settable") ? "table" : "target", block.getLocation());
                saveData();
                sender.sendMessage(color("&aCasino block set."));
            }
            return true;
        }