Skip to content

Commit

Permalink
Check if plugin is enabled before starting hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
NahuLD committed Oct 19, 2023
1 parent 35ba65d commit 600b994
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/kitteh/vanish/hooks/HookManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.kitteh.vanish.hooks;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand Down Expand Up @@ -161,6 +162,10 @@ public void onFakeQuit(@NonNull Player player) {
* @param hookClazz hook class to register
*/
public void registerHook(@NonNull String name, @NonNull Class<? extends Hook> hookClazz) {
if (!Bukkit.getPluginManager().isPluginEnabled(name)) {
Debuggle.log(String.format("Cannot hook into plugin '%s' because it was not enabled at time of call!", name));
return;
}
try {
this.registerHook(name, hookClazz.getConstructor(VanishPlugin.class).newInstance(this.plugin));
} catch (final Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.kitteh.vanish.hooks.plugins;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.checkerframework.checker.nullness.qual.NonNull;
Expand Down

0 comments on commit 600b994

Please sign in to comment.