Add api to resolve components (#7648)

This commit is contained in:
Jake Potrebic 2022-11-22 20:53:50 -08:00 committed by GitHub
parent 55a16d8581
commit e6e37ba5d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 238 additions and 89 deletions

View file

@ -553,10 +553,10 @@ index 0000000000000000000000000000000000000000..eb179aae1e1d2ce842442e49fe275827
+}
diff --git a/src/main/java/io/papermc/paper/text/PaperComponents.java b/src/main/java/io/papermc/paper/text/PaperComponents.java
new file mode 100644
index 0000000000000000000000000000000000000000..bff9a6295db367c6b89d69fb55459a40828265ea
index 0000000000000000000000000000000000000000..6e94562d79206d88b74b53814f9423f12a2e6e06
--- /dev/null
+++ b/src/main/java/io/papermc/paper/text/PaperComponents.java
@@ -0,0 +1,112 @@
@@ -0,0 +1,177 @@
+package io.papermc.paper.text;
+
+import net.kyori.adventure.text.Component;
@ -567,7 +567,12 @@ index 0000000000000000000000000000000000000000..bff9a6295db367c6b89d69fb55459a40
+import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
+import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
+import org.bukkit.Bukkit;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Entity;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.io.IOException;
+
+/**
+ * Paper API-specific methods for working with {@link Component}s and related.
@ -578,6 +583,66 @@ index 0000000000000000000000000000000000000000..bff9a6295db367c6b89d69fb55459a40
+ }
+
+ /**
+ * Resolves a component with a specific command sender and subject.
+ * <p>
+ * Note that in Vanilla, elevated permissions are usually required to use
+ * '@' selectors in various component types, but this method should not
+ * check such permissions from the sender.
+ * <p>
+ * A {@link CommandSender} argument is required to resolve:
+ * <ul>
+ * <li>{@link net.kyori.adventure.text.NBTComponent}</li>
+ * <li>{@link net.kyori.adventure.text.ScoreComponent}</li>
+ * <li>{@link net.kyori.adventure.text.SelectorComponent}</li>
+ * </ul>
+ * A {@link Entity} argument is optional to help resolve:
+ * <ul>
+ * <li>{@link net.kyori.adventure.text.ScoreComponent}</li>
+ * </ul>
+ * {@link net.kyori.adventure.text.TranslatableComponent}s don't require any extra arguments.
+ *
+ * @param input the component to resolve
+ * @param context the command sender to resolve with
+ * @param scoreboardSubject the scoreboard subject to use (for use with {@link net.kyori.adventure.text.ScoreComponent}s)
+ * @return the resolved component
+ * @throws IOException if a syntax error tripped during resolving
+ */
+ public static @NotNull Component resolveWithContext(@NotNull Component input, @Nullable CommandSender context, @Nullable Entity scoreboardSubject) throws IOException {
+ return resolveWithContext(input, context, scoreboardSubject, true);
+ }
+
+ /**
+ * Resolves a component with a specific command sender and subject.
+ * <p>
+ * Note that in Vanilla, elevated permissions are required to use
+ * '@' selectors in various component types. If the boolean {@code bypassPermissions}
+ * argument is {@code false}, the {@link CommandSender} argument will be used to query
+ * those permissions.
+ * <p>
+ * A {@link CommandSender} argument is required to resolve:
+ * <ul>
+ * <li>{@link net.kyori.adventure.text.NBTComponent}</li>
+ * <li>{@link net.kyori.adventure.text.ScoreComponent}</li>
+ * <li>{@link net.kyori.adventure.text.SelectorComponent}</li>
+ * </ul>
+ * A {@link Entity} argument is optional to help resolve:
+ * <ul>
+ * <li>{@link net.kyori.adventure.text.ScoreComponent}</li>
+ * </ul>
+ * {@link net.kyori.adventure.text.TranslatableComponent}s don't require any extra arguments.
+ *
+ * @param input the component to resolve
+ * @param context the command sender to resolve with
+ * @param scoreboardSubject the scoreboard subject to use (for use with {@link net.kyori.adventure.text.ScoreComponent}s)
+ * @param bypassPermissions true to bypass permissions checks for resolving components
+ * @return the resolved component
+ * @throws IOException if a syntax error tripped during resolving
+ */
+ public static @NotNull Component resolveWithContext(@NotNull Component input, @Nullable CommandSender context, @Nullable Entity scoreboardSubject, boolean bypassPermissions) throws IOException {
+ return Bukkit.getUnsafe().resolveWithContext(input, context, scoreboardSubject, bypassPermissions);
+ }
+
+ /**
+ * Return a component flattener that can use game data to resolve extra information about components.
+ *
+ * @return a component flattener
@ -1303,10 +1368,10 @@ index ac5e263d737973af077e3406a84a84baca4370db..2d91924b7f5ef16a91d40cdc1bfc3d68
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
index 01e11f882abb6c631f810584aa23646042688435..fa28b5bb0efd9d400277cd8969f38e039e6ea8ac 100644
index 01e11f882abb6c631f810584aa23646042688435..4f339debf113d103ffe0b5fdb03dfc82eafd1bd5 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -22,6 +22,14 @@ import org.bukkit.plugin.PluginDescriptionFile;
@@ -22,6 +22,15 @@ import org.bukkit.plugin.PluginDescriptionFile;
*/
@Deprecated
public interface UnsafeValues {
@ -1317,6 +1382,7 @@ index 01e11f882abb6c631f810584aa23646042688435..fa28b5bb0efd9d400277cd8969f38e03
+ @Deprecated(forRemoval = true) net.kyori.adventure.text.serializer.gson.GsonComponentSerializer gsonComponentSerializer();
+ @Deprecated(forRemoval = true) net.kyori.adventure.text.serializer.gson.GsonComponentSerializer colorDownsamplingGsonComponentSerializer();
+ @Deprecated(forRemoval = true) net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer legacyComponentSerializer();
+ net.kyori.adventure.text.Component resolveWithContext(net.kyori.adventure.text.Component component, org.bukkit.command.CommandSender context, org.bukkit.entity.Entity scoreboardSubject, boolean bypassPermissions) throws java.io.IOException;
+ // Paper end
Material toLegacy(Material material);

View file

@ -2834,18 +2834,18 @@ index 4d5c3af2e1f0030aa7415fbe9d11fe3580854fd5..a2ae6b84fe20e43292f1442401a472dc
* Sends the component to the player
*
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
index fa28b5bb0efd9d400277cd8969f38e039e6ea8ac..c9ecd5b1908e05a1b39dadcded27241672adcddf 100644
index 4f339debf113d103ffe0b5fdb03dfc82eafd1bd5..d45cc92ca30e79173f30aae10724beeec6d22398 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -31,6 +31,7 @@ public interface UnsafeValues {
@Deprecated(forRemoval = true) net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer legacyComponentSerializer();
@@ -32,6 +32,7 @@ public interface UnsafeValues {
net.kyori.adventure.text.Component resolveWithContext(net.kyori.adventure.text.Component component, org.bukkit.command.CommandSender context, org.bukkit.entity.Entity scoreboardSubject, boolean bypassPermissions) throws java.io.IOException;
// Paper end
+ void reportTimings(); // Paper
Material toLegacy(Material material);
Material fromLegacy(Material material);
@@ -86,4 +87,12 @@ public interface UnsafeValues {
@@ -87,4 +88,12 @@ public interface UnsafeValues {
Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers(Material material, EquipmentSlot slot);
CreativeCategory getCreativeCategory(Material material);

View file

@ -59,7 +59,7 @@ diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukk
index c9ecd5b1908e05a1b39dadcded27241672adcddf..355c46f1c1f08072446f3cc92c0d22898933a7fc 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -94,5 +94,12 @@ public interface UnsafeValues {
@@ -95,5 +95,12 @@ public interface UnsafeValues {
* @return name
*/
String getTimingsServerName();

View file

@ -10,7 +10,7 @@ diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukk
index 355c46f1c1f08072446f3cc92c0d22898933a7fc..cbf7df30a7ec8445c8492e3b9f108747dbe1717b 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -101,5 +101,11 @@ public interface UnsafeValues {
@@ -102,5 +102,11 @@ public interface UnsafeValues {
default com.destroystokyo.paper.util.VersionFetcher getVersionFetcher() {
return new com.destroystokyo.paper.util.VersionFetcher.DummyVersionFetcher();
}

View file

@ -6,10 +6,10 @@ Subject: [PATCH] Add Raw Byte ItemStack Serialization
Serializes using NBT which is safer for server data migrations than bukkits format.
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
index cbf7df30a7ec8445c8492e3b9f108747dbe1717b..1b5f36b78d81b688ded88ab91e36d9df8c5d64ee 100644
index 5e2135cf4310eeea5da5ddb12d6e6bc32ecec93d..7c74163031cd8b49b9fe98241356697fd06c54c5 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -107,5 +107,9 @@ public interface UnsafeValues {
@@ -108,5 +108,9 @@ public interface UnsafeValues {
static boolean isLegacyPlugin(org.bukkit.plugin.Plugin plugin) {
return !Bukkit.getUnsafe().isSupportedApiVersion(plugin.getDescription().getAPIVersion());
}

View file

@ -181,10 +181,10 @@ index 6eb0b9ba2b7ad5faba31220483c424203802e1d3..a4c7ff53b7e12e9d3ca649782008a4ce
/**
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
index 1b5f36b78d81b688ded88ab91e36d9df8c5d64ee..e10edf17a87d18e9d9a22c6793d6ac78054d841b 100644
index 7c74163031cd8b49b9fe98241356697fd06c54c5..b69e8210d6d7a534804af9ed1b877dab9d5bc139 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -111,5 +111,34 @@ public interface UnsafeValues {
@@ -112,5 +112,34 @@ public interface UnsafeValues {
byte[] serializeItem(ItemStack item);
ItemStack deserializeItem(byte[] data);

View file

@ -6,10 +6,10 @@ Subject: [PATCH] Expose the Entity Counter to allow plugins to use valid and
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
index e10edf17a87d18e9d9a22c6793d6ac78054d841b..035dfcd9d483152a050e45409f15b015b135fb38 100644
index b69e8210d6d7a534804af9ed1b877dab9d5bc139..0994d65c7ad94bcbf661ca66839ddfcc5c8b8899 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -140,5 +140,12 @@ public interface UnsafeValues {
@@ -141,5 +141,12 @@ public interface UnsafeValues {
* @return the translation key
*/
String getTranslationKey(ItemStack itemStack);

View file

@ -91,10 +91,10 @@ index 0000000000000000000000000000000000000000..f29e76a6b66ddfec12ddf8db6dcb2df6
+ }
+}
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
index 035dfcd9d483152a050e45409f15b015b135fb38..abe79e4a2233341d0030742b823a0cfb5af97f41 100644
index 0994d65c7ad94bcbf661ca66839ddfcc5c8b8899..ab2b02ad179354c791dbb17963977a5c1478d553 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -147,5 +147,15 @@ public interface UnsafeValues {
@@ -148,5 +148,15 @@ public interface UnsafeValues {
* Use this when sending custom packets, so that there are no collisions on the client or server.
*/
public int nextEntityId();

View file

@ -78,10 +78,10 @@ index 50542df291d90a667af119fb9fcc3db2535ae6b5..723057dcc769bd29acdb82561ee0126e
* Create a new virtual {@link WorldBorder}.
* <p>
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
index abe79e4a2233341d0030742b823a0cfb5af97f41..204ab103eeff976d3da4f5694c31beafab6e1fdd 100644
index ab2b02ad179354c791dbb17963977a5c1478d553..0fe8efe3f5d16768dde497693c3f098dffbd1584 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -157,5 +157,10 @@ public interface UnsafeValues {
@@ -158,5 +158,10 @@ public interface UnsafeValues {
* @throws IllegalArgumentException if there isn't a registry for that type
*/
<T extends Keyed> @org.jetbrains.annotations.NotNull Registry<T> registryFor(Class<T> classOfT);

View file

@ -61,10 +61,10 @@ index 90367a01199ad90f0f10b977e214585a6e1ecf8a..f24f1d7a676f3b83ab05f655bd66b81b
/**
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
index 204ab103eeff976d3da4f5694c31beafab6e1fdd..9616630817a3a302636a0d2fe8076cb7244b7996 100644
index 0fe8efe3f5d16768dde497693c3f098dffbd1584..50397eecc867810ad6a89ce740814592082ad99e 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -162,5 +162,22 @@ public interface UnsafeValues {
@@ -163,5 +163,22 @@ public interface UnsafeValues {
* Just don't use it.
*/
@org.jetbrains.annotations.NotNull String getMainLevelName();

View file

@ -5,10 +5,10 @@ Subject: [PATCH] Expose protocol version
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
index 9616630817a3a302636a0d2fe8076cb7244b7996..eadba6454530724619872034f6e680b4603b8a69 100644
index 50397eecc867810ad6a89ce740814592082ad99e..3a515f13fe5ec6582ddeb38eb316e919062a0e16 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -179,5 +179,12 @@ public interface UnsafeValues {
@@ -180,5 +180,12 @@ public interface UnsafeValues {
* @return the itemstack rarity
*/
public io.papermc.paper.inventory.ItemRarity getItemStackRarity(ItemStack itemStack);

View file

@ -5,10 +5,10 @@ Subject: [PATCH] ItemStack repair check API
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
index eadba6454530724619872034f6e680b4603b8a69..248453b259781aa45516133a0ed824f4e6f6a369 100644
index 3a515f13fe5ec6582ddeb38eb316e919062a0e16..55e09755499cc49ecb9068fec2ff60c8258af587 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -180,6 +180,16 @@ public interface UnsafeValues {
@@ -181,6 +181,16 @@ public interface UnsafeValues {
*/
public io.papermc.paper.inventory.ItemRarity getItemStackRarity(ItemStack itemStack);

View file

@ -31,10 +31,10 @@ index f24f1d7a676f3b83ab05f655bd66b81b0069f88c..163c3ed1974e50376b7c2b2805df2833
/**
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
index 248453b259781aa45516133a0ed824f4e6f6a369..a3045b63c4e63f8eac902beb0f48367a5e3e5d20 100644
index 55e09755499cc49ecb9068fec2ff60c8258af587..d71e2ef9b9274bfcf8d9885d1583dcb310849c43 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -190,6 +190,18 @@ public interface UnsafeValues {
@@ -191,6 +191,18 @@ public interface UnsafeValues {
*/
public boolean isValidRepairItemStack(@org.jetbrains.annotations.NotNull ItemStack itemToBeRepaired, @org.jetbrains.annotations.NotNull ItemStack repairMaterial);

View file

@ -5,10 +5,10 @@ Subject: [PATCH] Get entity default attributes
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
index a3045b63c4e63f8eac902beb0f48367a5e3e5d20..0a9a50251093e1ea605a748eb8d899f34b26ef7b 100644
index d71e2ef9b9274bfcf8d9885d1583dcb310849c43..7bd7bdf756f780752a127a786077f69cd85e1551 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -208,5 +208,22 @@ public interface UnsafeValues {
@@ -209,5 +209,22 @@ public interface UnsafeValues {
* @return the server's protocol version
*/
int getProtocolVersion();

View file

@ -26,10 +26,10 @@ index 163c3ed1974e50376b7c2b2805df283322d41777..cb00e050cd5fff3a037a32ac34e02eee
/**
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
index 0a9a50251093e1ea605a748eb8d899f34b26ef7b..be8d5c172b0a300648f21e2163ccf0a9cd7915ee 100644
index 7bd7bdf756f780752a127a786077f69cd85e1551..057a4f1a374fcc240998c6ac3fe52d22389458c3 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -225,5 +225,14 @@ public interface UnsafeValues {
@@ -226,5 +226,14 @@ public interface UnsafeValues {
* @throws IllegalArgumentException if the entity does not exist of have default attributes (use {@link #hasDefaultEntityAttributes(NamespacedKey)} first)
*/
@org.jetbrains.annotations.NotNull org.bukkit.attribute.Attributable getDefaultEntityAttributes(@org.jetbrains.annotations.NotNull NamespacedKey entityKey);

View file

@ -5,10 +5,10 @@ Subject: [PATCH] Add Raw Byte Entity Serialization
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
index be8d5c172b0a300648f21e2163ccf0a9cd7915ee..4fcafddf3792b66c618f91e04d102f374de565a8 100644
index 057a4f1a374fcc240998c6ac3fe52d22389458c3..70103054057abfec37a99f30075123f9daa4e4ce 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -112,6 +112,14 @@ public interface UnsafeValues {
@@ -113,6 +113,14 @@ public interface UnsafeValues {
ItemStack deserializeItem(byte[] data);

View file

@ -6,10 +6,10 @@ Subject: [PATCH] Add NamespacedKey biome methods
Co-authored-by: Thonk <30448663+ExcessiveAmountsOfZombies@users.noreply.github.com>
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
index 4fcafddf3792b66c618f91e04d102f374de565a8..88acc4d2bd56748630840dc9f1c2cb253711eb38 100644
index 70103054057abfec37a99f30075123f9daa4e4ce..9b6600853df559eb941eb85b33c71f98b8df4675 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -242,5 +242,32 @@ public interface UnsafeValues {
@@ -243,5 +243,32 @@ public interface UnsafeValues {
* @throws IllegalArgumentException if {@link Material#isBlock()} is false
*/
boolean isCollidable(@org.jetbrains.annotations.NotNull Material material);