Velox Delos
๐Ÿ“Ž 1 file 1,035 chars
๐Ÿ“„
pasted-code-1792880985709.txt
txt 1 lines
โ–ถ
when 1 or more players go in the end the and kill the ender dragon the dragon egg will spawn on a random spot on the island and when a player drops the dragon egg the egg will float in the air on the same hight as the players head and the dragon egg has purple and white particles and when it gets placed a circle pops up with purple particles that is 3x3 around the egg and when 1 player stands in the circle and hits the egg 5 times the egg dropes and with each punch the boss bar from the egg goes up and when 2 or more players stand in the cricle then no one can punch the egg and let it drop it just works when one player stand in the cricle and the egg ist explosion resistence and fire resistence and when the player dies the egg wil spawn on a random spot and will have the circle and the punch thing and when 2 or more dragon eggs exist in the world as an item or placed the second egg will stay in the world and the other egg will get deleted and when a player punches the egg 5 times it will explod an deal 5 damage an drop 
Kodari AI
KodariOct 24 at 10:35 pm 1
DragonEggRitual
Manages a unique dragon egg mechanic in the End dimension. When players kill the Ender Dragon, the egg spawns at a random island location. The egg floats at player head height with purple and white particles, surrounded by a 3x3 purple particle circle. Only one player standing in the circle can punch the egg; each punch fills a boss bar, and after five punches the egg explodes dealing 5 damage and drops. The egg is explosion and fire resistant. If multiple eggs exist, extras are deleted. If the holder dies, the egg respawns randomly with the ritual circle intact.

Created the DragonEggChallenge plugin. After an Ender Dragon dies, an egg spawns at a random spot nearby. Dropped eggs float at head height with purple and white particles; placed eggs get a particle circle and a five-hit boss bar. Only one player can be in the circle for hits to count. Completing the challenge drops the egg and deals 5 damage nearby. The plugin also protects eggs from fire and explosions and removes duplicate eggs it tracks in a world.

Kodari can make mistakes. Review important code before using.
Files
src
Code
2 372
src/main/java/com/kodari/dragonegg/DragonEggPlugin.java
package com.kodari.dragonegg;

import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XSound;
import com.cryptomorin.xseries.particles.XParticle;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.block.Block;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockExplodeEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import org.bukkit.NamespacedKey;

public final class DragonEggPlugin extends JavaPlugin implements Listener {
    private static final int REQUIRED_HITS = 5;
    private static final double CIRCLE_RADIUS = 1.5;

    private final Map<Location, EggProgress> progressByLocation = new HashMap<>();
    private final Map<java.util.UUID, Set<Location>> placedEggsByWorld = new HashMap<>();
    private NamespacedKey managedEggKey;
    private NamespacedKey floatingEggKey;
    private Material dragonEggMaterial;
    private Material airMaterial;

    @Override
    public void onEnable() {
        dragonEggMaterial = XMaterial.matchXMaterial("DRAGON_EGG")
                .map(XMaterial::parseMaterial)
                .orElse(null);
        airMaterial = XMaterial.matchXMaterial("AIR")
                .map(XMaterial::parseMaterial)
                .orElse(null);
        if (dragonEggMaterial == null || airMaterial == null) {
            getLogger().severe("This server version does not provide the materials required for dragon eggs.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }

        managedEggKey = new NamespacedKey(this, "managed_egg");
        floatingEggKey = new NamespacedKey(this, "floating_egg");
        getServer().getPluginManager().registerEvents(this, this);
        getServer().getScheduler().runTaskTimer(this, this::tick, 10L, 10L);
    }

    @Override
    public void onDisable() {
        for (EggProgress progress : progressByLocation.values()) {
            progress.bossBar.removeAll();
        }
        progressByLocation.clear();
    }

    @EventHandler(priority = EventPriority.MONITOR)
    public void onDragonDeath(EntityDeathEvent event) {
        if (!(event.getEntity() instanceof EnderDragon dragon)) {
            return;
        }
        World world = dragon.getWorld();
        Location spawnLocation = randomIslandLocation(dragon.getLocation());
        Item egg = world.dropItem(spawnLocation, new ItemStack(dragonEggMaterial));
        egg.setPickupDelay(0);
        markManaged(egg);
        enforceSingleEgg(world, egg, null);
    }

    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    public void onPlayerDropEgg(PlayerDropItemEvent event) {
        Item item = event.getItemDrop();
        if (!isDragonEggItem(item)) {
            return;
        }

        Location location = item.getLocation();
        location.setY(event.getPlayer().getEyeLocation().getY());
        item.teleport(location);
        item.setVelocity(new Vector(0, 0, 0));
        item.setGravity(false);
        item.setInvulnerable(true);
        item.setFireTicks(0);
        markManaged(item);
        item.getPersistentDataContainer().set(floatingEggKey, PersistentDataType.BYTE, (byte) 1);
        enforceSingleEgg(item.getWorld(), item, null);
    }

    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    public void onEggPlace(BlockPlaceEvent event) {
        Block block = event.getBlockPlaced();
        if (!isDragonEggBlock(block)) {
            return;
        }

        Location location = block.getLocation();
        placedEggsByWorld.computeIfAbsent(block.getWorld().getUID(), ignored -> new HashSet<>()).add(location);
        progressByLocation.computeIfAbsent(location, ignored -> new EggProgress());
        enforceSingleEgg(block.getWorld(), null, location);
    }

    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    public void onEggInteract(PlayerInteractEvent event) {
        Block block = event.getClickedBlock();
        if (block == null || !isDragonEggBlock(block)) {
            return;
        }

        event.setCancelled(true);
        if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
            attemptPunch(event.getPlayer(), block);
        }
    }

    @EventHandler(ignoreCancelled = true)
    public void onBlockBreak(BlockExplodeEvent event) {
        event.blockList().removeIf(this::isDragonEggBlock);
    }

    @EventHandler(ignoreCancelled = true)
    public void onEntityExplosion(EntityExplodeEvent event) {
        event.blockList().removeIf(this::isDragonEggBlock);
    }

    @EventHandler(ignoreCancelled = true)
    public void onEggBurn(BlockBurnEvent event) {
        if (isDragonEggBlock(event.getBlock())) {
            event.setCancelled(true);
        }
    }

    @EventHandler(ignoreCancelled = true)
    public void onEggIgnite(BlockIgniteEvent event) {
        if (isDragonEggBlock(event.getBlock())) {
            event.setCancelled(true);
        }
    }

    @EventHandler(ignoreCancelled = true)
    public void onEggItemDamage(EntityDamageEvent event) {
        if (!(event.getEntity() instanceof Item item) || !isDragonEggItem(item)) {
            return;
        }

        String cause = event.getCause().name();
        if (item.getPersistentDataContainer().has(managedEggKey, PersistentDataType.BYTE)
                || cause.equals("FIRE")
                || cause.equals("FIRE_TICK")
                || cause.equals("LAVA")
                || cause.equals("HOT_FLOOR")
                || cause.equals("BLOCK_EXPLOSION")
                || cause.equals("ENTITY_EXPLOSION")) {
            event.setCancelled(true);
        }
    }

    private Location randomIslandLocation(Location center) {
        ThreadLocalRandom random = ThreadLocalRandom.current();
        int x = center.getBlockX() + random.nextInt(-16, 17);
        int z = center.getBlockZ() + random.nextInt(-16, 17);
        int y = center.getWorld().getHighestBlockYAt(x, z) + 1;
        return new Location(center.getWorld(), x + 0.5, y, z + 0.5);
    }

    private void markManaged(Item item) {
        item.getPersistentDataContainer().set(managedEggKey, PersistentDataType.BYTE, (byte) 1);
    }

    private boolean isDragonEggItem(Item item) {
        return item.getItemStack().getType().equals(dragonEggMaterial);
    }