Scary M10

name: DonutSMPToolsShop version: 1.0 main: com.donutsmp.shop.DonutSMPToolsShop api-version: '1.21' depend: [Vault]

commands: donutsmptools: description: Opens the DonutSMP Tools Shop permission: donutsmp.shop.use permission-message: "§cYou do not have permission to open this shop!"

📎 1 file 10,499 chars
📄
pasted-code-1792469192671.txt
txt 253 lines
▶
package com.donutsmp.shop;

import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.ArrayList;
import java.util.List;

public class DonutSMPToolsShop extends JavaPlugin implements Listener, CommandExecutor {

    private static Economy econ = null;
    private final String GUI_TITLE = ChatColor.DARK_PURPLE + "" + ChatColor.BOLD + "DonutSMP Tools Shop";
    private final double TOOL_PRICE = 1000000.0; // 1 Million
    private NamespacedKey toolKey;

    @Override
    public void onEnable() {
        toolKey = new NamespacedKey(this, "custom_tool_id");

        if (!setupEconomy()) {
            getLogger().severe("Vault or Economy plugin not found! Disabling plugin.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }

        if (this.getCommand("donutsmptools") != null) {
            this.getCommand("donutsmptools").setExecutor(this);
        }

        getServer().getPluginManager().registerEvents(this, this);
        getLogger().info("DonutSMP Tools Shop Plugin (3x3 Mining) successfully enabled!");
    }

    private boolean setupEconomy() {
        if (getServer().getPluginManager().getPlugin("Vault") == null) return false;
        RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Economy.class);
        if (rsp == null) return false;
        econ = rsp.getProvider();
        return econ != null;
    }

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

    public void openShopGUI(Player player) {
        Inventory gui = Bukkit.createInventory(null, 27, GUI_TITLE);

        // Slot 11: Amethyst Pickaxe
        gui.setItem(11, createShopDisplayItem(Material.DIAMOND_PICKAXE, 
                ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Amethyst Pickaxe", 
                ChatColor.GRAY + "Ability: " + ChatColor.LIGHT_PURPLE + "3x3 (9 Blocks) Area Mining"));

        // Slot 13: Amethyst Axe
        gui.setItem(13, createShopDisplayItem(Material.DIAMOND_AXE, 
                ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Amethyst Axe", 
                ChatColor.GRAY + "Ability: " + ChatColor.RED + "Ultra High Efficiency & Damage"));

        // Slot 15: Amethyst Shovel
        gui.setItem(15, createShopDisplayItem(Material.DIAMOND_SHOVEL, 
                ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Amethyst Shovel", 
                ChatColor.GRAY + "Ability: " + ChatColor.YELLOW + "Instant Digging"));

        player.openInventory(gui);
    }

    private ItemStack createShopDisplayItem(Material material, String name, String specialLore) {
        ItemStack item = new ItemStack(material);
        ItemMeta meta = item.getItemMeta();
        if (meta != null) {
            meta.setDisplayName(name);
            List lore = new ArrayList<>();
            lore.add(specialLore);
            lore.add(ChatColor.GRAY + "Price: " + ChatColor.GREEN + "$1,000,000");
            lore.add("");
            lore.add(ChatColor.YELLOW + "Click to buy!");
            meta.setLore(lore);
            item.setItemMeta(meta);
        }
        return item;
    }

    // --- Custom Tool Generation ---
    private ItemStack createCustomTool(String toolType) {
        ItemStack item;
        ItemMeta meta;

        switch (toolType) {
            case "amethyst_pickaxe":
                item = new ItemStack(Material.DIAMOND_PICKAXE);
                meta = item.getItemMeta();
                if (meta != null) {
                    meta.setDisplayName(ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Amethyst Pickaxe");
                    List lore = new ArrayList<>();
                    lore.add(ChatColor.LIGHT_PURPLE + "✦ DonutSMP Special Tool");
                    lore.add(ChatColor.GRAY + "Mines a " + ChatColor.GOLD + "3x3 (9 Blocks)" + ChatColor.GRAY + " area at once!");
                    meta.setLore(lore);
                    meta.addEnchant(Enchantment.EFFICIENCY, 5, true);
                    meta.addEnchant(Enchantment.UNBREAKING, 3, true);
                    meta.addEnchant(Enchantment.FORTUNE, 3, true);
                    meta.getPersistentDataContainer().set(toolKey, PersistentDataType.STRING, "amethyst_pickaxe");
                    item.setItemMeta(meta);
                }
                return item;

            case "amethyst_axe":
                item = new ItemStack(Material.DIAMOND_AXE);
                meta = item.getItemMeta();
                if (meta != null) {
                    meta.setDisplayName(ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Amethyst Axe");
                    List lore = new ArrayList<>();
                    lore.add(ChatColor.LIGHT_PURPLE + "✦ DonutSMP Special Tool");
                    meta.setLore(lore);
                    meta.addEnchant(Enchantment.EFFICIENCY, 6, true);
                    meta.addEnchant(Enchantment.UNBREAKING, 3, true);
                    meta.addEnchant(Enchantment.SHARPNESS, 5, true);
                    meta.getPersistentDataContainer().set(toolKey, PersistentDataType.STRING, "amethyst_axe");
                    item.setItemMeta(meta);
                }
                return item;

            case "amethyst_shovel":
                item = new ItemStack(Material.DIAMOND_SHOVEL);
                meta = item.getItemMeta();
                if (meta != null) {
                    meta.setDisplayName(ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Amethyst Shovel");
                    List lore = new ArrayList<>();
                    lore.add(ChatColor.LIGHT_PURPLE + "✦ DonutSMP Special Tool");
                    meta.setLore(lore);
                    meta.addEnchant(Enchantment.EFFICIENCY, 5, true);
                    meta.addEnchant(Enchantment.UNBREAKING, 3, true);
                    meta.getPersistentDataContainer().set(toolKey, PersistentDataType.STRING, "amethyst_shovel");
                    item.setItemMeta(meta);
                }
                return item;

            default:
                return new ItemStack(Material.AIR);
        }
    }

    // --- GUI Inventory Click Event ---
    @EventHandler
    public void onInventoryClick(InventoryClickEvent event) {
        if (!event.getView().getTitle().equals(GUI_TITLE)) return;
        event.setCancelled(true); // Prevents taking items from GUI

        if (event.getCurrentItem() == null || event.getCurrentItem().getType() == Material.AIR) return;

        Player player = (Player) event.getWhoClicked();
        int slot = event.getSlot();

        String toolType = "";
        String toolName = "";

        if (slot == 11) {
            toolType = "amethyst_pickaxe";
            toolName = "Amethyst Pickaxe";
        } else if (slot == 13) {
            toolType = "amethyst_axe";
            toolName = "Amethyst Axe";
        } else if (slot == 15) {
            toolType = "amethyst_shovel";
            toolName = "Amethyst Shovel";
        } else {
            return;
        }

        if (econ.getBalance(player) >= TOOL_PRICE) {
            econ.withdrawPlayer(player, TOOL_PRICE);
            
            // Give item directly with intact Persistent NBT Data
            ItemStack tool = createCustomTool(toolType);
            player.getInventory().addItem(tool);

            player.sendMessage(ChatColor.GREEN + "✔ You have successfully purchased the " + toolName + " for $1,000,000!");
            player.closeInventory();
        } else {
            player.sendMessage(ChatColor.RED + "✖ You do not have enough money! ($1,000,000 required)");
        }
    }

    // --- 3x3 (9 Blocks) Mining Logic for Amethyst Pickaxe ---
    @EventHandler
    public void onBlockBreak(BlockBreakEvent event) {
        Player player = event.getPlayer();
        ItemStack tool = player.getInventory().getItemInMainHand();

        if (tool == null || !tool.hasItemMeta()) return;

        ItemMeta meta = tool.getItemMeta();
        if (meta == null) return;

        // Check if item is the Amethyst Pickaxe
        String toolId = meta.getPersistentDataContainer().get(toolKey, PersistentDataType.STRING);
        if (toolId == null || !toolId.equals("amethyst_pickaxe")) return;

        Block targetBlock = event.getBlock();

        // Prevent unbreakable blocks from breaking
        if (targetBlock.getType() == Material.BEDROCK || targetBlock.getType() == Material.BARRIER) return;

        BlockFace face = player.getTargetBlockFace(5);
        if (face == null) return;

        // Break 3x3 area based on player face angle
        for (int x = -1; x <= 1; x++) {
            for (int y = -1; y <= 1; y++) {
                for (int z = -1; z <= 1; z++) {
                    if (face == BlockFace.UP || face == BlockFace.DOWN) {
                        if (y != 0) continue;
                    } else if (face == BlockFace.NORTH || face == BlockFace.SOUTH) {
                        if (z != 0) continue;
                    } else if (face == BlockFace.EAST || face == BlockFace.WEST) {
                        if (x != 0) continue;
                    }

                    Block relative = targetBlock.getRelative(x, y, z);
                    if (relative.getType() != Material.AIR && relative.getType() != Material.BEDROCK && relative.getType() != Material.BARRIER) {
                        relative.breakNaturally(tool);
                    }
                }
            }
        }
    }
}
Kodari AI
KodariOct 20 at 4:08 am 1
DonutSMPToolsShop
A Minecraft plugin that provides a Vault-based economy GUI shop for purchasing custom amethyst tools. Players open a 27-slot inventory interface via command, displaying three purchasable items: the Amethyst Pickaxe with 3x3 area mining, the Amethyst Axe with enhanced efficiency, and the Amethyst Shovel for instant digging. Each tool costs $1,000,000, features custom enchantments and persistent data tags, and is verified through the plugin's click handler. The pickaxe implements a BlockBreakEvent listener that calculates the player's target face and breaks a 3x3 block area while protecting unbreakable materials. The plugin integrates with Vault economy for balance checking and transactions.

I’ll create the Vault-backed shop plugin with its command metadata and the three custom tools, including the pickaxe’s 3×3 mining behavior.

Created the DonutSMP Tools Shop plugin with /donutsmptools, Vault purchases for $1,000,000, and custom pickaxe, axe, and shovel items. The pickaxe mines a 3×3 area.

Kodari can make mistakes. Review important code before using.
Files
src
Code
2 301
src/main/java/com/donutsmp/shop/DonutSMPToolsShop.java
package com.donutsmp.shop;

import com.cryptomorin.xseries.XEnchantment;
import com.cryptomorin.xseries.XMaterial;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.NamespacedKey;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

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

public class DonutSMPToolsShop extends JavaPlugin implements Listener, CommandExecutor {

    private static final String GUI_TITLE = ChatColor.DARK_PURPLE + "" + ChatColor.BOLD + "DonutSMP Tools Shop";
    private static final double TOOL_PRICE = 1_000_000.0;
    private Economy economy;
    private NamespacedKey toolKey;

    @Override
    public void onEnable() {
        toolKey = new NamespacedKey(this, "custom_tool_id");

        if (!setupEconomy()) {
            getLogger().severe("Vault or an economy provider was not found. Disabling plugin.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }

        if (getCommand("donutsmptools") == null) {
            getLogger().severe("The donutsmptools command is missing from plugin.yml.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }

        getCommand("donutsmptools").setExecutor(this);
        getServer().getPluginManager().registerEvents(this, this);
        getLogger().info("DonutSMP Tools Shop enabled.");
    }

    private boolean setupEconomy() {
        if (getServer().getPluginManager().getPlugin("Vault") == null) {
            return false;
        }

        RegisteredServiceProvider<Economy> registration = getServer().getServicesManager().getRegistration(Economy.class);
        if (registration == null) {
            return false;
        }

        economy = registration.getProvider();
        return economy != null;
    }

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

        openShopGUI(player);
        return true;
    }

    private void openShopGUI(Player player) {
        Inventory gui = Bukkit.createInventory(null, 27, GUI_TITLE);
        setShopItem(gui, 11, "DIAMOND_PICKAXE", ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Amethyst Pickaxe",
                ChatColor.GRAY + "Ability: " + ChatColor.LIGHT_PURPLE + "3x3 (9 Blocks) Area Mining");
        setShopItem(gui, 13, "DIAMOND_AXE", ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Amethyst Axe",
                ChatColor.GRAY + "Ability: " + ChatColor.RED + "Ultra High Efficiency & Damage");
        setShopItem(gui, 15, "DIAMOND_SHOVEL", ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Amethyst Shovel",
                ChatColor.GRAY + "Ability: " + ChatColor.YELLOW + "Instant Digging");
        player.openInventory(gui);
    }

    private void setShopItem(Inventory inventory, int slot, String material, String name, String ability) {
        ItemStack item = createShopDisplayItem(material, name, ability);
        if (item != null) {
            inventory.setItem(slot, item);
        }
    }

    private ItemStack createShopDisplayItem(String materialName, String name, String specialLore) {
        ItemStack item = XMaterial.matchXMaterial(materialName).map(XMaterial::parseItem).orElse(null);
        if (item == null) {
            return null;
        }

        ItemMeta meta = item.getItemMeta();
        if (meta == null) {
            return null;
        }

        meta.setDisplayName(name);
        List<String> lore = new ArrayList<>();
        lore.add(specialLore);
        lore.add(ChatColor.GRAY + "Price: " + ChatColor.GREEN + "$1,000,000");
        lore.add("");
        lore.add(ChatColor.YELLOW + "Click to buy!");
        meta.setLore(lore);
        item.setItemMeta(meta);
        return item;
    }

    private ItemStack createCustomTool(String toolType) {
        String materialName;
        switch (toolType) {
            case "amethyst_pickaxe" -> materialName = "DIAMOND_PICKAXE";
            case "amethyst_axe" -> materialName = "DIAMOND_AXE";
            case "amethyst_shovel" -> materialName = "DIAMOND_SHOVEL";
            default -> {
                return null;
            }
        }

        ItemStack item = XMaterial.matchXMaterial(materialName).map(XMaterial::parseItem).orElse(null);
        if (item == null) {
            return null;
        }

        ItemMeta meta = item.getItemMeta();
        if (meta == null) {
            return null;
        }

        String toolName = switch (toolType) {
            case "amethyst_pickaxe" -> "Amethyst Pickaxe";
            case "amethyst_axe" -> "Amethyst Axe";
            default -> "Amethyst Shovel";
        };
        meta.setDisplayName(ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + toolName);

        List<String> lore = new ArrayList<>();
        lore.add(ChatColor.LIGHT_PURPLE + "✦ DonutSMP Special Tool");
        if (toolType.equals("amethyst_pickaxe")) {
            lore.add(ChatColor.GRAY + "Mines a " + ChatColor.GOLD + "3x3 (9 Blocks)" + ChatColor.GRAY + " area at once!");
        }
        meta.setLore(lore);

        switch (toolType) {
            case "amethyst_pickaxe" -> {
                addEnchantment(meta, "EFFICIENCY", 5);
                addEnchantment(meta, "UNBREAKING", 3);
                addEnchantment(meta, "FORTUNE", 3);
            }
            case "amethyst_axe" -> {
                addEnchantment(meta, "EFFICIENCY", 6);
                addEnchantment(meta, "UNBREAKING", 3);
                addEnchantment(meta, "SHARPNESS", 5);
            }
            case "amethyst_shovel" -> {
                addEnchantment(meta, "EFFICIENCY", 5);
                addEnchantment(meta, "UNBREAKING", 3);
            }
            default -> {
                return null;
            }
        }

        meta.getPersistentDataContainer().set(toolKey, PersistentDataType.STRING, toolType);
        item.setItemMeta(meta);
        return item;
    }

    private void addEnchantment(ItemMeta meta, String enchantmentName, int level) {
        XEnchantment.matchXEnchantment(enchantmentName)
                .ifPresent(enchantment -> meta.addEnchant(enchantment.getEnchant(), level, true));
    }

    @EventHandler
    public void onInventoryClick(InventoryClickEvent event) {
        if (!GUI_TITLE.equals(event.getView().getTitle())) {
            return;
        }

        event.setCancelled(true);
        if (!(event.getWhoClicked() instanceof Player player) || event.getRawSlot() < 0
                || event.getRawSlot() >= event.getView().getTopInventory().getSize()) {
            return;
        }