From 996a6e913a0749cfceb8846f0da872fac64f740a Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 4 Jan 2019 00:38:18 +0800 Subject: [PATCH] 1.0.0-SNAPSHOT-U173 + Completed the AutoSpawnInterval system + Updated TODO + Added some new suggestions to TODO + Added a new method to BossAPI to get BossEntity from name --- TODO | 5 ++- .../com/songoda/epicbosses/api/BossAPI.java | 11 +++++ .../types/IntervalSpawnElement.java | 40 +++++++++++++++++++ pom.xml | 2 +- 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index 5bd7940..aa1c3af 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,7 @@ -02:00 -> Add full AutoSpawns system -02:00 -> Interval based spawn system, so bosses will spawn at location after certain time 04:00 -> Add the AutoSpawns Editing GUI (with a button for toggling the type of the autospawn, from wilderness, to spawner, to interval and a button for editing data) 01:00 -> Interval - Button to change coords, list of possible spawns, spawnIfChunkIsntLoaded, maxActiveBosses, bossesPerInterval, spawnRate, spawnType (Interval or Random), placeholder, message 00:30 -> Connect the /boss time [section] to the AutoSpawns timer (can only be applied to Interval AutoSpawns) +00:30 -> Add HolographicDisplay/PlaceholderAPI support for custom placeholders on AutoSpawnInterval times 01:00 -> Add a new branch for the plugin and add support for Legacy version ----------- 8:30 hrs @@ -12,9 +11,11 @@ ------------------------------------- TO DO AFTER RELEASE --------------------------------------------------- 02:00 -> Randomly in the wilderness, bosses will spawn with x chance within coords as a player is loading chunks 00:45 -> Randomly from a spawner, bosses will spawn with x chance within coords when a spawner is spawning mobs of the same type +03:00 -> Randomly spawn in a biome bosses will spawn with x chance within each biome as they're loaded in by the players -> AutoSpawns Editing GUI 01:00 -> Wilderness - Button to change max coords, boss that autospawn applies to, maxActiveBosses, spawnChance 01:00 -> Spawner - Button to change max coords, boss that autospawn applies to, maxActiveBosses, spawnChance +01:00 -> Biome - Button to change max bosses per biome, boss that autospawn applies to, spawnChance ----------- 4:45 hrs \ No newline at end of file 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 32c42cf..43e7858 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/api/BossAPI.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/api/BossAPI.java @@ -153,6 +153,17 @@ public class BossAPI { return null; } + /** + * Used to get a BossEntity instance from a + * name. + * + * @param name - the specified boss you are looking for + * @return a bossEntity instance if found, or null if not found + */ + public static BossEntity getBossEntity(String name) { + return PLUGIN.getBossEntityContainer().getData().getOrDefault(name, null); + } + /** * Used to get the Skill configuration section * name from a Skill instance. 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 30b560c..d7a60a5 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 @@ -4,15 +4,20 @@ 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.entity.BossEntity; import com.songoda.epicbosses.holder.ActiveBossHolder; import com.songoda.epicbosses.holder.autospawn.ActiveIntervalAutoSpawnHolder; import com.songoda.epicbosses.listeners.IBossDeathHandler; +import com.songoda.epicbosses.utils.MessageUtils; +import com.songoda.epicbosses.utils.NumberUtils; import com.songoda.epicbosses.utils.ObjectUtils; import com.songoda.epicbosses.utils.StringUtils; import lombok.Getter; import lombok.Setter; import org.bukkit.Location; +import java.util.*; + /** * @author Charles Cullen * @version 1.0.0 @@ -36,9 +41,44 @@ public class IntervalSpawnElement { AutoSpawn autoSpawn = activeAutoSpawnHolder.getAutoSpawn(); AutoSpawnSettings autoSpawnSettings = autoSpawn.getAutoSpawnSettings(); boolean customSpawnMessage = ObjectUtils.getValue(autoSpawnSettings.getOverrideDefaultSpawnMessage(), false); + String spawnMessage = autoSpawnSettings.getSpawnMessage(); int amountToSpawn = ObjectUtils.getValue(autoSpawnSettings.getAmountPerSpawn(), 1); boolean shuffleList = ObjectUtils.getValue(autoSpawnSettings.getShuffleEntitiesList(), false); + List bosses = autoSpawn.getEntities(); + Location location = getSpawnLocation(); + if(bosses == null || bosses.isEmpty()) return false; + + if(shuffleList) Collections.shuffle(bosses); + + Queue queue = new LinkedList<>(bosses); + + for(int i = 1; i <= amountToSpawn; i++) { + if(queue.isEmpty()) queue = new LinkedList<>(bosses); + + BossEntity bossEntity = BossAPI.getBossEntity(queue.poll()); + ActiveBossHolder activeBossHolder = BossAPI.spawnNewBoss(bossEntity, location, null, null, customSpawnMessage); + + if(activeBossHolder == null) continue; + + activeBossHolder.getPostBossDeathHandlers().add(bossDeathHandler); + activeAutoSpawnHolder.getActiveBossHolders().add(activeBossHolder); + } + + if(customSpawnMessage && spawnMessage != null) { + String x = NumberUtils.get().formatDouble(location.getBlockX()); + String y = NumberUtils.get().formatDouble(location.getBlockY()); + String z = NumberUtils.get().formatDouble(location.getBlockZ()); + String world = StringUtils.get().formatString(location.getWorld().getName()); + + List spawnMessages = BossAPI.getStoredMessages(spawnMessage); + + if(spawnMessages != null) { + spawnMessages.replaceAll(s -> s.replace("{x}", x).replace("{y}", y).replace("{z}", z).replace("{world}", world)); + + MessageUtils.get().sendMessage(location, -1, spawnMessages); + } + } return true; } diff --git a/pom.xml b/pom.xml index fa09353..ce6954e 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ - 1.0.0-U172 + 1.0.0-U173 EpicBosses com.songoda.epicbosses.CustomBosses AMinecraftDev