12345bartek
📎 1 file 1,340 chars
📄
pasted-code-1777316657638.txt
txt 49 lines
▶
Create a Minecraft plugin (Spigot/Paper 1.20+) that allows creating special items (vouchers) which, when right-clicked, give the player previously saved items.

Requirements:

1. Command: /voucher create 

* saves the item currently held in the player's hand as a voucher
* saves FULL NBT data (name, enchantments, lore, everything)

2. Command: /voucher setitems 

* saves the current items from the player's inventory (either full inventory or armor + hotbar — choose the best approach)
* these items will be given as rewards when the voucher is used

3. On RIGHT CLICK with the voucher:

* check if the item is a registered voucher
* give the saved items to the player
* remove 1 voucher from the player's hand
* send a configurable message to the player

4. Config:

* customizable messages
* option to remove the item after use
* optional cooldown

5. Store all data in a YAML file

6. Safety requirements:

* no item duplication exploits
* only works on RIGHT CLICK
* should not interact with blocks like bedrock (avoid bugs/exploits)

7. Permissions:

* voucher.create
* voucher.setitems

8. Code structure:

* clean, well-organized classes (Main, Command, Listener, Manager)

Language: Java
API: Spigot / Paper

Generate full plugin code + plugin.yml + example config.yml
Kodari AI
KodariApr 27 at 7:05 pm 8,955 (v2)

I’ll create a comprehensive voucher system plugin with full NBT preservation and exploit prevention.

VoucherSystem
A voucher system that allows creating special items which give players saved rewards when right-clicked. Features full NBT preservation, configurable messages, cooldown system, and YAML storage. Includes anti-duplication measures and safe item handling to prevent exploits.

✅ VoucherSystem Plugin Created

Structure:

  • VoucherSystem.java - Main plugin with config message handling

  • VoucherManager.java - Handles voucher storage, cooldowns, validation, and Base64 item serialization

  • VoucherData.java - Lombok data class for voucher information

  • VoucherCommand.java - Commands for creating vouchers and setting rewards

  • VoucherListener.java - Right-click handler with exploit prevention

  • plugin.yml - Plugin metadata and permissions

  • config.yml - Fully customizable messages and settings

Anti-Exploit Features: ✓ PersistentDataContainer marks vouchers (NBT-based, impossible to fake)
✓ Only right-click interaction (left-click ignored)
✓ Block interaction prevention (no bedrock exploits)
✓ Cooldown system prevents spam
✓ Inventory space check before giving items
✓ Atomic item removal (checks amount > 1)
✓ Full NBT preservation via Bukkit serialization

Commands:

  • /voucher create <name> - Creates voucher from held item

  • /voucher setitems <name> - Saves inventory items as rewards

Permissions:

  • voucher.create - Create vouchers

  • voucher.setitems - Set reward items

Config Options:

  • Customizable messages with placeholders

  • Remove item after use toggle

  • Cooldown duration

  • Block interaction prevention

  • Inventory save mode (FULL/HOTBAR_AND_ARMOR/MAIN_ONLY)

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
manifest.kod
Code
9 622
src/main/java/com/example/vouchersystem/VoucherSystem.java
package com.example.vouchersystem;

import com.example.vouchersystem.command.VoucherCommand;
import com.example.vouchersystem.listener.VoucherListener;
import com.example.vouchersystem.manager.VoucherManager;
import lombok.Getter;
import org.bukkit.plugin.java.JavaPlugin;

@Getter
public class VoucherSystem extends JavaPlugin {
    
    private VoucherManager voucherManager;
    
    @Override
    public void onEnable() {
        saveDefaultConfig();
        
        this.voucherManager = new VoucherManager(this);
        this.voucherManager.loadVouchers();
        
        getCommand("voucher").setExecutor(new VoucherCommand(this));
        getServer().getPluginManager().registerEvents(new VoucherListener(this), this);
        
        getLogger().info("VoucherSystem has been enabled!");
    }
    
    @Override
    public void onDisable() {
        if (voucherManager != null) {
            voucherManager.saveVouchers();
        }
        getLogger().info("VoucherSystem has been disabled!");
    }
    
    public String getMessage(String key) {
        String prefix = getConfig().getString("messages.prefix", "&8[&6Voucher&8]&r ");
        String message = getConfig().getString("messages." + key, "&cMessage not found: " + key);
        return colorize(prefix + message);
    }
    
    public String getMessageWithoutPrefix(String key) {
        String message = getConfig().getString("messages." + key, "&cMessage not found: " + key);
        return colorize(message);
    }
    
    public String colorize(String message) {
        return message.replace("&", "§");
    }
}