+ Fixed AutoSpawn systems not spawning
+ Fixed debug saying mechanic failed because I flipped the boolean
This commit is contained in:
Charles 2019-01-30 01:21:14 +08:00
parent b0b00f899e
commit ab697c73cd
8 changed files with 95 additions and 95 deletions

View File

@ -37,16 +37,12 @@ public class AutoSpawn {
return null; return null;
} }
public boolean isLocked() {
return this.editing;
}
public boolean isCompleteEnoughToSpawn() { public boolean isCompleteEnoughToSpawn() {
if(this.type == null) return false; if(this.type == null) return false;
List<String> entities = this.entities; List<String> entities = getEntities();
if(this.entities == null || this.entities.isEmpty()) return false; if(entities == null || entities.isEmpty()) return false;
return true; return true;
} }

View File

@ -53,10 +53,19 @@ public class BossTimeCmd extends SubCommand {
ActiveAutoSpawnHolder activeAutoSpawnHolder = this.autoSpawnManager.getActiveAutoSpawnHolder(section); ActiveAutoSpawnHolder activeAutoSpawnHolder = this.autoSpawnManager.getActiveAutoSpawnHolder(section);
ActiveIntervalAutoSpawnHolder activeIntervalAutoSpawnHolder = (ActiveIntervalAutoSpawnHolder) activeAutoSpawnHolder; ActiveIntervalAutoSpawnHolder activeIntervalAutoSpawnHolder = (ActiveIntervalAutoSpawnHolder) activeAutoSpawnHolder;
long remainingMs = activeIntervalAutoSpawnHolder.getRemainingMs(); long remainingMs = activeIntervalAutoSpawnHolder.getRemainingMs();
if(remainingMs == 0 && activeIntervalAutoSpawnHolder.isSpawnAfterLastBossIsKilled()) {
Message.Boss_Time_CurrentlyActive.msg(sender);
return;
}
String s = Message.General_TimeLayout.toString(); String s = Message.General_TimeLayout.toString();
int remainingHours = (int) TimeUnit.MILLISECONDS.to(TimeUnit.HOURS, remainingMs); TimeUnit unit = TimeUnit.MILLISECONDS;
int remainingMins = (int) TimeUnit.MILLISECONDS.to(TimeUnit.MINUTES, remainingMs); int remainingHours = (int) unit.to(TimeUnit.HOURS, remainingMs);
int remainingSecs = (int) TimeUnit.MILLISECONDS.to(TimeUnit.SECONDS, remainingMs); remainingMs -= TimeUnit.HOURS.to(unit, remainingHours);
int remainingMins = (int) unit.to(TimeUnit.MINUTES, remainingMs);
remainingMs -= TimeUnit.MINUTES.to(unit, remainingMins);
int remainingSecs = (int) unit.to(TimeUnit.SECONDS, remainingMs);
s = s.replace("{hours}", NumberUtils.get().formatDouble(remainingHours)); s = s.replace("{hours}", NumberUtils.get().formatDouble(remainingHours));
s = s.replace("{mins}", NumberUtils.get().formatDouble(remainingMins)); s = s.replace("{mins}", NumberUtils.get().formatDouble(remainingMins));

View File

@ -39,7 +39,7 @@ public class ActiveIntervalAutoSpawnHolder extends ActiveAutoSpawnHolder {
@Override @Override
public boolean canSpawn() { public boolean canSpawn() {
if(getAutoSpawn().isLocked()) return false; if(getAutoSpawn().isEditing()) return false;
if(!getAutoSpawn().getType().equalsIgnoreCase("INTERVAL")) return false; if(!getAutoSpawn().getType().equalsIgnoreCase("INTERVAL")) return false;
int currentActiveAmount = getCurrentActiveBossHolders(); int currentActiveAmount = getCurrentActiveBossHolders();
@ -47,19 +47,22 @@ public class ActiveIntervalAutoSpawnHolder extends ActiveAutoSpawnHolder {
Location location = this.intervalSpawnElement.getSpawnLocation(); Location location = this.intervalSpawnElement.getSpawnLocation();
boolean spawnIfChunkNotLoaded = ObjectUtils.getValue(getAutoSpawn().getAutoSpawnSettings().getSpawnWhenChunkIsntLoaded(), false); boolean spawnIfChunkNotLoaded = ObjectUtils.getValue(getAutoSpawn().getAutoSpawnSettings().getSpawnWhenChunkIsntLoaded(), false);
boolean spawnAfterLastBossIsKilled = ObjectUtils.getValue(this.intervalSpawnElement.getSpawnAfterLastBossIsKilled(), false);
if(location == null) return false; if(location == null) return false;
if(!spawnIfChunkNotLoaded && !location.getChunk().isLoaded()) return false; if(!spawnIfChunkNotLoaded && !location.getChunk().isLoaded()) return false;
if(spawnAfterLastBossIsKilled && !getActiveBossHolders().isEmpty()) return false; if(isSpawnAfterLastBossIsKilled() && !getActiveBossHolders().isEmpty()) return false;
return currentActiveAmount < maxAmount; return currentActiveAmount < maxAmount;
} }
public boolean isSpawnAfterLastBossIsKilled() {
return ObjectUtils.getValue(this.intervalSpawnElement.getSpawnAfterLastBossIsKilled(), false);
}
public void restartInterval() { public void restartInterval() {
stopInterval(); stopInterval();
if(getAutoSpawn().isLocked()) return; if(getAutoSpawn().isEditing()) return;
Integer delay = this.intervalSpawnElement.getSpawnRate(); Integer delay = this.intervalSpawnElement.getSpawnRate();
@ -68,28 +71,28 @@ public class ActiveIntervalAutoSpawnHolder extends ActiveAutoSpawnHolder {
return; return;
} }
long delayMs = (long) TimeUnit.SECONDS.to(TimeUnit.MILLISECONDS, delay); int delaySec = (int) TimeUnit.MINUTES.to(TimeUnit.SECONDS, delay);
boolean spawnAfterLastBossIsKilled = ObjectUtils.getValue(this.intervalSpawnElement.getSpawnAfterLastBossIsKilled(), false);
updateNextCompleteTime(delayMs); this.intervalTask = ServerUtils.get().runTimer(delaySec*20, delaySec*20, () -> {
boolean canSpawn = canSpawn();
this.intervalTask = ServerUtils.get().runTimer(delayMs, delayMs, () -> { if(!canSpawn) return;
if(!canSpawn()) return;
if(this.intervalSpawnElement.attemptSpawn(this) && spawnAfterLastBossIsKilled) { this.intervalSpawnElement.attemptSpawn(this);
stopInterval();
if(isSpawnAfterLastBossIsKilled()) {
cancelCurrentInterval();
return; return;
} }
updateNextCompleteTime(delayMs); updateNextCompleteTime();
}); });
updateNextCompleteTime();
} }
public void stopInterval() { public void stopInterval() {
if(this.intervalTask != null) ServerUtils.get().cancelTask(this.intervalTask); cancelCurrentInterval();
this.nextCompletedTime = 0;
getActiveBossHolders().forEach(ActiveBossHolder::killAll); getActiveBossHolders().forEach(ActiveBossHolder::killAll);
getActiveBossHolders().clear(); getActiveBossHolders().clear();
} }
@ -112,12 +115,28 @@ public class ActiveIntervalAutoSpawnHolder extends ActiveAutoSpawnHolder {
if(spawnAfterLastBossIsKilled) { if(spawnAfterLastBossIsKilled) {
restartInterval(); restartInterval();
updateNextCompleteTime();
} }
} }
}; };
} }
private void updateNextCompleteTime(long delayMs) { private void cancelCurrentInterval() {
if(this.intervalTask != null) ServerUtils.get().cancelTask(this.intervalTask);
this.nextCompletedTime = 0;
}
private void updateNextCompleteTime() {
Integer delay = this.intervalSpawnElement.getSpawnRate();
if(delay == null) {
Debug.AUTOSPAWN_INTERVALNOTREAL.debug("null", BossAPI.getAutoSpawnName(getAutoSpawn()));
return;
}
long delayMs = (long) TimeUnit.MINUTES.to(TimeUnit.MILLISECONDS, delay);
this.nextCompletedTime = System.currentTimeMillis() + delayMs; this.nextCompletedTime = System.currentTimeMillis() + delayMs;
} }
} }

View File

@ -34,19 +34,17 @@ public class AutoSpawnManager {
public void startIntervalSystems() { public void startIntervalSystems() {
Map<String, AutoSpawn> autoSpawnMap = this.autoSpawnFileManager.getAutoSpawnMap(); Map<String, AutoSpawn> autoSpawnMap = this.autoSpawnFileManager.getAutoSpawnMap();
autoSpawnMap.forEach((name, autoSpawn) -> { if(!this.activeAutoSpawnHolders.isEmpty()) {
String autoSpawnType = autoSpawn.getType(); stopIntervalSystems();
SpawnType spawnType = SpawnType.getCurrent(autoSpawnType);
if(spawnType == SpawnType.INTERVAL) {
ActiveIntervalAutoSpawnHolder autoSpawnHolder = new ActiveIntervalAutoSpawnHolder(spawnType, autoSpawn);
if(!autoSpawn.isLocked()) {
autoSpawnHolder.restartInterval();
} }
this.activeAutoSpawnHolders.put(name, autoSpawnHolder);
autoSpawnMap.forEach(this::addAndCreateActiveAutoSpawnHolder);
} }
});
public void stopIntervalSystems() {
Map<String, ActiveAutoSpawnHolder> autoSpawnHolderMap = new HashMap<>(this.activeAutoSpawnHolders);
autoSpawnHolderMap.forEach((name, autoSpawnHolder) -> removeActiveAutoSpawnHolder(name));
} }
public List<String> getIntervalAutoSpawns() { public List<String> getIntervalAutoSpawns() {
@ -72,33 +70,23 @@ public class AutoSpawnManager {
return false; return false;
} }
public ActiveAutoSpawnHolder getAutoSpawnHolder(String name) {
if(!exists(name)) return null;
List<String> keyList = new ArrayList<>(this.activeAutoSpawnHolders.keySet());
for (String s : keyList) {
if(s.equalsIgnoreCase(name)) return this.activeAutoSpawnHolders.get(s);
}
return null;
}
public void addActiveAutoSpawnHolder(String name, ActiveAutoSpawnHolder autoSpawnHolder) {
if(this.activeAutoSpawnHolders.containsKey(name)) return;
this.activeAutoSpawnHolders.put(name, autoSpawnHolder);
}
public ActiveAutoSpawnHolder getActiveAutoSpawnHolder(AutoSpawn autoSpawn) {
return getActiveAutoSpawnHolder(BossAPI.getAutoSpawnName(autoSpawn));
}
public ActiveAutoSpawnHolder getActiveAutoSpawnHolder(String name) { public ActiveAutoSpawnHolder getActiveAutoSpawnHolder(String name) {
return this.activeAutoSpawnHolders.getOrDefault(name, null); return this.activeAutoSpawnHolders.getOrDefault(name, null);
} }
public void removeActiveAutoSpawnHolder(String name) { public void addAndCreateActiveAutoSpawnHolder(AutoSpawn autoSpawn) {
String name = BossAPI.getAutoSpawnName(autoSpawn);
addAndCreateActiveAutoSpawnHolder(name, autoSpawn);
}
public void removeActiveAutoSpawnHolder(AutoSpawn autoSpawn) {
String name = BossAPI.getAutoSpawnName(autoSpawn);
removeActiveAutoSpawnHolder(name);
}
private void removeActiveAutoSpawnHolder(String name) {
ActiveAutoSpawnHolder autoSpawnHolder = this.activeAutoSpawnHolders.getOrDefault(name, null); ActiveAutoSpawnHolder autoSpawnHolder = this.activeAutoSpawnHolders.getOrDefault(name, null);
if(autoSpawnHolder != null) { if(autoSpawnHolder != null) {
@ -107,28 +95,9 @@ public class AutoSpawnManager {
} }
} }
public void stopIntervalSystems() { private void stopInterval(ActiveAutoSpawnHolder autoSpawnHolder) {
Map<String, ActiveAutoSpawnHolder> autoSpawnHolderMap = new HashMap<>(this.activeAutoSpawnHolders); if (autoSpawnHolder != null) {
if (autoSpawnHolder.getSpawnType() == SpawnType.INTERVAL) {
autoSpawnHolderMap.forEach((name, autoSpawnHolder) -> removeActiveAutoSpawnHolder(name));
}
public void stopInterval(AutoSpawn autoSpawn) {
String name = BossAPI.getAutoSpawnName(autoSpawn);
stopInterval(name);
}
public void stopInterval(String name) {
ActiveAutoSpawnHolder autoSpawnHolder = this.activeAutoSpawnHolders.getOrDefault(name, null);
stopInterval(autoSpawnHolder);
}
public void stopInterval(ActiveAutoSpawnHolder autoSpawnHolder) {
if(autoSpawnHolder != null) {
if(autoSpawnHolder.getSpawnType() == SpawnType.INTERVAL) {
ActiveIntervalAutoSpawnHolder intervalAutoSpawnHolder = (ActiveIntervalAutoSpawnHolder) autoSpawnHolder; ActiveIntervalAutoSpawnHolder intervalAutoSpawnHolder = (ActiveIntervalAutoSpawnHolder) autoSpawnHolder;
intervalAutoSpawnHolder.stopInterval(); intervalAutoSpawnHolder.stopInterval();
@ -136,6 +105,20 @@ public class AutoSpawnManager {
} }
} }
private void addAndCreateActiveAutoSpawnHolder(String name, AutoSpawn autoSpawn) {
String autoSpawnType = autoSpawn.getType();
SpawnType spawnType = SpawnType.getCurrent(autoSpawnType);
if(spawnType == SpawnType.INTERVAL) {
ActiveIntervalAutoSpawnHolder autoSpawnHolder = new ActiveIntervalAutoSpawnHolder(spawnType, autoSpawn);
if(autoSpawn.isEditing()) return;
autoSpawnHolder.restartInterval();
this.activeAutoSpawnHolders.put(name, autoSpawnHolder);
}
}
public static ICustomSettingAction createAutoSpawnAction(String name, String current, List<String> extraInformation, ItemStack displayStack, ClickAction clickAction) { public static ICustomSettingAction createAutoSpawnAction(String name, String current, List<String> extraInformation, ItemStack displayStack, ClickAction clickAction) {
return new CustomAutoSpawnActionCreator(name, current, extraInformation, displayStack, clickAction); return new CustomAutoSpawnActionCreator(name, current, extraInformation, displayStack, clickAction);
} }

View File

@ -62,7 +62,7 @@ public class BossMechanicManager implements IMechanicManager<BossEntity, ActiveB
ServerUtils.get().logDebug("Applying " + mechanic.getClass().getSimpleName()); ServerUtils.get().logDebug("Applying " + mechanic.getClass().getSimpleName());
if(!didMechanicApplicationFail(mechanic, bossEntity, activeBossHolder)) { if(didMechanicApplicationFail(mechanic, bossEntity, activeBossHolder)) {
Debug.FAILED_TO_APPLY_MECHANIC.debug(mechanic.getClass().getSimpleName()); Debug.FAILED_TO_APPLY_MECHANIC.debug(mechanic.getClass().getSimpleName());
} }
} }

View File

@ -99,17 +99,9 @@ public class MainAutoSpawnEditorPanel extends VariablePanelHandler<AutoSpawn> {
player.closeInventory(); player.closeInventory();
if(autoSpawn.isEditing()) { if(autoSpawn.isEditing()) {
this.autoSpawnManager.stopInterval(autoSpawn); this.autoSpawnManager.removeActiveAutoSpawnHolder(autoSpawn);
} else { } else {
ActiveAutoSpawnHolder autoSpawnHolder = this.autoSpawnManager.getActiveAutoSpawnHolder(autoSpawn); this.autoSpawnManager.addAndCreateActiveAutoSpawnHolder(autoSpawn);
if(autoSpawnHolder != null) {
if(autoSpawnHolder.getSpawnType() == SpawnType.INTERVAL) {
ActiveIntervalAutoSpawnHolder intervalAutoSpawnHolder = (ActiveIntervalAutoSpawnHolder) autoSpawnHolder;
intervalAutoSpawnHolder.restartInterval();
}
}
} }
}; };
} }

View File

@ -210,7 +210,8 @@ public enum Message {
Boss_Time_NoPermission("&c&l(!) &cYou do not have access to this command."), Boss_Time_NoPermission("&c&l(!) &cYou do not have access to this command."),
Boss_Time_InvalidArgs("&c&l(!) &cYou must use &n/boss time [section]&c to check the time left on a boss spawn."), Boss_Time_InvalidArgs("&c&l(!) &cYou must use &n/boss time [section]&c to check the time left on a boss spawn."),
Boss_Time_DoesntExist("&c&l(!) &cThe specified interval spawn system doesn't exist. Please use one of the following active system names: &f{0}&c."), Boss_Time_DoesntExist("&c&l(!) &cThe specified interval spawn system doesn't exist or editing has been toggled on so the section isn't ticking at the moment. Please use one of the following active system names: &f{0}&c."),
Boss_Time_CurrentlyActive("&b&lEpicBosses &8» &7There is currently a boss spawned from this section so the countdown will not begin for the next to spawn until the last boss is killed."),
Boss_Time_GetRemainingTime("&b&lEpicBosses &8» &7There is currently &f{0}&7 remaining on the &f{1}&7 interval spawn system."); Boss_Time_GetRemainingTime("&b&lEpicBosses &8» &7There is currently &f{0}&7 remaining on the &f{1}&7 interval spawn system.");
private static FileConfiguration LANG; private static FileConfiguration LANG;

View File

@ -19,7 +19,7 @@
</modules> </modules>
<properties> <properties>
<plugin.version>1.0.3-U3</plugin.version> <plugin.version>1.0.4</plugin.version>
<plugin.name>EpicBosses</plugin.name> <plugin.name>EpicBosses</plugin.name>
<plugin.main>com.songoda.epicbosses.CustomBosses</plugin.main> <plugin.main>com.songoda.epicbosses.CustomBosses</plugin.main>
<plugin.author>AMinecraftDev</plugin.author> <plugin.author>AMinecraftDev</plugin.author>