Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import jakarta.inject.Provider;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jvnet.hk2.annotations.Service;

Expand Down Expand Up @@ -238,7 +239,11 @@ private void logEnableMessage() {
* Gets the MultiverseCoreApi
*
* @return The MultiverseCoreApi
*
* @deprecated Use {@link MultiverseCoreApi#get()} directly.
*/
@Deprecated(since = "5.1", forRemoval = true)
@ApiStatus.ScheduledForRemoval(inVersion = "6.0")
public MultiverseCoreApi getApi() {
return MultiverseCoreApi.get();
}
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/org/mvplugins/multiverse/core/MultiverseCoreApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.bukkit.Bukkit;
import org.bukkit.plugin.ServicePriority;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.mvplugins.multiverse.core.anchor.AnchorManager;
import org.mvplugins.multiverse.core.config.CoreConfig;
Expand All @@ -15,32 +16,78 @@
import org.mvplugins.multiverse.core.world.biomeprovider.BiomeProviderFactory;
import org.mvplugins.multiverse.core.world.generators.GeneratorProvider;

import java.util.ArrayList;

Check warning on line 19 in src/main/java/org/mvplugins/multiverse/core/MultiverseCoreApi.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Wrong order for 'java.util.ArrayList' import. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/MultiverseCoreApi.java:19:1: warning: Wrong order for 'java.util.ArrayList' import. (com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck)
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;

/**
* Provides access to the MultiverseCore API.
*/
public class MultiverseCoreApi {

private static MultiverseCoreApi instance;
private static final List<Consumer<MultiverseCoreApi>> whenLoadedCallbacks = new ArrayList<>();

Check warning on line 30 in src/main/java/org/mvplugins/multiverse/core/MultiverseCoreApi.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Constant name 'whenLoadedCallbacks' must match pattern '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/MultiverseCoreApi.java:30:60: warning: Constant name 'whenLoadedCallbacks' must match pattern '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'. (com.puppycrawl.tools.checkstyle.checks.naming.ConstantNameCheck)

static void init(@NotNull MultiverseCore multiverseCore) {
if (instance != null) {
throw new IllegalStateException("MultiverseCoreApi has already been initialized!");
}
instance = new MultiverseCoreApi(multiverseCore.getServiceLocator());
Bukkit.getServicesManager().register(MultiverseCoreApi.class, instance, multiverseCore, ServicePriority.Normal);

whenLoadedCallbacks.forEach(c -> c.accept(instance));
whenLoadedCallbacks.clear();
}

static void shutdown() {
Bukkit.getServicesManager().unregister(instance);
instance = null;
}

/**
* Hook your plugin into the MultiverseCoreApi here to ensure you only start using the API after it has been initialized.

Check warning on line 49 in src/main/java/org/mvplugins/multiverse/core/MultiverseCoreApi.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Line is longer than 120 characters (found 125). Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/MultiverseCoreApi.java:49:0: warning: Line is longer than 120 characters (found 125). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
* Use this if you know your plugin may load before Multiverse-Core is fully initialized.
* <br/>
* This handy method removes the need for you to check with plugin manager or listen to plugin enable event.
* <br/>
* Callback will be called immediately if the MultiverseCoreApi has already been initialized.
*
* @param consumer The callback to execute when the MultiverseCoreApi has been initialized.
*
* @since 5.1
*/
@ApiStatus.AvailableSince("5.1")
public static void whenLoaded(@NotNull Consumer<MultiverseCoreApi> consumer) {
if (instance != null) {
consumer.accept(instance);
} else {
whenLoadedCallbacks.add(consumer);
}
}

/**
* Checks if the MultiverseCoreApi has been initialized.
*
* @return True if the MultiverseCoreApi has been initialized, false otherwise
*
* @since 5.1
*/
@ApiStatus.AvailableSince("5.1")
public static boolean isLoaded() {
return instance != null;
}

/**
* Gets the MultiverseCoreApi. This will throw an exception if the Multiverse-Core has not been initialized.
* <br/>
* You can check if the MultiverseCoreApi has been initialized with {@link #isLoaded()} before using this method.
* <br/>
* Alternatively, you can use {@link #whenLoaded(Consumer)} to hook into the MultiverseCoreApi if your plugin may
* load before Multiverse-Core is fully initialized.
*
* @return The MultiverseCoreApi
* @throws IllegalStateException if the MultiverseCoreApi has not been initialized
*/
public static @NotNull MultiverseCoreApi get() {
if (instance == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,10 +660,11 @@ public boolean isShowingDonateMessage() {
}

/**
* Gets the underlying config file object
* Gets the underlying config file object. For internal use only.
*
* @return The config file
*/
@ApiStatus.Internal
public FileConfiguration getConfig() {
return configHandle.getConfig();
}
Expand Down