1.0.0-SNAPSHOT-U170

+ Continued to work on AutoSpawn
+ Added and completed the canSpawn method
+ Added and completed the delay handler
This commit is contained in:
Charles 2019-01-03 21:41:35 +08:00
parent 67feb1343b
commit 7cb8929027
8 changed files with 73 additions and 22 deletions

View File

@ -5,7 +5,7 @@
"entities": [
"SkeletonKing"
],
"settings": {
"autoSpawnSettings": {
"maxAliveAtOnce": 1,
"amountPerSpawn": 1,
"spawnWhenChunkIsntLoaded": false,

View File

@ -20,13 +20,13 @@ public class AutoSpawn {
@Expose @Getter @Setter private Boolean editing;
@Expose @Getter @Setter private String type;
@Expose @Getter @Setter private List<String> entities;
@Expose @Getter @Setter private AutoSpawnSettings settings;
@Expose @Getter @Setter private AutoSpawnSettings autoSpawnSettings;
@Expose @Getter @Setter private JsonObject customData;
public AutoSpawn(boolean editing, List<String> entities, AutoSpawnSettings autoSpawnSettings) {
this.editing = editing;
this.entities = entities;
this.settings = autoSpawnSettings;
this.autoSpawnSettings = autoSpawnSettings;
}
public IntervalSpawnElement getIntervalSpawnData() {
@ -37,6 +37,9 @@ public class AutoSpawn {
return null;
}
public boolean isLocked() {
return this.editing != null && this.editing;
}
}

View File

@ -0,0 +1,12 @@
package com.songoda.epicbosses.autospawns;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 03-Jan-19
*/
public interface IAutoSpawnElement {
void attemptSpawn();
}

View File

@ -1,15 +1,18 @@
package com.songoda.epicbosses.autospawns.types;
import com.google.gson.annotations.Expose;
import com.songoda.epicbosses.autospawns.IAutoSpawnElement;
import com.songoda.epicbosses.utils.StringUtils;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Location;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 02-Jan-19
*/
public class IntervalSpawnElement {
public class IntervalSpawnElement implements IAutoSpawnElement {
@Expose @Getter @Setter private String location, placeholder;
@Expose @Getter @Setter private Integer spawnRate;
@ -20,8 +23,13 @@ public class IntervalSpawnElement {
this.spawnRate = spawnRate;
}
@Override
public void attemptSpawn() {
}
public Location getSpawnLocation() {
return StringUtils.get().fromStringToLocation(this.location);
}
}

View File

@ -24,4 +24,12 @@ public class ActiveAutoSpawnHolder {
this.spawnType = spawnType;
}
public int getCurrentActiveBossHolders() {
return this.activeBossHolders.size();
}
protected boolean canSpawn() {
return true;
}
}

View File

@ -1,15 +1,16 @@
package com.songoda.epicbosses.holder.autospawn;
import com.songoda.epicbosses.CustomBosses;
import com.songoda.epicbosses.api.BossAPI;
import com.songoda.epicbosses.autospawns.AutoSpawn;
import com.songoda.epicbosses.autospawns.SpawnType;
import com.songoda.epicbosses.autospawns.types.IntervalSpawnElement;
import com.songoda.epicbosses.holder.ActiveAutoSpawnHolder;
import com.songoda.epicbosses.utils.Debug;
import com.songoda.epicbosses.utils.ObjectUtils;
import com.songoda.epicbosses.utils.ServerUtils;
import com.songoda.epicbosses.utils.time.TimeUnit;
import lombok.Getter;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.Location;
import org.bukkit.scheduler.BukkitTask;
/**
@ -19,41 +20,57 @@ import org.bukkit.scheduler.BukkitTask;
*/
public class ActiveIntervalAutoSpawnHolder extends ActiveAutoSpawnHolder {
@Getter private final IntervalSpawnElement intervalSpawnElement;
@Getter private BukkitTask intervalTask = null;
@Getter private long nextCompletedTime = 0L;
public ActiveIntervalAutoSpawnHolder(SpawnType spawnType, AutoSpawn autoSpawn) {
super(spawnType, autoSpawn);
this.intervalSpawnElement = autoSpawn.getIntervalSpawnData();
}
@Override
public boolean canSpawn() {
if(getAutoSpawn().isLocked()) return false;
int currentActiveAmount = getCurrentActiveBossHolders();
int maxAmount = getAutoSpawn().getAutoSpawnSettings().getMaxAliveAtOnce();
Location location = this.intervalSpawnElement.getSpawnLocation();
boolean spawnIfChunkNotLoaded = ObjectUtils.getValue(getAutoSpawn().getAutoSpawnSettings().getSpawnWhenCheckIsntLoaded(), false);
if(location == null) return false;
if(!spawnIfChunkNotLoaded && !location.getChunk().isLoaded()) return false;
return currentActiveAmount < maxAmount;
}
public void restartInterval() {
stopInterval();
if(getAutoSpawn().getEditing() != null && getAutoSpawn().getEditing()) return;
if(getAutoSpawn().isLocked()) return;
Integer delay = getAutoSpawn().getIntervalSpawnData().getSpawnRate();
Integer delay = this.intervalSpawnElement.getSpawnRate();
if(delay == null) {
Debug.AUTOSPAWN_INTERVALNOTREAL.debug("null", BossAPI.getAutoSpawnName(getAutoSpawn()));
return;
}
long currentMs = System.currentTimeMillis();
long delayMs = (long) TimeUnit.SECONDS.to(TimeUnit.MILLISECONDS, delay);
this.nextCompletedTime = currentMs + delayMs;
this.intervalTask = new BukkitRunnable() {
private int timerTime = delay;
updateNextCompleteTime(delayMs);
public void run() {
this.timerTime -= 1;
if(this.timerTime <= 0) {
}
this.intervalTask = ServerUtils.get().runTimer(delayMs, delayMs, () -> {
if(!canSpawn()) {
updateNextCompleteTime(delayMs);
return;
}
}.runTaskTimer(CustomBosses.get(), 20L, 20L);
});
}
public long getRemainingMs() {
@ -68,6 +85,8 @@ public class ActiveIntervalAutoSpawnHolder extends ActiveAutoSpawnHolder {
if(this.intervalTask != null) ServerUtils.get().cancelTask(this.intervalTask);
}
private void updateNextCompleteTime(long delayMs) {
this.nextCompletedTime = System.currentTimeMillis() + delayMs;
}
}

View File

@ -53,6 +53,8 @@ public class StringUtils {
}
public Location fromStringToLocation(String input) {
if(input == null) return null;
String[] split = input.split(",");
if(split.length != 4) return null;

View File

@ -19,8 +19,7 @@
</modules>
<properties>
<!--<plugin.version>maven-version-number-SNAPSHOT-U90</plugin.version>-->
<plugin.version>1.0.0-U169</plugin.version>
<plugin.version>1.0.0-U170</plugin.version>
<plugin.name>EpicBosses</plugin.name>
<plugin.main>com.songoda.epicbosses.CustomBosses</plugin.main>
<plugin.author>AMinecraftDev</plugin.author>