Tanish hit gamer
📎 1 file 8,259 chars
📄
pasted-code-1790158197236.txt
txt 428 lines
▶
Create a complete, production-ready Minecraft Paper plugin named **OP-Dirt** by **Tanish_hit**.

IMPORTANT:

* Generate the complete working plugin source code.
* Do not leave placeholders, TODOs, pseudocode, or incomplete methods.
* The plugin must compile successfully without errors.
* Target **Paper Minecraft 1.21.11** and Java 21.
* Use the official Paper API.
* Keep the plugin lightweight and optimized.

==================================================
PLUGIN IDENTITY
===============

Plugin Name:
OP-Dirt

Author:
Tanish_hit

Description:
Break Dirt and Grass Blocks to receive rare and overpowered Minecraft rewards.

Main package:
com.tanishhit.opdirt

==================================================
CORE MECHANIC
=============

The plugin must work ONLY when a player breaks:

1. DIRT
2. GRASS_BLOCK

No other block may trigger the reward system.

This is extremely important.

The following blocks must NOT trigger any OP reward:

* Stone
* Cobblestone
* Deepslate
* Sand
* Gravel
* Grass
* Logs
* Leaves
* Ores
* Nether blocks
* End blocks
* Any other Minecraft block

Only:

* minecraft:dirt
* minecraft:grass_block

==================================================
NORMAL DROPS
============

When a player successfully breaks Dirt or Grass Block:

* Cancel/remove the normal block drop.
* Generate exactly one random reward from the OP reward table.
* Drop the reward naturally at the broken block location.
* The player should be able to pick it up normally.

Do not give rewards from:

* placing blocks
* right clicking
* killing mobs
* crafting
* opening containers
* breaking any other block

==================================================
REWARD SYSTEM
=============

Create a weighted random reward system.

Common rewards should have higher chances.

Rare rewards should have lower chances.

Ultra-rare rewards should have extremely low chances.

The player must NOT receive an OP armor piece every time.

==================================================
COMMON OP REWARDS
=================

Include Minecraft items such as:

* Diamond
* Diamond Block
* Netherite Ingot
* Netherite Scrap
* Netherite Block
* Gold Block
* Emerald Block
* Golden Apple
* Enchanted Golden Apple
* Ender Pearl
* Experience Bottle
* Fire Charge
* Totem of Undying
* Elytra
* Trident
* Shield
* Firework Rocket
* Splash Potion
* Lingering Potion
* Enchanted Book

Also include:

* Netherite Sword
* Netherite Pickaxe
* Netherite Axe
* Netherite Shovel
* Netherite Hoe

==================================================
FIREWORK REWARDS
================

Firework Rockets must be included.

Possible amounts:

* 8
* 16
* 32
* 64

They should be relatively uncommon compared with basic materials.

==================================================
OP WEAPONS AND TOOLS
====================

Add enchanted Diamond and Netherite weapons/tools.

Examples:

Diamond Sword:

* Sharpness
* Unbreaking
* Mending

Netherite Sword:

* Sharpness
* Unbreaking
* Mending

Diamond Pickaxe:

* Efficiency
* Unbreaking
* Mending

Netherite Pickaxe:

* Efficiency
* Unbreaking
* Mending

Also include:

* Axe
* Shovel
* Hoe

Use valid Minecraft enchantments and make these rewards uncommon.

==================================================
OP BOW
======

Add rare enchanted bows.

Possible enchantments:

* Power
* Punch
* Unbreaking
* Mending
* Flame

==================================================
OP CROSSBOW
===========

Add rare enchanted crossbows.

Possible enchantments:

* Quick Charge
* Piercing
* Unbreaking
* Mending

==================================================
DIAMOND ARMOR
=============

Diamond armor must be rare.

Possible rewards:

* Diamond Helmet
* Diamond Chestplate
* Diamond Leggings
* Diamond Boots

Example enchantments:

* Protection V
* Unbreaking V
* Mending

Do not give full armor sets every time.

==================================================
NETHERITE ARMOR
===============

Netherite armor must be much rarer than Diamond armor.

Possible rewards:

* Netherite Helmet
* Netherite Chestplate
* Netherite Leggings
* Netherite Boots

Example enchantments:

* Protection X
* Unbreaking X
* Mending

==================================================
ULTRA-RARE OP ARMOR
===================

Create an extremely rare reward category.

Chance must be very low.

Possible reward:
A random Netherite armor piece.

Give it very high enchantment levels:

* Protection 100
* Unbreaking 100
* Mending 100
* Thorns 100
* Fire Protection 100

Use unsafe enchantment levels where required by the Paper API.

Give this item a special display name such as:

"Tanish OP Armor"

This reward must be MUCH rarer than normal Diamond or Netherite armor.

==================================================
POTIONS
=======

Include Minecraft potion rewards.

Examples:

* Splash Potion
* Lingering Potion

They should be uncommon/rare rewards.

Use valid Minecraft potion mechanics.

==================================================
ENCHANTED BOOKS
===============

Include Enchanted Books as rewards.

Possible enchantments can include:

* Protection
* Sharpness
* Efficiency
* Unbreaking
* Mending
* Power
* Fortune
* Looting
* Feather Falling

Make these uncommon rewards.

==================================================
RARITY SYSTEM
=============

Use a clear weighted rarity system such as:

COMMON:
High probability.

UNCOMMON:
Moderate probability.

RARE:
Low probability.

ULTRA RARE:
Very low probability.

Do not make every reward equally likely.

The Protection 100 Netherite armor should have an extremely low chance.

==================================================
IMPORTANT ANTI-BUG REQUIREMENTS
===============================

The plugin must:

* Work only on Dirt and Grass Block.
* Not affect other blocks.
* Not duplicate rewards.
* Not give rewards when the event is cancelled.
* Respect BlockBreakEvent cancellation.
* Remove normal Dirt/Grass drops before creating the custom reward.
* Drop exactly one reward per valid block break.
* Work correctly with normal survival mining.
* Avoid console errors.
* Avoid unnecessary repeating tasks.
* Avoid memory leaks.
* Avoid global event conflicts.
* Use ThreadLocalRandom or another safe random mechanism.
* Handle ItemMeta safely.
* Handle enchantments safely.
* Use proper Paper API methods for Minecraft 1.21.11.

==================================================
PLUGIN FILES
============

Generate:

1. pom.xml
2. plugin.yml
3. Complete Java source code
4. Any required configuration files

plugin.yml should contain:

name: OP-Dirt
version: 1.0.0
main: com.tanishhit.opdirt.OPDirt
api-version: '1.21'
author: Tanish_hit

==================================================
CONFIGURATION
=============

Create a config.yml so reward chances can be changed later.

Allow configuration of:

* Common reward chance
* Uncommon reward chance
* Rare reward chance
* Ultra-rare reward chance
* Firework amount
* Armor chances
* OP enchantment levels

Do not require configuration for the plugin to work.

The plugin must have sensible default values.

==================================================
CONSOLE MESSAGE
===============

When the plugin starts, show a simple console message:

"OP-Dirt by Tanish_hit enabled!"

==================================================
FINAL REQUIREMENT
=================

The final result must be a complete, compile-ready Paper plugin.

Do not provide pseudocode.

Do not omit classes or methods.

Do not use fake Minecraft API methods.

Do not include non-Minecraft items.

The plugin must specifically implement:

Dirt/Grass Block
→ Random weighted OP Minecraft reward

Nothing else should trigger the reward system.

After generating the code, verify imports, API usage, package names, plugin.yml, Maven configuration, and Java compatibility before presenting the final project.
Kodari AI
KodariSep 23 at 10:12 am 2
OPDirtRewards
A Paper plugin that transforms breaking Dirt and Grass Blocks into a weighted random reward system. Only minecraft:dirt and minecraft:grass_block trigger rewards, canceling normal drops and spawning one item from a rarity-based table. Includes common materials, enchanted weapons and tools, rare armor, and ultra-rare "Tanish OP Armor" with extreme enchantment levels. Configurable via config.yml with sensible defaults, safe random generation, and proper Paper API usage for Minecraft 1.21.11.
  1. Create the Maven project for Java 21 and Paper 1.21.11.

  2. Implement a weighted Dirt/Grass-only reward listener with configurable rarity, armor, fireworks, and OP enchantments.

  3. Add the plugin manifest and sensible default configuration.

Created the OP-Dirt Maven plugin with Java 21 and Paper 1.21.11 configuration.

  • Rewards trigger only on Dirt and Grass Block breaks; cancelled breaks do not drop a reward, and normal block drops are suppressed.

  • Added weighted rarity pools with materials, fireworks, potions, enchanted books, tools, bows, crossbows, armor, and ultra-rare “Tanish OP Armor.”

  • Added configurable rarity weights, armor weights, firework stack sizes, and ultra-rare armor enchantment levels.

  • Added pom.xml, plugin.yml, config.yml, and OPDirt.java.

Kodari can make mistakes. Review important code before using.
Files
src
pom.xml
Code
4 399
src/main/java/com/tanishhit/opdirt/OPDirt.java
package com.tanishhit.opdirt;

import com.cryptomorin.xseries.XEnchantment;
import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XPotion;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.World;

import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Supplier;

public final class OPDirt extends JavaPlugin implements Listener {
    private final Map<Rarity, List<Reward>> rewards = new EnumMap<>(Rarity.class);

    @Override
    public void onEnable() {
        saveDefaultConfig();
        buildRewards();
        getServer().getPluginManager().registerEvents(this, this);
        getLogger().info("OP-Dirt by Tanish_hit enabled!");
    }

    @EventHandler(ignoreCancelled = true)
    public void onBlockBreak(BlockBreakEvent event) {
        Block block = event.getBlock();
        String materialName = XMaterial.matchXMaterial(block.getType()).name();
        if (!materialName.equals("DIRT") && !materialName.equals("GRASS_BLOCK")) {
            return;
        }

        event.setDropItems(false);
        ItemStack reward = chooseReward();
        Location dropLocation = block.getLocation().add(0.5, 0.5, 0.5);
        World world = block.getWorld();
        getServer().getScheduler().runTask(this, () -> {
            if (!event.isCancelled()) {
                world.dropItemNaturally(dropLocation, reward);
            }
        });
    }

    private void buildRewards() {
        for (Rarity rarity : Rarity.values()) {
            rewards.put(rarity, new ArrayList<>());
        }

        add(Rarity.COMMON, 1.0, () -> item("DIAMOND", 3));
        add(Rarity.COMMON, 1.0, () -> item("DIAMOND_BLOCK", 1));
        add(Rarity.COMMON, 1.0, () -> item("NETHERITE_INGOT", 1));
        add(Rarity.COMMON, 1.0, () -> item("NETHERITE_SCRAP", 2));
        add(Rarity.COMMON, 1.0, () -> item("NETHERITE_BLOCK", 1));
        add(Rarity.COMMON, 1.0, () -> item("GOLD_BLOCK", 2));
        add(Rarity.COMMON, 1.0, () -> item("EMERALD_BLOCK", 1));
        add(Rarity.COMMON, 1.0, () -> item("GOLDEN_APPLE", 2));
        add(Rarity.COMMON, 1.0, () -> item("ENCHANTED_GOLDEN_APPLE", 1));
        add(Rarity.COMMON, 1.0, () -> item("ENDER_PEARL", 4));
        add(Rarity.COMMON, 1.0, () -> item("EXPERIENCE_BOTTLE", 8));
        add(Rarity.COMMON, 1.0, () -> item("FIRE_CHARGE", 4));
        add(Rarity.COMMON, 1.0, () -> item("TOTEM_OF_UNDYING", 1));
        add(Rarity.COMMON, 1.0, () -> item("ELYTRA", 1));
        add(Rarity.COMMON, 1.0, () -> item("TRIDENT", 1));
        add(Rarity.COMMON, 1.0, () -> item("SHIELD", 1));
        add(Rarity.COMMON, 1.0, () -> item("NETHERITE_SWORD", 1));
        add(Rarity.COMMON, 1.0, () -> item("NETHERITE_PICKAXE", 1));
        add(Rarity.COMMON, 1.0, () -> item("NETHERITE_AXE", 1));
        add(Rarity.COMMON, 1.0, () -> item("NETHERITE_SHOVEL", 1));
        add(Rarity.COMMON, 1.0, () -> item("NETHERITE_HOE", 1));

        add(Rarity.UNCOMMON, 0.45, this::fireworkReward);
        add(Rarity.UNCOMMON, 0.8, () -> potionReward("SPLASH_POTION", "SPEED"));
        add(Rarity.UNCOMMON, 0.6, () -> potionReward("LINGERING_POTION", "SPEED"));
        add(Rarity.UNCOMMON, 0.75, () -> enchantedBook("PROTECTION", 4));
        add(Rarity.UNCOMMON, 0.75, () -> enchantedBook("SHARPNESS", 5));
        add(Rarity.UNCOMMON, 0.75, () -> enchantedBook("EFFICIENCY", 5));
        add(Rarity.UNCOMMON, 0.75, () -> enchantedBook("UNBREAKING", 3));
        add(Rarity.UNCOMMON, 0.75, () -> enchantedBook("MENDING", 1));
        add(Rarity.UNCOMMON, 0.75, () -> enchantedBook("POWER", 5));
        add(Rarity.UNCOMMON, 0.75, () -> enchantedBook("FORTUNE", 3));
        add(Rarity.UNCOMMON, 0.75, () -> enchantedBook("LOOTING", 3));
        add(Rarity.UNCOMMON, 0.75, () -> enchantedBook("FEATHER_FALLING", 4));

        addToolRewards("DIAMOND");
        addToolRewards("NETHERITE");

        add(Rarity.RARE, 1.0, () -> enchantedItem("BOW", 1, Map.of(
                "POWER", 5, "PUNCH", 2, "UNBREAKING", 3, "MENDING", 1, "FLAME", 1), null));
        add(Rarity.RARE, 1.0, () -> enchantedItem("CROSSBOW", 1, Map.of(
                "QUICK_CHARGE", 3, "PIERCING", 4, "UNBREAKING", 3, "MENDING", 1), null));
        double diamondArmorWeight = configuredWeight("armor-chances.diamond-weight", 1.0);
        add(Rarity.RARE, diamondArmorWeight, () -> enchantedItem("DIAMOND_HELMET", 1,
                Map.of("PROTECTION", 5, "UNBREAKING", 5, "MENDING", 1), null));
        add(Rarity.RARE, diamondArmorWeight, () -> enchantedItem("DIAMOND_CHESTPLATE", 1,
                Map.of("PROTECTION", 5, "UNBREAKING", 5, "MENDING", 1), null));
        add(Rarity.RARE, diamondArmorWeight, () -> enchantedItem("DIAMOND_LEGGINGS", 1,
                Map.of("PROTECTION", 5, "UNBREAKING", 5, "MENDING", 1), null));
        add(Rarity.RARE, diamondArmorWeight, () -> enchantedItem("DIAMOND_BOOTS", 1,
                Map.of("PROTECTION", 5, "UNBREAKING", 5, "MENDING", 1), null));

        double netheriteArmorWeight = configuredWeight("armor-chances.netherite-weight", 0.15);
        add(Rarity.RARE, netheriteArmorWeight, () -> enchantedItem("NETHERITE_HELMET", 1,
                Map.of("PROTECTION", 10, "UNBREAKING", 10, "MENDING", 1), null));
        add(Rarity.RARE, netheriteArmorWeight, () -> enchantedItem("NETHERITE_CHESTPLATE", 1,
                Map.of("PROTECTION", 10, "UNBREAKING", 10, "MENDING", 1), null));
        add(Rarity.RARE, netheriteArmorWeight, () -> enchantedItem("NETHERITE_LEGGINGS", 1,
                Map.of("PROTECTION", 10, "UNBREAKING", 10, "MENDING", 1), null));
        add(Rarity.RARE, netheriteArmorWeight, () -> enchantedItem("NETHERITE_BOOTS", 1,
                Map.of("PROTECTION", 10, "UNBREAKING", 10, "MENDING", 1), null));

        double ultraRareArmorWeight = configuredWeight("armor-chances.ultra-rare-weight", 1.0);
        add(Rarity.ULTRA_RARE, ultraRareArmorWeight, () -> ultraRareArmor("NETHERITE_HELMET"));
        add(Rarity.ULTRA_RARE, ultraRareArmorWeight, () -> ultraRareArmor("NETHERITE_CHESTPLATE"));
        add(Rarity.ULTRA_RARE, ultraRareArmorWeight, () -> ultraRareArmor("NETHERITE_LEGGINGS"));
        add(Rarity.ULTRA_RARE, ultraRareArmorWeight, () -> ultraRareArmor("NETHERITE_BOOTS"));
    }

    private void addToolRewards(String material) {
        add(Rarity.UNCOMMON, 1.0, () -> enchantedItem(material + "_SWORD", 1,
                Map.of("SHARPNESS", 5, "UNBREAKING", 3, "MENDING", 1), null));
        add(Rarity.UNCOMMON, 1.0, () -> enchantedItem(material + "_PICKAXE", 1,
                Map.of("EFFICIENCY", 5, "UNBREAKING", 3, "MENDING", 1), null));
        add(Rarity.UNCOMMON, 1.0, () -> enchantedItem(material + "_AXE", 1,
                Map.of("SHARPNESS", 5, "EFFICIENCY", 5, "UNBREAKING", 3, "MENDING", 1), null));
        add(Rarity.UNCOMMON, 1.0, () -> enchantedItem(material + "_SHOVEL", 1,
                Map.of("EFFICIENCY", 5, "UNBREAKING", 3, "MENDING", 1), null));
        add(Rarity.UNCOMMON, 1.0, () -> enchantedItem(material + "_HOE", 1,
                Map.of("EFFICIENCY", 5, "UNBREAKING", 3, "MENDING", 1), null));
    }

    private ItemStack chooseReward() {
        List<Rarity> available = new ArrayList<>();
        List<Double> weights = new ArrayList<>();
        for (Rarity rarity : Rarity.values()) {
            if (rewards.get(rarity).isEmpty()) {
                continue;
            }
            double weight = configuredWeight("rarity-weights." + rarity.configKey, rarity.defaultWeight);
            if (rarity == Rarity.ULTRA_RARE) {
                weight *= configuredWeight("armor-chances.ultra-rare-weight", 1.0);
            }
            if (weight > 0.0) {
                available.add(rarity);
                weights.add(weight);
            }
        }

        if (available.isEmpty()) {
            return rewards.get(Rarity.COMMON).get(0).creator.get();
        }

        double totalWeight = weights.stream().mapToDouble(Double::doubleValue).sum();
        double roll = ThreadLocalRandom.current().nextDouble(totalWeight);
        Rarity selectedRarity = available.get(available.size() - 1);
        for (int i = 0; i < available.size(); i++) {
            roll -= weights.get(i);
            if (roll < 0.0) {
                selectedRarity = available.get(i);
                break;
            }
        }

        List<Reward> pool = rewards.get(selectedRarity);
        double rewardWeight = pool.stream().mapToDouble(Reward::weight).sum();
        if (rewardWeight <= 0.0) {
            return pool.get(ThreadLocalRandom.current().nextInt(pool.size())).creator.get();
        }

        roll = ThreadLocalRandom.current().nextDouble(rewardWeight);
        Reward selectedReward = pool.get(pool.size() - 1);
        for (Reward reward : pool) {
            roll -= reward.weight;
            if (roll < 0.0) {
                selectedReward = reward;
                break;
            }
        }
        return selectedReward.creator.get();
    }

    private double configuredWeight(String path, double fallback) {
        double value = getConfig().getDouble(path, fallback);
        if (!Double.isFinite(value) || value <= 0.0) {
            return 0.0;
        }
        return Math.min(value, 1_000_000.0);
    }

    private void add(Rarity rarity, double weight, Supplier<ItemStack> creator) {