#1423 Implement CMI spawn integration

This commit is contained in:
Gabriele C
2017-11-28 12:57:39 +01:00
parent 350321c80b
commit c7c8e673f0
6 changed files with 145 additions and 16 deletions
@@ -22,6 +22,7 @@ public class PluginHookService {
private final PluginManager pluginManager;
private Essentials essentials;
private Plugin cmi;
private MultiverseCore multiverse;
/**
@@ -33,6 +34,7 @@ public class PluginHookService {
public PluginHookService(PluginManager pluginManager) {
this.pluginManager = pluginManager;
tryHookToEssentials();
tryHookToCMI();
tryHookToMultiverse();
}
@@ -60,6 +62,19 @@ public class PluginHookService {
return null;
}
/**
* If CMI is hooked into, return CMI' data folder.
*
* @return The CMI data folder, or null if unavailable
*/
public File getCMIDataFolder() {
Plugin plugin = pluginManager.getPlugin("CMI");
if(plugin == null) {
return null;
}
return plugin.getDataFolder();
}
/**
* Return the spawn of the given world as defined by Multiverse (if available).
*
@@ -76,10 +91,10 @@ public class PluginHookService {
return null;
}
// ------
// "Is plugin available" methods
// ------
/**
* @return true if we have a hook to Essentials, false otherwise
*/
@@ -87,6 +102,13 @@ public class PluginHookService {
return essentials != null;
}
/**
* @return true if we have a hook to CMI, false otherwise
*/
public boolean isCMIAvailable() {
return cmi != null;
}
/**
* @return true if we have a hook to Multiverse, false otherwise
*/
@@ -109,6 +131,17 @@ public class PluginHookService {
}
}
/**
* Attempts to create a hook into CMI.
*/
public void tryHookToCMI() {
try {
cmi = getPlugin(pluginManager, "CMI", Plugin.class);
} catch (Exception | NoClassDefFoundError ignored) {
cmi = null;
}
}
/**
* Attempts to create a hook into Multiverse.
*/
@@ -123,6 +156,7 @@ public class PluginHookService {
// ------
// Unhook methods
// ------
/**
* Unhooks from Essentials.
*/
@@ -130,6 +164,13 @@ public class PluginHookService {
essentials = null;
}
/**
* Unhooks from CMI.
*/
public void unhookCMI() {
cmi = null;
}
/**
* Unhooks from Multiverse.
*/
@@ -140,6 +181,7 @@ public class PluginHookService {
// ------
// Helpers
// ------
private static <T extends Plugin> T getPlugin(PluginManager pluginManager, String name, Class<T> clazz)
throws Exception, NoClassDefFoundError {
if (pluginManager.isPluginEnabled(name)) {
@@ -150,5 +192,4 @@ public class PluginHookService {
return null;
}
}