PaperMC/patches/api/0270-Add-basic-Datapack-API.patch

313 lines
11 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Connor Linfoot <connorlinfoot@me.com>
Date: Sun, 16 May 2021 15:07:34 +0100
Subject: [PATCH] Add basic Datapack API
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/io/papermc/paper/datapack/Datapack.java b/src/main/java/io/papermc/paper/datapack/Datapack.java
new file mode 100644
index 0000000000000000000000000000000000000000..233a31afa9673c9cb8d9eb52551425ff15f79661
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datapack/Datapack.java
@@ -0,0 +1,98 @@
2021-06-11 14:02:28 +02:00
+package io.papermc.paper.datapack;
+
+import java.util.Set;
+import net.kyori.adventure.text.Component;
+import org.bukkit.FeatureFlag;
2021-06-11 14:02:28 +02:00
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.jetbrains.annotations.Contract;
+import org.jetbrains.annotations.Unmodifiable;
2021-06-11 14:02:28 +02:00
+
+/**
+ * This is a snapshot of a datapack on the server. It
+ * won't be updated as datapacks are updated.
+ */
2021-06-11 14:02:28 +02:00
+public interface Datapack {
+
+ /**
+ * Gets the name/id of this datapack.
+ *
2021-06-11 14:02:28 +02:00
+ * @return the name of the pack
+ */
+ @Contract(pure = true)
+ @NonNull String getName();
2021-06-11 14:02:28 +02:00
+
+ /**
+ * Gets the title component of this datapack.
+ *
+ * @return the title
+ */
+ @NonNull Component getTitle();
+
+ /**
+ * Gets the description component of this datapack.
+ *
+ * @return the description
+ */
+ @NonNull Component getDescription();
+
+ /**
+ * Gets if this datapack is required to be enabled.
+ *
+ * @return true if the pack is required
+ */
+ boolean isRequired();
+
+ /**
+ * Gets the compatibility status of this pack.
+ *
2021-06-11 14:02:28 +02:00
+ * @return the compatibility of the pack
+ */
+ @NonNull Compatibility getCompatibility();
2021-06-11 14:02:28 +02:00
+
+ /**
+ * Gets the set of required features for this datapack.
+ *
+ * @return the set of required features
+ */
+ @NonNull @Unmodifiable Set<FeatureFlag> getRequiredFeatures();
+
+ /**
+ * Gets the enabled state of this pack.
+ *
+ * @return whether the pack is currently enabled
2021-06-11 14:02:28 +02:00
+ */
+ boolean isEnabled();
+
+ /**
+ * Changes the enabled state of this pack. Will
+ * cause a reload of resources ({@code /minecraft:reload}) if
+ * any change happens.
+ *
+ * @param enabled true to enable, false to disable
+ * @apiNote This method may be deprecated in the future as setters on a "snapshot" type are undesirable.
+ */
2021-06-11 14:02:28 +02:00
+ void setEnabled(boolean enabled);
+
+ /**
+ * Gets the source for this datapack.
+ *
+ * @return the pack source
+ */
+ @NonNull DatapackSource getSource();
+
+ /**
+ * Computes the component vanilla Minecraft uses
+ * to display this datapack. Includes the {@link #getSource()},
+ * {@link #getDescription()}, {@link #getName()}, and the enabled state.
+ *
+ * @return a new component
+ */
+ @Contract(pure = true, value = "-> new")
+ @NonNull Component computeDisplayName();
+
2021-06-11 14:02:28 +02:00
+ enum Compatibility {
+ TOO_OLD,
+ TOO_NEW,
+ COMPATIBLE,
+ }
+}
diff --git a/src/main/java/io/papermc/paper/datapack/DatapackManager.java b/src/main/java/io/papermc/paper/datapack/DatapackManager.java
new file mode 100644
index 0000000000000000000000000000000000000000..bbb81a8058a67fd554c781dbb4908434ad339655
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datapack/DatapackManager.java
@@ -0,0 +1,43 @@
2021-06-11 14:02:28 +02:00
+package io.papermc.paper.datapack;
+
+import org.checkerframework.checker.nullness.qual.NonNull;
+
+import java.util.Collection;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.jetbrains.annotations.Unmodifiable;
2021-06-11 14:02:28 +02:00
+
+public interface DatapackManager {
+
+ /**
+ * Triggers a refresh of the available and selected datapacks. This
+ * can find new datapacks, remove old ones, and update the metadata for
+ * existing datapacks. Some of these changes will only take effect
+ * after the next {@link org.bukkit.Server#reloadData()} or {@code /minecraft:reload}.
+ */
+ void refreshPacks();
+
+ /**
+ * Gets a datapack by name. May require calling {@link #refreshPacks()} before
+ * to get the latest pack information.
+ *
+ * @param name the name/id of the datapack
+ * @return the datapack, or null if not found
+ */
+ @Nullable Datapack getPack(@NonNull String name);
+
+ /**
+ * Gets the available datapacks. May require calling {@link #refreshPacks()} before
+ * to get the latest pack information.
+ *
2021-06-11 14:02:28 +02:00
+ * @return all the packs known to the server
+ */
+ @NonNull @Unmodifiable Collection<Datapack> getPacks();
2021-06-11 14:02:28 +02:00
+
+ /**
+ * Gets the enabled datapacks. May require calling {@link #refreshPacks()} before
+ * to get the latest pack information.
+ *
2021-06-11 14:02:28 +02:00
+ * @return all the packs which are currently enabled
+ */
+ @NonNull @Unmodifiable Collection<Datapack> getEnabledPacks();
+}
diff --git a/src/main/java/io/papermc/paper/datapack/DatapackSource.java b/src/main/java/io/papermc/paper/datapack/DatapackSource.java
new file mode 100644
index 0000000000000000000000000000000000000000..1679cbd78920005475343092857e13906ab73f82
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datapack/DatapackSource.java
@@ -0,0 +1,17 @@
+package io.papermc.paper.datapack;
+
+/**
+ * Source of a datapack.
+ */
+public sealed interface DatapackSource permits DatapackSourceImpl {
2021-06-11 14:02:28 +02:00
+
+ DatapackSource DEFAULT = create("default");
+ DatapackSource BUILT_IN = create("built_in");
+ DatapackSource FEATURE = create("feature");
+ DatapackSource WORLD = create("world");
+ DatapackSource SERVER = create("server");
+
+ private static DatapackSource create(final String name) {
+ return new DatapackSourceImpl(name);
+ }
+}
diff --git a/src/main/java/io/papermc/paper/datapack/DatapackSourceImpl.java b/src/main/java/io/papermc/paper/datapack/DatapackSourceImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..3eb4d1df8187fdeab74948d261d9c8e03e55605c
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datapack/DatapackSourceImpl.java
@@ -0,0 +1,12 @@
+package io.papermc.paper.datapack;
+
+import org.jetbrains.annotations.ApiStatus;
+
+@ApiStatus.Internal
+record DatapackSourceImpl(String name) implements DatapackSource {
+
+ @Override
+ public String toString() {
+ return this.name;
+ }
2021-06-11 14:02:28 +02:00
+}
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index b558fa73dbcf3747690933e6aadf7061a0de2630..be68351555bde59a4e55bf1bad261e9f6bc9f704 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
2024-06-13 17:45:43 +02:00
@@ -328,9 +328,11 @@ public final class Bukkit {
/**
* Get the DataPack Manager.
*
+ * @deprecated use {@link #getDatapackManager()}
* @return the manager
*/
@NotNull
+ @Deprecated(forRemoval = true, since = "1.20")
public static DataPackManager getDataPackManager() {
return server.getDataPackManager();
}
@@ -2617,6 +2619,14 @@ public final class Bukkit {
2021-06-11 14:02:28 +02:00
public static com.destroystokyo.paper.entity.ai.MobGoals getMobGoals() {
return server.getMobGoals();
}
+
+ /**
+ * @return the datapack manager
+ */
+ @NotNull
+ public static io.papermc.paper.datapack.DatapackManager getDatapackManager() {
+ return server.getDatapackManager();
+ }
// Paper end
@NotNull
diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#11405) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 1fc1020a PR-1049: Add MenuType API 8ae2e3be PR-1055: Expand riptiding API cac68bfb SPIGOT-7890: AttributeModifier#getUniqueId() doesn't match the UUID passed to its constructor 7004fcf2 SPIGOT-7886: Fix mistake in AttributeModifier UUID shim 1ac7f950 PR-1054: Add FireworkMeta#hasPower 4cfb565f SPIGOT-7873: Add powered state for skulls CraftBukkit Changes: bbb30e7a8 SPIGOT-7894: NPE when sending tile entity update ba21e9472 SPIGOT-7895: PlayerItemBreakEvent not firing 0fb24bbe0 SPIGOT-7875: Fix PlayerItemConsumeEvent cancellation causing client-side desync 815066449 SPIGOT-7891: Can't remove second ingredient of MerchantRecipe 45c206f2c PR-1458: Add MenuType API 19c8ef9ae SPIGOT-7867: Merchant instanceof AbstractVillager always returns false 4e006d28f PR-1468: Expand riptiding API bd8aded7d Ignore checks in CraftPlayerProfile for ResolvableProfile used in profile components 8679620b5 SPIGOT-7889: Fix tool component deserialisation without speed and/or correct-for-drops 8d5222691 SPIGOT-7882, PR-1467: Fix conversion of name in Profile Component to empty if it is missing 63f91669a SPIGOT-7887: Remove duplicate ProjectileHitEvent for fireballs 7070de8c8 SPIGOT-7878: Server#getLootTable does not return null on invalid loot table 060ee6cae SPIGOT-7876: Can't kick player or disconnect player in PlayerLoginEvent when checking for cookies 7ccb86cc0 PR-1465: Add FireworkMeta#hasPower 804ad6491 SPIGOT-7873: Add powered state for skulls f9610cdcb Improve minecart movement Spigot Changes: a759b629 Rebuild patches Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
2024-09-15 21:39:53 +02:00
index 7f6cb6471c5f324e2bcdf47d6c7628c2231d7727..d0aaf145cf34e0c02d5c7b842c203d0630b04b53 100644
--- a/src/main/java/org/bukkit/Material.java
+++ b/src/main/java/org/bukkit/Material.java
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#11405) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 1fc1020a PR-1049: Add MenuType API 8ae2e3be PR-1055: Expand riptiding API cac68bfb SPIGOT-7890: AttributeModifier#getUniqueId() doesn't match the UUID passed to its constructor 7004fcf2 SPIGOT-7886: Fix mistake in AttributeModifier UUID shim 1ac7f950 PR-1054: Add FireworkMeta#hasPower 4cfb565f SPIGOT-7873: Add powered state for skulls CraftBukkit Changes: bbb30e7a8 SPIGOT-7894: NPE when sending tile entity update ba21e9472 SPIGOT-7895: PlayerItemBreakEvent not firing 0fb24bbe0 SPIGOT-7875: Fix PlayerItemConsumeEvent cancellation causing client-side desync 815066449 SPIGOT-7891: Can't remove second ingredient of MerchantRecipe 45c206f2c PR-1458: Add MenuType API 19c8ef9ae SPIGOT-7867: Merchant instanceof AbstractVillager always returns false 4e006d28f PR-1468: Expand riptiding API bd8aded7d Ignore checks in CraftPlayerProfile for ResolvableProfile used in profile components 8679620b5 SPIGOT-7889: Fix tool component deserialisation without speed and/or correct-for-drops 8d5222691 SPIGOT-7882, PR-1467: Fix conversion of name in Profile Component to empty if it is missing 63f91669a SPIGOT-7887: Remove duplicate ProjectileHitEvent for fireballs 7070de8c8 SPIGOT-7878: Server#getLootTable does not return null on invalid loot table 060ee6cae SPIGOT-7876: Can't kick player or disconnect player in PlayerLoginEvent when checking for cookies 7ccb86cc0 PR-1465: Add FireworkMeta#hasPower 804ad6491 SPIGOT-7873: Add powered state for skulls f9610cdcb Improve minecart movement Spigot Changes: a759b629 Rebuild patches Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
2024-09-15 21:39:53 +02:00
@@ -5499,6 +5499,7 @@ public enum Material implements Keyed, Translatable, net.kyori.adventure.transla
* @param world the world to check
* @return true if this material can be used in this World.
*/
+ @Deprecated(forRemoval = true, since = "1.20") // Paper
public boolean isEnabledByFeature(@NotNull World world) {
if (isItem()) {
return Bukkit.getDataPackManager().isEnabledByFeature(asItemType(), world);
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index 42930006b6425b5d82233e4ffe7025ce5397b277..45693e6c02eac37eb609cd3c59253a949a6ca4c0 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
2024-06-13 17:45:43 +02:00
@@ -267,9 +267,11 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
/**
* Get the DataPack Manager.
*
+ * @deprecated use {@link #getDatapackManager()}
* @return the manager
*/
@NotNull
+ @Deprecated(forRemoval = true, since = "1.20") // Paper
public DataPackManager getDataPackManager();
/**
@@ -2284,5 +2286,11 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
2021-06-11 14:02:28 +02:00
*/
@NotNull
com.destroystokyo.paper.entity.ai.MobGoals getMobGoals();
+
+ /**
+ * @return the datapack manager
+ */
+ @NotNull
+ io.papermc.paper.datapack.DatapackManager getDatapackManager();
// Paper end
}
diff --git a/src/main/java/org/bukkit/entity/EntityType.java b/src/main/java/org/bukkit/entity/EntityType.java
index 976f701ed9b9873945a5628173c580e2e6873864..eea0351559a2835280713f5d5d1d430c7cf857a0 100644
--- a/src/main/java/org/bukkit/entity/EntityType.java
+++ b/src/main/java/org/bukkit/entity/EntityType.java
@@ -449,6 +449,7 @@ public enum EntityType implements Keyed, Translatable, net.kyori.adventure.trans
* @param world the world to check
* @return true if this EntityType can be used to spawn an Entity for this World.
*/
+ @Deprecated(forRemoval = true, since = "1.20") // Paper
public boolean isEnabledByFeature(@NotNull World world) {
return Bukkit.getDataPackManager().isEnabledByFeature(this, world);
}
diff --git a/src/main/java/org/bukkit/packs/DataPack.java b/src/main/java/org/bukkit/packs/DataPack.java
index ea03c51d51e015e69d3aaa795547033ceabff9e0..f51d59e6369c76e333fd9e58e711c2b6f245882d 100644
--- a/src/main/java/org/bukkit/packs/DataPack.java
+++ b/src/main/java/org/bukkit/packs/DataPack.java
2024-06-13 17:45:43 +02:00
@@ -9,7 +9,9 @@ import org.jetbrains.annotations.NotNull;
* Represents a data pack.
*
* @see <a href="https://minecraft.wiki/w/Data_pack">Minecraft wiki</a>
+ * @deprecated use {@link io.papermc.paper.datapack.Datapack}
*/
+@Deprecated(forRemoval = true, since = "1.20") // Paper
public interface DataPack extends Keyed {
/**
diff --git a/src/main/java/org/bukkit/packs/DataPackManager.java b/src/main/java/org/bukkit/packs/DataPackManager.java
index aee6e828c6fac9b010356af1239a58b4579c1773..1b850e76a885f0da653d4b48db72e5f85ae72805 100644
--- a/src/main/java/org/bukkit/packs/DataPackManager.java
+++ b/src/main/java/org/bukkit/packs/DataPackManager.java
2024-06-13 17:45:43 +02:00
@@ -13,7 +13,9 @@ import org.jetbrains.annotations.Nullable;
/**
* Manager of data packs.
+ * @deprecated use {@link io.papermc.paper.datapack.DatapackManager}
*/
+@Deprecated(forRemoval = true, since = "1.20") // Paper
public interface DataPackManager {
/**