PaperMC/patches/api/0459-Suspicious-Effect-Entry-API.patch
Jake Potrebic ac554ad46d
Updated Upstream (Bukkit/CraftBukkit) (#10691)
Updated Upstream (Bukkit/CraftBukkit)

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:
fa99e752 PR-1007: Add ItemMeta#getAsComponentString()
94a91782 Fix copy-pasted BlockType.Typed documentation
9b34ac8c Largely restore deprecated PotionData API
51a6449b PR-1008: Deprecate ITEMS_TOOLS, removed in 1.20.5
702d15fe Fix Javadoc reference
42f6cdf4 PR-919: Add internal ItemType and BlockType, delegate Material methods to them
237bb37b SPIGOT-1166, SPIGOT-7647: Expose Damager BlockState in EntityDamageByBlockEvent
035ea146 SPIGOT-6993: Allow #setVelocity to change the speed of a fireball and add a note to #setDirection about it
8c7880fb PR-1004: Improve field rename handling and centralize conversion between bukkit and string more
87c90e93 SPIGOT-7650: Add DamageSource for EntityDeathEvent and PlayerDeathEvent

CraftBukkit Changes:
4af0f22e8 SPIGOT-7664: Item meta should prevail over block states
c2ccc46ec SPIGOT-7666: Fix access to llama and horse special slot
124ac66d7 SPIGOT-7665: Fix ThrownPotion#getEffects() implementation only bringing custom effects
66f1f439a Restore null page behaviour of signed books even though not strictly allowed by API
6118e5398 Fix regression listening to minecraft:brand custom payloads
c1a26b366 Fix unnecessary and potential not thread-safe chat visibility check
12360a7ec Remove unused imports
147b098b4 PR-1397: Add ItemMeta#getAsComponentString()
428aefe0e Largely restore deprecated PotionData API
afe5b5ee9 PR-1275: Add internal ItemType and BlockType, delegate Material methods to them
8afeafa7d SPIGOT-1166, SPIGOT-7647: Expose Damager BlockState in EntityDamageByBlockEvent
4e7d749d4 SPIGOT-6993: Allow #setVelocity to change the speed of a fireball and add a note to #setDirection about it
441880757 Support both entity_data and bucket_entity_data on axolotl/fish buckets
0e22fdd1e Fix custom direct BlockState being not correctly set in DamageSource
f2182ed47 SPIGOT-7659: TropicalFishBucketMeta should use BUCKET_ENTITY_DATA
2a6207fe1 PR-1393: Improve field rename handling and centralize conversion between bukkit and string more
c024a5039 SPIGOT-7650: Add DamageSource for EntityDeathEvent and PlayerDeathEvent
741b84480 PR-1390: Improve internal handling of damage sources
0364df4e1 SPIGOT-7657: Error when loading angry entities
2024-05-11 23:48:37 +02:00

216 lines
9.8 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
Date: Sun, 3 Mar 2024 19:45:52 +0100
Subject: [PATCH] Suspicious Effect Entry API
Exposes a new suspicious effect entry type that properly represents
storable effects in the context of suspicious effects as they only
define the potion effect type and duration.
This differentiates them from the existing PotionEffect API found in
bukkit and hence clarifies that storable values in the parts of the API
in which it replaces PotionEffect.
Co-authored-by: Yannick Lamprecht <yannicklamprecht@live.de>
diff --git a/src/main/java/io/papermc/paper/potion/SuspiciousEffectEntry.java b/src/main/java/io/papermc/paper/potion/SuspiciousEffectEntry.java
new file mode 100644
index 0000000000000000000000000000000000000000..6a96e339ff1466df5743b5d42a31ce6a67e48f16
--- /dev/null
+++ b/src/main/java/io/papermc/paper/potion/SuspiciousEffectEntry.java
@@ -0,0 +1,38 @@
+package io.papermc.paper.potion;
+
+import org.bukkit.potion.PotionEffect;
+import org.bukkit.potion.PotionEffectType;
+import org.jetbrains.annotations.Contract;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Represents a {@link PotionEffectType} paired with a duration.
+ */
+public sealed interface SuspiciousEffectEntry permits SuspiciousEffectEntryImpl {
+
+ /**
+ * Gets the effect type.
+ *
+ * @return effect type
+ */
+ @NotNull PotionEffectType effect();
+
+ /**
+ * Gets the duration for this effect instance.
+ *
+ * @return duration (in ticks) or {@link PotionEffect#INFINITE_DURATION}
+ */
+ int duration();
+
+ /**
+ * Creates a new instance of SuspiciousEffectEntry.
+ *
+ * @param effectType effect type
+ * @param duration duration (in ticks) or {@link PotionEffect#INFINITE_DURATION}
+ * @return new instance of an entry
+ */
+ @Contract(value = "_, _ -> new", pure = true)
+ static @NotNull SuspiciousEffectEntry create(final @NotNull PotionEffectType effectType, final int duration) {
+ return new SuspiciousEffectEntryImpl(effectType, duration);
+ }
+}
diff --git a/src/main/java/io/papermc/paper/potion/SuspiciousEffectEntryImpl.java b/src/main/java/io/papermc/paper/potion/SuspiciousEffectEntryImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..e5002ccaef9ea7a9db94296ad0d66cdae050cdd1
--- /dev/null
+++ b/src/main/java/io/papermc/paper/potion/SuspiciousEffectEntryImpl.java
@@ -0,0 +1,7 @@
+package io.papermc.paper.potion;
+
+import org.bukkit.potion.PotionEffectType;
+import org.jetbrains.annotations.NotNull;
+
+record SuspiciousEffectEntryImpl(@NotNull PotionEffectType effect, int duration) implements SuspiciousEffectEntry {
+}
diff --git a/src/main/java/org/bukkit/entity/MushroomCow.java b/src/main/java/org/bukkit/entity/MushroomCow.java
index 86c0043ef4e1288b6fe2f68a9b6d01c3de2c3454..21503b85e1e309e3e8b90517e98572fa6a29fc6f 100644
--- a/src/main/java/org/bukkit/entity/MushroomCow.java
+++ b/src/main/java/org/bukkit/entity/MushroomCow.java
@@ -34,14 +34,30 @@ public interface MushroomCow extends Cow, io.papermc.paper.entity.Shearable { //
* Adds a custom potion effect to be applied to the next suspicious stew
* received from milking this {@link MushroomCow}.
*
+ * @deprecated use {@link #addEffectToNextStew(io.papermc.paper.potion.SuspiciousEffectEntry, boolean)} as PotionEffect suggests that all attributes are used. In fact, only the PotionEffectType and the duration are used.
* @param effect the potion effect to add
* @param overwrite true if any existing effect of the same type should be
* overwritten
* @return true if the effects to be applied to the suspicious stew changed
* as a result of this call
*/
+ @Deprecated(forRemoval = true) // Paper - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
boolean addEffectToNextStew(@NotNull PotionEffect effect, boolean overwrite);
+ // Paper start - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
+ /**
+ * Adds a suspicious effect entry to be applied to the next suspicious stew
+ * received from milking this {@link MushroomCow}.
+ *
+ * @param suspiciousEffectEntry the suspicious effect entry to add
+ * @param overwrite true if any existing effect of the same type should be
+ * overwritten
+ * @return true if the effects to be applied to the suspicious stew changed
+ * as a result of this call
+ */
+ boolean addEffectToNextStew(@NotNull io.papermc.paper.potion.SuspiciousEffectEntry suspiciousEffectEntry, boolean overwrite);
+ // Paper end - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
+
/**
* Removes a custom potion effect from being applied to the next suspicious
* stew received from milking this {@link MushroomCow}.
@@ -95,4 +111,75 @@ public interface MushroomCow extends Cow, io.papermc.paper.entity.Shearable { //
*/
BROWN;
}
+ // Paper start
+ /**
+ * Gets how long the effect applied to stew
+ * from this mushroom cow is.
+ *
+ * @return duration of the effect (in ticks)
+ * @deprecated Mushroom cows can now hold multiple effects, use {@link #getStewEffects()}
+ */
+ @Deprecated(forRemoval = true)
+ @org.jetbrains.annotations.Contract("-> fail")
+ default int getStewEffectDuration() {
+ throw new UnsupportedOperationException("Mushroom cows can now hold multiple effects. Use #getStewEffects");
+ }
+
+ /**
+ * Sets how long the effect applied to stew
+ * from this mushroom cow is.
+ *
+ * @param duration duration of the effect (in ticks)
+ * @deprecated Mushroom cows can now hold multiple effects, use {@link #setStewEffects(java.util.List)}
+ */
+ @Deprecated(forRemoval = true)
+ @org.jetbrains.annotations.Contract("_ -> fail")
+ default void setStewEffectDuration(int duration) {
+ throw new UnsupportedOperationException("Mushroom cows can now hold multiple effects. Use #setStewEffects");
+ }
+
+ /**
+ * Gets the type of effect applied to stew
+ * from this mushroom cow is.
+ *
+ * @return effect type, or null if an effect is currently not set
+ * @deprecated Mushroom cows can now hold multiple effects, use {@link #getStewEffects()}
+ * @throws UnsupportedOperationException
+ */
+ @Deprecated(forRemoval = true)
+ @org.jetbrains.annotations.Contract("-> fail")
+ default org.bukkit.potion.PotionEffectType getStewEffectType() {
+ throw new UnsupportedOperationException("Mushroom cows can now hold multiple effects. Use #getStewEffects");
+ }
+
+ /**
+ * Sets the type of effect applied to stew
+ * from this mushroom cow is.
+ *
+ * @param type new effect type
+ * or null if this cow does not give effects
+ * @deprecated Mushroom cows can now hold multiple effects, use {@link #setStewEffects(java.util.List)}
+ * @throws UnsupportedOperationException
+ */
+ @Deprecated(forRemoval = true)
+ @org.jetbrains.annotations.Contract("_ -> fail")
+ default void setStewEffect(@org.jetbrains.annotations.Nullable org.bukkit.potion.PotionEffectType type) {
+ throw new UnsupportedOperationException("Mushroom cows can now hold multiple effects. Use #setStewEffects");
+ }
+
+ /**
+ * Returns an immutable collection of the effects applied to stew
+ * items for this mushroom cow.
+ *
+ * @return immutable effect entry collection
+ */
+ java.util.@NotNull @org.jetbrains.annotations.Unmodifiable List<io.papermc.paper.potion.SuspiciousEffectEntry> getStewEffects();
+
+ /**
+ * Sets effects applied to stew items for this mushroom cow.
+ *
+ * @param effects effect entry list
+ */
+ void setStewEffects(java.util.@NotNull List<io.papermc.paper.potion.SuspiciousEffectEntry> effects);
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/inventory/meta/SuspiciousStewMeta.java b/src/main/java/org/bukkit/inventory/meta/SuspiciousStewMeta.java
index c2f4282c188e7d8041459cb3acaad674443ba147..c5bfc062fcca56495f44039d83356fc1fd7568d0 100644
--- a/src/main/java/org/bukkit/inventory/meta/SuspiciousStewMeta.java
+++ b/src/main/java/org/bukkit/inventory/meta/SuspiciousStewMeta.java
@@ -32,13 +32,28 @@ public interface SuspiciousStewMeta extends ItemMeta {
/**
* Adds a custom potion effect to this suspicious stew.
*
+ * @deprecated use {@link #addCustomEffect(io.papermc.paper.potion.SuspiciousEffectEntry, boolean)} as PotionEffect suggests that all attributes are used. In fact, only the PotionEffectType and the duration are used.
* @param effect the potion effect to add
* @param overwrite true if any existing effect of the same type should be
* overwritten
* @return true if the suspicious stew meta changed as a result of this call
*/
+ @Deprecated // Paper - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
boolean addCustomEffect(@NotNull PotionEffect effect, boolean overwrite);
+ // Paper start - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
+ /**
+ * Adds a custom potion effect to this suspicious stew.
+ *
+ * @param suspiciousEffectEntry the suspicious effect entry to add
+ * @param overwrite true if any existing effect of the same type should be
+ * overwritten
+ * @return true if the suspicious stew meta changed as a result of this call
+ * as a result of this call
+ */
+ boolean addCustomEffect(@NotNull io.papermc.paper.potion.SuspiciousEffectEntry suspiciousEffectEntry, boolean overwrite);
+ // Paper end - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
+
/**
* Removes a custom potion effect from this suspicious stew.
*