help me write sell axe plugin like donut smp, it should hook into vault api and…
- User
help me write sell axe plugin like donut smp, it should hook into vault api and shopguiplus in order to sell the content inside a chest
- Assistant
Below is a complete, minimal-but-working example of a “Sell-Axe” plugin.
It does four things:- Adds a /sellaxe give command (OP / permission based) that gives the player a special axe.
- Detects when a player right-clicks a chest with that axe.
- Reads every stack inside the chest, asks ShopGUI+ what its sell price is, totals it up and clears the chest.
- Pays the player via Vault and sends a configurable message.
💡 The code is intentionally compact so you can copy-paste and expand it. Comments explain every step.
- Pom.xml (Maven) – set up dependencies
<project> <modelVersion>4.0.0</modelVersion> <groupId>com.yourname</groupId> <artifactId>SellAxe</artifactId> <version>1.0-SNAPSHOT</version> <repositories> <!-- Spigot → needed for compile-time API --> <repository> <id>spigot-repo</id> <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> </repository> <!-- ShopGUI+ repo (brcdev) --> <repository> <id>brcdev-repo</id> <url>https://repo.alonsoaliaga.com/nexus/repository/central/</url> </repository> <!-- Vault --> <repository> <id>enginehub</id> <url>https://maven.enginehub.org/repo/</url> </repository> </repositories> <dependencies> <dependency> <groupId>org.spigotmc</groupId> <artifactId>spigot-api</artifactId> <version>1.20.4-R0.1-SNAPSHOT</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.brcdev.shopgui</groupId> <artifactId>shopgui-api</artifactId> <version>1.90.0</version> <!-- match your ShopGUI+ build --> <scope>provided</scope> </dependency> <dependency> <groupId>com.github.MilkBowl</groupId> <artifactId>VaultAPI</artifactId> <version>1.7</version> <scope>provided</scope> </dependency> </dependencies> </project>Gradle users: translate as usual (
compileOnlyinstead ofprovided).
- plugin.yml
name: SellAxe main: com.yourname.sellaxe.SellAxe api-version: 1.20 version: 1.0 author: yourname depend: [Vault, ShopGUIPlus] # ensure we load after them commands: sellaxe: description: Gives you the Sell Axe usage: /sellaxe give permissions: sellaxe.give: default: op
- Main class (SellAxe.java)
package com.yourname.sellaxe; import me.brcdev.shopgui.ShopGuiPlusApi; import net.milkbowl.vault.economy.Economy; import org.bukkit.NamespacedKey; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.meta.Damageable; import org.bukkit.persistence.PersistentDataType; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.event.Listener; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.block.Action; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; public class SellAxe extends JavaPlugin implements Listener { private Economy econ; private NamespacedKey key; // PDC key to tag the axe @Override public void onEnable() { // Vault if (!setupEconomy()) { getLogger().severe("Vault not found! Disabling."); getServer().getPluginManager().disablePlugin(this); return; } // ShopGUI+ soft check if (!getServer().getPluginManager().isPluginEnabled("ShopGUIPlus")) { getLogger().severe("ShopGUIPlus not found! Disabling."); getServer().getPluginManager().disablePlugin(this); return; } key = new NamespacedKey(this, "sellaxe"); getServer().getPluginManager().registerEvents(this, this); saveDefaultConfig(); // creates config.yml w/ default messages getLogger().info("SellAxe enabled!"); } /* ====================================================== == EVENT LISTENER == ====================================================== */ @EventHandler public void onInteract(PlayerInteractEvent e) { // Right click block check if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return; if (e.getClickedBlock() == null) return; Material type = e.getClickedBlock().getType(); if (type != Material.CHEST && type != Material.TRAPPED_CHEST && type != Material.BARREL) return; ItemStack hand = e.getItem(); if (!isSellAxe(hand)) return; Player p = e.getPlayer(); Inventory inv = ((org.bukkit.block.Container)e.getClickedBlock().getState()).getInventory(); double total = 0; for (ItemStack stack : inv.getContents()) { if (stack == null || stack.getType() == Material.AIR) continue; // Ask ShopGUI+ how much this stack sells for double price = ShopGuiPlusApi.getItemStackPriceSell(p, stack); if (price <= 0) continue; total += price; inv.removeItem(stack); // wipe it } if (total > 0) { econ.depositPlayer(p, total); p.sendMessage(color(getConfig().getString("messages.sold") .replace("{money}", String.format("%.2f", total)))); // optional: damage the axe slightly if (hand.getItemMeta() instanceof Damageable dmg) { dmg.setDamage(dmg.getDamage() + 1); hand.setItemMeta((ItemMeta) dmg); } } else { p.sendMessage(color(getConfig().getString("messages.nothing"))); } e.setCancelled(true); // prevent chest opening sound (optional) } /* ====================================================== == COMMAND == ====================================================== */ @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (!(sender instanceof Player p)) { sender.sendMessage("Player only."); return true; } if (args.length == 1 && args[0].equalsIgnoreCase("give")) { if (!p.hasPermission("sellaxe.give")) { p.sendMessage(ChatColor.RED + "No permission."); return true; } ItemStack axe = createSellAxe(); p.getInventory().addItem(axe); p.sendMessage(ChatColor.GREEN + "Enjoy your Sell Axe!"); return true; } p.sendMessage(ChatColor.RED + "/sellaxe give"); return true; } /* ====================================================== == UTILITY == ====================================================== */ private boolean setupEconomy() { if (getServer().getPluginManager().getPlugin("Vault") == null) return false; RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class); if (rsp == null) return false; econ = rsp.getProvider(); return econ != null; } private ItemStack createSellAxe() { ItemStack axe = new ItemStack(Material.DIAMOND_AXE); ItemMeta meta = axe.getItemMeta(); meta.setDisplayName(ChatColor.GOLD + "Sell Axe"); meta.getPersistentDataContainer().set(key, PersistentDataType.BYTE, (byte) 1); meta.setLore(java.util.Arrays.asList( ChatColor.GRAY + "Right-click chests", ChatColor.GRAY + "to instantly sell their contents!" )); axe.setItemMeta(meta); return axe; } private boolean isSellAxe(ItemStack item) { if (item == null || item.getType() == Material.AIR) return false; ItemMeta meta = item.getItemMeta(); if (meta == null) return false; Byte tag = meta.getPersistentDataContainer().get(key, PersistentDataType.BYTE); return tag != null && tag == 1; } private String color(String s) { return ChatColor.translateAlternateColorCodes('&', s); } }
- config.yml (generated on first run)
messages: sold: '&e[SellAxe] &aYou sold everything for &b${money}&a!' nothing: '&e[SellAxe] &cThere was nothing worth selling in that chest.'Feel free to add options like:
sell-axe: material: GOLDEN_AXE damagePerUse: 1 sound: BLOCK_NOTE_BLOCK_PLING
- Key points & customization tips
• ShopGUI+ API methods
– getItemStackPriceSell(player, itemStack) will automatically respect multipliers, permissions, etc.
If you’re on an older/newer build, the method signature might be slightly different (check the javadocs or open de-compiled jar).• PersistentDataContainer vs. display-name
Using PDC makes sure your axe can’t be faked simply by renaming another axe in an anvil.• Damage / durability
Commented-in snippet shows how to damage the axe by one durability every sell (like DonutSMP). You can also consume XP, add a cooldown, etc.• Async / performance
For very large chests on big servers, consider running the price calculation asynchronously (BukkitScheduler#runTaskAsynchronously) and then scheduling the economy deposit back on the main thread.• External placeholders
If you want to integrate with PlaceholderAPI for messages, cache{money}placeholder accordingly.
- Building & running
mvn clean package
Drop the resulting SellAxe-1.0-SNAPSHOT.jar into your plugins folder together with Vault and ShopGUI+. Reload / restart. Run:
/sellaxe give
Right-click a chest filled with items you can legally sell in any ShopGUI+ shop → they vanish, money appears in your balance!Happy coding & enjoy your Donut-style Sell Axe! 🪓💰
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.