From a1b0cc8dcd80161e9b269edfce5608ba5d5323a8 Mon Sep 17 00:00:00 2001 From: HerozDotExe Date: Fri, 6 Feb 2026 22:42:52 +0100 Subject: [PATCH] feat: add a config option to spawn the egg somewhere randomly in the overworld above bedrock --- .../egghunt/Controller/EggController.java | 33 +++++-- .../egghunt/Model/Configuration.java | 86 +++++++++++++++---- src/main/resources/config.yml | 2 + 3 files changed, 95 insertions(+), 26 deletions(-) diff --git a/src/main/java/io/github/J0hnL0cke/egghunt/Controller/EggController.java b/src/main/java/io/github/J0hnL0cke/egghunt/Controller/EggController.java index 8fe21a0..92f9d55 100644 --- a/src/main/java/io/github/J0hnL0cke/egghunt/Controller/EggController.java +++ b/src/main/java/io/github/J0hnL0cke/egghunt/Controller/EggController.java @@ -1,9 +1,8 @@ package io.github.J0hnL0cke.egghunt.Controller; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.OfflinePlayer; +import org.bukkit.*; import org.bukkit.block.Block; +import org.bukkit.block.BlockType; import org.bukkit.entity.Entity; import org.bukkit.entity.Item; import org.bukkit.entity.Player; @@ -14,6 +13,8 @@ import io.github.J0hnL0cke.egghunt.Model.Configuration; import io.github.J0hnL0cke.egghunt.Model.Data; import io.github.J0hnL0cke.egghunt.Model.LogHandler; +import java.util.Random; + /** * Provides functionality relating to the dragon egg, but does not register any event handlers. * This is a pure fabrication class to simplify functionality used by multiple controllers. @@ -55,7 +56,11 @@ public class EggController { if (config.getRespawnImmediately()) { logger.log("Immediate respawn enabled- respawning egg"); respawnEgg(config, data, logger); - msg = "The dragon egg was destroyed and has respawned in The End!"; + if (config.getRespawnRandomlyInOverworld()) { + msg = "The dragon egg was destroyed and has respawned somewhere in the overworld!"; + } else { + msg = "The dragon egg was destroyed and has respawned in The End!"; + } if (oldOwner != null) { //prevent spamming of egg destruction } } else { @@ -72,12 +77,26 @@ public class EggController { } + private static int randomCoordinate() { + Random rand = new Random(); + int range = (int) Bukkit.getWorld("world").getWorldBorder().getSize() / 4; + int result = rand.nextInt(-range, range) + range; + return result; + } + /** - * Returns the location above the end fountain where the dragon will respawn + * Returns the location where the dragon egg will respawn */ public static Location getEggRespawnLocation(Configuration config) { - //the block above the bedrock fountain where the egg spawns - return config.getEndWorld().getEnderDragonBattle().getEndPortalLocation().add(0, 4, 0); + if (config.getRespawnRandomlyInOverworld()) { + double x = Math.random(); + + World world = Bukkit.getWorld("world"); + return new Location(world, randomCoordinate(), -50, randomCoordinate()); + } else { + //the block above the bedrock fountain where the egg spawns + return config.getEndWorld().getEnderDragonBattle().getEndPortalLocation().add(0, 4, 0); + } } /** diff --git a/src/main/java/io/github/J0hnL0cke/egghunt/Model/Configuration.java b/src/main/java/io/github/J0hnL0cke/egghunt/Model/Configuration.java index 34603e1..b1d4330 100644 --- a/src/main/java/io/github/J0hnL0cke/egghunt/Model/Configuration.java +++ b/src/main/java/io/github/J0hnL0cke/egghunt/Model/Configuration.java @@ -9,25 +9,68 @@ import io.github.J0hnL0cke.egghunt.Persistence.ConfigFileDAO; * Retrieve settings for this plugin */ public class Configuration { - private boolean debug; /** whether to show debug information in console log */ - private boolean eggInvulnerable; /** whether to make the egg immune to damage */ - private boolean respawnEgg; /** whether the egg should respawn when destroyed */ - private boolean respawnImmediately; /** if respawning the egg, whether it should immediately respawn in-place or whether it should generate after next dragon fight */ - private boolean resetOwnerOnTeleport; /** whether the egg should become "lost" when it is teleported */ - private boolean resetOwnerOnDrop; /** whether the egg should become "lost" when it is dropped */ + private boolean debug; + /** + * whether to show debug information in console log + */ + private boolean eggInvulnerable; + /** + * whether to make the egg immune to damage + */ + private boolean respawnEgg; + /** + * whether the egg should respawn when destroyed + */ + private boolean respawnImmediately; + /** + * if respawning the egg, whether it should immediately respawn in-place or whether it should generate after next dragon fight + */ + private boolean resetOwnerOnTeleport; + /** + * whether the egg should become "lost" when it is teleported + */ + private boolean resetOwnerOnDrop; + /** + * whether the egg should become "lost" when it is dropped + */ private boolean accurateLocation; - private boolean dropEnderchestedEgg; /** whether an existing egg already in an ender chest should be forced out or stuck there */ - private boolean canPackageEgg; /** whether the egg can be stored in a shulker box or bundle */ - private boolean tagOwner; /** whether to apply a tag to the owner of the egg */ - private boolean keepScore; /** whether to create and increment a scoreboard for time holding the egg */ - private boolean namedEntitiesGetScore; /** whether entities with custom names are counted on the scoreboard when holding the egg */ - private World endWorld; /** the name of the world that counts as the end on this server */ - private String ownerTagName; /** the name of the tag to apply to the owner, if enabled */ - - public static final String DEFAULT_END = "world_end"; /** default end world name for most spigot servers */ - + private boolean dropEnderchestedEgg; + /** + * whether an existing egg already in an ender chest should be forced out or stuck there + */ + private boolean canPackageEgg; + /** + * whether the egg can be stored in a shulker box or bundle + */ + private boolean tagOwner; + /** + * whether to apply a tag to the owner of the egg + */ + private boolean keepScore; + /** + * whether to create and increment a scoreboard for time holding the egg + */ + private boolean namedEntitiesGetScore; + /** + * whether entities with custom names are counted on the scoreboard when holding the egg + */ + private boolean respawnRandomlyInOverworld; + private World endWorld; + /** + * the name of the world that counts as the end on this server + */ + private String ownerTagName; + /** + * the name of the tag to apply to the owner, if enabled + */ + + public static final String DEFAULT_END = "world_end"; + /** + * default end world name for most spigot servers + */ + ConfigFileDAO fileDao; - + public Configuration(ConfigFileDAO fileDao) { this.fileDao = fileDao; loadData(); @@ -48,6 +91,7 @@ public class Configuration { tagOwner = fileDao.readBool("tag_owner"); keepScore = fileDao.readBool("keep_score"); namedEntitiesGetScore = fileDao.readBool("named_entities_keep_score"); + respawnRandomlyInOverworld = fileDao.readBool("respawnRandomlyInOverworld"); ownerTagName = fileDao.read("owner_tag_name", null); endWorld = Bukkit.getServer().getWorld(fileDao.read("end", DEFAULT_END)); @@ -61,6 +105,7 @@ public class Configuration { public boolean getEggInvulnerable() { return eggInvulnerable; } + public boolean getRespawnEgg() { return respawnEgg; } @@ -101,7 +146,11 @@ public class Configuration { return namedEntitiesGetScore; } - public String getOwnerTagName(){ + public boolean getRespawnRandomlyInOverworld() { + return respawnRandomlyInOverworld; + } + + public String getOwnerTagName() { return ownerTagName; } @@ -109,6 +158,5 @@ public class Configuration { return endWorld; } - } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 4ba6716..10e98dc 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -15,6 +15,8 @@ egg_inv: false resp_egg: true #Whether the egg respawns immediately (true) or after a new dragon is spawned and killed (false) after the egg is destroyed resp_imm: false +# If true and resp_imm true, will respawn the egg at a random place on top of bedrock in the overworld instead of in the end +respawnRandomlyInOverworld: false #Whether to drop any eggs that players have in their ender chest onto the ground. #Setting this to false will prevent the player from removing that egg from their ender chest.