mirror of
https://github.com/songoda/EpicBosses.git
synced 2024-12-23 08:27:49 +01:00
3.0.0-SNAPSHOT-U22
+ Completed Boss Create command + Fixed all API methods so that when you create a boss it will now save to the file
This commit is contained in:
parent
69cb000d1a
commit
41dbd03dab
@ -46,6 +46,7 @@
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${parent.artifactId}-1.13.x</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
@ -60,6 +61,7 @@
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
|
@ -11,6 +11,7 @@ import net.aminecraftdev.custombosses.managers.files.BossItemFileManager;
|
||||
import net.aminecraftdev.custombosses.managers.BossMechanicManager;
|
||||
import net.aminecraftdev.custombosses.managers.files.BossesFileManager;
|
||||
import net.aminecraftdev.custombosses.utils.IReloadable;
|
||||
import net.aminecraftdev.custombosses.utils.Message;
|
||||
import net.aminecraftdev.custombosses.utils.command.SubCommandService;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
@ -43,23 +44,28 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
|
||||
System.out.println("Boss API loaded (took " + (System.currentTimeMillis() - beginMs) + "ms)");
|
||||
beginMs = System.currentTimeMillis();
|
||||
|
||||
loadFileManagersAndHandlers();
|
||||
|
||||
this.bossEntityContainer = new BossEntityContainer();
|
||||
this.bossMechanicManager = new BossMechanicManager(this);
|
||||
this.bossCommandManager = new BossCommandManager(new BossCmd(), this);
|
||||
|
||||
System.out.println("Managers and Containers loaded (took " + (System.currentTimeMillis() - beginMs) + "ms)");
|
||||
beginMs = System.currentTimeMillis();
|
||||
|
||||
loadFileManagersAndHandlers();
|
||||
|
||||
System.out.println("File Handlers and File Managers loaded (took " + (System.currentTimeMillis() - beginMs) + "ms)");
|
||||
beginMs = System.currentTimeMillis();
|
||||
|
||||
this.bossCommandManager = new BossCommandManager(new BossCmd(), this);
|
||||
this.bossCommandManager.load();
|
||||
|
||||
System.out.println("All commands and listeners loaded (took " + (System.currentTimeMillis() - beginMs) + "ms)");
|
||||
beginMs = System.currentTimeMillis();
|
||||
|
||||
reload();
|
||||
saveMessagesToFile();
|
||||
|
||||
System.out.println("Reloaded all fields (took " + (System.currentTimeMillis() - beginMs) + "ms) and plugin is now loaded. Took a total of " + (System.currentTimeMillis() - startMs) + "ms.");
|
||||
System.out.println("Reloaded all fields, saved messages (took " + (System.currentTimeMillis() - beginMs) + "ms) and plugin is now loaded. Took a total of " + (System.currentTimeMillis() - startMs) + "ms.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -69,6 +75,19 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
|
||||
this.bossMechanicManager.load();
|
||||
|
||||
this.lang = this.langFileHandler.loadFile();
|
||||
Message.setFile(getLang());
|
||||
}
|
||||
|
||||
private void saveMessagesToFile() {
|
||||
FileConfiguration lang = getLang();
|
||||
|
||||
for(Message message : Message.values()) {
|
||||
if(!lang.contains(message.getPath())) {
|
||||
lang.set(message.getPath(), message.getDefault());
|
||||
}
|
||||
}
|
||||
|
||||
this.langFileHandler.saveFile(lang);
|
||||
}
|
||||
|
||||
private void loadFileManagersAndHandlers() {
|
||||
|
@ -43,6 +43,24 @@ public class BossAPI {
|
||||
Panel.setPlugin(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to register a Boss Entity into
|
||||
* the plugin after it has been created
|
||||
* using the BossAPI#createBaseBossEntity
|
||||
* method or by manually creating a BossEntity.
|
||||
*
|
||||
* @param name - Name for the boss section.
|
||||
* @param bossEntity - The boss section.
|
||||
* @return false if it failed, true if it saved successfully.
|
||||
*/
|
||||
public static boolean registerBossEntity(String name, BossEntity bossEntity) {
|
||||
if(name == null || bossEntity == null) return false;
|
||||
|
||||
PLUGIN.getBossEntityContainer().saveData(name, bossEntity);
|
||||
PLUGIN.getBossesFileManager().save();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the Boss configuration section name
|
||||
* from a BossEntity instance.
|
||||
@ -74,6 +92,11 @@ public class BossAPI {
|
||||
String input = entityTypeInput.split(":")[0];
|
||||
EntityFinder entityFinder = EntityFinder.get(input);
|
||||
|
||||
if(PLUGIN.getBossEntityContainer().exists(name)) {
|
||||
Debug.BOSS_NAME_EXISTS.debug(name);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (entityFinder == null) return null;
|
||||
|
||||
List<MainStatsElement> mainStatsElements = new ArrayList<>(Arrays.asList(new MainStatsElement()));
|
||||
@ -99,6 +122,8 @@ public class BossAPI {
|
||||
return null;
|
||||
}
|
||||
|
||||
PLUGIN.getBossesFileManager().save();
|
||||
|
||||
return bossEntity;
|
||||
}
|
||||
|
||||
|
@ -1,23 +1,76 @@
|
||||
package net.aminecraftdev.custombosses.commands.boss;
|
||||
|
||||
import net.aminecraftdev.custombosses.api.BossAPI;
|
||||
import net.aminecraftdev.custombosses.container.BossEntityContainer;
|
||||
import net.aminecraftdev.custombosses.entity.BossEntity;
|
||||
import net.aminecraftdev.custombosses.utils.EntityFinder;
|
||||
import net.aminecraftdev.custombosses.utils.Message;
|
||||
import net.aminecraftdev.custombosses.utils.Permission;
|
||||
import net.aminecraftdev.custombosses.utils.StringUtils;
|
||||
import net.aminecraftdev.custombosses.utils.command.SubCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 02-Oct-18
|
||||
*
|
||||
* TODO
|
||||
*/
|
||||
public class BossCreateCmd extends SubCommand {
|
||||
|
||||
public BossCreateCmd() {
|
||||
private BossEntityContainer bossEntityContainer;
|
||||
|
||||
public BossCreateCmd(BossEntityContainer bossEntityContainer) {
|
||||
super("create");
|
||||
|
||||
this.bossEntityContainer = bossEntityContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!Permission.create.hasPermission(sender)) {
|
||||
Message.Boss_Create_NoPermission.msg(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (args.length) {
|
||||
case 2:
|
||||
List<EntityFinder> availableEntities = new ArrayList<>(Arrays.asList(EntityFinder.values()));
|
||||
String list = StringUtils.get().appendList(availableEntities);
|
||||
|
||||
Message.Boss_Create_NoEntitySpecified.msg(sender, list);
|
||||
return;
|
||||
case 3:
|
||||
String name = args[1];
|
||||
String entityTypeInput = args[2];
|
||||
|
||||
if(this.bossEntityContainer.exists(name)) {
|
||||
Message.Boss_Create_NameAlreadyExists.msg(sender, name);
|
||||
return;
|
||||
}
|
||||
|
||||
EntityFinder entityFinder = EntityFinder.get(entityTypeInput);
|
||||
|
||||
if(entityFinder == null) {
|
||||
Message.Boss_Create_EntityTypeNotFound.msg(sender, entityTypeInput);
|
||||
return;
|
||||
}
|
||||
|
||||
BossEntity bossEntity = BossAPI.createBaseBossEntity(name, entityTypeInput);
|
||||
|
||||
if(bossEntity == null) {
|
||||
Message.Boss_Create_SomethingWentWrong.msg(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
Message.Boss_Create_SuccessfullyCreated.msg(sender, name, entityFinder.getFancyName());
|
||||
return;
|
||||
default:
|
||||
Message.Boss_Create_InvalidArgs.msg(sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
package net.aminecraftdev.custombosses.commands.boss;
|
||||
|
||||
import net.aminecraftdev.custombosses.managers.files.BossesFileManager;
|
||||
import net.aminecraftdev.custombosses.utils.command.SubCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 09-Oct-18
|
||||
*/
|
||||
public class BossDebugCmd extends SubCommand {
|
||||
|
||||
private BossesFileManager bossesFileManager;
|
||||
|
||||
public BossDebugCmd(BossesFileManager bossesFileManager) {
|
||||
super("debug");
|
||||
|
||||
this.bossesFileManager = bossesFileManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
this.bossesFileManager.getBossEntities().forEach((name, entity) -> stringBuilder.append(name).append(", "));
|
||||
|
||||
System.out.println("CURRENT BOSSES: " +
|
||||
"\n" + stringBuilder.toString());
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package net.aminecraftdev.custombosses.container;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import net.aminecraftdev.custombosses.entity.BossEntity;
|
||||
import net.aminecraftdev.custombosses.utils.Debug;
|
||||
import net.aminecraftdev.custombosses.utils.IContainer;
|
||||
@ -14,7 +13,7 @@ import java.util.Map;
|
||||
* @version 1.0.0
|
||||
* @since 18-Jul-18
|
||||
*/
|
||||
public class BossEntityContainer implements IContainer<Map<String, BossEntity>> {
|
||||
public class BossEntityContainer implements IContainer<Map<String, BossEntity>, String> {
|
||||
|
||||
private Map<String, BossEntity> container = new HashMap<>();
|
||||
|
||||
@ -55,4 +54,9 @@ public class BossEntityContainer implements IContainer<Map<String, BossEntity>>
|
||||
public void clearContainer() {
|
||||
this.container.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(String string) {
|
||||
return this.container.containsKey(string);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package net.aminecraftdev.custombosses.managers;
|
||||
|
||||
import net.aminecraftdev.custombosses.CustomBosses;
|
||||
import net.aminecraftdev.custombosses.commands.boss.*;
|
||||
import net.aminecraftdev.custombosses.utils.Debug;
|
||||
import net.aminecraftdev.custombosses.utils.ILoadable;
|
||||
import net.aminecraftdev.custombosses.utils.IReloadable;
|
||||
import net.aminecraftdev.custombosses.utils.command.SubCommandService;
|
||||
|
||||
/**
|
||||
@ -15,9 +15,9 @@ public class BossCommandManager implements ILoadable {
|
||||
|
||||
private SubCommandService<?> commandService;
|
||||
private boolean hasBeenLoaded = false;
|
||||
private IReloadable customBosses;
|
||||
private CustomBosses customBosses;
|
||||
|
||||
public BossCommandManager(SubCommandService<?> commandService, IReloadable customBosses) {
|
||||
public BossCommandManager(SubCommandService<?> commandService, CustomBosses customBosses) {
|
||||
this.commandService = commandService;
|
||||
this.customBosses = customBosses;
|
||||
}
|
||||
@ -29,7 +29,8 @@ public class BossCommandManager implements ILoadable {
|
||||
return;
|
||||
}
|
||||
|
||||
this.commandService.registerSubCommand(new BossCreateCmd());
|
||||
this.commandService.registerSubCommand(new BossCreateCmd(this.customBosses.getBossEntityContainer()));
|
||||
this.commandService.registerSubCommand(new BossDebugCmd(this.customBosses.getBossesFileManager()));
|
||||
this.commandService.registerSubCommand(new BossDropTableCmd());
|
||||
this.commandService.registerSubCommand(new BossEditCmd());
|
||||
this.commandService.registerSubCommand(new BossHelpCmd());
|
||||
|
@ -9,6 +9,8 @@ import net.aminecraftdev.custombosses.utils.IReloadable;
|
||||
import net.aminecraftdev.custombosses.utils.ISavable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
@ -46,4 +48,8 @@ public class BossesFileManager implements ILoadable, ISavable, IReloadable {
|
||||
public BossEntity getBossEntity(String name) {
|
||||
return this.bossEntityContainer.getData().getOrDefault(name, null);
|
||||
}
|
||||
|
||||
public Map<String, BossEntity> getBossEntities() {
|
||||
return this.bossEntityContainer.getData();
|
||||
}
|
||||
}
|
||||
|
@ -95,6 +95,11 @@ public enum EntityFinder {
|
||||
this.customEntityHandler = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.fancyName;
|
||||
}
|
||||
|
||||
public LivingEntity spawnNewLivingEntity(String input, Location location) {
|
||||
if(this.customEntityHandler != null) {
|
||||
LivingEntity livingEntity;
|
||||
|
@ -5,7 +5,7 @@ package net.aminecraftdev.custombosses.utils;
|
||||
* @version 1.0.0
|
||||
* @since 18-Jul-18
|
||||
*/
|
||||
public interface IContainer<StorageType> {
|
||||
public interface IContainer<StorageType, KeyType> {
|
||||
|
||||
StorageType getData();
|
||||
|
||||
@ -13,4 +13,6 @@ public interface IContainer<StorageType> {
|
||||
|
||||
void clearContainer();
|
||||
|
||||
boolean exists(KeyType keyType);
|
||||
|
||||
}
|
||||
|
@ -15,14 +15,22 @@ import org.bukkit.inventory.ItemStack;
|
||||
*/
|
||||
public enum Message {
|
||||
|
||||
Boss_Create_EntityTypeNotFound("&c&l(!) &cThe specified entity type {0} was not found. If you think this is an error please contact &fAMinecraftDev&c."),
|
||||
Boss_Create_InvalidArgs("&c&l(!) &cYou must use &n/boss create [name] [entity] &c to create a boss."),
|
||||
Boss_Create_NameAlreadyExists("&c&l(!) &cA boss already exists with the name {0}."),
|
||||
Boss_Create_NoEntitySpecified("&c&l(!) &cNo entity type was specified. Make sure to add an entity type! Possible entity types are: \n&7{0}"),
|
||||
Boss_Create_NoPermission("&c&l(!) &cYou do not have access to this command."),
|
||||
Boss_Create_SomethingWentWrong("&c&l(!) &cSomething went wrong in the API class while finalising the boss creation."),
|
||||
Boss_Create_SuccessfullyCreated("&e&lCustomBosses &8» &7A boss has successfully been created with the name &f{0}&7 and the entity type &f{1}&7."),
|
||||
|
||||
Boss_Help_Page1(
|
||||
"&8&m----*--------&6&l[ &e&lBoss Help &7(Page 1) &6&l]&8&m--------*----\n" +
|
||||
"&e/boss help (page) &8» &7Displays boss commands.\n" +
|
||||
"&e/boss create [name] &8» &7Start the creation of a boss.\n" +
|
||||
"&e/boss create [name] [entity] &8» &7Start the creation of a boss.\n" +
|
||||
"&e/boss edit [name] &8» &7Edit the specified boss.\n" +
|
||||
"&e/boss info [name] &8» &7Shows information on the specified boss.\n" +
|
||||
"&e/gang nearby (radius) &8» &7Shows the nearby bosses.\n" +
|
||||
"&e/gang reload &8» &7Reloads the boss plugin.\n" +
|
||||
"&e/boss nearby (radius) &8» &7Shows the nearby bosses.\n" +
|
||||
"&e/boss reload &8» &7Reloads the boss plugin.\n" +
|
||||
"&7\n" +
|
||||
"&7Use /boss help 2 to view the next page.\n" +
|
||||
"&8&m----*-----------------------------------*----"),
|
||||
@ -35,7 +43,6 @@ public enum Message {
|
||||
"&e/boss items &8» &7Shows all current custom items.\n" +
|
||||
"&e/boss skills &8» &7Shows all current set skills.\n" +
|
||||
"&7\n" +
|
||||
"&7\n" +
|
||||
"&8&m----*-----------------------------------*----"),
|
||||
|
||||
Boss_Reload_NoPermission("&c&l(!) &cYou do not have access to this command."),
|
||||
|
@ -10,6 +10,7 @@ import org.bukkit.command.CommandSender;
|
||||
*/
|
||||
public enum Permission {
|
||||
|
||||
create("boss.create"),
|
||||
reload("boss.reload");
|
||||
|
||||
@Getter private String permission;
|
||||
|
@ -2,6 +2,10 @@ package net.aminecraftdev.custombosses.utils;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
@ -19,6 +23,55 @@ public class StringUtils {
|
||||
return ChatColor.translateAlternateColorCodes('&', string);
|
||||
}
|
||||
|
||||
public <T> String appendList(List<T> list) {
|
||||
Queue<T> queue = new LinkedList<>(list);
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
while(!queue.isEmpty()) {
|
||||
T object = queue.poll();
|
||||
|
||||
if(object == null) continue;
|
||||
|
||||
stringBuilder.append(object.toString());
|
||||
|
||||
if(queue.isEmpty()) {
|
||||
stringBuilder.append(".");
|
||||
} else {
|
||||
stringBuilder.append(", ");
|
||||
}
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
public String formatString(String string) {
|
||||
string = string.toLowerCase();
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
if(string.contains(" ")) {
|
||||
for(String z : string.split(" ")) {
|
||||
stringBuilder.append(Character.toUpperCase(z.charAt(0))).append(z.substring(1).toLowerCase());
|
||||
}
|
||||
} else if(string.contains("_")) {
|
||||
String[] split = string.split("_");
|
||||
|
||||
for(int i = 0; i < split.length; i++) {
|
||||
String z = split[i];
|
||||
|
||||
stringBuilder.append(Character.toUpperCase(z.charAt(0))).append(z.substring(1).toLowerCase());
|
||||
|
||||
if(i != (split.length - 1)) {
|
||||
stringBuilder.append(" ");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return Character.toUpperCase(string.charAt(0)) + string.substring(1).toLowerCase();
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
public static StringUtils get() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user