2016-11-12 14:52:08 +00:00
|
|
|
package alisolarflare.components;
|
2016-10-31 04:12:40 +00:00
|
|
|
|
2016-11-12 03:32:25 +00:00
|
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
2016-10-31 04:12:40 +00:00
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
2016-11-03 19:44:03 +00:00
|
|
|
import buttondevteam.lib.TBMCCoreAPI;
|
2016-11-03 00:22:51 +00:00
|
|
|
import buttondevteam.lib.chat.TBMCChatAPI;
|
|
|
|
import buttondevteam.lib.chat.TBMCCommandBase;
|
|
|
|
|
2016-10-31 04:12:40 +00:00
|
|
|
/**
|
2016-11-06 21:44:56 +00:00
|
|
|
* A Module class allows the compacting of projects into one single package.
|
|
|
|
*
|
|
|
|
* Each feature can have its commands and listeners coded into the Module class,
|
|
|
|
* as well as any other pointers to memory units, or other classes in the package.
|
2016-10-31 04:12:40 +00:00
|
|
|
*
|
|
|
|
* This package can then be moved from eclipse project to eclipse project smoothly,
|
|
|
|
* as long as the destination project has the Module abstract class, and as long as all dependencies are either
|
|
|
|
* contained in the moved package, or moved along with it.
|
|
|
|
* @author Alisolarflare
|
|
|
|
*
|
|
|
|
*/
|
2016-11-12 14:52:08 +00:00
|
|
|
public abstract class Component{
|
2016-11-12 03:32:25 +00:00
|
|
|
|
2016-10-31 04:12:40 +00:00
|
|
|
/**
|
2016-11-06 21:44:56 +00:00
|
|
|
* Registers the module, when called by the JavaPlugin class. Call
|
|
|
|
* registerCommand() and registerListener() within this method.
|
2016-10-31 04:12:40 +00:00
|
|
|
*
|
|
|
|
* @param plugin Plugin class called to register commands and listeners
|
|
|
|
*/
|
|
|
|
public abstract void register(JavaPlugin plugin);
|
|
|
|
/**
|
2016-11-06 21:44:56 +00:00
|
|
|
* Registers a TBMCCommand to the plugin
|
2016-10-31 04:12:40 +00:00
|
|
|
* @param plugin Main plugin responsible for stuff
|
|
|
|
* @param label Name of the command in plugin.yml
|
|
|
|
* @param commandExecutor Custom coded CommandExecutor class
|
|
|
|
*/
|
2016-11-11 19:06:15 +00:00
|
|
|
protected void registerCommand(JavaPlugin plugin, TBMCCommandBase commandBase){
|
|
|
|
TBMCChatAPI.AddCommand(plugin, commandBase);
|
2016-10-31 04:12:40 +00:00
|
|
|
}
|
2016-11-06 21:44:56 +00:00
|
|
|
/**
|
|
|
|
* Registers a Listener to this plugin
|
|
|
|
* @param plugin Main plugin responsible for stuff
|
|
|
|
* @param label Name of the command in plugin.yml
|
|
|
|
* @param commandExecutor Custom coded CommandExecutor class
|
|
|
|
*/
|
2016-10-31 04:12:40 +00:00
|
|
|
protected Listener registerListener(JavaPlugin plugin, Listener listener){
|
2016-11-03 19:44:03 +00:00
|
|
|
TBMCCoreAPI.RegisterEventsForExceptions(listener, plugin);
|
2016-10-31 04:12:40 +00:00
|
|
|
return listener;
|
|
|
|
}
|
2016-11-12 03:32:25 +00:00
|
|
|
|
|
|
|
public void saveData(FileConfiguration config, String pathToData, Object data){
|
|
|
|
|
|
|
|
config.set("moduledata." + this.getClassName() + "." + pathToData, data);
|
|
|
|
}
|
|
|
|
public Object getData(FileConfiguration config, String pathToData, Object data){
|
|
|
|
return config.get("moduledata." + this.getClassName() + "." + pathToData, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getClassName(){
|
|
|
|
Class<?> enclosingClass = getClass().getEnclosingClass();
|
|
|
|
String className = "nullModule";
|
|
|
|
if (enclosingClass != null) {
|
|
|
|
className = (enclosingClass.getName());
|
|
|
|
} else {
|
|
|
|
className = (getClass().getName());
|
|
|
|
}
|
|
|
|
return className;
|
|
|
|
}
|
2016-11-06 21:44:56 +00:00
|
|
|
|
2016-10-31 04:12:40 +00:00
|
|
|
}
|