Skip to content

Commit

Permalink
Expand out datapack API
Browse files Browse the repository at this point in the history
  • Loading branch information
Machine-Maker authored and lynxplay committed Sep 22, 2024
1 parent 2f50b87 commit c1e88ce
Show file tree
Hide file tree
Showing 2 changed files with 240 additions and 41 deletions.
139 changes: 124 additions & 15 deletions patches/api/0270-Add-basic-Datapack-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,180 @@ From: Connor Linfoot <[email protected]>
Date: Sun, 16 May 2021 15:07:34 +0100
Subject: [PATCH] Add basic Datapack API

Co-authored-by: Jake Potrebic <[email protected]>

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..7b2ab0be10a21e0496ad1d485ff8cb2c0b92a2cb
index 0000000000000000000000000000000000000000..2a7a45bffb14ead0c3e7a4d477d9f2e2b9668fc8
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datapack/Datapack.java
@@ -0,0 +1,32 @@
@@ -0,0 +1,80 @@
+package io.papermc.paper.datapack;
+
+import java.util.Set;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.ComponentLike;
+import org.bukkit.FeatureFlag;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.jetbrains.annotations.Unmodifiable;
+
+public interface Datapack {
+/**
+ * It is not supported to hold references to instances of this class, just
+ * query them from {@link DatapackManager} when needed. There are no guarantees
+ * an instance will remain valid.
+ */
+public interface Datapack extends ComponentLike {
+
+ /**
+ * Gets the name/id of this datapack.
+ *
+ * @return the name of the pack
+ */
+ @NonNull
+ String getName();
+ @NonNull String getName();
+
+ /**
+ * Gets the description of this datapack.
+ *
+ * @return the description
+ */
+ @NonNull Component description();
+
+ /**
+ * 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.
+ *
+ * @return the compatibility of the pack
+ */
+ @NonNull
+ Compatibility getCompatibility();
+ @NonNull Compatibility getCompatibility();
+
+ /**
+ * Gets the set of required features for this datapack.
+ *
+ * @return the set of required features
+ */
+ @NonNull @Unmodifiable Set<FeatureFlag> getRequiredFeatures();
+
+ /**
+ * @return whether or not the pack is currently enabled
+ * Gets the enabled state of this pack.
+ *
+ * @return whether the pack is currently enabled
+ */
+ 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
+ */
+ void setEnabled(boolean enabled);
+
+ /**
+ * Gets the source for this datapack.
+ *
+ * @return the pack source
+ */
+ @NonNull DatapackSource getSource();
+
+ 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..58f78d5e91beacaf710f62461cf869f70d08b2a2
index 0000000000000000000000000000000000000000..bbb81a8058a67fd554c781dbb4908434ad339655
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datapack/DatapackManager.java
@@ -0,0 +1,21 @@
@@ -0,0 +1,43 @@
+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;
+
+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.
+ *
+ * @return all the packs known to the server
+ */
+ @NonNull
+ Collection<Datapack> getPacks();
+ @NonNull @Unmodifiable Collection<Datapack> getPacks();
+
+ /**
+ * Gets the enabled datapacks. May require calling {@link #refreshPacks()} before
+ * to get the latest pack information.
+ *
+ * @return all the packs which are currently enabled
+ */
+ @NonNull
+ Collection<Datapack> getEnabledPacks();
+ @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..65d380a011cad84753aa0aa45e6b4ebdac087044
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datapack/DatapackSource.java
@@ -0,0 +1,14 @@
+package io.papermc.paper.datapack;
+
+public sealed interface DatapackSource permits DatapackSourceImpl {
+
+ 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;
+ }
+}
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index b558fa73dbcf3747690933e6aadf7061a0de2630..be68351555bde59a4e55bf1bad261e9f6bc9f704 100644
Expand Down
Loading

0 comments on commit c1e88ce

Please sign in to comment.