diff --git a/plugin-modules/Core/resources-json/autospawns.json b/plugin-modules/Core/resources-json/autospawns.json index 13aae52..0ac00e3 100644 --- a/plugin-modules/Core/resources-json/autospawns.json +++ b/plugin-modules/Core/resources-json/autospawns.json @@ -14,8 +14,8 @@ }, "customData": { "location": "world,0,150,0", - "spawnRate": "30", - "placeholder": "{customBosses_1}" + "placeholder": "{customBosses_1}", + "spawnRate": 30 } } } \ No newline at end of file diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/CustomBosses.java b/plugin-modules/Core/src/com/songoda/epicbosses/CustomBosses.java index 99ce30e..e87ac9c 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/CustomBosses.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/CustomBosses.java @@ -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); diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/autospawns/AutoSpawn.java b/plugin-modules/Core/src/com/songoda/epicbosses/autospawns/AutoSpawn.java index 85e7830..78b7a2c 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/autospawns/AutoSpawn.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/autospawns/AutoSpawn.java @@ -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; + } + } diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/autospawns/SpawnTypes.java b/plugin-modules/Core/src/com/songoda/epicbosses/autospawns/SpawnTypes.java index 9cd8880..2e65789 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/autospawns/SpawnTypes.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/autospawns/SpawnTypes.java @@ -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 getSpawnTypes() { + List 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; + } } diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/autospawns/types/IntervalSpawnElement.java b/plugin-modules/Core/src/com/songoda/epicbosses/autospawns/types/IntervalSpawnElement.java new file mode 100644 index 0000000..a317211 --- /dev/null +++ b/plugin-modules/Core/src/com/songoda/epicbosses/autospawns/types/IntervalSpawnElement.java @@ -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; + } + +} diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/file/AutoSpawnFileHandler.java b/plugin-modules/Core/src/com/songoda/epicbosses/file/AutoSpawnFileHandler.java new file mode 100644 index 0000000..9426fb6 --- /dev/null +++ b/plugin-modules/Core/src/com/songoda/epicbosses/file/AutoSpawnFileHandler.java @@ -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> { + + 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 loadFile() { + Map 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 map) { + try { + FileWriter fileWriter = new FileWriter(getFile()); + Type type = new TypeToken>(){}.getType(); + + fileWriter.write(GSON.toJson(new HashMap<>(map), type)); + fileWriter.flush(); + fileWriter.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } +} diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/managers/AutoSpawnManager.java b/plugin-modules/Core/src/com/songoda/epicbosses/managers/AutoSpawnManager.java new file mode 100644 index 0000000..cfb18bb --- /dev/null +++ b/plugin-modules/Core/src/com/songoda/epicbosses/managers/AutoSpawnManager.java @@ -0,0 +1,9 @@ +package com.songoda.epicbosses.managers; + +/** + * @author Charles Cullen + * @version 1.0.0 + * @since 02-Jan-19 + */ +public class AutoSpawnManager { +} diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/managers/files/AutoSpawnFileManager.java b/plugin-modules/Core/src/com/songoda/epicbosses/managers/files/AutoSpawnFileManager.java new file mode 100644 index 0000000..6bf4451 --- /dev/null +++ b/plugin-modules/Core/src/com/songoda/epicbosses/managers/files/AutoSpawnFileManager.java @@ -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 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 getAutoSpawnMap() { + return new HashMap<>(this.autoSpawnMap); + } +} diff --git a/pom.xml b/pom.xml index 22b10d4..96f76b0 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ - 1.0.0-U167 + 1.0.0-U168 EpicBosses com.songoda.epicbosses.CustomBosses AMinecraftDev