mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-28 13:36:16 +01:00
6483ecb8a2
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: a6aba46f PR-1078: Improve Javadocs of Player#loadData() and Player#saveData() 1e2e6a18 SPIGOT-7946: API for server pause when empty seconds 54a36938 SPIGOT-7944, PR-1077: Allow nullable fields in DamageTypeTags CraftBukkit Changes: 2702c5c8e SPIGOT-7946: API for server pause when empty seconds 485f910fc SPIGOT-7947: addPassenger doesn't work if the vehicle is a player ecf3dff0e SPIGOT-7949: Registering a new scoreboard objective with an empty display name throws a NPE 9b048cc84 SPIGOT-7948: `Bukkit#dispatchCommand` uses the wrong `CommandListenerWrapper` for Players 7b44d4640 SPIGOT-7931: Fix sync in Anvil View when result item is taken
319 lines
11 KiB
Diff
319 lines
11 KiB
Diff
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>
|
|
|
|
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..95039ec90f81993cb2e36f82b7d13e9e7a30220e
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/datapack/Datapack.java
|
|
@@ -0,0 +1,99 @@
|
|
+package io.papermc.paper.datapack;
|
|
+
|
|
+import java.util.Set;
|
|
+import net.kyori.adventure.text.Component;
|
|
+import org.bukkit.FeatureFlag;
|
|
+import org.jetbrains.annotations.Contract;
|
|
+import org.jetbrains.annotations.Unmodifiable;
|
|
+import org.jspecify.annotations.NullMarked;
|
|
+
|
|
+/**
|
|
+ * This is a snapshot of a datapack on the server. It
|
|
+ * won't be updated as datapacks are updated.
|
|
+ */
|
|
+@NullMarked
|
|
+public interface Datapack {
|
|
+
|
|
+ /**
|
|
+ * Gets the name/id of this datapack.
|
|
+ *
|
|
+ * @return the name of the pack
|
|
+ */
|
|
+ @Contract(pure = true)
|
|
+ String getName();
|
|
+
|
|
+ /**
|
|
+ * Gets the title component of this datapack.
|
|
+ *
|
|
+ * @return the title
|
|
+ */
|
|
+ Component getTitle();
|
|
+
|
|
+ /**
|
|
+ * Gets the description component of this datapack.
|
|
+ *
|
|
+ * @return the description
|
|
+ */
|
|
+ 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.
|
|
+ *
|
|
+ * @return the compatibility of the pack
|
|
+ */
|
|
+ Compatibility getCompatibility();
|
|
+
|
|
+ /**
|
|
+ * Gets the set of required features for this datapack.
|
|
+ *
|
|
+ * @return the set of required features
|
|
+ */
|
|
+ @Unmodifiable Set<FeatureFlag> getRequiredFeatures();
|
|
+
|
|
+ /**
|
|
+ * 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
|
|
+ * @apiNote This method may be deprecated in the future as setters on a "snapshot" type are undesirable.
|
|
+ */
|
|
+ void setEnabled(boolean enabled);
|
|
+
|
|
+ /**
|
|
+ * Gets the source for this datapack.
|
|
+ *
|
|
+ * @return the pack source
|
|
+ */
|
|
+ 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")
|
|
+ Component computeDisplayName();
|
|
+
|
|
+ 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..4f758a781612bb14c8f2ee41b2b6f40a074e6359
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/datapack/DatapackManager.java
|
|
@@ -0,0 +1,43 @@
|
|
+package io.papermc.paper.datapack;
|
|
+
|
|
+import java.util.Collection;
|
|
+import org.jetbrains.annotations.Unmodifiable;
|
|
+import org.jspecify.annotations.NullMarked;
|
|
+import org.jspecify.annotations.Nullable;
|
|
+
|
|
+@NullMarked
|
|
+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(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
|
|
+ */
|
|
+ @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
|
|
+ */
|
|
+ @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..b9b81cd974c2df501fef55bd8d9b78406c073038
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/datapack/DatapackSource.java
|
|
@@ -0,0 +1,20 @@
|
|
+package io.papermc.paper.datapack;
|
|
+
|
|
+import org.jspecify.annotations.NullMarked;
|
|
+
|
|
+/**
|
|
+ * Source of a datapack.
|
|
+ */
|
|
+@NullMarked
|
|
+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..0dfd101f01d16cc38f21831ca873633453dc6c9e
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/datapack/DatapackSourceImpl.java
|
|
@@ -0,0 +1,14 @@
|
|
+package io.papermc.paper.datapack;
|
|
+
|
|
+import org.jetbrains.annotations.ApiStatus;
|
|
+import org.jspecify.annotations.NullMarked;
|
|
+
|
|
+@ApiStatus.Internal
|
|
+@NullMarked
|
|
+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 885c83ba1d94460cb72b177c2cff1afdaa8696bc..f81250ff8fd0fe8caa780719624b8d9c731fe188 100644
|
|
--- a/src/main/java/org/bukkit/Bukkit.java
|
|
+++ b/src/main/java/org/bukkit/Bukkit.java
|
|
@@ -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();
|
|
}
|
|
@@ -2641,6 +2643,14 @@ public final class Bukkit {
|
|
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
|
|
index 39277b3113a3bd0736330773e3c5c1f747773b55..c18fb0c9a6635a67041ba7499e8b2f97ce9a76d4 100644
|
|
--- a/src/main/java/org/bukkit/Material.java
|
|
+++ b/src/main/java/org/bukkit/Material.java
|
|
@@ -5683,6 +5683,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);
|
|
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
|
|
index a85281b4099fe26b8e27b76d3dac6ee917c48c75..5b0aee3b7956d07a45eefa24e57dac674882f8ff 100644
|
|
--- a/src/main/java/org/bukkit/Server.java
|
|
+++ b/src/main/java/org/bukkit/Server.java
|
|
@@ -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();
|
|
|
|
/**
|
|
@@ -2302,5 +2304,11 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
|
|
*/
|
|
@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 a5e5c252405a7b940afbb6715abcda7ec9007dd3..1f241e74c256eb3e824a029798f623ad9d38efe2 100644
|
|
--- a/src/main/java/org/bukkit/entity/EntityType.java
|
|
+++ b/src/main/java/org/bukkit/entity/EntityType.java
|
|
@@ -496,6 +496,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
|
|
@@ -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
|
|
@@ -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 {
|
|
|
|
/**
|