Skip to content

Commit

Permalink
Version 1.3.0
Browse files Browse the repository at this point in the history
 * Updated to `api-version` 1.18
 * Store current stage number and next stage (during
   transition) in `config.yml` rather than trying to
   infer the stage number from the presence of
   entities. This should be more reliable.
  • Loading branch information
totemo committed Oct 6, 2022
1 parent 2337f3c commit 8b76ec8
Show file tree
Hide file tree
Showing 9 changed files with 507 additions and 241 deletions.
36 changes: 31 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>nu.nerd</groupId>
<artifactId>DragonFight</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>

<description>Custom dragon fight.</description>
<url>https://github.com/NerdNu/${project.name}</url>
Expand All @@ -17,8 +17,17 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!--
See: https://mkyong.com/maven/maven-error-invalid-target-release-17/
You will need to tell Maven to use Java 17.
Do: mvn -version to check the version of Java used by Maven.
Then set JAVA_HOME as appropriate to your platform:
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk
-->
<maven.compiler.release>17</maven.compiler.release>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
</properties>

<repositories>
Expand All @@ -32,12 +41,21 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.15.2-R0.1-SNAPSHOT</version>
<version>1.18.1-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>nu.nerd</groupId>
<artifactId>BeastMaster</artifactId>
<version>2.14.0</version>
<version>2.17.0</version>
</dependency>
<dependency>
<!--
Work around java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor
for whatever is using it: Minecraft? Spigot?
-->
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
</dependency>
</dependencies>

Expand All @@ -49,5 +67,13 @@
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.9.0</version>
</plugin>
</plugins>
</build>
</project>

60 changes: 53 additions & 7 deletions src/main/java/nu/nerd/df/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,38 @@ public class Configuration {
*/
public String DEBUG_PREFIX;

/**
* Current stage number: 0 to 11.
*
* Stage 0 is before the fight, Stage 1 => first crystal removed and boss
* spawned. Stage 10 => final boss spawned. Stage 11: dragon. In Stage N, N
* crystals have been removed.
*/
public int STAGE_NUMBER;

/**
* The new value of STAGE_NUMBER, when there is a transition between stages.
*
* Spawn animations for the dragon and for stage bosses take time. To handle
* server restarts during these spawn sequences, we need to record the fact
* that it is underway and at least the new stage number. But in this
* plugin, we record both as that makes backwards stage transitions feasible
* (although not currently implemented).
*
* When NEW_STAGE_NUMBER != STAGE_NUMBER, the fight is part-way through
* transitioning from STAGE_NUMBER to NEW_STAGE_NUMBER. The STAGE_NUMBER
* will be set to NEW_STAGE_NUMBER when the transition is complete, in a few
* seconds.
*/
public int NEW_STAGE_NUMBER;

/**
* Total boss maximum health.
*
* This needs to be preserved across restarts, since a stage fight may have
* a random number of bosses, some of which may have died. THere is no easy
* way to work infer the total maximum boss health points in the stage after
* a restart.
* a random number of bosses, some of which may have died. There is no easy
* way to infer the total maximum boss health points in the stage after a
* restart.
*/
public double TOTAL_BOSS_MAX_HEALTH;

Expand Down Expand Up @@ -102,15 +127,18 @@ public Stage getStage(int stageNumber) {

// ------------------------------------------------------------------------
/**
* Reload the configuration.
* Reload the fight state.
*
* The fight state changes as the plugin runs, so only call this method when
* loading the plugin.
*/
public void reload() {
public void reloadFightState() {
DragonFight.PLUGIN.reloadConfig();
FileConfiguration config = DragonFight.PLUGIN.getConfig();
Logger logger = DragonFight.PLUGIN.getLogger();

LOG_PREFIX = config.getString("settings.log-prefix");
DEBUG_PREFIX = config.getString("settings.debug-prefix");
STAGE_NUMBER = config.getInt("state.stage-number", 0);
NEW_STAGE_NUMBER = config.getInt("state.new-stage-number", 0);

TOTAL_BOSS_MAX_HEALTH = config.getDouble("state.total-boss-max-health");
try {
Expand All @@ -131,6 +159,22 @@ public void reload() {
logger.warning("Unclaimed dragon prize registered to invalid UUID: " + key);
}
}
}

// ------------------------------------------------------------------------
/**
* Reload the configuration.
*
* This method is the counterpart to {@link #reloadFightState}. This method
* only loads the settings of the fight that are not modified as the fight
* progresses.
*/
public void reloadConfiguration() {
DragonFight.PLUGIN.reloadConfig();
FileConfiguration config = DragonFight.PLUGIN.getConfig();

LOG_PREFIX = config.getString("settings.log-prefix");
DEBUG_PREFIX = config.getString("settings.debug-prefix");

for (int stageNumber = 1; stageNumber <= 11; ++stageNumber) {
getStage(stageNumber).load(getStageSection(stageNumber));
Expand All @@ -147,6 +191,8 @@ public void save() {
config.set("settings.log-prefix", LOG_PREFIX);
config.set("settings.debug-prefix", DEBUG_PREFIX);

config.set("state.stage-number", STAGE_NUMBER);
config.set("state.new-stage-number", NEW_STAGE_NUMBER);
config.set("state.total-boss-max-health", TOTAL_BOSS_MAX_HEALTH);
config.set("state.fight-owner", (FIGHT_OWNER == null) ? null : FIGHT_OWNER.toString());

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/nu/nerd/df/DragonFight.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public class DragonFight extends JavaPlugin {
public void onEnable() {
PLUGIN = this;
saveDefaultConfig();
CONFIG.reload();
CONFIG.reloadConfiguration();
CONFIG.reloadFightState();

addCommandExecutor(new DFExecutor());
addCommandExecutor(new DragonExecutor());
Expand All @@ -61,7 +62,7 @@ public void onDisable() {
// ------------------------------------------------------------------------
/**
* Add the specified CommandExecutor and set it as its own TabCompleter.
*
*
* @param executor the CommandExecutor.
*/
protected void addCommandExecutor(ExecutorBase executor) {
Expand Down
27 changes: 14 additions & 13 deletions src/main/java/nu/nerd/df/DragonUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
// --------------------------------------------------------------------------
/**
* DragonFight utility functions.
*
*
* Note that the DragonFight plugin also references BeastMaster's DragonUtil
* class, so to avoid a qualified name, we name this class differently.
*/
public class DragonUtil {
// ------------------------------------------------------------------------
/**
* Return the world where the dragon fight occurs.
*
*
* @return the world where the dragon fight occurs.
*/
public static World getFightWorld() {
Expand All @@ -35,7 +35,7 @@ public static World getFightWorld() {
/**
* Return true if the specified world is the one where the dragon fight can
* occur.
*
*
* @param world the world.
* @return true if the specified world is the one where the dragon fight can
* occur.
Expand All @@ -48,9 +48,9 @@ public static boolean isFightWorld(World world) {
// ------------------------------------------------------------------------
/**
* Remove a specific dragon.
*
*
* Because Entity.remove() would be too easy.
*
*
* @param dragon the ender dragon to remove.
*/
public static void removeDragon(EnderDragon dragon) {
Expand All @@ -77,9 +77,9 @@ public static void removeAllDragons() {
/**
* Return true if an entity has the specified scoreboard tag or BeastMaster
* group.
*
*
* @param entity the entity.
* @param tag the tag or group to look for.
* @param tag the tag or group to look for.
* @return true if the entity has the tag or group.
*/
public static boolean hasTagOrGroup(Entity entity, String tag) {
Expand All @@ -102,7 +102,7 @@ public static boolean hasTagOrGroup(Entity entity, String tag) {
* Return the magnitude of the X and Z components of location, i.e. the
* distance between loc and the world origin in the XZ plane (ignoring Y
* coordinate).
*
*
* @param loc the location.
* @return sqrt(x^2 + z^2).
*/
Expand All @@ -114,11 +114,11 @@ public static double getMagnitude2D(Location loc) {
/**
* Return true if the specified location is on the circle where the centre
* of the obsidian pillars are placed.
*
*
* The pillars about placed in a circle about 40 blocks from (0,0). The
* largest pillars have a radius of 5 blocks, including the centre block, so
* ensure that we block placements up to 6 blocks away (6/40 = 0.15).
*
*
* Note that:
* <ul>
* <li>This method assumes that the world has already been confirmed to be
Expand All @@ -129,19 +129,20 @@ public static double getMagnitude2D(Location loc) {
* spawning of crystals on pillars, because when the crystal on the pillar
* spawns, the block underneath it comes back as AIR, not BEDROCK.</li>
* </ul>
*
*
* @param loc the location.
* @return if the location is about the right range from the origin of the
* world to be the centre of a pillar.
*/
public static boolean isOnPillarCircle(Location loc) {
return Math.abs(getMagnitude2D(loc) - DragonUtil.PILLAR_CIRCLE_RADIUS) < 0.15 * DragonUtil.PILLAR_CIRCLE_RADIUS;
return loc.getWorld().getName().equals("world_the_end") &&
Math.abs(getMagnitude2D(loc) - DragonUtil.PILLAR_CIRCLE_RADIUS) < 0.15 * DragonUtil.PILLAR_CIRCLE_RADIUS;
}

// ------------------------------------------------------------------------
/**
* The World where the fight occurs.
*
*
* It could be configurable, but for now is constant.
*/
private static final String FIGHT_WORLD = "world_the_end";
Expand Down
Loading

0 comments on commit 8b76ec8

Please sign in to comment.