cosa112233
๐Ÿ“Ž 1 file 1,472 chars
๐Ÿ“„
pasted-code-1772429556953.txt
txt 53 lines
โ–ถ
Create a complete Minecraft plugin for Spigot/Paper (latest version 1.21) using Java.

Plugin name: RandomBuilderTool

Features:

1. Add a custom item:
   - Type: Golden Hoe
   - Name: "Random Builder Tool" (gold colored)
   - Custom lore explaining usage
   - Unbreakable
   - Hide unbreakable tag
   - Use PersistentDataContainer to identify the item safely

2. Add custom crafting recipe:
   Pattern:
   Gold Ingot   Diamond   Gold Ingot
        Stick        Stick

   Require permission: randombuilder.craft

3. Add command:
   /randombuilder get [player]

   - Gives the Random Builder Tool
   - Requires permission: randombuilder.use
   - Console must specify a player
   - Add tab completion for online players

4. Tool Ability:
   When player right-clicks with the tool:
   - Randomly select a placeable block from hotbar slots 0โ€“8
   - Place the block where the player is looking (max 5 block distance)
   - Remove 1 block from that stack
   - Prevent placing inside player
   - If no valid blocks found, send:
     "No placeable blocks in hotbar."

5. Prevent normal block placement while holding the tool.

6. Clean structure:
   - Main class
   - Listener class
   - Command class
   - Utility method for creating the item

7. Include:
   - Full working code
   - plugin.yml
   - Proper null checks
   - Compatible with latest Paper API
   - No deprecated methods
   - Clean, optimized, production-ready code
Kodari AI
KodariMar 2 at 5:33 am 8,805 (v2)
RandomBuilderTool
A Minecraft plugin that adds a custom Golden Hoe tool called "Random Builder Tool". Players can craft it using gold ingots, a diamond, and sticks with the required permission. Right-clicking with the tool randomly selects a placeable block from the player's hotbar and places it at the looked-at location (max 5 blocks). Includes a /randombuilder get command, tab completion, crafting permission checks, and safe item identification via PersistentDataContainer.

Plan:

  • ItemUtil โ€” creates the tool with PDC tag, unbreakable, MiniMessage name/lore

  • ToolListener โ€” handles right-click placement, block place prevention, craft permission

  • ToolCommand โ€” /randombuilder get [player] with tab completion

  • RandomBuilderTool โ€” main class registers recipe, events, command

Five files created:

  • RandomBuilderTool.java โ€” registers the shaped recipe, events, and command on enable

  • ItemUtil.java โ€” builds the Golden Hoe with MiniMessage name/lore, unbreakable flag hidden, PDC tag for safe identification

  • ToolListener.java โ€” handles right-click placement (random hotbar block โ†’ target face, player intersection check, stack decrement), blocks normal placement while holding the tool, and enforces the randombuilder.craft permission on crafting

  • ToolCommand.java โ€” /randombuilder get [player] with console enforcement, online-player tab completion, and permission guard

  • plugin.yml โ€” declares the command, permissions, and api-version: 1.21

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
6 359
src/main/java/com/randombuilder/RandomBuilderTool.java
package com.randombuilder;

import com.randombuilder.command.ToolCommand;
import com.randombuilder.listener.ToolListener;
import com.randombuilder.util.ItemUtil;
import com.cryptomorin.xseries.XMaterial;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.plugin.java.JavaPlugin;

public class RandomBuilderTool extends JavaPlugin {

    @Getter private static RandomBuilderTool instance;
    @Getter private NamespacedKey toolKey;

    @Override
    public void onEnable() {
        instance = this;
        this.toolKey = new NamespacedKey(this, "random_builder_tool");
        registerRecipe();
        getServer().getPluginManager().registerEvents(new ToolListener(this), this);
        ToolCommand toolCommand = new ToolCommand(this);
        getCommand("randombuilder").setExecutor(toolCommand);
        getCommand("randombuilder").setTabCompleter(toolCommand);
    }

    @Override
    public void onDisable() {
        Bukkit.removeRecipe(toolKey);
    }

    private void registerRecipe() {
        ShapedRecipe recipe = new ShapedRecipe(toolKey, ItemUtil.createTool(this));
        recipe.shape("GDG", " S ", " S ");
        Material gold = XMaterial.matchXMaterial("GOLD_INGOT").map(XMaterial::parseMaterial).orElse(null);
        Material diamond = XMaterial.matchXMaterial("DIAMOND").map(XMaterial::parseMaterial).orElse(null);
        Material stick = XMaterial.matchXMaterial("STICK").map(XMaterial::parseMaterial).orElse(null);
        if (gold == null || diamond == null || stick == null) return;
        recipe.setIngredient('G', gold);
        recipe.setIngredient('D', diamond);
        recipe.setIngredient('S', stick);
        Bukkit.addRecipe(recipe);
    }
}