1.0.0-SNAPSHOT-U137

+ Added boss new skill command
+ Fixed up a few more issues
+ Added some commenting to methods in BossAPI
+ Added method to skillsFileManager to handle saving of new skill
This commit is contained in:
Charles 2018-12-23 01:39:19 +08:00
parent 44668e297f
commit 80db161ddd
9 changed files with 105 additions and 6 deletions

1
TODO
View File

@ -1,4 +1,3 @@
00:30 -> Add the new Skill aspect (via command) (30mins)
03:00 -> Add the DropTable Main Editing GUI (Will have buttons for DropType and Rewards) (3hrs)
01:00 -> Add the DropTable Rewards Editing GUI (1hr)
01:00 -> Spray - Has a button for Rewards List (with chances), button for RandomSpray, button for MaxDistance, button for MaxDrops (1hr)

View File

@ -211,8 +211,13 @@ public class BossAPI {
return jsonParser.parse(jsonString).getAsJsonObject();
}
/**
* Used to create convert a class in to a
* JsonObject for file saving.
*
* @param object - object to convert
* @return a jsonObject of what was trying to be converted
*/
public static <T> JsonObject convertObjectToJsonObject(T object) {
JsonParser jsonParser = new JsonParser();
String jsonString = BossesGson.get().toJson(object);
@ -220,6 +225,27 @@ public class BossAPI {
return jsonParser.parse(jsonString).getAsJsonObject();
}
/**
* Used to create a new base skill table
* with the specified arguments.
*
* @param name - name of the skill table.
* @param type - skill table type.
* @param mode - skill table mode.
* @return an instance of the drop table if successful
*/
public static Skill createBaseSkill(String name, String type, String mode) {
if(PLUGIN.getSkillsFileManager().getSkill(name) != null) {
Debug.SKILL_NAME_EXISTS.debug(name);
return null;
}
Skill skill = new Skill(mode, type, 100.0, "", "");
PLUGIN.getSkillsFileManager().saveSkill(name, skill);
return skill;
}
/**
* Used to create a new base drop table
* with the specified arguments.

View File

@ -4,9 +4,13 @@ import com.songoda.epicbosses.CustomBosses;
import com.songoda.epicbosses.api.BossAPI;
import com.songoda.epicbosses.droptable.DropTable;
import com.songoda.epicbosses.managers.BossDropTableManager;
import com.songoda.epicbosses.managers.BossSkillManager;
import com.songoda.epicbosses.managers.files.CommandsFileManager;
import com.songoda.epicbosses.managers.files.DropTableFileManager;
import com.songoda.epicbosses.managers.files.MessagesFileManager;
import com.songoda.epicbosses.managers.files.SkillsFileManager;
import com.songoda.epicbosses.skills.Skill;
import com.songoda.epicbosses.skills.SkillMode;
import com.songoda.epicbosses.utils.Message;
import com.songoda.epicbosses.utils.Permission;
import com.songoda.epicbosses.utils.command.SubCommand;
@ -31,10 +35,14 @@ public class BossNewCmd extends SubCommand {
private BossDropTableManager bossDropTableManager;
private MessagesFileManager messagesFileManager;
private CommandsFileManager commandsFileManager;
private SkillsFileManager skillsFileManager;
private BossSkillManager bossSkillManager;
public BossNewCmd(CustomBosses plugin) {
super("new");
this.bossSkillManager = plugin.getBossSkillManager();
this.skillsFileManager = plugin.getSkillsFileManager();
this.dropTableFileManager = plugin.getDropTableFileManager();
this.bossDropTableManager = plugin.getBossDropTableManager();
this.messagesFileManager = plugin.getBossMessagesFileManager();
@ -127,8 +135,49 @@ public class BossNewCmd extends SubCommand {
//-------------------
// S K I L L
//-------------------
if(args.length == 3 && args[1].equalsIgnoreCase("skill")) {
//TODO: Complete new skill command
if(args.length == 5 && args[1].equalsIgnoreCase("skill")) {
String nameInput = args[2];
String typeInput = args[3];
String modeInput = args[4];
boolean validType = false, validMode = false;
List<SkillMode> skillModes = SkillMode.getSkillModes();
if(this.skillsFileManager.getSkill(nameInput) != null) {
Message.Boss_New_AlreadyExists.msg(sender, "Skill");
return;
}
for(String s : this.bossSkillManager.getValidSkillTypes()) {
if(s.equalsIgnoreCase(typeInput)) {
validType = true;
break;
}
}
for(SkillMode skillMode : skillModes) {
if(skillMode.name().equalsIgnoreCase(modeInput)) {
validMode = true;
break;
}
}
if(!validType) {
Message.Boss_New_InvalidSkillType.msg(sender);
return;
}
if(!validMode) {
Message.Boss_New_InvalidSkillMode.msg(sender);
return;
}
Skill skill = BossAPI.createBaseSkill(nameInput, typeInput, modeInput);
if(skill == null) {
Message.Boss_New_SomethingWentWrong.msg(sender, "Skill");
} else {
Message.Boss_New_Skill.msg(sender, nameInput, typeInput);
}
return;
}

View File

@ -32,6 +32,7 @@ public class BossSkillManager implements ILoadable {
private static final Set<CustomSkillHandler> SKILLS = new HashSet<>();
@Getter private final List<String> validSkillTypes = Arrays.asList("Potion", "Group", "Custom", "Command");
private CustomBosses plugin;
public BossSkillManager(CustomBosses plugin) {

View File

@ -43,6 +43,13 @@ public class SkillsFileManager implements ILoadable, IReloadable, ISavable {
this.skillsFileHandler.saveFile(this.skillMap);
}
public void saveSkill(String name, Skill skill) {
if(this.skillMap.containsKey(name)) return;
this.skillMap.put(name, skill);
save();
}
public Skill getSkill(String name) {
return this.skillMap.getOrDefault(name, null);
}

View File

@ -1,5 +1,8 @@
package com.songoda.epicbosses.skills;
import java.util.ArrayList;
import java.util.List;
/**
* @author Charles Cullen
* @version 1.0.0
@ -33,6 +36,16 @@ public enum SkillMode {
return BLANK;
}
public static List<SkillMode> getSkillModes() {
List<SkillMode> list = new ArrayList<>();
for(SkillMode skillMode : values()) {
if(skillMode.rank > 0) list.add(skillMode);
}
return list;
}
private static SkillMode get(int rank) {
for(SkillMode skillMode : values()) {
if(skillMode.rank == rank) {

View File

@ -17,6 +17,7 @@ public enum Debug {
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."),
DROPTABLE_NAME_EXISTS("A droptable was attempted to be created with the name {0} but there is already a drop table with that name."),
SKILL_NAME_EXISTS("A skill was attempted to be created with the name {0} but there is already a skill 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}"),

View File

@ -142,7 +142,10 @@ public enum Message {
Boss_New_CreateArgumentsCommand("&b&lEpicBosses &8» &7Create a new command with the command &f/boss new command [name] [command(s)]. \n&7&oUse &f|| &7&oto reference a new line."),
Boss_New_AlreadyExists("&c&l(!) &cThe specified {0} name already exists. Please try another name."),
Boss_New_InvalidDropTableType("&c&l(!) &cThe specified DropTable type is invalid. Please use &fGive, Drop, Spray&c."),
Boss_New_InvalidSkillType("&c&l(!) &cThe specified Skill type is invalid. Please use &fCustom, Command, Group, Potion&c."),
Boss_New_InvalidSkillMode("&c&l(!) &cThe specified Skill mode is invalid. Please use &fAll, Random, One, Boss&c."),
Boss_New_DropTable("&b&lEpicBosses &8» &7You have created a new drop table with the name &f{0}&7 and type &f{1}&7."),
Boss_New_Skill("&b&lEpicBosses &8» &7You have created a new skill with the name &f{0}&7 and type &f{1}&7."),
Boss_New_Command("&b&lEpicBosses &8» &7You have created a new command with the name &f{0}&7."),
Boss_New_Message("&b&lEpicBosses &8» &7You have created a new message with the name &f{0}&7."),
Boss_New_SomethingWentWrong("&c&l(!) &cSomething went wrong while trying to create a new &f{0}&c."),

View File

@ -20,7 +20,7 @@
<properties>
<!--<plugin.version>maven-version-number-SNAPSHOT-U90</plugin.version>-->
<plugin.version>1.0.0-U136</plugin.version>
<plugin.version>1.0.0-U137</plugin.version>
<plugin.name>EpicBosses</plugin.name>
<plugin.main>com.songoda.epicbosses.CustomBosses</plugin.main>
<plugin.author>AMinecraftDev</plugin.author>