mirror of
https://github.com/songoda/EpicBosses.git
synced 2025-03-12 14:39:05 +01:00
1.0.0-SNAPSHOT-U168
+ Continued implementation of the AutoSpawn system + Updated the autospawns.json file to be suitable for abstract spawn type + Added AutoSpawnFileManager and Handler + Created AutoSpawnManager
This commit is contained in:
parent
f41aa38ef7
commit
6badd928b7
@ -14,8 +14,8 @@
|
||||
},
|
||||
"customData": {
|
||||
"location": "world,0,150,0",
|
||||
"spawnRate": "30",
|
||||
"placeholder": "{customBosses_1}"
|
||||
"placeholder": "{customBosses_1}",
|
||||
"spawnRate": 30
|
||||
}
|
||||
}
|
||||
}
|
@ -34,6 +34,7 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
|
||||
|
||||
@Getter private MessagesFileManager bossMessagesFileManager;
|
||||
@Getter private CommandsFileManager bossCommandFileManager;
|
||||
@Getter private AutoSpawnFileManager autoSpawnFileManager;
|
||||
@Getter private DropTableFileManager dropTableFileManager;
|
||||
@Getter private MinionsFileManager minionsFileManager;
|
||||
@Getter private BossesFileManager bossesFileManager;
|
||||
@ -119,6 +120,7 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
|
||||
this.bossCommandFileManager.reload();
|
||||
this.bossMessagesFileManager.reload();
|
||||
this.dropTableFileManager.reload();
|
||||
this.autoSpawnFileManager.reload();
|
||||
|
||||
this.bossCommandManager = new BossCommandManager(new BossCmd(), this);
|
||||
this.bossListenerManager = new BossListenerManager(this);
|
||||
@ -149,6 +151,7 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
|
||||
this.skillsFileManager.reload();
|
||||
this.itemStackManager.reload();
|
||||
this.dropTableFileManager.reload();
|
||||
this.autoSpawnFileManager.reload();
|
||||
|
||||
this.bossMechanicManager.load();
|
||||
|
||||
@ -170,6 +173,7 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
|
||||
this.bossMessagesFileManager = new MessagesFileManager(this);
|
||||
this.dropTableFileManager = new DropTableFileManager(this);
|
||||
this.skillsFileManager = new SkillsFileManager(this);
|
||||
this.autoSpawnFileManager = new AutoSpawnFileManager(this);
|
||||
|
||||
this.langFileHandler = new LangFileHandler(this);
|
||||
this.editorFileHandler = new EditorFileHandler(this);
|
||||
|
@ -3,6 +3,8 @@ package com.songoda.epicbosses.autospawns;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.songoda.epicbosses.autospawns.settings.AutoSpawnSettings;
|
||||
import com.songoda.epicbosses.autospawns.types.IntervalSpawnElement;
|
||||
import com.songoda.epicbosses.utils.BossesGson;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@ -27,4 +29,12 @@ public class AutoSpawn {
|
||||
this.settings = autoSpawnSettings;
|
||||
}
|
||||
|
||||
public IntervalSpawnElement getIntervalSpawnData() {
|
||||
if(getType().equalsIgnoreCase("INTERVAL")) {
|
||||
return BossesGson.get().fromJson(this.customData, IntervalSpawnElement.class);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package com.songoda.epicbosses.autospawns;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
@ -15,12 +18,38 @@ public enum SpawnTypes {
|
||||
SpawnTypes(int rank) {
|
||||
this.rank = rank;
|
||||
}
|
||||
//
|
||||
// public SkillMode getNext() {
|
||||
// return get(this.rank+1);
|
||||
// }
|
||||
//
|
||||
// public static SpawnTypes getCurrent(String input) {
|
||||
//
|
||||
// }
|
||||
|
||||
public SpawnTypes getNext() {
|
||||
return get(this.rank+1);
|
||||
}
|
||||
|
||||
public static SpawnTypes getCurrent(String input) {
|
||||
if(input == null || input.isEmpty()) return BLANK;
|
||||
|
||||
for(SpawnTypes spawnTypes : values()) {
|
||||
if(spawnTypes.name().equalsIgnoreCase(input)) return spawnTypes;
|
||||
}
|
||||
|
||||
return BLANK;
|
||||
}
|
||||
|
||||
public static List<SpawnTypes> getSpawnTypes() {
|
||||
List<SpawnTypes> list = new ArrayList<>();
|
||||
|
||||
for(SpawnTypes spawnTypes : values()) {
|
||||
if(spawnTypes.rank > 0) list.add(spawnTypes);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private static SpawnTypes get(int rank) {
|
||||
for(SpawnTypes spawnTypes : values()) {
|
||||
if(spawnTypes.rank == rank) {
|
||||
return spawnTypes;
|
||||
}
|
||||
}
|
||||
|
||||
return INTERVAL;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
package com.songoda.epicbosses.autospawns.types;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 02-Jan-19
|
||||
*/
|
||||
public class IntervalSpawnElement {
|
||||
|
||||
@Expose @Getter @Setter private String location, placeholder;
|
||||
@Expose @Getter @Setter private Integer spawnRate;
|
||||
|
||||
public IntervalSpawnElement(String location, String placeholder, Integer spawnRate) {
|
||||
this.location = location;
|
||||
this.placeholder = placeholder;
|
||||
this.spawnRate = spawnRate;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package com.songoda.epicbosses.file;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.songoda.epicbosses.autospawns.AutoSpawn;
|
||||
import com.songoda.epicbosses.utils.file.FileHandler;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 02-Jan-19
|
||||
*/
|
||||
public class AutoSpawnFileHandler extends FileHandler<Map<String, AutoSpawn>> {
|
||||
|
||||
private static final Gson GSON = new GsonBuilder()
|
||||
.setPrettyPrinting()
|
||||
.excludeFieldsWithoutExposeAnnotation()
|
||||
.create();
|
||||
|
||||
public AutoSpawnFileHandler(JavaPlugin javaPlugin, boolean saveResource, File file) {
|
||||
super(javaPlugin, saveResource, file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, AutoSpawn> loadFile() {
|
||||
Map<String, AutoSpawn> autoSpawnMap = new HashMap<>();
|
||||
|
||||
createFile();
|
||||
|
||||
try {
|
||||
FileReader fileReader = new FileReader(getFile());
|
||||
JsonObject jsonObject = GSON.fromJson(fileReader, JsonObject.class);
|
||||
|
||||
fileReader.close();
|
||||
|
||||
if(jsonObject != null) {
|
||||
jsonObject.entrySet().forEach(entry -> {
|
||||
String id = entry.getKey();
|
||||
AutoSpawn autoSpawn = GSON.fromJson(entry.getValue(), AutoSpawn.class);
|
||||
|
||||
autoSpawnMap.put(id, autoSpawn);
|
||||
});
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return autoSpawnMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveFile(Map<String, AutoSpawn> map) {
|
||||
try {
|
||||
FileWriter fileWriter = new FileWriter(getFile());
|
||||
Type type = new TypeToken<Map<String, AutoSpawn>>(){}.getType();
|
||||
|
||||
fileWriter.write(GSON.toJson(new HashMap<>(map), type));
|
||||
fileWriter.flush();
|
||||
fileWriter.close();
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.songoda.epicbosses.managers;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 02-Jan-19
|
||||
*/
|
||||
public class AutoSpawnManager {
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package com.songoda.epicbosses.managers.files;
|
||||
|
||||
import com.songoda.epicbosses.CustomBosses;
|
||||
import com.songoda.epicbosses.autospawns.AutoSpawn;
|
||||
import com.songoda.epicbosses.file.AutoSpawnFileHandler;
|
||||
import com.songoda.epicbosses.utils.ILoadable;
|
||||
import com.songoda.epicbosses.utils.IReloadable;
|
||||
import com.songoda.epicbosses.utils.ISavable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 02-Jan-19
|
||||
*/
|
||||
public class AutoSpawnFileManager implements ILoadable, ISavable, IReloadable {
|
||||
|
||||
private Map<String, AutoSpawn> autoSpawnMap = new HashMap<>();
|
||||
private AutoSpawnFileHandler autoSpawnFileHandler;
|
||||
|
||||
public AutoSpawnFileManager(CustomBosses plugin) {
|
||||
File file = new File(plugin.getDataFolder(), "autospawns.json");
|
||||
|
||||
this.autoSpawnFileHandler = new AutoSpawnFileHandler(plugin, true, file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
this.autoSpawnMap = this.autoSpawnFileHandler.loadFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
this.autoSpawnFileHandler.saveFile(this.autoSpawnMap);
|
||||
}
|
||||
|
||||
public void saveAutoSpawn(String name, AutoSpawn autoSpawn) {
|
||||
if(this.autoSpawnMap.containsKey(name)) return;
|
||||
|
||||
this.autoSpawnMap.put(name, autoSpawn);
|
||||
save();
|
||||
}
|
||||
|
||||
public AutoSpawn getAutoSpawn(String name) {
|
||||
return this.autoSpawnMap.getOrDefault(name, null);
|
||||
}
|
||||
|
||||
public Map<String, AutoSpawn> getAutoSpawnMap() {
|
||||
return new HashMap<>(this.autoSpawnMap);
|
||||
}
|
||||
}
|
2
pom.xml
2
pom.xml
@ -20,7 +20,7 @@
|
||||
|
||||
<properties>
|
||||
<!--<plugin.version>maven-version-number-SNAPSHOT-U90</plugin.version>-->
|
||||
<plugin.version>1.0.0-U167</plugin.version>
|
||||
<plugin.version>1.0.0-U168</plugin.version>
|
||||
<plugin.name>EpicBosses</plugin.name>
|
||||
<plugin.main>com.songoda.epicbosses.CustomBosses</plugin.main>
|
||||
<plugin.author>AMinecraftDev</plugin.author>
|
||||
|
Loading…
Reference in New Issue
Block a user