Implemented basic Hooks API

WIP
This commit is contained in:
Florian CUNY 2018-10-29 21:29:07 +01:00
parent 5b97d16a2d
commit 5cdfe690f4
3 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,26 @@
package world.bentobox.bentobox.api.hooks;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
/**
* @author Poslovitch
*/
public abstract class BaseHook implements Hook {
private String pluginName;
public BaseHook(String pluginName) {
this.pluginName = pluginName;
}
@Override
public Plugin getPlugin() {
return Bukkit.getPluginManager().getPlugin(pluginName);
}
@Override
public boolean isPluginAvailable() {
return getPlugin() != null && getPlugin().isEnabled();
}
}

View File

@ -0,0 +1,27 @@
package world.bentobox.bentobox.api.hooks;
import org.bukkit.plugin.Plugin;
/**
* @author Poslovitch
*/
public interface Hook {
/**
* Returns the Plugin instance related to this Hook or null if it could not be found.
* @return the Plugin instance of the plugin this Hook hooks into.
*/
Plugin getPlugin();
/**
* Returns whether the plugin is available or not.
* @return true if the plugin is available, false otherwise.
*/
boolean isPluginAvailable();
/**
* Tries to hook into the plugin and returns whether it succeeded or not.
* @return true if it successfully hooked into the plugin, false otherwise.
*/
boolean hook();
}

View File

@ -0,0 +1,17 @@
package world.bentobox.bentobox.managers;
import world.bentobox.bentobox.api.hooks.Hook;
import java.util.List;
/**
* @author Poslovitch
*/
public class HooksManager {
private List<Hook> hooks;
public List<Hook> getHooks() {
return hooks;
}
}