Add FeatureFlag API
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package io.papermc.paper.world.flag;
|
||||
|
||||
import java.util.Set;
|
||||
import org.bukkit.FeatureFlag;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* Implemented by types in built-in registries that are controlled by {@link FeatureFlag FeatureFlags}.
|
||||
* Types in data-driven registries that are controlled by feature flags just will not exist in that registry.
|
||||
* @apiNote When a type that currently implements this interface transitions to being data-drive, this
|
||||
* interface will be removed from that type in the following major version.
|
||||
*/
|
||||
@NullMarked
|
||||
@ApiStatus.NonExtendable
|
||||
public interface FeatureDependant {
|
||||
|
||||
/**
|
||||
* Gets the set of required feature flags for this
|
||||
* to be enabled.
|
||||
*
|
||||
* @return the immutable set of feature flags
|
||||
*/
|
||||
default @Unmodifiable Set<FeatureFlag> requiredFeatures() {
|
||||
return FeatureFlagProvider.provider().requiredFeatures(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package io.papermc.paper.world.flag;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.Set;
|
||||
import org.bukkit.FeatureFlag;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
@ApiStatus.Internal
|
||||
interface FeatureFlagProvider {
|
||||
|
||||
Optional<FeatureFlagProvider> PROVIDER = ServiceLoader.load(FeatureFlagProvider.class).findFirst();
|
||||
|
||||
static FeatureFlagProvider provider() {
|
||||
return PROVIDER.orElseThrow();
|
||||
}
|
||||
|
||||
Set<FeatureFlag> requiredFeatures(FeatureDependant dependant);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package io.papermc.paper.world.flag;
|
||||
|
||||
import java.util.Set;
|
||||
import org.bukkit.FeatureFlag;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* Implemented by types that hold {@link FeatureFlag FeatureFlags} like
|
||||
* {@link org.bukkit.generator.WorldInfo} and {@link org.bukkit.RegionAccessor}.
|
||||
*/
|
||||
@NullMarked
|
||||
@ApiStatus.NonExtendable
|
||||
public interface FeatureFlagSetHolder {
|
||||
|
||||
/**
|
||||
* Checks if this is enabled based on the loaded feature flags.
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
default boolean isEnabled(final FeatureDependant featureDependant) {
|
||||
return this.getFeatureFlags().containsAll(featureDependant.requiredFeatures());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all {@link FeatureFlag FeatureFlags} enabled in this world.
|
||||
*
|
||||
* @return all enabled {@link FeatureFlag FeatureFlags}
|
||||
*/
|
||||
@Unmodifiable Set<FeatureFlag> getFeatureFlags();
|
||||
}
|
||||
Reference in New Issue
Block a user