priyanshu_2010
📎 1 file 16,298 chars
📄
pasted-code-1790607822129.txt
txt 1077 lines
▶
Create a complete Minecraft plugin called **Zenith Crates** for **Paper 1.21.11**.

The plugin must work with Java players and Geyser/Floodgate Bedrock players.

The plugin should be clean, optimized, configurable, and production-ready.

# 1. CRATE TYPES

Create exactly 5 crate types:

1. Normal Crate
2. Prime Crate
3. Crimson Crate
4. Spawner Crate
5. Zenith Crate

Each crate must have:

* A unique crate ID
* A unique crate key
* A configurable display name
* A configurable crate material/block
* A configurable key material
* Its own rewards
* Its own opening GUI
* Its own configured locations
* Its own top/hologram name

The plugin name must always be:

**Zenith Crates**

Do NOT call the plugin Donut Crates or Zenith Spawners.

---

# 2. CRATE KEY SYSTEM

Every crate has its own key.

Keys must be unique using PersistentDataContainer/PDC so that renamed normal items cannot be used as keys.

Default keys:

* Normal Key
* Prime Key
* Crimson Key
* Spawner Key
* Zenith Key

A key should only work with its corresponding crate.

Examples:

Prime Key → Prime Crate

Crimson Key → Crimson Crate

Spawner Key → Spawner Crate

Zenith Key → Zenith Crate

Normal Key → Normal Crate

If a player tries to use the wrong key, do not open the crate and show a configurable error message.

---

# 3. KEY GIVE COMMANDS

Create these commands:

```text
/crate key give   
```

Example:

```text
/crate key give Steve prime 5
```

This gives Steve 5 Prime Keys.

Also:

```text
/crate key giveall  
```

Example:

```text
/crate key giveall crimson 3
```

This gives 3 Crimson Keys to every online player.

Support all crate types.

Add tab completion for:

* Player names
* Crate IDs
* Amounts

---

# 4. KEYALL SYSTEM

Create a normal/specific KeyAll command:

```text
/keyall  
```

Example:

```text
/keyall prime 3
```

Every online player receives 3 Prime Keys.

Broadcast a configurable announcement.

Example:

```text
&b&lZENITH KEYALL
&fEveryone received &e3 Prime Keys&f!
```

The message should support placeholders:

```text
%crate%
%crate_name%
%amount%
```

---

# 5. RANDOM KEYALL

Create:

```text
/randomkeyall
```

This automatically selects a crate and gives keys to every online player.

IMPORTANT:

Normal Crate must NEVER be selected by Random KeyAll.

Random KeyAll can only select:

* Prime
* Crimson
* Spawner
* Zenith

The default weighted selection should be:

```text
Prime   = 50%
Crimson = 30%
Spawner = 15%
Zenith  = 5%
```

Prime therefore has the highest configured probability, followed by Crimson, then Spawner, then Zenith.

These are the ONLY chances/probabilities in the plugin.

There must be NO chance/probability setting for individual rewards.

---

# 6. RANDOM KEYALL AMOUNTS

When `/randomkeyall` runs, the number of keys given must randomly be one of:

```text
1
3
5
```

Example results:

```text
Everyone received 1 Prime Key!
```

or

```text
Everyone received 5 Crimson Keys!
```

or

```text
Everyone received 3 Spawner Keys!
```

or

```text
Everyone received 1 Zenith Key!
```

The possible amounts must be configurable.

Default:

```yaml
amounts:
  - 1
  - 3
  - 5
```

---

# 7. RANDOM KEYALL CONFIGURATION

Use a configuration similar to:

```yaml
random-keyall:
  enabled: true

  crates:
    prime:
      weight: 50

    crimson:
      weight: 30

    spawner:
      weight: 15

    zenith:
      weight: 5

  amounts:
    - 1
    - 3
    - 5
```

Normal Crate must not appear in this section.

The system must use weighted random selection.

Make these weights configurable so the server owner can change them later.

---

# 8. AUTOMATIC RANDOM KEYALL

Add an optional automatic Random KeyAll system.

Configuration:

```yaml
random-keyall:
  automatic:
    enabled: false
    interval-seconds: 3600
```

If enabled, the server automatically performs a Random KeyAll every configured number of seconds.

Example:

```text
3600 seconds = 1 hour
```

The automatic system must survive server reloads correctly and must not create duplicate timers.

---

# 9. CRATE CREATION

Create:

```text
/crate create 
```

Examples:

```text
/crate create normal
/crate create prime
/crate create crimson
/crate create spawner
/crate create zenith
```

The plugin should also have the five default crate types available.

Prevent duplicate crate IDs.

---

# 10. CRATE LIST

Command:

```text
/crate list
```

Show all available crates.

Example:

```text
Zenith Crates

Normal
Prime
Crimson
Spawner
Zenith
```

---

# 11. CRATE NAME SETUP

Command:

```text
/crate setname  
```

Example:

```text
/crate setname prime &b&lPrime Crate
```

This changes the display name of the crate.

Support:

* Colors
* Bold
* Italic
* Underline
* Other supported Minecraft formatting

---

# 12. TOP NAME / HOLOGRAM NAME

I want to be able to set the name displayed above the crate.

Command:

```text
/crate settop  
```

Example:

```text
/crate settop prime &b&lPRIME CRATE
```

The configured top name should appear above the crate.

It should support:

* Color codes
* Formatting
* Placeholder support where appropriate

Also provide:

```text
/crate removetop 
```

to remove the top name.

Do not require an external hologram plugin.

The plugin should handle the crate's floating/top display itself.

---

# 13. CRATE LOCATION

Create:

```text
/crate setlocation 
```

The administrator looks at the desired block and runs the command.

The plugin saves that block as the crate location.

Example:

```text
/crate setlocation prime
```

Also:

```text
/crate removelocation 
```

and:

```text
/crate locations
```

The location must persist after server restarts.

Multiple locations should be supported for the same crate type.

For example, multiple Prime Crates can exist in different locations.

---

# 14. CRATE EDITOR

This is very important.

I will manually add the rewards/items myself.

Command:

```text
/crate edit 
```

Example:

```text
/crate edit prime
```

This opens a GUI reward editor.

The GUI must allow me to directly place items into reward slots.

I should be able to:

* Take an item from my inventory
* Put it into the reward GUI
* Remove an item
* Move an item
* Change the item amount
* Add custom items
* Add enchanted items
* Add renamed items
* Add items with custom lore
* Add Minecraft items
* Save the rewards
* Clear the rewards

There must be a clearly visible:

**SAVE**

button.

There should also be:

**CANCEL**

and:

**CLEAR**

buttons.

---

# 15. NO INDIVIDUAL REWARD CHANCES

IMPORTANT:

Do NOT create a reward chance system.

Do NOT ask me to enter:

```text
Chance: 10%
Chance: 25%
Chance: 50%
```

I do not want this.

I will manually put the rewards/items into the crate.

If I put 10 different reward items into a crate, the plugin should randomly select from those configured reward entries.

The only chance/weight system in the entire plugin should be the Random KeyAll crate selection.

---

# 16. REWARD EXAMPLE

If I edit the Prime Crate and add:

```text
5 Diamonds
10 Emeralds
1 Netherite Ingot
3 Golden Apples
1 custom item
```

those become the Prime Crate rewards.

When someone opens the Prime Crate, the plugin randomly selects one of the configured rewards.

There should be no percentage settings for these rewards.

The same system applies independently to:

* Normal
* Prime
* Crimson
* Spawner
* Zenith

---

# 17. ADD ITEM COMMAND

Also provide an easy command:

```text
/crate additem 
```

The administrator holds the desired item in their hand.

Example:

```text
/crate additem prime
```

The plugin copies the held item into the Prime Crate reward list.

The original item in the administrator's inventory should not be removed unless explicitly configured.

Also provide:

```text
/crate clear 
```

to remove all rewards from that crate.

---

# 18. COMMAND REWARDS

In addition to physical items, allow optional command rewards.

For example:

```yaml
rewards:
  - type: COMMAND
    commands:
      - "eco give %player% 10000"
```

Support:

```text
%player%
%uuid%
```

The command should execute when the player wins that reward.

However, there should still be NO chance setting for command rewards.

---

# 19. CRATE OPENING

When a player right-clicks a configured crate with its correct key:

1. Detect the correct key.
2. Remove exactly one key.
3. Open the crate animation GUI.
4. Display available rewards.
5. Run the opening animation.
6. Select a reward.
7. Show the winning reward.
8. Give the reward to the player.
9. Play configurable sounds/particles.
10. Close the GUI.

If the player does not have the correct key, do not consume anything.

---

# 20. CRATE ANIMATION

Create a configurable crate-opening animation.

The GUI should visually roll through reward items before stopping on the winning reward.

Configuration should allow:

* Animation duration
* Animation speed
* Sounds
* Winning sound
* Particles
* GUI title

Make the animation smooth and compatible with both Java and Geyser/Floodgate players.

---

# 21. FULL INVENTORY HANDLING

If a player wins an item but their inventory is full:

Do not delete the reward.

Use a configurable fallback.

Default behavior:

Drop the reward safely at the player's location.

Optionally support:

```yaml
full-inventory:
  drop-item: true
```

---

# 22. CRATE MATERIAL

Allow the crate block/material to be configured.

Example:

```yaml
crates:
  prime:
    material: CHEST
```

Each crate can have its own material.

---

# 23. KEY CONFIGURATION

Allow each key to be customized.

Example:

```yaml
keys:
  prime:
    material: TRIPWIRE_HOOK
    name: "&b&lPrime Key"
    lore:
      - "&7Use this key to open"
      - "&bPrime Crate"
```

Do this for every crate.

The actual key identity must be stored using PDC.

---

# 24. CONFIGURATION

Create a detailed `config.yml`.

It should contain settings for:

* All 5 crates
* Crate names
* Crate materials
* Key materials
* Key names
* Key lore
* Messages
* Sounds
* Particles
* Animation
* Reward settings
* Crate locations
* Top names
* Random KeyAll
* Random KeyAll weights
* Random KeyAll amounts
* Automatic Random KeyAll
* Full inventory behavior

Do not hard-code settings that should reasonably be configurable.

---

# 25. MESSAGES

Create a separate configurable messages section/file.

Include messages for:

* No permission
* Crate created
* Crate deleted
* Crate saved
* Reward added
* Reward removed
* Invalid crate
* Wrong key
* No key
* Key given
* KeyAll
* Random KeyAll
* Reload
* Full inventory
* Crate opening

Example:

```yaml
messages:
  no-permission: "&cYou don't have permission."
  no-key: "&cYou don't have the required key."
  wrong-key: "&cThis key cannot open this crate."
  reload: "&aZenith Crates has been reloaded."
```

---

# 26. ADMIN COMMANDS

Implement:

```text
/crate
/crate create 
/crate delete 
/crate list
/crate edit 
/crate additem 
/crate clear 
/crate setname  
/crate settop  
/crate removetop 
/crate setlocation 
/crate removelocation 
/crate locations
/crate key give   
/crate key giveall  
/crate reload

/keyall  
/randomkeyall
```

Add proper tab completion.

---

# 27. PERMISSIONS

Use permissions:

```text
zenithcrates.admin
zenithcrates.create
zenithcrates.delete
zenithcrates.edit
zenithcrates.key
zenithcrates.keyall
zenithcrates.randomkeyall
zenithcrates.reload
```

Normal players must only need permission to use/open crates if desired.

---

# 28. OPERATOR COMMANDS

Operators must have access to all administrative commands by default.

The plugin must properly respect Bukkit/Paper permissions.

---

# 29. DATA STORAGE

Store all crate data safely.

Store:

* Crate IDs
* Crate names
* Crate materials
* Rewards
* Locations
* Top names
* Key configuration

All data must survive:

* Server restart
* Plugin reload
* Server reload

Do not lose items or crate configuration.

---

# 30. RELOAD

Command:

```text
/crate reload
```

or:

```text
/zenithcrates reload
```

Reload:

* config
* messages
* crates
* rewards
* locations
* Random KeyAll settings

Do not duplicate automatic KeyAll tasks after reload.

---

# 31. DEFAULT CRATES

The plugin should create these default crates if they do not exist:

```text
normal
prime
crimson
spawner
zenith
```

However, I will manually configure their rewards.

Do not automatically fill them with random rewards.

---

# 32. RANDOM KEYALL EXAMPLE

If I execute:

```text
/randomkeyall
```

the plugin first chooses one of:

```text
Prime
Crimson
Spawner
Zenith
```

Normal is completely excluded.

Then it randomly chooses one amount:

```text
1
3
5
```

Then every online player receives that number of the selected key.

Example:

```text
Random result:
Crimson
Amount:
3
```

Broadcast:

```text
&8&m━━━━━━━━━━━━━━━━━━━━━━
&b&lZENITH RANDOM KEYALL
&fEveryone received &c3 Crimson Keys&f!
&8&m━━━━━━━━━━━━━━━━━━━━━━
```

---

# 33. IMPORTANT DISTINCTION

There are NO reward chances.

There are only Random KeyAll weights.

### Rewards

Manually added by me.

No percentage/chance configuration.

### Random KeyAll

Uses configurable weighted selection:

```text
Prime   → 50
Crimson → 30
Spawner → 15
Zenith  → 5
```

Normal is excluded.

### Key Amount

Randomly chooses:

```text
1
3
5
```

---

# 34. Geyser/FLOODGATE COMPATIBILITY

The plugin must work properly for Bedrock players connected through:

* Geyser
* Floodgate

Avoid Java-only GUI mechanics that would make the crate impossible to use on Bedrock.

All important crate interactions must work through normal inventory/container interactions.

---

# 35. PAPER VERSION

Target:

**Paper 1.21.11**

Use the appropriate Paper API for 1.21.11.

Do not build against an outdated Minecraft API.

Avoid deprecated APIs wherever possible.

---

# 36. DEPENDENCIES

Keep dependencies minimal.

Required:

* Paper 1.21.11

Optional:

* Vault for economy command/reward integration

The plugin should not require unnecessary plugins.

---

# 37. PERFORMANCE

The plugin must be optimized.

Do not constantly run expensive tasks for every crate.

Only create necessary tasks for:

* Active crate animations
* Automatic Random KeyAll timer
* Top-name displays if required

Cancel tasks correctly when:

* Player disconnects
* GUI closes
* Plugin reloads
* Server shuts down

Avoid memory leaks.

---

# 38. FINAL REQUIREMENT

The finished plugin must be called:

**Zenith Crates**

It must provide a complete crate/key system with:

* Normal Crate
* Prime Crate
* Crimson Crate
* Spawner Crate
* Zenith Crate
* Individual keys
* Key giving
* KeyAll
* Random KeyAll
* Random KeyAll weighted crate selection
* Random key amounts of 1, 3, or 5
* Manual reward/item placement
* GUI reward editor
* No individual reward chances
* Crate creation
* Crate locations
* Multiple locations
* Configurable crate names
* Configurable top names
* Crate opening animation
* Commands
* Permissions
* Tab completion
* Full configuration
* Persistent data
* Paper 1.21.11 compatibility
* Geyser/Floodgate compatibility

Make the plugin ready to compile and use on a real Paper 1.21.11 server.
Kodari AI
KodariSep 28 at 3:06 pm 2
ZenithCrates
A comprehensive crate and key management plugin for Paper 1.21.11 servers. Features five configurable crate types (Normal, Prime, Crimson, Spawner, Zenith) with unique PDC-verified keys, GUI-based reward editor with manual item placement, weighted Random KeyAll system excluding Normal crates, automatic timed key distributions, persistent crate locations with hologram-style top displays, animated crate opening sequences, and full Geyser/Floodgate compatibility. Includes complete admin commands with tab completion, configurable messages, sounds, particles, and full-inventory fallback handling. All settings managed through detailed config.yml with no individual reward chances.
  1. Create the Paper 1.21.11 project, plugin metadata, and a fully populated config.yml.

  2. Implement persisted crate/key data, commands, permissions, tab completion, and editable reward GUIs.

  3. Add crate interactions, animated openings, top displays, and reload-safe automatic Random KeyAll.

Created the Zenith Crates Paper 1.21.11 project with a populated config.yml, plugin metadata, and Gradle setup.

It includes the five default crate types, PDC-identified keys, crate/key commands with tab completion, persistent rewards and locations, a reward editor GUI, animated openings, floating crate names, weighted Random KeyAll (excluding Normal), and an optional automatic timer. Reward selection has no per-reward chance settings. The editor and crate interactions use standard inventories for Geyser/Floodgate compatibility.

priyanshu_2010

the console says name issue

Kodari AI
KodariSep 28 at 4:35 pm 1
  • Fix the plugin name in plugin.yml to remove the space.

  • Keep config.yml intact; it already contains usable settings.

Changed the plugin name in plugin.yml from Zenith Crates to ZenithCrates, which should resolve the name validation issue. Your config.yml remains populated with the existing settings. Rebuild the plugin and replace the JAR on your server.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
manifest.kod
settings.gradle
Code
11 1,421
src/main/java/com/zenithcrates/ZenithCratesPlugin.java
package com.zenithcrates;

import com.cryptomorin.xseries.XSound;
import com.cryptomorin.xseries.particles.XParticle;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.UUID;

public final class ZenithCratesPlugin extends JavaPlugin {
    private final Random random = new Random();
    private final Map<UUID, BukkitTask> animations = new HashMap<>();
    private CrateManager crateManager;
    private CrateListener crateListener;
    private BukkitTask automaticKeyAllTask;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        crateManager = new CrateManager(this);
        crateManager.load();
        crateListener = new CrateListener(this);
        Bukkit.getPluginManager().registerEvents(crateListener, this);
        CrateCommand crateCommand = new CrateCommand(this);
        getCommand("crate").setExecutor(crateCommand);
        getCommand("crate").setTabCompleter(crateCommand);
        getCommand("zenithcrates").setExecutor(crateCommand);
        getCommand("zenithcrates").setTabCompleter(crateCommand);
        KeyAllCommand keyAllCommand = new KeyAllCommand(this);
        getCommand("keyall").setExecutor(keyAllCommand);
        getCommand("keyall").setTabCompleter(keyAllCommand);
        getCommand("randomkeyall").setExecutor(keyAllCommand);
        getCommand("randomkeyall").setTabCompleter(keyAllCommand);
        scheduleAutomaticKeyAll();
    }

    @Override
    public void onDisable() {
        cancelAutomaticKeyAll();
        animations.values().forEach(BukkitTask::cancel);
        animations.clear();
        if (crateManager != null) {
            crateManager.close();
        }
    }

    public CrateManager getCrateManager() {
        return crateManager;
    }

    public CrateListener getCrateListener() {
        return crateListener;
    }

    public String crateName(String id) {
        CrateData crate = crateManager.get(id);
        return crate == null ? id : ChatColor.translateAlternateColorCodes('&', crate.getDisplayName());
    }

    public void sendMessage(CommandSender sender, String path) {
        sendMessage(sender, path, Map.of());
    }

    public void sendMessage(CommandSender sender, String path, Map<String, String> replacements) {
        String prefix = getConfig().getString("messages.prefix", "");
        String message = getConfig().getString("messages." + path, "&cMissing message: " + path);
        for (Map.Entry<String, String> replacement : replacements.entrySet()) {
            message = message.replace(replacement.getKey(), replacement.getValue());
        }
        for (String line : message.split("\\n")) {
            sender.sendMessage(ChatColor.translateAlternateColorCodes('&', prefix + line));
        }
    }

    public void broadcastMessage(String path, Map<String, String> replacements) {
        String message = getConfig().getString("messages." + path, "");
        for (Map.Entry<String, String> replacement : replacements.entrySet()) {
            message = message.replace(replacement.getKey(), replacement.getValue());
        }
        String prefix = getConfig().getString("messages.prefix", "");
        for (String line : message.split("\\n")) {
            Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', prefix + line));
        }
    }

    public boolean hasPermission(CommandSender sender, String permission) {
        return sender.hasPermission("zenithcrates.admin") || sender.hasPermission(permission);
    }

    public void reloadPlugin() {
        animations.values().forEach(BukkitTask::cancel);
        animations.clear();
        cancelAutomaticKeyAll();
        crateManager.load();
        scheduleAutomaticKeyAll();
    }

    public boolean isAnimating(Player player) {
        return animations.containsKey(player.getUniqueId());
    }

    public void cancelAnimation(Player player) {
        BukkitTask task = animations.remove(player.getUniqueId());
        if (task != null) {
            task.cancel();
        }
    }

    public void startOpening(Player player, CrateData crate, List<CrateData.RewardEntry> rewards) {
        cancelAnimation(player);
        String title = getConfig().getString("animation.gui-title", "&8Opening %crate_name%")
                .replace("%crate%", crate.getId()).replace("%crate_name%", crateName(crate.getId()));
        Inventory inventory = Bukkit.createInventory(null, 27, ChatColor.translateAlternateColorCodes('&', title));
        player.openInventory(inventory);
        sendMessage(player, "opening", Map.of("%crate%", crate.getId(), "%crate_name%", crateName(crate.getId())));
        CrateData.RewardEntry winner = rewards.get(random.nextInt(rewards.size()));
        int duration = Math.max(1, getConfig().getInt("animation.duration-ticks", 80));
        int speed = Math.max(1, getConfig().getInt("animation.speed-ticks", 3));
        int[] elapsed = {0};
        BukkitTask task = Bukkit.getScheduler().runTaskTimer(this, () -> {
            if (!player.isOnline() || player.getOpenInventory().getTopInventory() != inventory) {
                cancelAnimation(player);
                return;
            }
            elapsed[0] += speed;
            for (int slot = 10; slot <= 16; slot++) {
                CrateData.RewardEntry rolling = rewards.get(random.nextInt(rewards.size()));
                inventory.setItem(slot, icon(rolling));
            }
            playSound(player, getConfig().getString("animation.rolling-sound", "UI_BUTTON_CLICK"));
            if (elapsed[0] >= duration) {
                BukkitTask running = animations.remove(player.getUniqueId());
                if (running != null) {
                    running.cancel();
                }
                inventory.clear();
                inventory.setItem(13, icon(winner));
                playSound(player, getConfig().getString("animation.winning-sound", "ENTITY_PLAYER_LEVELUP"));
                String particleName = getConfig().getString("animation.particle", "FIREWORK");
                XParticle.of(particleName).ifPresent(particle -> player.getWorld().spawnParticle(
                        particle.get(), player.getLocation().add(0, 1, 0),
                        Math.max(0, getConfig().getInt("animation.particle-count", 20))));
                giveReward(player, winner);
                Bukkit.getScheduler().runTaskLater(this, () -> {
                    if (player.isOnline() && player.getOpenInventory().getTopInventory() == inventory) {
                        player.closeInventory();
                    }
                }, 20L);
            }
        }, 0L, speed);
        animations.put(player.getUniqueId(), task);
    }

    public void giveReward(Player player, CrateData.RewardEntry reward) {
        if (reward.isCommand()) {
            for (String configured : reward.commands()) {
                String command = configured.replace("%player%", player.getName()).replace("%uuid%", player.getUniqueId().toString());
                Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
            }
            return;
        }
        if (reward.item() == null) {
            return;
        }
        var overflow = player.getInventory().addItem(reward.item().clone());
        if (!overflow.isEmpty()) {
            overflow.values().forEach(item -> player.getWorld().dropItemNaturally(player.getLocation(), item));
            sendMessage(player, "full-inventory");
        }
    }

    public void runRandomKeyAll() {
        if (!getConfig().getBoolean("random-keyall.enabled", true)) {
            Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&',
                    getConfig().getString("messages.prefix", "") + getConfig().getString("messages.random-keyall-disabled", "&cDisabled.")));
            return;
        }
        List<String> ids = List.of("prime", "crimson", "spawner", "zenith");
        List<String> candidates = new ArrayList<>();
        long totalWeight = 0;
        for (String id : ids) {
            if (crateManager.get(id) == null) {
                continue;
            }
            int weight = Math.max(0, getConfig().getInt("random-keyall.crates." + id + ".weight", 0));
            if (weight > 0) {
                candidates.add(id);