mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-22 00:58:04 +01:00
Mid-work.
This commit is contained in:
parent
b1f798ae5b
commit
4fc33cb9f7
@ -0,0 +1,62 @@
|
||||
package us.tastybento.bskyblock.api.addons;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Map;
|
||||
|
||||
import us.tastybento.bskyblock.api.module.Module;
|
||||
import us.tastybento.bskyblock.api.module.ModuleDescription;
|
||||
import us.tastybento.bskyblock.api.module.ModuleDescription.ModuleDescriptionBuilder;
|
||||
import us.tastybento.bskyblock.api.module.exception.InvalidModuleFormatException;
|
||||
import us.tastybento.bskyblock.api.module.exception.InvalidModuleInheritException;
|
||||
|
||||
public class ModuleClassLoader extends URLClassLoader{
|
||||
|
||||
public Module module;
|
||||
|
||||
public ModuleClassLoader(Map<String, String>data, File path, BufferedReader reader, ClassLoader loaders) throws InvalidModuleInheritException, MalformedURLException, InvalidModuleFormatException {
|
||||
super(new URL[]{path.toURI().toURL()}, loaders);
|
||||
|
||||
Module module = null;
|
||||
|
||||
Class<?> javaClass = null;
|
||||
try {
|
||||
javaClass = Class.forName(data.get("Main"), true, this);
|
||||
if(data.get("Main").contains("net.essence")){
|
||||
throw new InvalidModuleFormatException("Packages declaration cannot start with 'net.essence'");
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Class<? extends Module> moduleClass;
|
||||
try{
|
||||
moduleClass = javaClass.asSubclass(Module.class);
|
||||
}catch(ClassCastException e){
|
||||
throw new InvalidModuleInheritException("Main class doesn't not extends super class 'Module'");
|
||||
}
|
||||
|
||||
try {
|
||||
module = moduleClass.newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
module.setDescription(this.asDescription(data));
|
||||
|
||||
this.module = module;
|
||||
}
|
||||
|
||||
private ModuleDescription asDescription(Map<String, String> data){
|
||||
|
||||
String[] authors = data.get("Author").split("\\,");
|
||||
|
||||
return new ModuleDescriptionBuilder(data.get("Name"))
|
||||
.withVersion(data.get("Version"))
|
||||
.withAuthor(authors).build();
|
||||
}
|
||||
|
||||
}
|
77
src/main/java/us/tastybento/bskyblock/api/module/Module.java
Normal file
77
src/main/java/us/tastybento/bskyblock/api/module/Module.java
Normal file
@ -0,0 +1,77 @@
|
||||
package us.tastybento.bskyblock.api.module;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import us.tastybento.bskyblock.api.module.command.CommandManager;
|
||||
import us.tastybento.bskyblock.module.command.ModuleCommand;
|
||||
import us.tastybento.bskyblock.module.event.ListenerManager;
|
||||
import us.tastybento.bskyblock.module.event.ModuleListener;
|
||||
|
||||
public abstract class Module{
|
||||
|
||||
private ListenerManager listenerManager;
|
||||
private boolean enabled;
|
||||
private ModuleDescription description;
|
||||
private List<ModuleCommand> registeredCommands;
|
||||
|
||||
public Module(){
|
||||
this.enabled = false;
|
||||
this.listenerManager = new ListenerManager();
|
||||
this.registeredCommands = new ArrayList<>();
|
||||
}
|
||||
|
||||
public abstract void Enable();
|
||||
public abstract void Disable();
|
||||
public abstract void Load();
|
||||
|
||||
public void registerListener(ModuleListener listener){
|
||||
this.listenerManager.registerListener(listener);
|
||||
}
|
||||
|
||||
public void registerCommand(ModuleCommand command){
|
||||
CommandManager.registerCmd(command);
|
||||
this.registeredCommands.add(command);
|
||||
}
|
||||
|
||||
public JavaPlugin getUsedPlugin(){
|
||||
return Main.getInstance();
|
||||
}
|
||||
|
||||
public ListenerManager getListenerManager() {
|
||||
return listenerManager;
|
||||
}
|
||||
|
||||
public void setListenerManager(ListenerManager listenerManager) {
|
||||
this.listenerManager = listenerManager;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public ModuleDescription getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(ModuleDescription desc){
|
||||
this.description = desc;
|
||||
}
|
||||
|
||||
public List<ModuleCommand> getRegisteredCommands() {
|
||||
return registeredCommands;
|
||||
}
|
||||
|
||||
public void setRegisteredCommands(List<ModuleCommand> registeredCommands) {
|
||||
this.registeredCommands = registeredCommands;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package us.tastybento.bskyblock.api.module;
|
||||
|
||||
public class ModuleDescription {
|
||||
|
||||
public class ModuleDescriptionBuilder {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package us.tastybento.bskyblock.api.module.exception;
|
||||
|
||||
public class InvalidModuleFormatException {
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package us.tastybento.bskyblock.api.module.exception;
|
||||
|
||||
public class InvalidModuleInheritException {
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user