Mylan Van goor

The Upgrader is a special item used for a risk-and-reward gamble.

When a player right-clicks the Upgrader, a GUI opens.

Left side: The player places the item they want to gamble.

Each item has a set value. The total value is calculated by:

Item value × amount = total value

Example:

1 Flower = 25 value 10 Flowers = 25 × 10 = 250 value 64 Flowers = 25 × 64 = 1,600 value Right side: The player can search through the entire Minecraft item list and choose the item they want to gamble for.

Middle: A circular indicator shows the chance of winning the selected item.

The chance is based on the value of the input item compared to the value of the target item.

For example:

Input: 1,600 value Target: 500 value → Higher chance

Input: 1,600 value Target: 10,000 value → Lower chance

The GUI should display the exact percentage, such as 12.5% Chance.

After selecting the item, the player clicks the Gamble/Upgrade button. The system randomly decides whether the player wins the target item.

The system should support any Minecraft item with a configured value, and the amount can be 1 item up to a full stack (64).

Kodari AI
KodariSep 25 at 5:18 pm 1
RiskUpgrader
A high-stakes gambling plugin where players risk items for a chance to win better ones. Right-clicking the Upgrader opens a GUI with an input slot on the left for placing gamble items, and a searchable item browser on the right to select the target reward. A circular indicator displays the exact win percentage calculated from item values and stack amounts. Clicking the Gamble button triggers a random outcome based on the displayed odds, consuming the input items and granting the target item on success. Supports all Minecraft items with configurable values and stack sizes up to 64.
  1. Build a Paper plugin with a configurable, value-based item catalog and an Upgrader item.

  2. Add the GUI for wagering, searching targets, displaying the chance, and resolving the gamble.

  3. Register the command, listeners, and default configuration.

Implemented the Upgrader plugin. Right-click the item to open its GUI, or use /upgrader to get one and /upgrader open to open the menu directly.

Configure per-item values in config.yml. The GUI lets players wager configured items, search and select configured targets, and see the chance calculated from wager value ÷ target value, capped at 100%. A failed gamble consumes the wager; a win awards one target item.

Mylan Van goor

make sure you can gamble for everything and with everyting en make sure carpets are worth 25 each

Kodari AI
KodariSep 26 at 9:24 am 1
  1. Make every server-supported item a wager and target using a configurable default value.

  2. Set every carpet color to 25 per item, with explicit config entries.

The Upgrader now supports every item available on the server as both a wager and a target. Unconfigured items use a default value of 25 each; existing configured values still override that default. All 16 carpet colors are explicitly set to 25 per carpet.

Mylan Van goor

can i have the new file and make sure when you wanna search a gui comes up with all the items in minecraft exept the dragon egg

Kodari AI
KodariSep 26 at 9:30 am 1
  1. Inspect the current Upgrader menu and click handling to see how target searching works.

  2. Add a dedicated item-search GUI that lists every available item except the dragon egg, and connect it to the Upgrader.

Added ItemSearchMenu.java. Clicking Browse all targets opens a paginated GUI with the available Minecraft items, excluding the Dragon Egg. Players can filter items from that GUI, and selecting one returns them to the Upgrader.

Mylan Van goor

where is the new file

Kodari AI
KodariSep 26 at 9:33 am 1

The new file is src/main/java/com/kodari/upgrader/ItemSearchMenu.java.

Mylan Van goor

can you send it

Kodari AI
KodariSep 26 at 9:33 am 1

ItemSearchMenu.java:

Java
package com.kodari.upgrader;

import com.cryptomorin.xseries.XMaterial;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

public final class ItemSearchMenu implements InventoryHolder {
    private static final int ITEM_SLOTS = 45;
    private final UpgraderPlugin plugin;
    private final UpgraderListener listener;
    private final UpgraderMenu upgraderMenu;
    private final Inventory inventory;
    private String search = "";
    private int page;
    private boolean awaitingSearch;

    public ItemSearchMenu(UpgraderPlugin plugin, UpgraderListener listener, UpgraderMenu upgraderMenu) {
        this.plugin = plugin;
        this.listener = listener;
        this.upgraderMenu = upgraderMenu;
        inventory = Bukkit.createInventory(this, 54, ChatColor.DARK_PURPLE + "Choose Target Item");
        refresh();
    }

    @Override
    public Inventory getInventory() {
        return inventory;
    }

    public UpgraderMenu getUpgraderMenu() {
        return upgraderMenu;
    }

    public void handleClick(Player player, InventoryClickEvent event) {
        int slot = event.getSlot();
        if (slot < ITEM_SLOTS) {
            List<XMaterial> items = filteredItems();
            int itemIndex = page * ITEM_SLOTS + slot;
            if (itemIndex < items.size()) {
                upgraderMenu.selectTarget(items.get(itemIndex));
                player.closeInventory();
            }
            return;
        }

        switch (slot) {
            case 45 -> {
                page = Math.max(0, page - 1);
                refresh();
            }
            case 49 -> requestSearch(player);
            case 53 -> {
                int lastPage = Math.max(0, (filteredItems().size() - 1) / ITEM_SLOTS);
                page = Math.min(lastPage, page + 1);
                refresh();
            }
            default -> {
            }
        }
    }

    public void handleClose(Player player) {
        if (!awaitingSearch) {
            listener.itemSearchClosed(player, this);
        }
    }

    public void beginSearch() {
        awaitingSearch = true;
    }

    public void cancelSearch() {
        awaitingSearch = false;
    }

    public void finishSearch(String query) {
        awaitingSearch = false;
        if (query != null) {
            search = query.toLowerCase(Locale.ROOT);
            page = 0;
        }
        refresh();
    }

    private void requestSearch(Player player) {
        beginSearch();
        listener.beginItemSearch(player, this);
        player.sendMessage(ChatColor.YELLOW + "Type an item name to filter the list, or 'cancel' to keep the current search.");
        player.closeInventory();
    }

    private void refresh() {
        ItemStack background = createItem("BLACK_STAINED_GLASS_PANE", " ", List.of());
        for (int slot = 0; slot < inventory.getSize(); slot++) {
            inventory.setItem(slot, background == null ? null : background.clone());
        }

        List<XMaterial> items = filteredItems();
        int lastPage = Math.max(0, (items.size() - 1) / ITEM_SLOTS);
        page = Math.min(page, lastPage);
        for (int slot = 0; slot < ITEM_SLOTS; slot++) {
            int itemIndex = page * ITEM_SLOTS + slot;
            if (itemIndex >= items.size()) {
                break;
            }

            XMaterial material = items.get(itemIndex);
            ItemStack icon = material.parseItem();
            if (icon == null || icon.getItemMeta() == null) {
                continue;
            }
            icon.setAmount(1);
            ItemMeta meta = icon.getItemMeta();
            meta.setDisplayName(ChatColor.AQUA + displayName(material));
            meta.setLore(List.of(
                ChatColor.GRAY + "Value: " + format(plugin.getItemValue(material)),
                material.equals(upgraderMenu.getSelectedTarget())
                    ? ChatColor.GREEN + "Currently selected"
                    : ChatColor.YELLOW + "Click to choose"
            ));
            icon.setItemMeta(meta);
            inventory.setItem(slot, icon);
        }

        if (items.isEmpty()) {
            inventory.setItem(22, createItem("BARRIER", "&cNo matching items", List.of("&7Try another search term.")));
        }
        inventory.setItem(45, createItem("ARROW", "&ePrevious page", List.of("&7Page " + (page + 1) + " of " + (lastPage + 1))));
        inventory.setItem(49, createItem("PAPER", "&bSearch items", List.of(
            "&7Current: " + (search.isEmpty() ? "All items" : search),
            "&eClick and type in chat."
        )));
        inventory.setItem(50, createItem("BOOK", "&fPage " + (page + 1) + " / " + (lastPage + 1), List.of(
            "&7" + items.size() + " available items",
            "&7Dragon Egg is excluded."
        )));
        inventory.setItem(53, createItem("ARROW", "&eNext page", List.of("&7Page " + (page + 1) + " of " + (lastPage + 1))));
    }

    private List<XMaterial> filteredItems() {
        List<XMaterial> items = new ArrayList<>();
        for (XMaterial material : plugin.getCatalog()) {
            if (material.name().equals("DRAGON_EGG")) {
                continue;
            }
            if (search.isEmpty() || material.name().toLowerCase(Locale.ROOT).contains(search)) {
                items.add(material);
            }
        }
        return items;
    }

    private ItemStack createItem(String materialName, String name, List<String> lore) {
        ItemStack item = XMaterial.matchXMaterial(materialName)
            .map(XMaterial::parseItem)
            .orElseGet(() -> XMaterial.matchXMaterial("PAPER").map(XMaterial::parseItem).orElse(null));
        if (item == null) {
            return null;
        }
        ItemMeta meta = item.getItemMeta();
        if (meta == null) {
            return item;
        }
        meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
        List<String> coloredLore = new ArrayList<>();
        for (String line : lore) {
            coloredLore.add(ChatColor.translateAlternateColorCodes('&', line));
        }
        meta.setLore(coloredLore);
        item.setItemMeta(meta);
        return item;
    }

    private String displayName(XMaterial material) {
        String[] words = material.name().toLowerCase(Locale.ROOT).split("_");
        StringBuilder name = new StringBuilder();
        for (String word : words) {
            if (!name.isEmpty()) {
                name.append(' ');
            }
            name.append(Character.toUpperCase(word.charAt(0))).append(word.substring(1));
        }
        return name.toString();
    }

    private String format(double value) {
        return new DecimalFormat("0.##", DecimalFormatSymbols.getInstance(Locale.US)).format(value);
    }
}
Mylan Van goor

how can i download it

Kodari AI
KodariSep 26 at 9:33 am 1

To save it, create src/main/java/com/kodari/upgrader/ItemSearchMenu.java in your plugin project, then copy the code from my previous message into that file.

If you’re using Kodari’s project workspace, open that file in the file browser and use the workspace’s download/export option if available.

Mylan Van goor

i do not understand

Kodari AI
KodariSep 26 at 9:35 am 1

Sorry—I made that confusing. ItemSearchMenu.java is already in your project. Look in the project’s file list for:

src/main/java/com/kodari/upgrader/ItemSearchMenu.java

Open it, then use your project workspace’s Download or Export option. I can’t attach a separate download link in this chat.

Mylan Van goor

i just clicked on compile and downloaded is that good

Kodari AI
KodariSep 26 at 9:38 am 1

Yes—if the compile finished successfully, the downloaded .jar is the plugin. Put it in your server’s plugins folder and restart the server. Then check the console for any errors.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
8 1,041
src/main/java/com/kodari/upgrader/UpgraderPlugin.java
package com.kodari.upgrader;

import com.cryptomorin.xseries.XMaterial;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.NamespacedKey;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;

public final class UpgraderPlugin extends JavaPlugin implements CommandExecutor {
    private final Map<XMaterial, Double> itemValues = new LinkedHashMap<>();
    private final List<XMaterial> catalog = new ArrayList<>();
    private double defaultItemValue = 25.0;
    private NamespacedKey upgraderKey;
    private UpgraderListener listener;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        upgraderKey = new NamespacedKey(this, "upgrader");
        loadItemValues();
        listener = new UpgraderListener(this);
        getServer().getPluginManager().registerEvents(listener, this);
        getCommand("upgrader").setExecutor(this);
    }

    @Override
    public void onDisable() {
        if (listener != null) {
            listener.shutdown();
        }
    }

    private void loadItemValues() {
        defaultItemValue = getConfig().getDouble("default-item-value", 25.0);
        if (!Double.isFinite(defaultItemValue) || defaultItemValue <= 0.0) {
            getLogger().warning("Invalid default-item-value; using 25.0");
            defaultItemValue = 25.0;
        }

        ConfigurationSection section = getConfig().getConfigurationSection("item-values");
        if (section != null) {
            for (String key : section.getKeys(false)) {
                double value = section.getDouble(key, 0.0);
                if (!Double.isFinite(value) || value <= 0.0) {
                    getLogger().warning("Ignoring non-positive item value for " + key);
                    continue;
                }

                XMaterial.matchXMaterial(key).ifPresent(material -> {
                    if (material.parseItem() != null) {
                        itemValues.put(material, value);
                    } else {
                        getLogger().warning("Ignoring non-item material in item-values: " + key);
                    }
                });
            }
        }

        Set<XMaterial> availableItems = new LinkedHashSet<>(itemValues.keySet());
        for (XMaterial material : XMaterial.values()) {
            ItemStack item = material.parseItem();
            if (item != null && !item.getType().name().equals("AIR")) {
                availableItems.add(XMaterial.matchXMaterial(item.getType()));
            }
        }
        catalog.addAll(availableItems);
        catalog.sort(Comparator.comparing(XMaterial::name));
    }

    public List<XMaterial> getCatalog() {
        return catalog;
    }

    public double getItemValue(ItemStack item) {
        if (item == null || item.getAmount() <= 0) {
            return 0.0;
        }
        XMaterial material = XMaterial.matchXMaterial(item.getType());
        return itemValues.getOrDefault(material, defaultItemValue);
    }

    public double getItemValue(XMaterial material) {
        return itemValues.getOrDefault(material, defaultItemValue);
    }

    public ItemStack createUpgraderItem() {
        String materialName = getConfig().getString("upgrader-item.material", "NETHER_STAR");
        ItemStack item = XMaterial.matchXMaterial(materialName)
            .map(XMaterial::parseItem)
            .orElseGet(() -> XMaterial.matchXMaterial("NETHER_STAR").map(XMaterial::parseItem).orElse(null));
        if (item == null) {
            return null;
        }

        ItemMeta meta = item.getItemMeta();
        if (meta == null) {
            return null;
        }
        String name = getConfig().getString("upgrader-item.name", "&d&lUpgrader");
        meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
        List<String> lore = new ArrayList<>();
        for (String line : getConfig().getStringList("upgrader-item.lore")) {
            lore.add(ChatColor.translateAlternateColorCodes('&', line));
        }
        meta.setLore(lore);
        meta.getPersistentDataContainer().set(upgraderKey, PersistentDataType.BYTE, (byte) 1);
        item.setItemMeta(meta);
        return item;
    }

    public boolean isUpgraderItem(ItemStack item) {
        if (item == null || item.getAmount() <= 0 || !item.hasItemMeta()) {
            return false;
        }
        ItemMeta meta = item.getItemMeta();
        return meta != null && meta.getPersistentDataContainer().has(upgraderKey, PersistentDataType.BYTE);
    }

    public void openMenu(Player player) {
        listener.openMenu(player);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player player)) {
            sender.sendMessage("This command can only be used by a player.");
            return true;
        }

        if (args.length > 0 && args[0].equalsIgnoreCase("open")) {
            openMenu(player);
            return true;
        }

        ItemStack upgrader = createUpgraderItem();
        if (upgrader == null) {
            player.sendMessage(ChatColor.RED + "The configured Upgrader item is invalid.");
            return true;
        }
        Map<Integer, ItemStack> leftovers = player.getInventory().addItem(upgrader);
        leftovers.values().forEach(leftover -> player.getWorld().dropItemNaturally(player.getLocation(), leftover));
        player.sendMessage(ChatColor.GREEN + "You received an Upgrader.");
        return true;
    }
}