Skip to content

Commit

Permalink
Simplify plugin enable check logic
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverSchlueter committed Nov 14, 2024
1 parent 40cc8bf commit 31598f8
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.oliver.fancyanalytics.logger.ExtendedFancyLogger;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.concurrent.ScheduledExecutorService;
Expand Down Expand Up @@ -65,18 +66,22 @@ class EnabledChecker {
private static FancyHologramsPlugin plugin;

public static Boolean isFancyHologramsEnabled() {
if (enabled == null) {
enabled = Bukkit.getPluginManager().isPluginEnabled("FancyHolograms");
if (enabled) {
try {
plugin = (FancyHologramsPlugin) Bukkit.getPluginManager().getPlugin("FancyHolograms");
} catch (ClassCastException e) {
throw new IllegalStateException("API failed to access plugin, if using the FancyHolograms API make sure to set the dependency to compile only.");
}
if (enabled != null) return enabled;

Plugin pl = Bukkit.getPluginManager().getPlugin("FancyHolograms");

if (pl != null && pl.isEnabled()) {
try {
plugin = (FancyHologramsPlugin) pl;
} catch (ClassCastException e) {
throw new IllegalStateException("API failed to access plugin, if using the FancyHolograms API make sure to set the dependency to compile only.");
}

enabled = true;
return true;
}

return enabled;
return false;
}

public static FancyHologramsPlugin getPlugin() {
Expand Down

0 comments on commit 31598f8

Please sign in to comment.