From f941bb45f02559773fe76c45862cca0d94b64722 Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 3 Jan 2019 23:58:29 +0800 Subject: [PATCH] 1.0.0-SNAPSHOT-U172 + Started the implementation of the AutoSpawn spawn system + Updated BossAPI#spawnBoss method to allow for a boolean for custom spawn message. --- .../com/songoda/epicbosses/api/BossAPI.java | 4 +- .../types/IntervalSpawnElement.java | 16 +++++++- .../commands/boss/BossSpawnCmd.java | 2 +- .../epicbosses/holder/ActiveBossHolder.java | 2 +- .../ActiveIntervalAutoSpawnHolder.java | 39 ++++++++++--------- .../listeners/pre/BossSpawnListener.java | 2 +- pom.xml | 2 +- 7 files changed, 42 insertions(+), 25 deletions(-) diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/api/BossAPI.java b/plugin-modules/Core/src/com/songoda/epicbosses/api/BossAPI.java index fc283f1..32c42cf 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/api/BossAPI.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/api/BossAPI.java @@ -432,7 +432,7 @@ public class BossAPI { * @param itemStack - The itemstack used to spawn the boss. * @return ActiveBossHolder class with stored information */ - public static ActiveBossHolder spawnNewBoss(BossEntity bossEntity, Location location, Player player, ItemStack itemStack) { + public static ActiveBossHolder spawnNewBoss(BossEntity bossEntity, Location location, Player player, ItemStack itemStack, boolean customSpawnMessage) { if(bossEntity.isEditing()) { Debug.ATTEMPTED_TO_SPAWN_WHILE_DISABLED.debug(); return null; @@ -447,6 +447,8 @@ public class BossAPI { return null; } + activeBossHolder.setCustomSpawnMessage(customSpawnMessage); + PreBossSpawnEvent preBossSpawnEvent; if(player != null && itemStack != null) { diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/autospawns/types/IntervalSpawnElement.java b/plugin-modules/Core/src/com/songoda/epicbosses/autospawns/types/IntervalSpawnElement.java index e6c58f3..30b560c 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/autospawns/types/IntervalSpawnElement.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/autospawns/types/IntervalSpawnElement.java @@ -1,12 +1,17 @@ package com.songoda.epicbosses.autospawns.types; import com.google.gson.annotations.Expose; +import com.songoda.epicbosses.api.BossAPI; +import com.songoda.epicbosses.autospawns.AutoSpawn; +import com.songoda.epicbosses.autospawns.settings.AutoSpawnSettings; +import com.songoda.epicbosses.holder.ActiveBossHolder; +import com.songoda.epicbosses.holder.autospawn.ActiveIntervalAutoSpawnHolder; import com.songoda.epicbosses.listeners.IBossDeathHandler; +import com.songoda.epicbosses.utils.ObjectUtils; import com.songoda.epicbosses.utils.StringUtils; import lombok.Getter; import lombok.Setter; import org.bukkit.Location; -import org.bukkit.event.Listener; /** * @author Charles Cullen @@ -26,7 +31,14 @@ public class IntervalSpawnElement { this.spawnAfterLastBossIsKilled = spawnAfterLastBossIsKilled; } - public boolean attemptSpawn(IBossDeathHandler bossDeathHandler) { + public boolean attemptSpawn(ActiveIntervalAutoSpawnHolder activeAutoSpawnHolder) { + IBossDeathHandler bossDeathHandler = activeAutoSpawnHolder.getPostDeathHandler(); + AutoSpawn autoSpawn = activeAutoSpawnHolder.getAutoSpawn(); + AutoSpawnSettings autoSpawnSettings = autoSpawn.getAutoSpawnSettings(); + boolean customSpawnMessage = ObjectUtils.getValue(autoSpawnSettings.getOverrideDefaultSpawnMessage(), false); + int amountToSpawn = ObjectUtils.getValue(autoSpawnSettings.getAmountPerSpawn(), 1); + boolean shuffleList = ObjectUtils.getValue(autoSpawnSettings.getShuffleEntitiesList(), false); + return true; } diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/commands/boss/BossSpawnCmd.java b/plugin-modules/Core/src/com/songoda/epicbosses/commands/boss/BossSpawnCmd.java index 254a72d..3852f57 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/commands/boss/BossSpawnCmd.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/commands/boss/BossSpawnCmd.java @@ -66,7 +66,7 @@ public class BossSpawnCmd extends SubCommand { return; } - BossAPI.spawnNewBoss(bossEntity, spawnLocation, null, null); + BossAPI.spawnNewBoss(bossEntity, spawnLocation, null, null, false); Message.Boss_Spawn_Spawned.msg(sender, bossInput, StringUtils.get().translateLocation(spawnLocation)); } } diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/holder/ActiveBossHolder.java b/plugin-modules/Core/src/com/songoda/epicbosses/holder/ActiveBossHolder.java index d30a411..eb0d7d5 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/holder/ActiveBossHolder.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/holder/ActiveBossHolder.java @@ -29,7 +29,7 @@ public class ActiveBossHolder implements IActiveHolder { @Getter private Map mapOfDamagingUsers = new HashMap<>(); @Getter @Setter private TargetHandler targetHandler = null; - @Getter @Setter private boolean isDead = false; + @Getter @Setter private boolean isDead = false, customSpawnMessage = false; public ActiveBossHolder(BossEntity bossEntity, Location spawnLocation, String name) { this.location = spawnLocation; diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/holder/autospawn/ActiveIntervalAutoSpawnHolder.java b/plugin-modules/Core/src/com/songoda/epicbosses/holder/autospawn/ActiveIntervalAutoSpawnHolder.java index f053aa7..180f973 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/holder/autospawn/ActiveIntervalAutoSpawnHolder.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/holder/autospawn/ActiveIntervalAutoSpawnHolder.java @@ -50,6 +50,7 @@ public class ActiveIntervalAutoSpawnHolder extends ActiveAutoSpawnHolder { if(location == null) return false; if(!spawnIfChunkNotLoaded && !location.getChunk().isLoaded()) return false; + if(spawnAfterLastBossIsKilled && !getActiveBossHolders().isEmpty()) return false; return currentActiveAmount < maxAmount; } @@ -72,12 +73,14 @@ public class ActiveIntervalAutoSpawnHolder extends ActiveAutoSpawnHolder { updateNextCompleteTime(delayMs); this.intervalTask = ServerUtils.get().runTimer(delayMs, delayMs, () -> { - updateNextCompleteTime(delayMs); - if(!canSpawn()) return; - if(this.intervalSpawnElement.attemptSpawn(getPostDeathHandler()) && spawnAfterLastBossIsKilled) { + + if(this.intervalSpawnElement.attemptSpawn(this) && spawnAfterLastBossIsKilled) { stopInterval(); + return; } + + updateNextCompleteTime(delayMs); }); } @@ -89,6 +92,21 @@ public class ActiveIntervalAutoSpawnHolder extends ActiveAutoSpawnHolder { return this.nextCompletedTime - currentMs; } + public IBossDeathHandler getPostDeathHandler() { + return event -> { + boolean spawnAfterLastBossIsKilled = ObjectUtils.getValue(this.intervalSpawnElement.getSpawnAfterLastBossIsKilled(), false); + ActiveBossHolder activeBossHolder = event.getActiveBossHolder(); + + if(getActiveBossHolders().contains(activeBossHolder)) { + getActiveBossHolders().remove(activeBossHolder); + + if(spawnAfterLastBossIsKilled) { + restartInterval(); + } + } + }; + } + private void stopInterval() { if(this.intervalTask != null) ServerUtils.get().cancelTask(this.intervalTask); @@ -101,19 +119,4 @@ public class ActiveIntervalAutoSpawnHolder extends ActiveAutoSpawnHolder { private void updateNextCompleteTime(long delayMs) { this.nextCompletedTime = System.currentTimeMillis() + delayMs; } - - private IBossDeathHandler getPostDeathHandler() { - return event -> { - boolean spawnAfterLastBossIsKilled = ObjectUtils.getValue(this.intervalSpawnElement.getSpawnAfterLastBossIsKilled(), false); - ActiveBossHolder activeBossHolder = event.getActiveBossHolder(); - - if(getActiveBossHolders().contains(activeBossHolder)) { - getActiveBossHolders().remove(activeBossHolder); - - if(spawnAfterLastBossIsKilled) { - restartInterval(); - } - } - }; - } } diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/listeners/pre/BossSpawnListener.java b/plugin-modules/Core/src/com/songoda/epicbosses/listeners/pre/BossSpawnListener.java index 39ad1f0..41fe1fe 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/listeners/pre/BossSpawnListener.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/listeners/pre/BossSpawnListener.java @@ -95,7 +95,7 @@ public class BossSpawnListener implements Listener { event.setCancelled(true); - ActiveBossHolder activeBossHolder = BossAPI.spawnNewBoss(bossEntity, location, player, itemStack); + ActiveBossHolder activeBossHolder = BossAPI.spawnNewBoss(bossEntity, location, player, itemStack, false); if(activeBossHolder == null) { event.setCancelled(true); diff --git a/pom.xml b/pom.xml index b5e9d39..fa09353 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ - 1.0.0-U171 + 1.0.0-U172 EpicBosses com.songoda.epicbosses.CustomBosses AMinecraftDev