3.0.0-SNAPSHOT-U21

Added YmlFileHandler, started working on Messages and Permissions enum, modified a few things to support better.

TODO: Make a seperate jar which supports Minecraft 1.8.
This commit is contained in:
AMinecraftDev 2018-10-08 22:02:31 +08:00
parent d175810c89
commit 69cb000d1a
37 changed files with 768 additions and 28 deletions

View File

@ -2,13 +2,18 @@ package net.aminecraftdev.custombosses;
import lombok.Getter;
import net.aminecraftdev.custombosses.api.BossAPI;
import net.aminecraftdev.custombosses.commands.BossCmd;
import net.aminecraftdev.custombosses.container.BossEntityContainer;
import net.aminecraftdev.custombosses.file.BossesFileHandler;
import net.aminecraftdev.custombosses.file.LangFileHandler;
import net.aminecraftdev.custombosses.managers.BossCommandManager;
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.command.SubCommandService;
import org.bstats.bukkit.Metrics;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
/**
@ -20,9 +25,13 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
@Getter private BossEntityContainer bossEntityContainer;
@Getter private BossMechanicManager bossMechanicManager;
@Getter private BossCommandManager bossCommandManager;
@Getter private BossItemFileManager itemStackManager;
@Getter private BossesFileManager bossesFileManager;
@Getter private LangFileHandler langFileHandler;
@Getter private FileConfiguration lang;
@Override
public void onEnable() {
final long startMs = System.currentTimeMillis();
@ -34,24 +43,38 @@ 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.itemStackManager = new BossItemFileManager(this);
this.bossesFileManager = new BossesFileManager(this);
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();
this.bossCommandManager.load();
System.out.println("All commands and listeners loaded (took " + (System.currentTimeMillis() - beginMs) + "ms)");
beginMs = System.currentTimeMillis();
reload();
System.out.println("Reloaded all fields (took " + (System.currentTimeMillis() - beginMs) + "ms) and plugin is now loaded. Took a total of " + (System.currentTimeMillis() - startMs) + "ms.");
}
@Override
public void reload() {
this.itemStackManager.reload();
this.bossesFileManager.reload();
this.bossMechanicManager.load();
this.lang = this.langFileHandler.loadFile();
}
private void loadFileManagersAndHandlers() {
this.itemStackManager = new BossItemFileManager(this);
this.bossesFileManager = new BossesFileManager(this);
this.langFileHandler = new LangFileHandler(this);
}
}

View File

@ -95,6 +95,7 @@ public class BossAPI {
boolean result = PLUGIN.getBossEntityContainer().saveData(name, bossEntity);
if (!result) {
Debug.FAILED_TO_SAVE_THE_NEW_BOSS.debug(name, entityFinder.getFancyName());
return null;
}

View File

@ -4,6 +4,7 @@ import net.aminecraftdev.custombosses.utils.command.SubCommandService;
import net.aminecraftdev.custombosses.utils.command.attributes.Alias;
import net.aminecraftdev.custombosses.utils.command.attributes.Description;
import net.aminecraftdev.custombosses.utils.command.attributes.Name;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
/**
@ -23,6 +24,13 @@ public class BossCmd extends SubCommandService<CommandSender> {
@Override
public void execute(CommandSender sender, String[] args) {
if(args.length == 0) {
Bukkit.dispatchCommand(sender, "boss help");
return;
}
if(handleSubCommand(sender, args)) return;
Bukkit.dispatchCommand(sender, "boss help");
}
}

View File

@ -0,0 +1,23 @@
package net.aminecraftdev.custombosses.commands.boss;
import net.aminecraftdev.custombosses.utils.command.SubCommand;
import org.bukkit.command.CommandSender;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 02-Oct-18
*
* TODO
*/
public class BossCreateCmd extends SubCommand {
public BossCreateCmd() {
super("create");
}
@Override
public void execute(CommandSender sender, String[] args) {
}
}

View File

@ -0,0 +1,23 @@
package net.aminecraftdev.custombosses.commands.boss;
import net.aminecraftdev.custombosses.utils.command.SubCommand;
import org.bukkit.command.CommandSender;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 04-Oct-18
*
* TODO
*/
public class BossDropTableCmd extends SubCommand {
public BossDropTableCmd() {
super("droptable");
}
@Override
public void execute(CommandSender sender, String[] args) {
}
}

View File

@ -0,0 +1,23 @@
package net.aminecraftdev.custombosses.commands.boss;
import net.aminecraftdev.custombosses.utils.command.SubCommand;
import org.bukkit.command.CommandSender;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 02-Oct-18
*
* TODO
*/
public class BossEditCmd extends SubCommand {
public BossEditCmd() {
super("edit");
}
@Override
public void execute(CommandSender sender, String[] args) {
}
}

View File

@ -0,0 +1,41 @@
package net.aminecraftdev.custombosses.commands.boss;
import net.aminecraftdev.custombosses.utils.Message;
import net.aminecraftdev.custombosses.utils.NumberUtils;
import net.aminecraftdev.custombosses.utils.command.SubCommand;
import org.bukkit.command.CommandSender;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 02-Oct-18
*/
public class BossHelpCmd extends SubCommand {
public BossHelpCmd() {
super("help");
}
@Override
public void execute(CommandSender sender, String[] args) {
int pageNumber = 0;
if(args.length > 1) {
Integer newNumber = NumberUtils.get().getInteger(args[1]);
if(newNumber != null) pageNumber = newNumber;
}
switch (pageNumber) {
default:
case 1:
Message.Boss_Help_Page1.msg(sender);
break;
case 2:
Message.Boss_Help_Page2.msg(sender);
break;
}
return;
}
}

View File

@ -0,0 +1,23 @@
package net.aminecraftdev.custombosses.commands.boss;
import net.aminecraftdev.custombosses.utils.command.SubCommand;
import org.bukkit.command.CommandSender;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 02-Oct-18
*
* TODO
*/
public class BossInfoCmd extends SubCommand {
public BossInfoCmd() {
super("info");
}
@Override
public void execute(CommandSender sender, String[] args) {
}
}

View File

@ -0,0 +1,21 @@
package net.aminecraftdev.custombosses.commands.boss;
import net.aminecraftdev.custombosses.utils.command.SubCommand;
import org.bukkit.command.CommandSender;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 04-Oct-18
*/
public class BossItemsCmd extends SubCommand {
public BossItemsCmd() {
super("items", "item");
}
@Override
public void execute(CommandSender sender, String[] args) {
}
}

View File

@ -0,0 +1,23 @@
package net.aminecraftdev.custombosses.commands.boss;
import net.aminecraftdev.custombosses.utils.command.SubCommand;
import org.bukkit.command.CommandSender;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 02-Oct-18
*
* TODO
*/
public class BossKillAllCmd extends SubCommand {
public BossKillAllCmd() {
super("killall");
}
@Override
public void execute(CommandSender sender, String[] args) {
}
}

View File

@ -0,0 +1,23 @@
package net.aminecraftdev.custombosses.commands.boss;
import net.aminecraftdev.custombosses.utils.command.SubCommand;
import org.bukkit.command.CommandSender;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 02-Oct-18
*
* TODO
*/
public class BossListCmd extends SubCommand {
public BossListCmd() {
super("list", "show");
}
@Override
public void execute(CommandSender sender, String[] args) {
}
}

View File

@ -0,0 +1,23 @@
package net.aminecraftdev.custombosses.commands.boss;
import net.aminecraftdev.custombosses.utils.command.SubCommand;
import org.bukkit.command.CommandSender;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 02-Oct-18
*
* TODO
*/
public class BossNearbyCmd extends SubCommand {
public BossNearbyCmd() {
super("nearby");
}
@Override
public void execute(CommandSender sender, String[] args) {
}
}

View File

@ -0,0 +1,36 @@
package net.aminecraftdev.custombosses.commands.boss;
import net.aminecraftdev.custombosses.utils.IReloadable;
import net.aminecraftdev.custombosses.utils.Message;
import net.aminecraftdev.custombosses.utils.Permission;
import net.aminecraftdev.custombosses.utils.command.SubCommand;
import org.bukkit.command.CommandSender;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 02-Oct-18
*/
public class BossReloadCmd extends SubCommand {
private IReloadable masterReloadable;
public BossReloadCmd(IReloadable reloadable) {
super("reload");
this.masterReloadable = reloadable;
}
@Override
public void execute(CommandSender sender, String[] args) {
if(!Permission.reload.hasPermission(sender)) {
Message.Boss_Reload_NoPermission.msg(sender);
return;
}
long currentMs = System.currentTimeMillis();
this.masterReloadable.reload();
Message.Boss_Reload_Successful.msg(sender, (System.currentTimeMillis() - currentMs));
}
}

View File

@ -0,0 +1,21 @@
package net.aminecraftdev.custombosses.commands.boss;
import net.aminecraftdev.custombosses.utils.command.SubCommand;
import org.bukkit.command.CommandSender;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 04-Oct-18
*/
public class BossSkillsCmd extends SubCommand {
public BossSkillsCmd() {
super("skills");
}
@Override
public void execute(CommandSender sender, String[] args) {
}
}

View File

@ -0,0 +1,23 @@
package net.aminecraftdev.custombosses.commands.boss;
import net.aminecraftdev.custombosses.utils.command.SubCommand;
import org.bukkit.command.CommandSender;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 02-Oct-18
*
* TODO
*/
public class BossSpawnCmd extends SubCommand {
public BossSpawnCmd() {
super("spawn");
}
@Override
public void execute(CommandSender sender, String[] args) {
}
}

View File

@ -0,0 +1,23 @@
package net.aminecraftdev.custombosses.commands.boss;
import net.aminecraftdev.custombosses.utils.command.SubCommand;
import org.bukkit.command.CommandSender;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 02-Oct-18
*
* TODO
*/
public class BossTimeCmd extends SubCommand {
public BossTimeCmd() {
super("time");
}
@Override
public void execute(CommandSender sender, String[] args) {
}
}

View File

@ -0,0 +1,19 @@
package net.aminecraftdev.custombosses.file;
import net.aminecraftdev.custombosses.utils.file.YmlFileHandler;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 04-Oct-18
*/
public class LangFileHandler extends YmlFileHandler {
public LangFileHandler(JavaPlugin javaPlugin) {
super(javaPlugin, false, new File(javaPlugin.getDataFolder(), "lang.yml"));
}
}

View File

@ -0,0 +1,48 @@
package net.aminecraftdev.custombosses.managers;
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;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 02-Oct-18
*/
public class BossCommandManager implements ILoadable {
private SubCommandService<?> commandService;
private boolean hasBeenLoaded = false;
private IReloadable customBosses;
public BossCommandManager(SubCommandService<?> commandService, IReloadable customBosses) {
this.commandService = commandService;
this.customBosses = customBosses;
}
@Override
public void load() {
if(this.hasBeenLoaded) {
Debug.FAILED_TO_LOAD_BOSSCOMMANDMANAGER.debug();
return;
}
this.commandService.registerSubCommand(new BossCreateCmd());
this.commandService.registerSubCommand(new BossDropTableCmd());
this.commandService.registerSubCommand(new BossEditCmd());
this.commandService.registerSubCommand(new BossHelpCmd());
this.commandService.registerSubCommand(new BossInfoCmd());
this.commandService.registerSubCommand(new BossItemsCmd());
this.commandService.registerSubCommand(new BossKillAllCmd());
this.commandService.registerSubCommand(new BossListCmd());
this.commandService.registerSubCommand(new BossNearbyCmd());
this.commandService.registerSubCommand(new BossReloadCmd(this.customBosses));
this.commandService.registerSubCommand(new BossSkillsCmd());
this.commandService.registerSubCommand(new BossSpawnCmd());
this.commandService.registerSubCommand(new BossTimeCmd());
this.hasBeenLoaded = true;
}
}

View File

@ -7,6 +7,8 @@ import net.aminecraftdev.custombosses.mechanics.*;
import net.aminecraftdev.custombosses.utils.Debug;
import net.aminecraftdev.custombosses.utils.ILoadable;
import net.aminecraftdev.custombosses.utils.IMechanic;
import net.aminecraftdev.custombosses.utils.mechanics.IOptionalMechanic;
import net.aminecraftdev.custombosses.utils.mechanics.IPrimaryMechanic;
import java.util.LinkedList;
import java.util.Queue;
@ -19,7 +21,8 @@ import java.util.Queue;
public class BossMechanicManager implements ILoadable {
private final CustomBosses customBosses;
private Queue<IMechanic> mechanicQueue;
private Queue<IOptionalMechanic> optionalMechanics;
private Queue<IPrimaryMechanic> primaryMechanics;
public BossMechanicManager(CustomBosses customBosses) {
this.customBosses = customBosses;
@ -27,34 +30,55 @@ public class BossMechanicManager implements ILoadable {
@Override
public void load() {
this.mechanicQueue = new LinkedList<>();
this.primaryMechanics = new LinkedList<>();
this.optionalMechanics = new LinkedList<>();
this.mechanicQueue.add(new EntityTypeMechanic());
this.mechanicQueue.add(new NameMechanic());
this.mechanicQueue.add(new HealthMechanic());
this.mechanicQueue.add(new EquipmentMechanic(this.customBosses.getItemStackManager()));
this.mechanicQueue.add(new WeaponMechanic(this.customBosses.getItemStackManager()));
this.mechanicQueue.add(new PotionMechanic());
this.mechanicQueue.add(new SettingsMechanic());
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());
}
public boolean handleMechanicApplication(BossEntity bossEntity, ActiveBossHolder activeBossHolder) {
if(this.mechanicQueue != null && bossEntity != null && activeBossHolder != null) {
Queue<IMechanic> queue = new LinkedList<>(this.mechanicQueue);
if(bossEntity != null && activeBossHolder != null) {
Queue<IMechanic> queue = new LinkedList<>(this.primaryMechanics);
while(!queue.isEmpty()) {
IMechanic mechanic = queue.poll();
if(mechanic == null) continue;
if(!handleMechanicApplication(mechanic, bossEntity, activeBossHolder)) return false;
if(!didMechanicApplicationFail(mechanic, bossEntity, activeBossHolder)) return false;
}
queue = new LinkedList<>(this.optionalMechanics);
while(!queue.isEmpty()) {
IMechanic mechanic = queue.poll();
if(mechanic == null) continue;
if(didMechanicApplicationFail(mechanic, bossEntity, activeBossHolder)) return false;
}
}
return true;
}
private boolean handleMechanicApplication(IMechanic mechanic, BossEntity bossEntity, ActiveBossHolder activeBossHolder) {
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();
}
}
private boolean didMechanicApplicationFail(IMechanic mechanic, BossEntity bossEntity, ActiveBossHolder activeBossHolder) {
if(mechanic == null) return false;
if(!mechanic.applyMechanic(bossEntity, activeBossHolder)) {

View File

@ -8,6 +8,7 @@ import net.aminecraftdev.custombosses.holder.ActiveBossHolder;
import net.aminecraftdev.custombosses.utils.Debug;
import net.aminecraftdev.custombosses.utils.EntityFinder;
import net.aminecraftdev.custombosses.utils.IMechanic;
import net.aminecraftdev.custombosses.utils.mechanics.IPrimaryMechanic;
import org.bukkit.entity.LivingEntity;
import java.util.Map;
@ -17,7 +18,7 @@ import java.util.Map;
* @version 1.0.0
* @since 01-Jun-18
*/
public class EntityTypeMechanic implements IMechanic {
public class EntityTypeMechanic implements IPrimaryMechanic {
@Override
public boolean applyMechanic(BossEntity bossEntity, ActiveBossHolder activeBossHolder) {

View File

@ -6,6 +6,7 @@ import net.aminecraftdev.custombosses.holder.ActiveBossHolder;
import net.aminecraftdev.custombosses.managers.files.BossItemFileManager;
import net.aminecraftdev.custombosses.utils.IMechanic;
import net.aminecraftdev.custombosses.utils.itemstack.holder.ItemStackHolder;
import net.aminecraftdev.custombosses.utils.mechanics.IOptionalMechanic;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
@ -15,7 +16,7 @@ import org.bukkit.inventory.ItemStack;
* @version 1.0.0
* @since 03-Jun-18
*/
public class EquipmentMechanic implements IMechanic {
public class EquipmentMechanic implements IOptionalMechanic {
private BossItemFileManager itemStackManager;

View File

@ -5,6 +5,7 @@ import net.aminecraftdev.custombosses.holder.ActiveBossHolder;
import net.aminecraftdev.custombosses.utils.Debug;
import net.aminecraftdev.custombosses.utils.IMechanic;
import net.aminecraftdev.custombosses.utils.file.reader.SpigotYmlReader;
import net.aminecraftdev.custombosses.utils.mechanics.IPrimaryMechanic;
import org.bukkit.entity.LivingEntity;
/**
@ -12,7 +13,7 @@ import org.bukkit.entity.LivingEntity;
* @version 1.0.0
* @since 27-Jun-18
*/
public class HealthMechanic implements IMechanic {
public class HealthMechanic implements IPrimaryMechanic {
@Override
public boolean applyMechanic(BossEntity bossEntity, ActiveBossHolder activeBossHolder) {

View File

@ -4,6 +4,7 @@ import net.aminecraftdev.custombosses.entity.BossEntity;
import net.aminecraftdev.custombosses.holder.ActiveBossHolder;
import net.aminecraftdev.custombosses.utils.IMechanic;
import net.aminecraftdev.custombosses.utils.StringUtils;
import net.aminecraftdev.custombosses.utils.mechanics.IOptionalMechanic;
import org.bukkit.entity.LivingEntity;
/**
@ -11,7 +12,7 @@ import org.bukkit.entity.LivingEntity;
* @version 1.0.0
* @since 27-Jun-18
*/
public class NameMechanic implements IMechanic {
public class NameMechanic implements IOptionalMechanic {
@Override
public boolean applyMechanic(BossEntity bossEntity, ActiveBossHolder activeBossHolder) {

View File

@ -3,6 +3,7 @@ package net.aminecraftdev.custombosses.mechanics;
import net.aminecraftdev.custombosses.entity.BossEntity;
import net.aminecraftdev.custombosses.holder.ActiveBossHolder;
import net.aminecraftdev.custombosses.utils.IMechanic;
import net.aminecraftdev.custombosses.utils.mechanics.IOptionalMechanic;
import net.aminecraftdev.custombosses.utils.potion.PotionEffectConverter;
import net.aminecraftdev.custombosses.utils.potion.holder.PotionEffectHolder;
import org.bukkit.entity.LivingEntity;
@ -14,7 +15,7 @@ import java.util.List;
* @version 1.0.0
* @since 27-Jun-18
*/
public class PotionMechanic implements IMechanic {
public class PotionMechanic implements IOptionalMechanic {
private PotionEffectConverter potionEffectConverter;

View File

@ -6,6 +6,7 @@ import net.aminecraftdev.custombosses.utils.Debug;
import net.aminecraftdev.custombosses.utils.IMechanic;
import net.aminecraftdev.custombosses.utils.StringUtils;
import net.aminecraftdev.custombosses.utils.file.reader.SpigotYmlReader;
import net.aminecraftdev.custombosses.utils.mechanics.IPrimaryMechanic;
import net.aminecraftdev.custombosses.utils.version.VersionHandler;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.EntityEquipment;
@ -15,7 +16,7 @@ import org.bukkit.inventory.EntityEquipment;
* @version 1.0.0
* @since 02-Jun-18
*/
public class SettingsMechanic implements IMechanic {
public class SettingsMechanic implements IPrimaryMechanic {
private VersionHandler versionHandler;

View File

@ -5,6 +5,7 @@ import net.aminecraftdev.custombosses.entity.elements.HandsElement;
import net.aminecraftdev.custombosses.holder.ActiveBossHolder;
import net.aminecraftdev.custombosses.managers.files.BossItemFileManager;
import net.aminecraftdev.custombosses.utils.IMechanic;
import net.aminecraftdev.custombosses.utils.mechanics.IOptionalMechanic;
import net.aminecraftdev.custombosses.utils.version.VersionHandler;
import net.aminecraftdev.custombosses.utils.itemstack.holder.ItemStackHolder;
import org.bukkit.entity.LivingEntity;
@ -16,7 +17,7 @@ import org.bukkit.inventory.ItemStack;
* @version 1.0.0
* @since 27-Jun-18
*/
public class WeaponMechanic implements IMechanic {
public class WeaponMechanic implements IOptionalMechanic {
private BossItemFileManager itemStackManager;
private VersionHandler versionHandler;

View File

@ -17,7 +17,11 @@ public enum Debug {
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("The {0} boss/minion attempted to spawn while editing is enabled."),
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_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_LOAD_BOSSCOMMANDMANAGER("The boss command manager tried to load again, but it has already loaded previously."),
MECHANIC_TYPE_NOT_STORED("This mechanic type is not stored, therefore will not be applied. Valid mechanic types are IOptionalMechanic and IPrimaryMechanic.");
private String message;

View File

@ -0,0 +1,164 @@
package net.aminecraftdev.custombosses.utils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 04-Oct-18
*/
public enum Message {
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 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" +
"&7\n" +
"&7Use /boss help 2 to view the next page.\n" +
"&8&m----*-----------------------------------*----"),
Boss_Help_Page2(
"&8&m----*--------&6&l[ &e&lBoss Help &7(Page 2) &6&l]&8&m--------*----\n" +
"&e/boss spawn [name] (location) &8» &7Spawns a boss at your location or the specified location.\n" +
" &7&o(Separate location with commas, an example is: world,0,100,0)\n" +
"&e/boss time (section) &8» &7Shows the time left till next auto spawn.\n" +
"&e/boss droptable &8» &7Shows all current drop tables.\n" +
"&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."),
Boss_Reload_Successful("&e&lCustomBosses &8» &7All boss data has been reloaded. The process took &f{0}ms&7.");
private static FileConfiguration LANG;
private final String path, msg;
Message(String string) {
this.path = this.name().replace("_", ".");
this.msg = string;
}
public static void setFile(FileConfiguration configuration) {
LANG = configuration;
}
@Override
public String toString() {
return StringUtils.get().translateColor(LANG.getString(this.path, this.msg));
}
public String toString(Object... args) {
return getFinalized(StringUtils.get().translateColor(LANG.getString(this.path, this.msg)), args);
}
public String getDefault() {
return this.msg;
}
public String getPath() {
return this.path;
}
public void msg(CommandSender p, Object... order) {
String s = toString(order);
if(s.contains("\n")) {
String[] split = s.split("\n");
for(String inner : split) {
sendMessage(p, inner, order);
}
} else {
sendMessage(p, s, order);
}
}
public void broadcast(Object... order) {
String s = toString();
if(s.contains("\n")) {
String[] split = s.split("\n");
for(String inner : split) {
for(Player player : Bukkit.getOnlinePlayers()) {
sendMessage(player, inner, order);
}
}
} else {
for(Player player : Bukkit.getOnlinePlayers()) {
sendMessage(player, s, order);
}
}
}
private String getFinalized(String string, Object... order) {
int current = 0;
for(Object object : order) {
String placeholder = "{" + current + "}";
if(string.contains(placeholder)) {
if(object instanceof CommandSender) {
string = string.replace(placeholder, ((CommandSender) object).getName());
}
else if(object instanceof OfflinePlayer) {
string = string.replace(placeholder, ((OfflinePlayer) object).getName());
}
else if(object instanceof Location) {
Location location = (Location) object;
String repl = location.getWorld().getName() + ", " + location.getBlockX() + ", " + location.getBlockY() + ", " + location.getBlockZ();
string = string.replace(placeholder, repl);
}
else if(object instanceof String) {
string = string.replace(placeholder, StringUtils.get().translateColor((String) object));
}
else if(object instanceof Long) {
string = string.replace(placeholder, ""+object);
}
else if(object instanceof Double) {
string = string.replace(placeholder, ""+object);
}
else if(object instanceof Integer) {
string = string.replace(placeholder, ""+object);
}
else if(object instanceof ItemStack) {
string = string.replace(placeholder, getItemStackName((ItemStack) object));
} else if(object instanceof Boolean) {
string = string.replace(placeholder, ""+object);
}
}
current++;
}
return string;
}
private void sendMessage(CommandSender target, String string, Object... order) {
target.sendMessage(getFinalized(string, order));
}
private String getItemStackName(ItemStack itemStack) {
String name = itemStack.getType().toString().replace("_", " ");
if(itemStack.hasItemMeta() && itemStack.getItemMeta().hasDisplayName()) {
return itemStack.getItemMeta().getDisplayName();
}
return name;
}
}

View File

@ -19,6 +19,12 @@ public class NumberUtils {
return true;
}
public Integer getInteger(String input) {
if(!isInt(input)) return null;
return Integer.valueOf(input);
}
public boolean isDouble(String string) {
try {
Double.valueOf(string);
@ -29,6 +35,12 @@ public class NumberUtils {
return true;
}
public Double getDouble(String input) {
if(!isDouble(input)) return null;
return Double.valueOf(input);
}
public static NumberUtils get() {
return INSTANCE;
}

View File

@ -0,0 +1,25 @@
package net.aminecraftdev.custombosses.utils;
import lombok.Getter;
import org.bukkit.command.CommandSender;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 04-Oct-18
*/
public enum Permission {
reload("boss.reload");
@Getter private String permission;
Permission(String permission) {
this.permission = permission;
}
public boolean hasPermission(CommandSender commandSender) {
return commandSender.hasPermission(getPermission());
}
}

View File

@ -9,7 +9,7 @@ import org.bukkit.command.CommandSender;
*/
public interface ISubCommandHandler {
void addSubCommand(SubCommand subCommand);
void registerSubCommand(SubCommand subCommand);
boolean handleSubCommand(CommandSender commandSender, String[] args);

View File

@ -19,7 +19,7 @@ public abstract class SubCommandService<T extends CommandSender> extends Command
}
@Override
public void addSubCommand(SubCommand subCommand) {
public void registerSubCommand(SubCommand subCommand) {
this.subCommands.add(subCommand);
}

View File

@ -12,8 +12,9 @@ import java.io.File;
*/
public abstract class FileHandler<T> implements IFileHandler<T> {
private final JavaPlugin javaPlugin;
private final boolean saveResource;
private final JavaPlugin javaPlugin;
private final boolean saveResource;
@Getter private final File file;
public FileHandler(JavaPlugin javaPlugin, boolean saveResource, File file) {
@ -22,6 +23,7 @@ public abstract class FileHandler<T> implements IFileHandler<T> {
this.file = file;
}
@Override
public void createFile() {
if(!this.file.exists()) {
if(this.saveResource) {

View File

@ -7,6 +7,8 @@ package net.aminecraftdev.custombosses.utils.file;
*/
public interface IFileHandler<ReturnObject> {
void createFile();
ReturnObject loadFile();
void saveFile(ReturnObject returnObject);

View File

@ -0,0 +1,53 @@
package net.aminecraftdev.custombosses.utils.file;
import lombok.Getter;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 04-Oct-18
*/
public class YmlFileHandler implements IFileHandler<FileConfiguration> {
private final JavaPlugin javaPlugin;
private final boolean saveResource;
@Getter private final File file;
public YmlFileHandler(JavaPlugin javaPlugin, boolean saveResource, File file) {
this.javaPlugin = javaPlugin;
this.saveResource = saveResource;
this.file = file;
}
@Override
public void createFile() {
if(!this.file.exists()) {
if(this.saveResource) {
String path = this.file.getName();
if(this.javaPlugin.getResource(path) != null) {
this.javaPlugin.saveResource(path, false);
return;
}
}
FileUtils.get().createFile(this.file);
}
}
@Override
public FileConfiguration loadFile() {
return FileUtils.get().loadFile(this.file);
}
@Override
public void saveFile(FileConfiguration config) {
FileUtils.get().saveFile(this.file, config);
}
}

View File

@ -0,0 +1,11 @@
package net.aminecraftdev.custombosses.utils.mechanics;
import net.aminecraftdev.custombosses.utils.IMechanic;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 02-Oct-18
*/
public interface IOptionalMechanic extends IMechanic {
}

View File

@ -0,0 +1,11 @@
package net.aminecraftdev.custombosses.utils.mechanics;
import net.aminecraftdev.custombosses.utils.IMechanic;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 02-Oct-18
*/
public interface IPrimaryMechanic extends IMechanic {
}