mirror of
https://github.com/songoda/EpicBosses.git
synced 2024-12-23 08:27:49 +01:00
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.
This commit is contained in:
parent
3744dbf0cd
commit
f941bb45f0
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public class ActiveBossHolder implements IActiveHolder {
|
||||
@Getter private Map<UUID, Double> mapOfDamagingUsers = new HashMap<>();
|
||||
|
||||
@Getter @Setter private TargetHandler<ActiveBossHolder> 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;
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user