Skip to content

Commit

Permalink
feat: allow onStart to return a boolean to cancel the loading
Browse files Browse the repository at this point in the history
  • Loading branch information
ProdPreva1l committed Mar 10, 2025
1 parent 5b9e59e commit e9e376a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main/java/info/preva1l/hooker/Hooker.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,18 @@ private int loadHooks(List<Class<?>> hooks) {

Object hook = hookClass.getDeclaredConstructor().newInstance();

boolean loaded = false;
for (Method method : hookClass.getDeclaredMethods()) {
if (!method.isAnnotationPresent(OnStart.class)) continue;
method.invoke(hook);
Object response = method.invoke(hook);
if (response instanceof Boolean load) {
loaded = load;
} else {
loaded = true;
}
break;
}
if (!loaded) continue;
owningPlugin.getLogger().info("Loaded hook: " + hookAnnotation.id());
loadedHooks.put(hookClass, hook);
count++;
Expand Down

0 comments on commit e9e376a

Please sign in to comment.