A
📎 1 file 9,361 chars
📄
pasted-code-1788034011449.txt
txt 489 lines
▶
# Minecraft Plugin – EggEvent

Create a complete, professional Minecraft plugin called **EggEvent** for **Paper 1.20.1**, written in **Java 21** using **Maven**.

The plugin is an event system based around special **Sniffer Eggs**.

## 1. Plugin Name

Plugin name:

**EggEvent**

The plugin must be fully standalone and optimized for **Paper 1.20.1**.

---

## 2. Admin Command – /dajjajko

Create the command:

`/dajjajko`

Only players with the permission:

`eggevent.admin`

or OP can use this command.

When executed, the player receives a special **Sniffer Egg**.

Item:

**Sniffer Egg**

Display name:

`&a&lJajko Sniffera`

Lore:

`&7Specjalne jajko eventowe`
`&7Zbierz 15 jajek, aby otrzymać nagrodę!`

The item must have a unique **PersistentDataContainer (PDC)** tag so the plugin can recognize it as the special event egg.

Do NOT identify the item only by its name or lore.

---

## 3. Placing the Special Egg

When a player places the special Sniffer Egg:

* It should be placed normally in the world.
* It should look exactly like a normal Sniffer Egg.
* It must NOT hatch.
* It must NEVER spawn a Sniffer.
* The plugin must remember its exact location.
* The placed egg becomes an active event egg.

The player must NOT receive another egg after placing it.

---

## 4. Collecting the Event Egg

The event egg must be collected by **right-clicking it with the mouse (PPM)**.

When a player right-clicks an active event egg:

1. Cancel the normal interaction.
2. Remove the Sniffer Egg from the world.
3. Add **1** to the player's event progress.
4. Play a pickup sound.
5. Send a message showing current progress.

Example:

`&8[&aEVENT&8] &7Zebrałeś &a1 &7jajko Sniffera! &8(&a7&7/&f15&8)`

The player should NOT receive a physical egg item.

The egg should disappear immediately.

---

## 5. Egg Respawn

After an event egg is collected, it should automatically respawn at **the exact same location**.

The respawn time must be configurable.

Example:

```yaml
respawn-time: 120
```

The value is in seconds.

Supported examples:

* `60`
* `120`
* `180`

When the timer ends, the Sniffer Egg should appear again at exactly the same coordinates.

The respawned egg must be collectible again.

Each event egg location must have its own independent respawn timer.

---

## 6. Player Progress

Every player has their own collection progress.

The default goal is:

**15 eggs**

Examples:

`0/15`

`5/15`

`10/15`

`14/15`

`15/15`

When the player reaches **15 eggs**:

* Execute the reward command.
* Reset their progress to `0/15`.
* Allow them to collect another 15 eggs for another reward.

Player progress must be saved permanently so restarting the server does not reset it.

Use:

`players.yml`

Store data by player UUID.

---

## 7. Reward

When the player reaches 15 collected eggs, execute this command from the console:

`/case give  anarchiczna 3`

The reward command must be configurable.

Example:

```yaml
required-eggs: 15
reward-command: "case give %player% anarchiczna 3"
```

Replace `%player%` with the player's Minecraft username.

After receiving the reward, send:

`&8&m--------------------------------`
`&a&lEGG EVENT`
`` `&7Zebrałeś &a15 &7jajek Sniffera!` `&7Otrzymujesz &a3x Klucz Anarchiczny!` ``
`&8&m--------------------------------`

Also play a reward sound and show a title to the player.

---

## 8. Event Egg Locations

Create the administrative command:

`/eggevent add`

This adds an event egg at the admin's current location.

Save the exact:

* World
* X
* Y
* Z

Also create:

`/eggevent remove`

Removes the event egg at the admin's current location.

`/eggevent list`

Displays all configured egg locations.

`/eggevent reload`

Reloads the configuration.

`/eggevent give`

Gives the special Sniffer Egg.

`/dajjajko`

Must also give the special Sniffer Egg.

---

## 9. Egg Storage

Store all event egg locations in:

`eggs.yml`

Example:

```yaml
eggs:
  egg1:
    world: world
    x: 100.5
    y: 65.0
    z: -50.5
```

When the server starts, load all configured eggs.

The plugin should automatically restore the eggs into the world.

---

## 10. Protection / Anti-Exploit

Players must NOT be able to exploit event eggs.

Prevent:

* Normal breaking of event eggs.
* Obtaining event eggs by breaking them.
* Silk Touch collection.
* Pistons moving event eggs.
* Explosions destroying event eggs.
* TNT destroying event eggs.
* Duplication.
* Hoppers moving event eggs.
* Other normal mechanics that could remove or duplicate them.

The ONLY normal way to collect an event egg is **PPM/right-clicking it**.

---

## 11. Egg Hatch Protection

Every event Sniffer Egg must be permanently prevented from hatching.

It must never:

* Hatch naturally.
* Hatch after random ticks.
* Spawn a Sniffer.

The event egg should remain completely safe until a player collects it using PPM.

---

## 12. Configuration

Create a clean `config.yml`:

```yaml
respawn-time: 120

required-eggs: 15

reward-command: "case give %player% anarchiczna 3"

messages:
  received: "&8[&aEVENT&8] &7Zebrałeś &a1 &7jajko Sniffera! &8(&a%current%&7/&f%required%&8)"
  reward: "&8[&aEVENT&8] &a&lGRATULACJE! &7Zebrałeś wymaganą liczbę jajek!"
  no-permission: "&cNie masz uprawnień do tej komendy."
  egg-added: "&aDodano jajko eventowe!"
  egg-removed: "&cUsunięto jajko eventowe!"
  no-egg: "&cW tym miejscu nie ma jajka eventowego!"

sounds:
  pickup: "ENTITY_ITEM_PICKUP"
  reward: "ENTITY_PLAYER_LEVELUP"
```

Everything important must be configurable.

---

## 13. Placeholders

If PlaceholderAPI is installed, support:

`%eggevent_progress%`

Example:

`7/15`

Also:

`%eggevent_collected%`

Example:

`7`

PlaceholderAPI must be optional.

EggEvent must work normally without PlaceholderAPI.

---

## 14. Permissions

Create:

`eggevent.admin`

Allows administrative EggEvent commands.

`eggevent.give`

Allows `/dajjajko` and `/eggevent give`.

Normal players do NOT need any permission to collect eggs.

---

## 15. Commands

Implement:

```text
/dajjajko
/eggevent add
/eggevent remove
/eggevent list
/eggevent reload
/eggevent give
```

Add complete tab completion.

Show proper usage messages when commands are used incorrectly.

---

## 16. Visual / Event Feedback

When collecting an egg:

* Play pickup sound.
* Send progress message.
* Optionally spawn small particles.
* Make the collection feel like an actual server event.

When reaching 15 eggs:

* Play reward sound.
* Show a title.
* Send the reward message.
* Execute the reward command.

Do not spam the entire server with messages unless configured.

---

## 17. Technical Requirements

Use:

* **Paper 1.20.1**
* **Java 21**
* **Maven**
* Paper/Bukkit API
* PersistentDataContainer
* YAML configuration
* UUID-based player data
* Bukkit scheduler for respawn timers

Avoid unnecessary dependencies.

The plugin must be efficient.

Do NOT scan entire worlds every tick.

Only manage registered EggEvent locations.

Use proper event listeners and scheduled tasks.

---

## 18. File Structure

Generate a professional structure similar to:

```text
EggEvent/
├── pom.xml
├── src/
│   └── main/
│       ├── java/
│       │   └── pl/
│       │       └── eggevent/
│       │           ├── EggEvent.java
│       │           ├── commands/
│       │           ├── listeners/
│       │           ├── managers/
│       │           └── utils/
│       └── resources/
│           ├── plugin.yml
│           ├── config.yml
│           ├── eggs.yml
│           └── players.yml
```

Organize the code cleanly.

---

## 19. Important Behavior

Make sure the following exact scenario works:

1. Admin uses `/dajjajko`.
2. Admin receives the special Sniffer Egg.
3. Admin places it somewhere.
4. The egg looks normal.
5. The egg cannot hatch.
6. A player walks up to it.
7. The player uses PPM.
8. The egg disappears.
9. The player gets `1/15`.
10. After the configured amount of seconds, the egg returns to exactly the same location.
11. Another player can collect it again.
12. Once a player reaches `15/15`, the plugin executes:
    `case give  anarchiczna 3`
13. The player's progress resets to `0/15`.
14. They can start collecting another 15 eggs.

---

## 20. Final Deliverable

Generate the **complete working EggEvent plugin**.

Include:

* Complete Java source code.
* `pom.xml`.
* `plugin.yml`.
* `config.yml`.
* `eggs.yml`.
* Player data management.
* `/dajjajko`.
* `/eggevent` commands.
* Tab completion.
* Permissions.
* Event listeners.
* Special egg PDC identification.
* Egg placement system.
* PPM collection system.
* Respawn timers.
* Egg hatch prevention.
* Anti-exploit protection.
* Reward system.
* Optional PlaceholderAPI support.
* Clean professional architecture.

Do NOT provide pseudocode.

Do NOT leave TODOs.

Everything must be fully implemented and ready to compile with Maven and put directly into the Paper 1.20.1 `plugins` folder.
Kodari AI
KodariAug 29 at 8:12 pm 2
EggEvent
EggEvent is a Paper 1.20.1 plugin implementing a Sniffer Egg collection event system. Admins place special event eggs marked with PersistentDataContainer tags that cannot hatch or be broken by normal means. Players collect eggs by right-clicking them, progressing toward a configurable goal of 15 eggs. Each egg location has an independent respawn timer. Upon reaching the goal, the plugin executes a configurable reward command, resets progress, and displays celebratory feedback. Includes admin commands for managing egg locations, player data persistence via YAML, anti-exploit protections against pistons, explosions, and hoppers, plus optional PlaceholderAPI support.
A

The compilation failed with this error:

code
Compilation failed with 1 error(s):

ERROR in src/main/java/pl/eggevent/managers/EggManager.java at line 205: '(' or '[' expected
        YamlConfiguration data = new YamlConfiguration;
                                                      ^


=== COMPILATION ERROR ANALYSIS ===

SYNTAX ERRORS:
  - Line 205: '(' or '[' expected
ACTION: Check for missing semicolons or brackets

FILES TO INVESTIGATE:
  - src/main/java/pl/eggevent/managers/EggManager.java

Please fix this error by creating a new artifact with the corrected code.

Kodari AI
KodariAug 29 at 8:13 pm 1
  1. Correct the YamlConfiguration instantiation syntax in EggManager.

  2. Leave the existing egg storage and respawn behavior unchanged.

Fixed the compilation error in EggManager.java.

Changed:

Java
YamlConfiguration data = new YamlConfiguration;

to:

Java
YamlConfiguration data = new YamlConfiguration();

The corrected artifact is ready for compilation.

Kodari can make mistakes. Review important code before using.
Files
src
pom.xml
Code
13 1,085
src/main/java/pl/eggevent/EggEvent.java
package pl.eggevent;

import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Sound;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import pl.eggevent.commands.DajjajkoCommand;
import pl.eggevent.commands.EggEventCommand;
import pl.eggevent.commands.EggEventTabCompleter;
import pl.eggevent.listeners.EggListener;
import pl.eggevent.managers.EggManager;
import pl.eggevent.managers.PlayerDataManager;
import pl.eggevent.placeholders.EggEventPlaceholderExpansion;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

public final class EggEvent extends JavaPlugin {
    private NamespacedKey specialEggKey;
    private Material snifferEggMaterial;
    private EggManager eggManager;
    private PlayerDataManager playerDataManager;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        saveResource("eggs.yml", false);
        saveResource("players.yml", false);

        this.snifferEggMaterial = Material.matchMaterial("SNIFFER_EGG");
        if (this.snifferEggMaterial == null) {
            getLogger().severe("The SNIFFER_EGG material is unavailable. EggEvent will be disabled.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }

        this.specialEggKey = new NamespacedKey(this, "special_event_egg");
        this.playerDataManager = new PlayerDataManager(this);
        this.eggManager = new EggManager(this);
        this.eggManager.load();

        EggListener listener = new EggListener(this);
        getServer().getPluginManager().registerEvents(listener, this);

        DajjajkoCommand dajjajkoCommand = new DajjajkoCommand(this);
        EggEventCommand eggEventCommand = new EggEventCommand(this);

        if (getCommand("dajjajko") != null) {
            getCommand("dajjajko").setExecutor(dajjajkoCommand);
        }

        if (getCommand("eggevent") != null) {
            getCommand("eggevent").setExecutor(eggEventCommand);
            getCommand("eggevent").setTabCompleter(new EggEventTabCompleter());
        }

        if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
            new EggEventPlaceholderExpansion(this).register();
        }
    }

    @Override
    public void onDisable() {
        if (eggManager != null) {
            eggManager.shutdown();
        }
        if (playerDataManager != null) {
            playerDataManager.save();
        }
    }

    public ItemStack createSpecialEgg() {
        ItemStack item = new ItemStack(snifferEggMaterial);
        ItemMeta meta = item.getItemMeta();

        if (meta != null) {
            meta.setDisplayName(color("&a&lJajko Sniffera"));
            meta.setLore(List.of(
                    color("&7Specjalne jajko eventowe"),
                    color("&7Zbierz 15 jajek, aby otrzymać nagrodę!")
            ));
            meta.getPersistentDataContainer().set(
                    specialEggKey,
                    PersistentDataType.BYTE,
                    (byte) 1
            );
            item.setItemMeta(meta);
        }

        return item;
    }

    public boolean isSpecialEgg(ItemStack item) {
        if (item == null || item.getType() != snifferEggMaterial) {
            return false;
        }

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

        Byte value = meta.getPersistentDataContainer().get(
                specialEggKey,
                PersistentDataType.BYTE
        );
        return value != null && value == 1;
    }

    public void giveSpecialEgg(Player player) {
        player.getInventory().addItem(createSpecialEgg());
        sendMessage(player, "messages.egg-given");
    }

    public void handleCollection(Player player) {
        int required = getRequiredEggs();
        int current = playerDataManager.increment(player.getUniqueId());

        sendMessage(player, "messages.received",
                "%current%", String.valueOf(current),
                "%required%", String.valueOf(required));

        playSound(player, getConfig().getString("sounds.pickup", "ENTITY_ITEM_PICKUP"));

        if (current < required) {
            return;
        }

        String rewardCommand = getConfig().getString("reward-command", "")
                .replace("%player%", player.getName());

        if (!rewardCommand.isBlank()) {
            ConsoleCommandSender console = Bukkit.getConsoleSender();
            Bukkit.dispatchCommand(console, rewardCommand.startsWith("/")
                    ? rewardCommand.substring(1)
                    : rewardCommand);
        }

        sendMessage(player, "messages.reward",
                "%required%", String.valueOf(required));

        List<String> rewardLines = getConfig().getStringList("messages.reward-lines");
        if (rewardLines.isEmpty()) {
            rewardLines = new ArrayList<>();
            rewardLines.add("&a&lEGG EVENT");
            rewardLines.add("&7Otrzymujesz nagrodę za ukończenie eventu!");
        }

        for (String line : rewardLines) {
            player.sendMessage(color(line
                    .replace("%player%", player.getName())
                    .replace("%required%", String.valueOf(required))));
        }

        String title = getConfig().getString("reward.title", "");
        String subtitle = getConfig().getString("reward.subtitle", "");
        player.sendTitle(color(title), color(subtitle), 10, 70, 20);
        playSound(player, getConfig().getString("sounds.reward", "ENTITY_PLAYER_LEVELUP"));

        playerDataManager.reset(player.getUniqueId());
    }

    public void reloadPlugin() {
        reloadConfig();
        eggManager.reload();
    }

    public void sendMessage(Player player, String path, String... replacements) {
        String message = getConfig().getString(path, "");
        for (int i = 0; i + 1 < replacements.length; i += 2) {
            message = message.replace(replacements[i], replacements[i + 1]);
        }
        player.sendMessage(color(message));
    }

    public void playSound(Player player, String configuredSound) {
        if (configuredSound == null || configuredSound.isBlank()) {
            return;
        }

        try {
            Field field = Sound.class.getField(configuredSound.toUpperCase(Locale.ROOT));
            Object value = field.get(null);
            if (value instanceof Sound sound) {
                player.playSound(player.getLocation(), sound, 1.0f, 1.0f);
            }
        } catch (ReflectiveOperationException ignored) {
            getLogger().warning("Unknown sound configured: " + configuredSound);
        }
    }