Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions src/main/java/org/mineacademy/boss/spawn/SpawnRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,20 @@ protected boolean checkLastExecuted() {
protected boolean canRun() {

// Respawn rules are ticked in a runnable task
if (this.checkLastExecuted())
if (this.lastExecuted != -1 && System.currentTimeMillis() - this.lastExecuted + 1 < this.delay.getTimeSeconds() * 1000) {
Debugger.debug("spawning", "[SpawnRule=" + this.getName() + "] Not running due to last executed " + (System.currentTimeMillis() - this.lastExecuted) / 1000 + "s ago and delay is " + this.delay.getTimeSeconds() + "s");
if (this.checkLastExecuted()) {
final long now = System.currentTimeMillis();
final long lastDeathTime = this.getLastDeathTime();

// Use whichever happened later: the last successful spawn or the last death of a boss spawned by this rule.
// This way "Delay" also acts as a cooldown after death, not just between spawn attempts.
final long effectiveLast = Math.max(this.lastExecuted, lastDeathTime);

if (effectiveLast > 0 && now - effectiveLast + 1 < this.delay.getTimeSeconds() * 1000) {
Debugger.debug("spawning", "[SpawnRule=" + this.getName() + "] Not running due to last spawn/death " + (now - effectiveLast) / 1000 + "s ago and delay is " + this.delay.getTimeSeconds() + "s");

return false;
}
}

if (!RandomUtil.chanceD(this.getChance())) {
Debugger.debug("spawning", "[SpawnRule=" + this.getName() + "] Not running due to chance did not pass: " + this.getChance() * 100 + "%");
Expand Down Expand Up @@ -341,6 +349,21 @@ public final void spawn(Location location, SpawnData data) {
this.lastExecuted = System.currentTimeMillis();
}

/**
* Returns the latest death timestamp of any boss that was spawned by this rule, or 0 if none.
*
* @return
*/
public long getLastDeathTime() {
long lastDeathTime = 0;

for (final Boss boss : Boss.getBosses())
if (this.getBosses().contains(boss.getName()))
lastDeathTime = Math.max(lastDeathTime, boss.getLastDeathFromSpawnRule(this));

return lastDeathTime;
}

/* ------------------------------------------------------------------------------- */
/* Menu system */
/* ------------------------------------------------------------------------------- */
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/org/mineacademy/boss/spawn/SpawnRuleRespawn.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,4 @@ protected boolean canRun(Boss boss, SpawnData data) {

return true;
}

public long getLastDeathTime() {
long lastDeathTime = 0;

for (final Boss boss : Boss.getBosses())
if (this.getBosses().contains(boss.getName()))
lastDeathTime = Math.max(lastDeathTime, boss.getLastDeathFromSpawnRule(this));

return lastDeathTime;
}
}