mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-28 05:35:44 +01:00
Finished Hooks API
This commit is contained in:
parent
66bbed48c6
commit
8fe4b16805
@ -20,6 +20,7 @@ import world.bentobox.bentobox.listeners.PanelListenerManager;
|
||||
import world.bentobox.bentobox.managers.AddonsManager;
|
||||
import world.bentobox.bentobox.managers.CommandsManager;
|
||||
import world.bentobox.bentobox.managers.FlagsManager;
|
||||
import world.bentobox.bentobox.managers.HooksManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
@ -28,6 +29,8 @@ import world.bentobox.bentobox.managers.RanksManager;
|
||||
import world.bentobox.bentobox.managers.SchemsManager;
|
||||
import world.bentobox.bentobox.util.heads.HeadGetter;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Main BentoBox class
|
||||
* @author tastybento, Poslovitch
|
||||
@ -47,6 +50,7 @@ public class BentoBox extends JavaPlugin {
|
||||
private IslandWorldManager islandWorldManager;
|
||||
private RanksManager ranksManager;
|
||||
private SchemsManager schemsManager;
|
||||
private HooksManager hooksManager;
|
||||
|
||||
// Settings
|
||||
private Settings settings;
|
||||
@ -120,24 +124,28 @@ public class BentoBox extends JavaPlugin {
|
||||
playersManager.save(true);
|
||||
islandsManager.save(true);
|
||||
}, getSettings().getDatabaseBackupPeriod() * 20 * 60L, getSettings().getDatabaseBackupPeriod() * 20 * 60L);
|
||||
isLoaded = true;
|
||||
|
||||
flagsManager.registerListeners();
|
||||
|
||||
// Load metrics
|
||||
if (settings.isMetrics()) {
|
||||
BStats bStats = new BStats(this);
|
||||
bStats.registerMetrics();
|
||||
}
|
||||
|
||||
// Load hooks
|
||||
hooksManager = new HooksManager(this);
|
||||
|
||||
// Fire plugin ready event
|
||||
isLoaded = true;
|
||||
Bukkit.getServer().getPluginManager().callEvent(new BentoBoxReadyEvent());
|
||||
|
||||
instance.log("#############################################");
|
||||
instance.log(instance.getDescription().getFullName() + " has been fully enabled.");
|
||||
instance.log("It took: " + (System.currentTimeMillis() - startMillis + "ms"));
|
||||
instance.log("Thanks for using our plugin !");
|
||||
instance.log("- Tastybento and Poslovitch, 2017-2018");
|
||||
instance.log("#############################################");
|
||||
|
||||
// Load metrics
|
||||
|
||||
if (settings.isMetrics()) {
|
||||
BStats bStats = new BStats(this);
|
||||
bStats.registerMetrics();
|
||||
}
|
||||
|
||||
// Fire plugin ready event
|
||||
Bukkit.getServer().getPluginManager().callEvent(new BentoBoxReadyEvent());
|
||||
});
|
||||
}
|
||||
|
||||
@ -306,4 +314,12 @@ public class BentoBox extends JavaPlugin {
|
||||
public boolean isLoaded() {
|
||||
return isLoaded;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the HooksManager
|
||||
*/
|
||||
public HooksManager getHooks() {
|
||||
return hooksManager;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,9 +11,21 @@ public abstract class Hook {
|
||||
private String pluginName;
|
||||
|
||||
public Hook(String pluginName) {
|
||||
if (pluginName == null || pluginName.isEmpty()) {
|
||||
throw new IllegalArgumentException("Plugin name cannot be null nor empty.");
|
||||
}
|
||||
this.pluginName = pluginName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the plugin related to this Hook.
|
||||
* Cannot be null.
|
||||
* @return the plugin name.
|
||||
*/
|
||||
public String getPluginName() {
|
||||
return pluginName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
@ -1,17 +1,39 @@
|
||||
package world.bentobox.bentobox.managers;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.hooks.Hook;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author Poslovitch
|
||||
*/
|
||||
public class HooksManager {
|
||||
|
||||
private BentoBox plugin;
|
||||
private List<Hook> hooks;
|
||||
|
||||
public HooksManager(BentoBox plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void registerHook(Hook hook) {
|
||||
if (hook.isPluginAvailable()) {
|
||||
plugin.log("Hooking with " + hook.getPluginName() + "...");
|
||||
if (hook.hook()) {
|
||||
hooks.add(hook);
|
||||
} else {
|
||||
plugin.log("Could not hook with " + hook.getPluginName() + ". Skipping...");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Hook> getHooks() {
|
||||
return hooks;
|
||||
}
|
||||
|
||||
public Optional<Hook> getHook(String pluginName) {
|
||||
return hooks.stream().filter(hook -> hook.getPluginName().equals(pluginName)).findFirst();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user