feat: add a config option to spawn the egg somewhere randomly in the overworld above bedrock
This commit is contained in:
parent
1ef334318f
commit
a1b0cc8dcd
3 changed files with 95 additions and 26 deletions
|
|
@ -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);
|
||||
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,13 +77,27 @@ 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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop the egg out of the given player's inventory
|
||||
|
|
|
|||
|
|
@ -9,22 +9,65 @@ 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 */
|
||||
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 */
|
||||
public static final String DEFAULT_END = "world_end";
|
||||
/**
|
||||
* default end world name for most spigot servers
|
||||
*/
|
||||
|
||||
ConfigFileDAO fileDao;
|
||||
|
||||
|
|
@ -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,6 +146,10 @@ public class Configuration {
|
|||
return namedEntitiesGetScore;
|
||||
}
|
||||
|
||||
public boolean getRespawnRandomlyInOverworld() {
|
||||
return respawnRandomlyInOverworld;
|
||||
}
|
||||
|
||||
public String getOwnerTagName() {
|
||||
return ownerTagName;
|
||||
}
|
||||
|
|
@ -110,5 +159,4 @@ public class Configuration {
|
|||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue