Hamza Gado

create a plugin for a /shop and then it a donutsmp like it a donutsmp shop replica add a nether and end and food and gear and nature and make a /sell

Kodari AI
KodariNov 14 at 11:54 am 3
DonutShopReplica
A Minecraft plugin that recreates the DonutSMP shop experience. Features a comprehensive /shop command with multiple categories including Nether, End, Food, Gear, and Nature sections. Each category contains curated items with configurable prices. Includes a /sell command that allows players to sell items from their inventory at defined rates, with automatic payment in currency. The plugin supports configurable shop stock, item quantities, and pricing through a YAML configuration file. Provides a user-friendly GUI interface with pagination for browsing items, and handles transaction logic securely with inventory validation and economy integration.

I’ll build a DonutSMP-inspired shop with five categories, configurable prices, and /sell hand and /sell all using Vault economy.

Created a DonutSMP-inspired shop with Nether, End, Food, Gear, and Nature categories.

  • /shop opens the shop; /shop reload reloads prices.

  • /sell hand sells the held stack; /sell all sells eligible inventory items.

  • Prices are configurable in config.yml. Custom or modified items aren’t sold.

Requires Vault and a compatible economy plugin.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
5 451
src/main/java/com/kodari/donutshop/DonutShop.java
package com.kodari.donutshop;

import com.cryptomorin.xseries.XMaterial;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
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.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class DonutShop extends JavaPlugin implements Listener {
    private Economy economy;

    private static final class Menu implements InventoryHolder {
        private Inventory inventory;
        private final Map<Integer, String> entries = new HashMap<>();
        private final String category;

        private Menu(String category) {
            this.category = category;
        }

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

    @Override
    public void onEnable() {
        saveDefaultConfig();
        RegisteredServiceProvider<Economy> provider = getServer().getServicesManager().getRegistration(Economy.class);
        if (provider == null || provider.getProvider() == null) {
            getLogger().severe("Vault needs an economy provider; disabling DonutShop.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }
        economy = provider.getProvider();
        getServer().getPluginManager().registerEvents(this, this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (command.getName().equalsIgnoreCase("shop") && args.length == 1 && args[0].equalsIgnoreCase("reload")) {
            if (!sender.hasPermission("donutshop.admin")) {
                sender.sendMessage(color("&cYou don't have permission."));
                return true;
            }
            reloadConfig();
            sender.sendMessage(color("&aShop configuration reloaded."));
            return true;
        }
        if (!(sender instanceof Player)) {
            sender.sendMessage("Only players can use this command.");
            return true;
        }
        Player player = (Player) sender;
        if (command.getName().equalsIgnoreCase("shop")) {
            openCategories(player);
        } else if (args.length == 1 && args[0].equalsIgnoreCase("hand")) {
            sellHand(player);
        } else if (args.length == 1 && args[0].equalsIgnoreCase("all")) {
            sellAll(player);
        } else {
            player.sendMessage(color("&eUse &f/sell hand &eor &f/sell all&e."));
        }
        return true;
    }

    private void openCategories(Player player) {
        Menu menu = new Menu(null);
        menu.inventory = Bukkit.createInventory(menu, 27, color("&8Shop"));
        ConfigurationSection categories = getConfig().getConfigurationSection("categories");
        if (categories != null) {
            int slot = 10;
            for (String key : categories.getKeys(false)) {
                if (slot > 16) break;
                ConfigurationSection category = categories.getConfigurationSection(key);
                if (category == null) continue;
                ItemStack icon = materialItem(category.getString("icon", "STONE"));
                if (icon == null) continue;
                decorate(icon, category.getString("name", key), Arrays.asList("&7Click to browse items"));
                menu.inventory.setItem(slot, icon);
                menu.entries.put(slot++, key);
            }
        }
        player.openInventory(menu.inventory);
    }

    private void openCategory(Player player, String key) {
        ConfigurationSection category = getConfig().getConfigurationSection("categories." + key);
        if (category == null) {
            openCategories(player);
            return;
        }
        Menu menu = new Menu(key);
        menu.inventory = Bukkit.createInventory(menu, 54, color("&8Shop &7» " + category.getString("name", key)));
        ConfigurationSection items = category.getConfigurationSection("items");
        if (items != null) {
            int slot = 0;
            for (String material : items.getKeys(false)) {
                if (slot >= 45) break;
                ItemStack icon = materialItem(material);
                ConfigurationSection item = items.getConfigurationSection(material);
                if (icon == null || item == null) continue;
                double buy = price(item, "buy");
                double sell = price(item, "sell");
                List<String> lore = new ArrayList<>();
                lore.add("&7Buy: " + (buy > 0 ? "&a" + economy.format(buy) : "&cUnavailable"));
                lore.add("&7Sell: " + (sell > 0 ? "&a" + economy.format(sell) : "&cUnavailable"));
                lore.add("&eLeft-click to buy one");
                lore.add("&eShift-left-click to buy a stack");
                lore.add("&eRight-click to sell one");
                lore.add("&eShift-right-click to sell a stack");
                decorate(icon, "&f" + pretty(material), lore);
                menu.inventory.setItem(slot, icon);
                menu.entries.put(slot++, material);
            }
        }
        ItemStack back = materialItem("ARROW");
        if (back != null) {
            decorate(back, "&eBack", Arrays.asList("&7Return to categories"));
            menu.inventory.setItem(49, back);
        }
        player.openInventory(menu.inventory);
    }

    @EventHandler
    public void onClick(InventoryClickEvent event) {
        Inventory top = event.getView().getTopInventory();
        if (!(top.getHolder() instanceof Menu)) return;
        event.setCancelled(true);
        if (!(event.getWhoClicked() instanceof Player) || event.getRawSlot() < 0 || event.getRawSlot() >= top.getSize()) return;
        Player player = (Player) event.getWhoClicked();
        Menu menu = (Menu) top.getHolder();
        if (menu.category != null && event.getRawSlot() == 49) {
            openCategories(player);
            return;
        }
        String entry = menu.entries.get(event.getRawSlot());
        if (entry == null) return;
        if (menu.category == null) {
            openCategory(player, entry);
            return;
        }
        ConfigurationSection item = getConfig().getConfigurationSection("categories." + menu.category + ".items." + entry);
        ItemStack stack = materialItem(entry);
        if (item == null || stack == null) return;
        if (event.isLeftClick()) {
            int amount = event.isShiftClick() ? stack.getMaxStackSize() : 1;
            buy(player, stack, amount, price(item, "buy"));
        } else if (event.isRightClick()) {
            int amount = event.isShiftClick() ? stack.getMaxStackSize() : 1;
            sellType(player, stack.getType(), amount, price(item, "sell"));
        }
    }

    @EventHandler
    public void onDrag(InventoryDragEvent event) {
        if (event.getView().getTopInventory().getHolder() instanceof Menu) event.setCancelled(true);
    }

    private void buy(Player player, ItemStack stack, int amount, double unitPrice) {
        if (unitPrice <= 0) {
            player.sendMessage(color("&cThis item cannot be bought."));
            return;
        }
        int space = 0;
        for (ItemStack existing : player.getInventory().getStorageContents()) {
            if (existing == null || existing.getType().isAir()) space += stack.getMaxStackSize();
            else if (existing.isSimilar(stack)) space += Math.max(0, existing.getMaxStackSize() - existing.getAmount());
        }
        if (space < amount) {
            player.sendMessage(color("&cYou don't have enough inventory space."));
            return;
        }
        double total = unitPrice * amount;
        if (!economy.withdrawPlayer(player, total).transactionSuccess()) {
            player.sendMessage(color("&cPurchase failed. Check your balance."));
            return;
        }
        stack.setAmount(amount);