0

APIv4, support for spigot 1.12 (and up) #6

Merged
Pepich merged 13 commits from APIv4_spigot_1.12 into master 2017-10-31 15:53:31 +00:00
Showing only changes of commit 95896beadc - Show all commits

View File

@ -37,18 +37,18 @@ import net.nemez.chatapi.click.Message;
/** The module loader, mother of all modules. Responsible for loading and taking care of all modules. /** The module loader, mother of all modules. Responsible for loading and taking care of all modules.
* *
* @author Pepich */ * @author Pepich */
@Version(major = 4, minor = 0, revision = 0, compatible = 4) @Version(major = 4, minor = 0, revision = 1, compatible = 4)
public final class ModuleLoader implements CoreModule public final class ModuleLoader implements CoreModule
{ {
private static ModuleLoader instance; private static ModuleLoader instance;
private static final HashMap<Module, Boolean> modules = new HashMap<Module, Boolean>(); private static final HashMap<Module, Boolean> modules = new HashMap<>();
private static URL[] urls; private static URL[] urls;
private static URLClassLoader mainLoader; private static URLClassLoader mainLoader;
private static HashMap<Module, URLClassLoader> loaders = new HashMap<Module, URLClassLoader>(); private static HashMap<Module, URLClassLoader> loaders = new HashMap<>();
private static File configFile; private static File configFile;
private static FileConfiguration config; private static FileConfiguration config;
private static boolean debugMode = false; private static boolean debugMode = false;
private static HashMap<Module, ModuleLogger> loggers = new HashMap<Module, ModuleLogger>(); private static HashMap<Module, ModuleLogger> loggers = new HashMap<>();
private ModuleLoader() private ModuleLoader()
{ {
@ -152,7 +152,7 @@ public final class ModuleLoader implements CoreModule
{ {
instance.getLogger().error("Couldn't autocomplete path for module name: " + s instance.getLogger().error("Couldn't autocomplete path for module name: " + s
+ "! If you're on a case sensitive filesystem, please take note that case correction does not work. Make sure that the classname has proper capitalisation."); + "! If you're on a case sensitive filesystem, please take note that case correction does not work. Make sure that the classname has proper capitalisation.");
} }
for (String s : autoload) for (String s : autoload)
if (!s.startsWith("#")) if (!s.startsWith("#"))
@ -160,7 +160,7 @@ public final class ModuleLoader implements CoreModule
{ {
instance.getLogger().error("Couldn't autocomplete path for module name: " + s instance.getLogger().error("Couldn't autocomplete path for module name: " + s
+ "! If you're on a case sensitive filesystem, please take note that case correction does not work. Make sure that the classname has proper capitalisation."); + "! If you're on a case sensitive filesystem, please take note that case correction does not work. Make sure that the classname has proper capitalisation.");
} }
updateConfig(); updateConfig();
} }
@ -237,14 +237,12 @@ public final class ModuleLoader implements CoreModule
if (module.onEnable()) if (module.onEnable())
{ {
modules.put(module, true); modules.put(module, true);
if (oldVersion.toString().equals("0.0.0.0")) if (VersionHelper.getString(oldVersion).equals("0.0.0.0"))
module.firstLoad(); module.firstLoad();
else if (!VersionHelper.getVersion(module.getClass()).equals(oldVersion)) else if (!VersionHelper.getVersion(module.getClass()).equals(VersionHelper.getString(oldVersion)))
module.migrate(oldVersion); module.migrate(oldVersion);
if (VersionHelper.isCompatible(VersionHelper.create(4, 0, 0, 3), module.getClass())) if (VersionHelper.isCompatible(VersionHelper.create(4, 0, 0, 3), module.getClass()))
{
module.postEnable(); module.postEnable();
}
if (VersionHelper.isCompatible(VersionHelper.create(4, 0, 0, 4), module.getClass())) if (VersionHelper.isCompatible(VersionHelper.create(4, 0, 0, 4), module.getClass()))
{ {
Commands ann = module.getClass().getAnnotation(Commands.class); Commands ann = module.getClass().getAnnotation(Commands.class);
@ -375,7 +373,7 @@ public final class ModuleLoader implements CoreModule
private static ArrayList<String> getAllHooks(Module module) private static ArrayList<String> getAllHooks(Module module)
{ {
ArrayList<String> commands = new ArrayList<String>(); ArrayList<String> commands = new ArrayList<>();
for (Method m : module.getClass().getMethods()) for (Method m : module.getClass().getMethods())
{ {
Command cmd = m.getDeclaredAnnotation(Command.class); Command cmd = m.getDeclaredAnnotation(Command.class);
@ -393,7 +391,7 @@ public final class ModuleLoader implements CoreModule
{ {
instance.getLogger().message(sender, true, "Couldn't autocomplete path for module name: " + name instance.getLogger().message(sender, true, "Couldn't autocomplete path for module name: " + name
+ "! If you're on a case sensitive filesystem, please take note that case correction does not work. Make sure that the classname has proper capitalisation."); + "! If you're on a case sensitive filesystem, please take note that case correction does not work. Make sure that the classname has proper capitalisation.");
} }
updateConfig(); updateConfig();
return true; return true;
@ -500,10 +498,9 @@ public final class ModuleLoader implements CoreModule
{ {
if (!debugMode) if (!debugMode)
{ {
instance.getLogger() instance.getLogger().error("Detected equal module versions, " + (debugMode
.error("Detected equal module versions, " + (debugMode ? " aborting now... Set debugMode to true in your config if you want to continue!"
? " aborting now... Set debugMode to true in your config if you want to continue!" : " continueing anyways."));
: " continueing anyways."));
if (!debugMode) if (!debugMode)
{ {
try try
@ -680,9 +677,9 @@ public final class ModuleLoader implements CoreModule
public static void updateConfig() public static void updateConfig()
{ {
List<String> coremods = config.getStringList("coremods"); List<String> coremods = config.getStringList("coremods");
ArrayList<String> new_coremods = new ArrayList<String>(); ArrayList<String> new_coremods = new ArrayList<>();
List<String> autoload = config.getStringList("autoload"); List<String> autoload = config.getStringList("autoload");
ArrayList<String> new_autoload = new ArrayList<String>(); ArrayList<String> new_autoload = new ArrayList<>();
for (String s : coremods) for (String s : coremods)
{ {