mirror of
https://github.com/songoda/EpicBosses.git
synced 2025-02-02 12:11:20 +01:00
1.0.0-SNAPSHOT-U45
+ Added the beginning of Minions into the plugin + Added new methods to support the creation of minions + Made BossEntity extend from MinionsEntity to make some methods easier to use + Added minions.json to have them seperated and clean
This commit is contained in:
parent
846244ffe6
commit
1d4dc9b6ad
38
plugin-modules/Core/resources-json/minions.json
Normal file
38
plugin-modules/Core/resources-json/minions.json
Normal file
@ -0,0 +1,38 @@
|
||||
{
|
||||
"SkeletonKingMinion": {
|
||||
"editing": true,
|
||||
"targeting": "RandomNearby",
|
||||
"entityStats": [
|
||||
{
|
||||
"mainStats": {
|
||||
"position": 1,
|
||||
"entityType": "SKELETON",
|
||||
"health": 500,
|
||||
"displayName": "&6&lSkeleton King Boss"
|
||||
},
|
||||
"equipment": {
|
||||
"helmet": "SKHelmet",
|
||||
"chestplate": "SKChestplate",
|
||||
"leggings": "SKLeggings",
|
||||
"boots": "SKBoots"
|
||||
},
|
||||
"hands": {
|
||||
"mainHand": "SKMainHand",
|
||||
"offHand": "SKOffHand"
|
||||
},
|
||||
"potions": [
|
||||
{
|
||||
"type": "resistance",
|
||||
"level": 3,
|
||||
"duration": -1
|
||||
},
|
||||
{
|
||||
"type": "speed",
|
||||
"level": 1,
|
||||
"duration": 500
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.songoda.epicbosses;
|
||||
|
||||
import com.songoda.epicbosses.container.MinionEntityContainer;
|
||||
import lombok.Getter;
|
||||
import com.songoda.epicbosses.api.BossAPI;
|
||||
import com.songoda.epicbosses.commands.BossCmd;
|
||||
@ -29,6 +30,7 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
|
||||
@Getter private MessagesFileManager bossMessagesFileManager;
|
||||
@Getter private CommandsFileManager bossCommandFileManager;
|
||||
@Getter private DropTableFileManager dropTableFileManager;
|
||||
@Getter private MinionsFileManager minionsFileManager;
|
||||
@Getter private BossesFileManager bossesFileManager;
|
||||
@Getter private ItemsFileManager itemStackManager;
|
||||
|
||||
@ -44,9 +46,14 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
|
||||
@Getter private BossSkillManager bossSkillManager;
|
||||
@Getter private BossTauntManager bossTauntManager;
|
||||
@Getter private BossHookManager bossHookManager;
|
||||
|
||||
@Getter private MinionMechanicManager minionMechanicManager;
|
||||
@Getter private MinionEntityContainer minionEntityContainer;
|
||||
|
||||
@Getter private VersionHandler versionHandler;
|
||||
@Getter private DebugManager debugManager;
|
||||
|
||||
|
||||
@Getter private YmlFileHandler langFileHandler, editorFileHandler, configFileHandler;
|
||||
@Getter private FileConfiguration lang, editor, config;
|
||||
|
||||
@ -68,7 +75,9 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
|
||||
this.bossTauntManager = new BossTauntManager(this);
|
||||
this.bossTargetManager = new BossTargetManager(this);
|
||||
this.bossEntityContainer = new BossEntityContainer();
|
||||
this.minionEntityContainer = new MinionEntityContainer();
|
||||
this.bossMechanicManager = new BossMechanicManager(this);
|
||||
this.minionMechanicManager = new MinionMechanicManager(this);
|
||||
this.bossLocationManager = new BossLocationManager(this);
|
||||
this.bossDropTableManager = new BossDropTableManager(this);
|
||||
|
||||
@ -83,6 +92,7 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
|
||||
|
||||
this.itemStackManager.reload();
|
||||
this.bossesFileManager.reload();
|
||||
this.minionsFileManager.reload();
|
||||
this.bossCommandFileManager.reload();
|
||||
this.bossMessagesFileManager.reload();
|
||||
this.dropTableFileManager.reload();
|
||||
@ -96,6 +106,7 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
|
||||
this.bossHookManager.reload();
|
||||
this.bossLocationManager.reload();
|
||||
this.bossMechanicManager.load();
|
||||
this.minionMechanicManager.load();
|
||||
|
||||
saveMessagesToFile();
|
||||
|
||||
@ -109,6 +120,7 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
|
||||
public void reload() {
|
||||
this.bossMessagesFileManager.reload();
|
||||
this.bossCommandFileManager.reload();
|
||||
this.minionsFileManager.reload();
|
||||
this.bossesFileManager.reload();
|
||||
this.itemStackManager.reload();
|
||||
this.dropTableFileManager.reload();
|
||||
@ -128,6 +140,7 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
|
||||
private void loadFileManagersAndHandlers() {
|
||||
this.itemStackManager = new ItemsFileManager(this);
|
||||
this.bossesFileManager = new BossesFileManager(this);
|
||||
this.minionsFileManager = new MinionsFileManager(this);
|
||||
this.bossCommandFileManager = new CommandsFileManager(this);
|
||||
this.bossMessagesFileManager = new MessagesFileManager(this);
|
||||
this.dropTableFileManager = new DropTableFileManager(this);
|
||||
|
@ -2,11 +2,13 @@ package com.songoda.epicbosses.api;
|
||||
|
||||
import com.songoda.epicbosses.CustomBosses;
|
||||
import com.songoda.epicbosses.entity.BossEntity;
|
||||
import com.songoda.epicbosses.entity.MinionEntity;
|
||||
import com.songoda.epicbosses.entity.elements.*;
|
||||
import com.songoda.epicbosses.holder.ActiveBossHolder;
|
||||
import com.songoda.epicbosses.managers.files.CommandsFileManager;
|
||||
import com.songoda.epicbosses.managers.files.ItemsFileManager;
|
||||
import com.songoda.epicbosses.managers.files.MessagesFileManager;
|
||||
import com.songoda.epicbosses.skills.custom.Minions;
|
||||
import com.songoda.epicbosses.skills.types.CustomSkill;
|
||||
import com.songoda.epicbosses.utils.Debug;
|
||||
import com.songoda.epicbosses.utils.EntityFinder;
|
||||
@ -65,6 +67,23 @@ public class BossAPI {
|
||||
PLUGIN.getBossesFileManager().save();
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Used to register a Minion Entity into
|
||||
* the plugin after it has been created
|
||||
* using the BossAPI#createBaseMinionEntity
|
||||
* method or by manually creating a MinionEntity.
|
||||
*
|
||||
* @param name - Name for the minion section.
|
||||
* @param minionEntity - The minion section.
|
||||
* @return false if it failed, true if it saved successfully.
|
||||
*/
|
||||
public static boolean registerMinionEntity(String name, MinionEntity minionEntity) {
|
||||
if(name == null || minionEntity == null) return false;
|
||||
|
||||
PLUGIN.getMinionEntityContainer().saveData(name, minionEntity);
|
||||
PLUGIN.getMinionsFileManager().save();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to register skills into the
|
||||
@ -112,6 +131,23 @@ public class BossAPI {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the Minion configuration section name
|
||||
* from a MinionEntity instance.
|
||||
*
|
||||
* @param minionEntity - the Minion Entity instance
|
||||
* @return name of the minion from the MinionContainer or null if not found.
|
||||
*/
|
||||
public static String getMinionEntityName(MinionEntity minionEntity) {
|
||||
for(Map.Entry<String, MinionEntity> entry : PLUGIN.getMinionEntityContainer().getData().entrySet()) {
|
||||
if(entry.getValue().equals(minionEntity)) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to create a base BossEntity model which
|
||||
* can be used to fine tune and then once the main
|
||||
@ -166,6 +202,55 @@ public class BossAPI {
|
||||
return bossEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to create a base MinionEntity model which
|
||||
* can be used to fine tune and then once the main
|
||||
* elements are filled in editing can be disabled
|
||||
* and the minion can be spawned in skills.
|
||||
*
|
||||
* @param name - minion name
|
||||
* @param entityTypeInput - entity type
|
||||
* @return null if something went wrong, or the MinionEntity that was created.
|
||||
*/
|
||||
public static MinionEntity createBaseMinionEntity(String name, String entityTypeInput) {
|
||||
String input = entityTypeInput.split(":")[0];
|
||||
EntityFinder entityFinder = EntityFinder.get(input);
|
||||
|
||||
if(PLUGIN.getMinionEntityContainer().exists(name)) {
|
||||
Debug.MINION_NAME_EXISTS.debug(name);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (entityFinder == null) return null;
|
||||
|
||||
List<EntityStatsElement> entityStatsElements = new ArrayList<>();
|
||||
EntityStatsElement entityStatsElement = new EntityStatsElement();
|
||||
MainStatsElement mainStatsElement = new MainStatsElement();
|
||||
|
||||
mainStatsElement.setHealth(50D);
|
||||
mainStatsElement.setDisplayName(name);
|
||||
mainStatsElement.setEntityType(entityFinder.getFancyName());
|
||||
|
||||
entityStatsElement.setMainStats(mainStatsElement);
|
||||
entityStatsElement.setEquipment(new EquipmentElement());
|
||||
entityStatsElement.setHands(new HandsElement());
|
||||
entityStatsElement.setPotions(new ArrayList<>());
|
||||
|
||||
entityStatsElements.add(entityStatsElement);
|
||||
|
||||
MinionEntity minionEntity = new MinionEntity(true,entityStatsElements);
|
||||
boolean result = PLUGIN.getMinionEntityContainer().saveData(name, minionEntity);
|
||||
|
||||
if (!result) {
|
||||
Debug.FAILED_TO_SAVE_THE_NEW_MINION.debug(name, entityFinder.getFancyName());
|
||||
return null;
|
||||
}
|
||||
|
||||
PLUGIN.getMinionsFileManager().save();
|
||||
|
||||
return minionEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to spawn a new active boss for the
|
||||
* specified bossEntity.
|
||||
@ -185,6 +270,24 @@ public class BossAPI {
|
||||
return PLUGIN.getBossEntityManager().createActiveBossHolder(bossEntity, location, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to spawn a new minion for the specified
|
||||
* bossEntity, under the activebossholder.
|
||||
*
|
||||
* @param activeBossHolder - targeted active boss
|
||||
* @param minionEntity - MinionEntity to spawn
|
||||
* @param minions - Minion skill class
|
||||
* @return ActiveBossHolder class with stored information
|
||||
*/
|
||||
public static ActiveBossHolder spawnNewMinion(ActiveBossHolder activeBossHolder, MinionEntity minionEntity, Minions minions) {
|
||||
// if(minionEntity.isEditing()) {
|
||||
// Debug.ATTEMPTED_TO_SPAWN_WHILE_DISABLED.debug();
|
||||
// return null;
|
||||
// }
|
||||
|
||||
return PLUGIN.getBossEntityManager().spawnMinionsOnBossHolder(activeBossHolder, minionEntity, minions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to obtain an item stack holder
|
||||
* of the specified item stack from the
|
||||
|
@ -40,6 +40,7 @@ public class BossEntityContainer implements IContainer<Map<String, BossEntity>,
|
||||
if(getData().containsKey(entry.getKey())) {
|
||||
failed += 1;
|
||||
stringBuilder.append(entry.getKey()).append("; ");
|
||||
continue;
|
||||
}
|
||||
|
||||
this.container.put(entry.getKey(), entry.getValue());
|
||||
|
@ -0,0 +1,70 @@
|
||||
package com.songoda.epicbosses.container;
|
||||
|
||||
import com.songoda.epicbosses.entity.MinionEntity;
|
||||
import com.songoda.epicbosses.utils.Debug;
|
||||
import com.songoda.epicbosses.utils.IContainer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 12-Nov-18
|
||||
*/
|
||||
public class MinionEntityContainer implements IContainer<Map<String, MinionEntity>, String> {
|
||||
|
||||
private Map<String, MinionEntity> container = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Map<String, MinionEntity> getData() {
|
||||
return new HashMap<>(this.container);
|
||||
}
|
||||
|
||||
public String getName(MinionEntity minionEntity) {
|
||||
for(Map.Entry<String, MinionEntity> entry : getData().entrySet()) {
|
||||
if(entry.getValue().equals(minionEntity)) return entry.getKey();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveData(Map<String, MinionEntity> stringMinionEntityMap) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
int completed = 0;
|
||||
int failed = 0;
|
||||
|
||||
for(Map.Entry<String, MinionEntity> entry : stringMinionEntityMap.entrySet()) {
|
||||
if(getData().containsKey(entry.getKey())) {
|
||||
failed += 1;
|
||||
stringBuilder.append(entry.getKey()).append("; ");
|
||||
continue;
|
||||
}
|
||||
|
||||
this.container.put(entry.getKey(), entry.getValue());
|
||||
completed++;
|
||||
}
|
||||
|
||||
if(failed > 0) {
|
||||
Debug.MINION_CONTAINER_SAVE.debug(completed, failed, stringBuilder.toString());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean saveData(String string, MinionEntity minionEntity) {
|
||||
return saveData(Collections.singletonMap(string, minionEntity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearContainer() {
|
||||
this.container.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(String s) {
|
||||
return this.container.containsKey(s);
|
||||
}
|
||||
}
|
@ -13,21 +13,19 @@ import java.util.List;
|
||||
* @version 1.0.0
|
||||
* @since 14-May-18
|
||||
*/
|
||||
public class BossEntity {
|
||||
public class BossEntity extends MinionEntity {
|
||||
|
||||
@Expose @Getter private final List<EntityStatsElement> entityStats;
|
||||
@Expose @Getter private final MessagesElement messages;
|
||||
@Expose @Getter private final CommandsElement commands;
|
||||
@Expose @Getter private final SkillsElement skills;
|
||||
@Expose @Getter private final DropsElement drops;
|
||||
|
||||
@Expose @Getter @Setter private boolean editing;
|
||||
@Expose @Getter @Setter private String spawnItem, targeting;
|
||||
|
||||
public BossEntity(boolean editing, String spawnItem, List<EntityStatsElement> entityStats, SkillsElement skills, DropsElement drops, MessagesElement messages, CommandsElement commands) {
|
||||
this.editing = editing;
|
||||
super(editing, entityStats);
|
||||
|
||||
this.spawnItem = spawnItem;
|
||||
this.entityStats = entityStats;
|
||||
this.skills = skills;
|
||||
this.drops = drops;
|
||||
this.messages = messages;
|
||||
|
@ -0,0 +1,26 @@
|
||||
package com.songoda.epicbosses.entity;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.songoda.epicbosses.entity.elements.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 12-Nov-18
|
||||
*/
|
||||
public class MinionEntity {
|
||||
|
||||
@Expose @Getter private final List<EntityStatsElement> entityStats;
|
||||
|
||||
@Expose @Getter @Setter private String targeting;
|
||||
@Expose @Getter @Setter private boolean editing;
|
||||
|
||||
public MinionEntity(boolean editing, List<EntityStatsElement> entityStats) {
|
||||
this.editing = editing;
|
||||
this.entityStats = entityStats;
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
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.entity.BossEntity;
|
||||
import com.songoda.epicbosses.entity.MinionEntity;
|
||||
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 12-Nov-18
|
||||
*/
|
||||
public class MinionsFileHandler extends FileHandler<Map<String, MinionEntity>> {
|
||||
|
||||
private static final Gson GSON = new GsonBuilder()
|
||||
.setPrettyPrinting()
|
||||
.excludeFieldsWithoutExposeAnnotation()
|
||||
.create();
|
||||
|
||||
public MinionsFileHandler(JavaPlugin javaPlugin, boolean saveResource, File file) {
|
||||
super(javaPlugin, saveResource, file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, MinionEntity> loadFile() {
|
||||
Map<String, MinionEntity> minionEntityMap = 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();
|
||||
MinionEntity minionEntity = GSON.fromJson(entry.getValue(), MinionEntity.class);
|
||||
|
||||
minionEntityMap.put(id, minionEntity);
|
||||
});
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return minionEntityMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveFile(Map<String, MinionEntity> stringMinionEntityMap) {
|
||||
try {
|
||||
FileWriter fileWriter = new FileWriter(getFile());
|
||||
Type type = new TypeToken<Map<String, MinionEntity>>(){}.getType();
|
||||
|
||||
fileWriter.write(GSON.toJson(new HashMap<>(stringMinionEntityMap), type));
|
||||
fileWriter.flush();
|
||||
fileWriter.close();
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -8,9 +8,7 @@ import com.songoda.epicbosses.exception.AlreadySetException;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
@ -25,6 +23,7 @@ public class ActiveBossHolder {
|
||||
|
||||
@Getter private Map<Integer, LivingEntity> livingEntityMap = new HashMap<>();
|
||||
@Getter private Map<UUID, Double> mapOfDamagingUsers = new HashMap<>();
|
||||
@Getter private List<LivingEntity> minionList = new ArrayList<>();
|
||||
|
||||
@Getter @Setter private TargetHandler targetHandler = null;
|
||||
@Getter @Setter private boolean isDead = false;
|
||||
|
@ -7,11 +7,13 @@ import com.songoda.epicbosses.droptable.elements.DropTableElement;
|
||||
import com.songoda.epicbosses.droptable.elements.GiveTableElement;
|
||||
import com.songoda.epicbosses.droptable.elements.SprayTableElement;
|
||||
import com.songoda.epicbosses.entity.BossEntity;
|
||||
import com.songoda.epicbosses.entity.MinionEntity;
|
||||
import com.songoda.epicbosses.holder.ActiveBossHolder;
|
||||
import com.songoda.epicbosses.holder.DeadBossHolder;
|
||||
import com.songoda.epicbosses.managers.files.BossesFileManager;
|
||||
import com.songoda.epicbosses.managers.files.DropTableFileManager;
|
||||
import com.songoda.epicbosses.managers.files.ItemsFileManager;
|
||||
import com.songoda.epicbosses.skills.custom.Minions;
|
||||
import com.songoda.epicbosses.utils.Debug;
|
||||
import com.songoda.epicbosses.utils.RandomUtils;
|
||||
import com.songoda.epicbosses.utils.itemstack.holder.ItemStackHolder;
|
||||
@ -33,6 +35,7 @@ public class BossEntityManager {
|
||||
|
||||
private static final List<ActiveBossHolder> ACTIVE_BOSS_HOLDERS = new ArrayList<>();
|
||||
|
||||
private MinionMechanicManager minionMechanicManager;
|
||||
private DropTableFileManager dropTableFileManager;
|
||||
private BossDropTableManager bossDropTableManager;
|
||||
private BossMechanicManager bossMechanicManager;
|
||||
@ -40,6 +43,7 @@ public class BossEntityManager {
|
||||
private BossesFileManager bossesFileManager;
|
||||
|
||||
public BossEntityManager(CustomBosses customBosses) {
|
||||
this.minionMechanicManager = customBosses.getMinionMechanicManager();
|
||||
this.dropTableFileManager = customBosses.getDropTableFileManager();
|
||||
this.bossDropTableManager = customBosses.getBossDropTableManager();
|
||||
this.bossMechanicManager = customBosses.getBossMechanicManager();
|
||||
@ -170,6 +174,18 @@ public class BossEntityManager {
|
||||
return activeBossHolder;
|
||||
}
|
||||
|
||||
public ActiveBossHolder spawnMinionsOnBossHolder(ActiveBossHolder activeBossHolder, MinionEntity minionEntity, Minions minions) {
|
||||
//TODO: Add Minions json class
|
||||
//TODO: Finish minions spawn method
|
||||
|
||||
if(!this.minionMechanicManager.handleMechanicApplication(minionEntity, activeBossHolder)) {
|
||||
Debug.FAILED_TO_CREATE_ACTIVE_BOSS_HOLDER.debug();
|
||||
return null;
|
||||
}
|
||||
|
||||
return activeBossHolder;
|
||||
}
|
||||
|
||||
public ActiveBossHolder getActiveBossHolder(LivingEntity livingEntity) {
|
||||
List<ActiveBossHolder> currentList = new ArrayList<>(ACTIVE_BOSS_HOLDERS);
|
||||
|
||||
|
@ -3,6 +3,7 @@ package com.songoda.epicbosses.managers;
|
||||
import com.songoda.epicbosses.CustomBosses;
|
||||
import com.songoda.epicbosses.entity.BossEntity;
|
||||
import com.songoda.epicbosses.holder.ActiveBossHolder;
|
||||
import com.songoda.epicbosses.managers.interfaces.IMechanicManager;
|
||||
import com.songoda.epicbosses.mechanics.*;
|
||||
import com.songoda.epicbosses.utils.Debug;
|
||||
import com.songoda.epicbosses.utils.ILoadable;
|
||||
@ -19,7 +20,7 @@ import java.util.Queue;
|
||||
* @version 1.0.0
|
||||
* @since 27-Jun-18
|
||||
*/
|
||||
public class BossMechanicManager implements ILoadable {
|
||||
public class BossMechanicManager implements IMechanicManager<BossEntity, ActiveBossHolder> {
|
||||
|
||||
private final CustomBosses customBosses;
|
||||
private Queue<IOptionalMechanic> optionalMechanics;
|
||||
@ -43,6 +44,7 @@ public class BossMechanicManager implements ILoadable {
|
||||
registerMechanic(new SettingsMechanic());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerMechanic(IMechanic mechanic) {
|
||||
if(mechanic instanceof IPrimaryMechanic) {
|
||||
this.primaryMechanics.add((IPrimaryMechanic) mechanic);
|
||||
@ -53,6 +55,7 @@ public class BossMechanicManager implements ILoadable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMechanicApplication(BossEntity bossEntity, ActiveBossHolder activeBossHolder) {
|
||||
if(bossEntity != null && activeBossHolder != null) {
|
||||
// if(bossEntity.isEditing()) {
|
||||
|
@ -0,0 +1,99 @@
|
||||
package com.songoda.epicbosses.managers;
|
||||
|
||||
import com.songoda.epicbosses.CustomBosses;
|
||||
import com.songoda.epicbosses.entity.MinionEntity;
|
||||
import com.songoda.epicbosses.holder.ActiveBossHolder;
|
||||
import com.songoda.epicbosses.managers.interfaces.IMechanicManager;
|
||||
import com.songoda.epicbosses.mechanics.*;
|
||||
import com.songoda.epicbosses.utils.Debug;
|
||||
import com.songoda.epicbosses.utils.IMechanic;
|
||||
import com.songoda.epicbosses.utils.ServerUtils;
|
||||
import com.songoda.epicbosses.utils.mechanics.IOptionalMechanic;
|
||||
import com.songoda.epicbosses.utils.mechanics.IPrimaryMechanic;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 12-Nov-18
|
||||
*/
|
||||
public class MinionMechanicManager implements IMechanicManager<MinionEntity, ActiveBossHolder> {
|
||||
|
||||
private final CustomBosses customBosses;
|
||||
private Queue<IOptionalMechanic> optionalMechanics;
|
||||
private Queue<IPrimaryMechanic> primaryMechanics;
|
||||
|
||||
public MinionMechanicManager(CustomBosses customBosses) {
|
||||
this.customBosses = customBosses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
this.primaryMechanics = new LinkedList<>();
|
||||
|
||||
registerMechanic(new EntityTypeMechanic());
|
||||
registerMechanic(new NameMechanic());
|
||||
registerMechanic(new HealthMechanic());
|
||||
registerMechanic(new EquipmentMechanic(this.customBosses.getItemStackManager()));
|
||||
registerMechanic(new WeaponMechanic(this.customBosses.getItemStackManager()));
|
||||
registerMechanic(new PotionMechanic());
|
||||
registerMechanic(new SettingsMechanic());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerMechanic(IMechanic mechanic) {
|
||||
if(mechanic instanceof IPrimaryMechanic) {
|
||||
this.primaryMechanics.add((IPrimaryMechanic) mechanic);
|
||||
} else if(mechanic instanceof IOptionalMechanic) {
|
||||
this.optionalMechanics.add((IOptionalMechanic) mechanic);
|
||||
} else {
|
||||
Debug.MECHANIC_TYPE_NOT_STORED.debug();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMechanicApplication(MinionEntity minionEntity, ActiveBossHolder activeBossHolder) {
|
||||
if(minionEntity != null && activeBossHolder != null) {
|
||||
// if(bossEntity.isEditing()) {
|
||||
// Debug.ATTEMPTED_TO_SPAWN_WHILE_DISABLED.debug();
|
||||
// return false;
|
||||
// }
|
||||
|
||||
Queue<IMechanic> queue = new LinkedList<>(this.primaryMechanics);
|
||||
|
||||
while(!queue.isEmpty()) {
|
||||
IMechanic mechanic = queue.poll();
|
||||
|
||||
if(mechanic == null) continue;
|
||||
|
||||
ServerUtils.get().logDebug("Applying " + mechanic.getClass().getSimpleName());
|
||||
|
||||
if(didMechanicApplicationFail(mechanic, minionEntity, activeBossHolder)) return false;
|
||||
}
|
||||
|
||||
queue = new LinkedList<>(this.optionalMechanics);
|
||||
|
||||
while(!queue.isEmpty()) {
|
||||
IMechanic mechanic = queue.poll();
|
||||
|
||||
if(mechanic == null) continue;
|
||||
if(didMechanicApplicationFail(mechanic, minionEntity, activeBossHolder)) continue;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean didMechanicApplicationFail(IMechanic mechanic, MinionEntity minionEntity, ActiveBossHolder activeBossHolder) {
|
||||
if(mechanic == null) return true;
|
||||
|
||||
if(!mechanic.applyMechanic(minionEntity, activeBossHolder)) {
|
||||
Debug.MECHANIC_APPLICATION_FAILED.debug(mechanic.getClass().getSimpleName());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package com.songoda.epicbosses.managers.files;
|
||||
|
||||
import com.songoda.epicbosses.CustomBosses;
|
||||
import com.songoda.epicbosses.container.MinionEntityContainer;
|
||||
import com.songoda.epicbosses.entity.MinionEntity;
|
||||
import com.songoda.epicbosses.file.MinionsFileHandler;
|
||||
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.Map;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 12-Nov-18
|
||||
*/
|
||||
public class MinionsFileManager implements ILoadable, ISavable, IReloadable {
|
||||
|
||||
private MinionEntityContainer minionEntityContainer;
|
||||
private MinionsFileHandler minionsFileHandler;
|
||||
|
||||
public MinionsFileManager(CustomBosses customBosses) {
|
||||
File file = new File(customBosses.getDataFolder(), "minions.json");
|
||||
|
||||
this.minionsFileHandler = new MinionsFileHandler(customBosses, true, file);
|
||||
this.minionEntityContainer = customBosses.getMinionEntityContainer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
this.minionEntityContainer.clearContainer();
|
||||
this.minionEntityContainer.saveData(this.minionsFileHandler.loadFile());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
this.minionsFileHandler.saveFile(this.minionEntityContainer.getData());
|
||||
}
|
||||
|
||||
public MinionEntity getMinionEntity(String name) {
|
||||
return this.minionEntityContainer.getData().getOrDefault(name, null);
|
||||
}
|
||||
|
||||
public Map<String, MinionEntity> getMinionEntities() {
|
||||
return this.minionEntityContainer.getData();
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.songoda.epicbosses.managers.interfaces;
|
||||
|
||||
import com.songoda.epicbosses.utils.ILoadable;
|
||||
import com.songoda.epicbosses.utils.IMechanic;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 12-Nov-18
|
||||
*/
|
||||
public interface IMechanicManager<T, J> extends ILoadable {
|
||||
|
||||
void registerMechanic(IMechanic mechanic);
|
||||
|
||||
boolean handleMechanicApplication(T t, J j);
|
||||
|
||||
}
|
@ -16,7 +16,9 @@ public enum Debug {
|
||||
MAX_HEALTH("You cannot set the max health higher than {0}. You can adjust your max health in the spigot.yml file and restart your server to increase this."),
|
||||
MECHANIC_APPLICATION_FAILED("Some mechanics have failed to be applied. It got stuck at {0} mechanic."),
|
||||
BOSS_NAME_EXISTS("A boss was attempted to be created with the name {0} but there is already a boss with that name."),
|
||||
MINION_NAME_EXISTS("A minion was attempted to be created with the name {0} but there is already a minion with that name."),
|
||||
BOSS_CONTAINER_SAVE("The BossEntity map was saved in, {0} succeeded, and {1} failed. Listed below are the saved data which already existed in the container: \n{2}"),
|
||||
MINION_CONTAINER_SAVE("The MinionEntity map was saved in, {0} succeeded, and {1} failed. Listed below are the saved data which already existed in the container: \n{2}"),
|
||||
|
||||
ATTEMPTED_TO_UPDATE_PLUGIN("Something has attempted to update the PLUGIN variable in the BossAPI class while it is already initialized."),
|
||||
ATTEMPTED_TO_SPAWN_WHILE_DISABLED("A boss/minion attempted to spawn while editing is enabled."),
|
||||
@ -25,6 +27,7 @@ public enum Debug {
|
||||
FAILED_ATTEMPT_TO_SPAWN_BOSS("A boss has attempted to spawn but cannot spawn for the following reason: \n{0}"),
|
||||
FAILED_ATTEMPT_TO_STACK_BOSSES("A boss has failed to stack on top of another boss under the {0} boss configuration."),
|
||||
FAILED_TO_SAVE_THE_NEW_BOSS("The {0} with EntityType boss was successfully created but failed to save."),
|
||||
FAILED_TO_SAVE_THE_NEW_MINION("The {0} with EntityType minion was successfully created but failed to save."),
|
||||
FAILED_TO_LOAD_BOSSCOMMANDMANAGER("The boss command manager tried to load again, but it has already loaded previously."),
|
||||
FAILED_TO_LOAD_BOSSLISTENERMANAGER("The boss listener manager tried to load again, but it has already loaded previously."),
|
||||
FAILED_TO_LOAD_CUSTOM_ITEM("The itemstack name that is provided ({0}) for the spawn item doesn't exist or wasn't found."),
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.epicbosses.utils;
|
||||
|
||||
import com.songoda.epicbosses.entity.BossEntity;
|
||||
import com.songoda.epicbosses.entity.MinionEntity;
|
||||
import com.songoda.epicbosses.holder.ActiveBossHolder;
|
||||
|
||||
/**
|
||||
@ -10,6 +10,6 @@ import com.songoda.epicbosses.holder.ActiveBossHolder;
|
||||
*/
|
||||
public interface IMechanic {
|
||||
|
||||
boolean applyMechanic(BossEntity bossEntity, ActiveBossHolder activeBossHolder);
|
||||
boolean applyMechanic(MinionEntity bossEntity, ActiveBossHolder activeBossHolder);
|
||||
|
||||
}
|
||||
|
2
pom.xml
2
pom.xml
@ -19,7 +19,7 @@
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<plugin.version>1.0.0-SNAPSHOT-U44</plugin.version>
|
||||
<plugin.version>1.0.0-SNAPSHOT-U45</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