Added Hook#getFailureCause() and fixed NPE in HooksManager

This commit is contained in:
Florian CUNY 2018-10-30 15:33:16 +01:00
parent 8fe4b16805
commit c236e1a3bc
2 changed files with 9 additions and 1 deletions

View File

@ -47,4 +47,10 @@ public abstract class Hook {
* @return true if it successfully hooked into the plugin, false otherwise. * @return true if it successfully hooked into the plugin, false otherwise.
*/ */
public abstract boolean hook(); public abstract boolean hook();
/**
* Returns an explanation that will be sent to the user to tell them why the hook process did not succeed.
* @return the probable causes why the hook process did not succeed.
*/
public abstract String getFailureCause();
} }

View File

@ -3,6 +3,7 @@ package world.bentobox.bentobox.managers;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.hooks.Hook; import world.bentobox.bentobox.api.hooks.Hook;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -16,6 +17,7 @@ public class HooksManager {
public HooksManager(BentoBox plugin) { public HooksManager(BentoBox plugin) {
this.plugin = plugin; this.plugin = plugin;
this.hooks = new ArrayList<>();
} }
public void registerHook(Hook hook) { public void registerHook(Hook hook) {
@ -24,7 +26,7 @@ public class HooksManager {
if (hook.hook()) { if (hook.hook()) {
hooks.add(hook); hooks.add(hook);
} else { } else {
plugin.log("Could not hook with " + hook.getPluginName() + ". Skipping..."); plugin.log("Could not hook with " + hook.getPluginName() + " because: " + hook.getFailureCause() + ". Skipping...");
} }
} }
} }