SPIGOT-7195, SPIGOT-7197: Add DataPack API

By: Doc <nachito94@msn.com>
This commit is contained in:
Bukkit/Spigot 2023-05-30 19:05:41 +10:00
parent dc42ac1025
commit f45d2e6a77
10 changed files with 283 additions and 0 deletions

View file

@ -41,6 +41,7 @@ import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.loot.LootTable;
import org.bukkit.map.MapView;
import org.bukkit.packs.DataPackManager;
import org.bukkit.permissions.Permissible;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.ServicesManager;
@ -248,6 +249,26 @@ public final class Bukkit {
return server.getAllowNether();
}
@NotNull
public static List<String> getInitialEnabledPacks() {
return server.getInitialEnabledPacks();
}
@NotNull
public static List<String> getInitialDisabledPacks() {
return server.getInitialDisabledPacks();
}
/**
* Get the DataPack Manager.
*
* @return the manager
*/
@NotNull
public static DataPackManager getDataPackManager() {
return server.getDataPackManager();
}
/**
* Gets the server resource pack uri, or empty string if not specified.
*

View file

@ -0,0 +1,21 @@
package org.bukkit;
import org.jetbrains.annotations.ApiStatus;
/**
* This represents a Feature Flag for a World.
*/
@ApiStatus.Experimental
public interface FeatureFlag extends Keyed {
public static final FeatureFlag VANILLA = Bukkit.getUnsafe().getFeatureFlag(NamespacedKey.minecraft("vanilla"));
@MinecraftExperimental
public static final FeatureFlag BUNDLE = Bukkit.getUnsafe().getFeatureFlag(NamespacedKey.minecraft("bundle"));
/**
* <strong>AVAILABLE BETWEEN VERSIONS:</strong> 1.19 - 1.19.4
*/
@MinecraftExperimental
public static final FeatureFlag UPDATE_1_20 = Bukkit.getUnsafe().getFeatureFlag(NamespacedKey.minecraft("update_1_20"));
}

View file

@ -11061,4 +11061,14 @@ public enum Material implements Keyed, Translatable {
public String getItemTranslationKey() {
return Bukkit.getUnsafe().getItemTranslationKey(this);
}
/**
* Gets if the Material is enabled by the features in a world.
*
* @param world the world to check
* @return true if this material can be used in this World.
*/
public boolean isEnabledByFeature(@NotNull World world) {
return Bukkit.getDataPackManager().isEnabledByFeature(this, world);
}
}

View file

@ -41,6 +41,7 @@ import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.loot.LootTable;
import org.bukkit.map.MapView;
import org.bukkit.packs.DataPackManager;
import org.bukkit.permissions.Permissible;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.ServicesManager;
@ -205,6 +206,30 @@ public interface Server extends PluginMessageRecipient {
*/
public boolean getAllowNether();
/**
* Gets a list of packs to be enabled.
*
* @return a list of packs names
*/
@NotNull
public List<String> getInitialEnabledPacks();
/**
* Gets a list of packs that will not be enabled automatically.
*
* @return a list of packs names
*/
@NotNull
public List<String> getInitialDisabledPacks();
/**
* Get the DataPack Manager.
*
* @return the manager
*/
@NotNull
public DataPackManager getDataPackManager();
/**
* Gets the server resource pack uri, or empty string if not specified.
*

View file

@ -12,6 +12,8 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import org.bukkit.plugin.InvalidPluginException;
import org.bukkit.plugin.PluginDescriptionFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* This interface provides value conversions that may be specific to a
@ -87,4 +89,7 @@ public interface UnsafeValues {
String getTranslationKey(EntityType entityType);
String getTranslationKey(ItemStack itemStack);
@Nullable
FeatureFlag getFeatureFlag(@NotNull NamespacedKey key);
}

View file

@ -5,6 +5,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
@ -2670,6 +2671,14 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
@Nullable
public DragonBattle getEnderDragonBattle();
/**
* Get all {@link FeatureFlag} enabled in this world.
*
* @return all enabled {@link FeatureFlag}
*/
@NotNull
public Set<FeatureFlag> getFeatureFlags();
/**
* Represents various map environment types that a world may be
*/

View file

@ -444,4 +444,14 @@ public enum EntityType implements Keyed, Translatable {
public String getTranslationKey() {
return Bukkit.getUnsafe().getTranslationKey(this);
}
/**
* Gets if this EntityType is enabled by feature in a world.
*
* @param world the world to check
* @return true if this EntityType can be used to spawn an Entity for this World.
*/
public boolean isEnabledByFeature(@NotNull World world) {
return Bukkit.getDataPackManager().isEnabledByFeature(this, world);
}
}

View file

@ -0,0 +1,107 @@
package org.bukkit.packs;
import java.util.Set;
import org.bukkit.FeatureFlag;
import org.bukkit.Keyed;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
/**
* Represents a data pack.
*/
@ApiStatus.Experimental
public interface DataPack extends Keyed {
/**
* Gets the title of the data pack.
*
* @return the title
*/
@NotNull
public String getTitle();
/**
* Gets the description of the data pack.
*
* @return the description
*/
@NotNull
public String getDescription();
/**
* Gets the pack version.
* <br>
* This is related to the server version to work.
*
* @return the pack version
*/
public int getPackFormat();
/**
* Gets if the data pack is enabled on the server.
*
* @return True if is enabled
*/
public boolean isEnabled();
/**
* Gets if the data pack is required on the server.
*
* @return True if is required
*/
public boolean isRequired();
/**
* Gets the compatibility of this data pack with the server.
*
* @return an enum
*/
@NotNull
public Compatibility getCompatibility();
/**
* Gets a set of features requested by this data pack.
*
* @return a set of features
*/
@NotNull
public Set<FeatureFlag> getRequestedFeatures();
/**
* Gets the source of this data pack.
*
* @return the source
*/
@NotNull
public Source getSource();
/**
* Show the compatibility of the data pack with the server.
*/
public enum Compatibility {
/**
* It's newer than the server pack version.
*/
NEW,
/**
* It's older than the server pack version.
*/
OLD,
/**
* Its compatible with the server pack version.
*/
COMPATIBLE;
}
/**
* Represent the source of a data pack.
*/
public enum Source {
DEFAULT,
BUILT_IN,
FEATURE,
WORLD,
SERVER;
}
}

View file

@ -0,0 +1,70 @@
package org.bukkit.packs;
import java.util.Collection;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.entity.EntityType;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Manager of data packs.
*/
@ApiStatus.Experimental
public interface DataPackManager {
/**
* Return all the available {@link DataPack}s on the server.
*
* @return a Collection of {@link DataPack}
*/
@NotNull
public Collection<DataPack> getDataPacks();
/**
* Gets a {@link DataPack} by its key.
*
* @param dataPackKey the key of the {@link DataPack}
* @return the {@link DataPack} or null if it does not exist
*/
@Nullable
public DataPack getDataPack(@NotNull NamespacedKey dataPackKey);
/**
* Return all the enabled {@link DataPack} in the World.
*
* @param world the world to search
* @return a Collection of {@link DataPack}
*/
@NotNull
public Collection<DataPack> getEnabledDataPacks(@NotNull World world);
/**
* Return all the disabled {@link DataPack} in the World.
*
* @param world the world to search
* @return a Collection of {@link DataPack}
*/
@NotNull
public Collection<DataPack> getDisabledDataPacks(@NotNull World world);
/**
* Gets if the Material is enabled for use by the features in World.
*
* @param material Material to check (needs to be an {@link Material#isItem()} or {@link Material#isBlock()})
* @param world World to check
* @return {@code True} if the Item/Block related to the material is enabled
*/
public boolean isEnabledByFeature(@NotNull Material material, @NotNull World world);
/**
* Gets if the EntityType is enabled for use by the Features in World.
*
* @param entityType EntityType to check
* @param world World to check
* @return {@code True} if the type of entity is enabled
*/
public boolean isEnabledByFeature(@NotNull EntityType entityType, @NotNull World world);
}

View file

@ -0,0 +1,5 @@
/**
* Classes dedicated to handling data pack information.
*/
@org.jetbrains.annotations.ApiStatus.Experimental
package org.bukkit.packs;