+ * Use it whenever a null check is needed to avoid a non-descriptive {@link NullPointerException}.
+ */
+ private static void validateInstance() {
+ if (instance == null) {
+ throw new IllegalStateException("Cannot invoke static method, Slimefun instance is null.");
+ }
+ }
+
/**
* This returns the global instance of {@link SlimefunPlugin}.
* This may return null if the {@link Plugin} was disabled.
@@ -667,69 +694,97 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
return instance;
}
- public static Config getCfg() {
- return instance.config;
- }
-
- public static Config getResearchCfg() {
- return instance.researches;
- }
-
- public static Config getItemCfg() {
- return instance.items;
- }
-
- public static GPSNetwork getGPSNetwork() {
- return instance.gpsNetwork;
- }
-
- public static TickerTask getTickerTask() {
- return instance.ticker;
- }
-
/**
* This returns the version of Slimefun that is currently installed.
*
* @return The currently installed version of Slimefun
*/
+ @Nonnull
public static String getVersion() {
+ validateInstance();
return instance.getDescription().getVersion();
}
+ @Nonnull
+ public static Config getCfg() {
+ validateInstance();
+ return instance.config;
+ }
+
+ @Nonnull
+ public static Config getResearchCfg() {
+ validateInstance();
+ return instance.researches;
+ }
+
+ @Nonnull
+ public static Config getItemCfg() {
+ validateInstance();
+ return instance.items;
+ }
+
+ @Nonnull
+ public static GPSNetwork getGPSNetwork() {
+ validateInstance();
+ return instance.gpsNetwork;
+ }
+
+ @Nonnull
+ public static TickerTask getTickerTask() {
+ validateInstance();
+ return instance.ticker;
+ }
+
/**
* This returns the {@link LocalizationService} of Slimefun.
*
* @return The {@link LocalizationService} of Slimefun
*/
+ @Nonnull
public static LocalizationService getLocalization() {
+ validateInstance();
return instance.local;
}
+ @Nonnull
public static ProtectionManager getProtectionManager() {
+ validateInstance();
return instance.protections;
}
+ @Nonnull
public static MinecraftRecipeService getMinecraftRecipeService() {
+ validateInstance();
return instance.recipeService;
}
+ @Nonnull
public static CustomItemDataService getItemDataService() {
+ validateInstance();
return instance.itemDataService;
}
+ @Nonnull
public static CustomTextureService getItemTextureService() {
+ validateInstance();
return instance.textureService;
}
+ @Nonnull
public static PermissionsService getPermissionsService() {
+ validateInstance();
return instance.permissionsService;
}
+ @Nonnull
public static BlockDataService getBlockDataService() {
+ validateInstance();
return instance.blockDataService;
}
+ @Nonnull
public static PerWorldSettingsService getWorldSettingsService() {
+ validateInstance();
return instance.worldSettingsService;
}
@@ -753,6 +808,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
*/
@Nonnull
public static IntegrationsManager getIntegrations() {
+ validateInstance();
return instance.integrations;
}
@@ -762,7 +818,9 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
*
* @return The {@link UpdaterService} for Slimefun
*/
+ @Nonnull
public static UpdaterService getUpdater() {
+ validateInstance();
return instance.updaterService;
}
@@ -772,7 +830,9 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
*
* @return The {@link MetricsService} for Slimefun
*/
+ @Nonnull
public static MetricsService getMetricsService() {
+ validateInstance();
return instance.metricsService;
}
@@ -782,30 +842,99 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
*
* @return The {@link GitHubService} for Slimefun
*/
+ @Nonnull
public static GitHubService getGitHubService() {
+ validateInstance();
return instance.gitHubService;
}
+ @Nonnull
public static SlimefunRegistry getRegistry() {
+ validateInstance();
return instance.registry;
}
+ @Nonnull
public static NetworkManager getNetworkManager() {
+ validateInstance();
return instance.networkManager;
}
+ @Nonnull
public static GrapplingHookListener getGrapplingHookListener() {
+ validateInstance();
return instance.grapplingHookListener;
}
+ @Nonnull
public static BackpackListener getBackpackListener() {
+ validateInstance();
return instance.backpackListener;
}
+ @Nonnull
public static SlimefunBowListener getBowListener() {
+ validateInstance();
return instance.bowListener;
}
+ /**
+ * The {@link Command} that was added by Slimefun.
+ *
+ * @return Slimefun's command
+ */
+ @Nonnull
+ public static SlimefunCommand getCommand() {
+ validateInstance();
+ return instance.command;
+ }
+
+ /**
+ * This returns our instance of the {@link SlimefunProfiler}, a tool that is used
+ * to analyse performance and lag.
+ *
+ * @return The {@link SlimefunProfiler}
+ */
+ @Nonnull
+ public static SlimefunProfiler getProfiler() {
+ validateInstance();
+ return instance.profiler;
+ }
+
+ /**
+ * This returns the currently installed version of Minecraft.
+ *
+ * @return The current version of Minecraft
+ */
+ @Nonnull
+ public static MinecraftVersion getMinecraftVersion() {
+ validateInstance();
+ return instance.minecraftVersion;
+ }
+
+ /**
+ * This method returns whether this version of Slimefun was newly installed.
+ * It will return true if this {@link Server} uses Slimefun for the very first time.
+ *
+ * @return Whether this is a new installation of Slimefun
+ */
+ public static boolean isNewlyInstalled() {
+ validateInstance();
+ return instance.isNewlyInstalled;
+ }
+
+ @Nonnull
+ public static String getCSCoreLibVersion() {
+ validateInstance();
+ Plugin cscorelib = instance.getServer().getPluginManager().getPlugin("CS-CoreLib");
+
+ if (cscorelib == null) {
+ throw new IllegalStateException("CS-CoreLib is not installed.");
+ } else {
+ return cscorelib.getDescription().getVersion();
+ }
+ }
+
/**
* This method returns a {@link Set} of every {@link Plugin} that lists Slimefun
* as a required or optional dependency.
@@ -816,6 +945,8 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
*/
@Nonnull
public static Set