13
0
geforkt von Mirrors/Paper

add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta (#10245)

The existing method with PotionEffect suggests that all attributes are used. In fact, only the PotionEffectType and the duration are used.



---------

Co-authored-by: Bjarne Koll <lynxplay101@gmail.com>
Dieser Commit ist enthalten in:
Yannick Lamprecht 2024-03-03 22:40:18 +01:00 committet von GitHub
Ursprung 60218cd207
Commit b21eb4d9a4
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
8 geänderte Dateien mit 502 neuen und 198 gelöschten Zeilen

Datei anzeigen

@ -63,62 +63,6 @@ index 0000000000000000000000000000000000000000..39ad7d283609d7e427a2ab35b6fad839
+ SchoolableFish getSchoolLeader();
+
+}
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..c8446678e39e777bd2c9992d5c577f4c7606ce15
--- /dev/null
+++ b/src/main/java/io/papermc/paper/potion/SuspiciousEffectEntry.java
@@ -0,0 +1,37 @@
+package io.papermc.paper.potion;
+
+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 type
+ */
+ @NotNull PotionEffectType effect();
+
+ /**
+ * Gets the duration for this effect instance.
+ *
+ * @return duration (in ticks)
+ */
+ int duration();
+
+ /**
+ * Creates a new instance of SuspiciousEffectEntry.
+ *
+ * @param effectType effect type
+ * @param duration duration (in ticks)
+ * @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/AbstractHorse.java b/src/main/java/org/bukkit/entity/AbstractHorse.java
index 0d88dce9978243a1f995c5fb448c5d71b01136eb..8b1048c94dffd058eb9fd9144f7f59fc9bd219ad 100644
--- a/src/main/java/org/bukkit/entity/AbstractHorse.java
@ -719,86 +663,6 @@ index 11b6d1aba7d1f6ae1f3c822193486f5a1478e105..709c8fc3dde786f45ff13d6ee6c405ff
+ * @see #isAggressive()
+ */
+ void setAggressive(boolean aggressive);
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/entity/MushroomCow.java b/src/main/java/org/bukkit/entity/MushroomCow.java
index cef1700834643fe28ed5737578d91ecefbe99e2f..794b7b4a870a0d289476074e3a3f46552604c954 100644
--- a/src/main/java/org/bukkit/entity/MushroomCow.java
+++ b/src/main/java/org/bukkit/entity/MushroomCow.java
@@ -95,4 +95,75 @@ public interface MushroomCow extends Cow {
*/
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/entity/Panda.java b/src/main/java/org/bukkit/entity/Panda.java

Datei anzeigen

@ -0,0 +1,215 @@
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..c8446678e39e777bd2c9992d5c577f4c7606ce15
--- /dev/null
+++ b/src/main/java/io/papermc/paper/potion/SuspiciousEffectEntry.java
@@ -0,0 +1,37 @@
+package io.papermc.paper.potion;
+
+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 type
+ */
+ @NotNull PotionEffectType effect();
+
+ /**
+ * Gets the duration for this effect instance.
+ *
+ * @return duration (in ticks)
+ */
+ int duration();
+
+ /**
+ * Creates a new instance of SuspiciousEffectEntry.
+ *
+ * @param effectType effect type
+ * @param duration duration (in ticks)
+ * @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.
*

Datei anzeigen

@ -3482,12 +3482,13 @@ index 0000000000000000000000000000000000000000..cea9c098ade00ee87b8efc8164ab72f5
+}
diff --git a/src/main/java/io/papermc/paper/util/MCUtil.java b/src/main/java/io/papermc/paper/util/MCUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..8ebef203d1e2584aed61bd61a93e231416eda749
index 0000000000000000000000000000000000000000..722dcae9ab65bcacb9fb89dfaa63715d87816476
--- /dev/null
+++ b/src/main/java/io/papermc/paper/util/MCUtil.java
@@ -0,0 +1,528 @@
@@ -0,0 +1,554 @@
+package io.papermc.paper.util;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import io.papermc.paper.math.BlockPosition;
+import io.papermc.paper.math.FinePosition;
@ -3509,6 +3510,7 @@ index 0000000000000000000000000000000000000000..8ebef203d1e2584aed61bd61a93e2314
+import org.bukkit.block.BlockFace;
+import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.util.Waitable;
+import org.jetbrains.annotations.NotNull;
+import org.spigotmc.AsyncCatcher;
+
+import javax.annotation.Nonnull;
@ -3524,6 +3526,7 @@ index 0000000000000000000000000000000000000000..8ebef203d1e2584aed61bd61a93e2314
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+import java.util.function.Supplier;
+
+public final class MCUtil {
@ -4013,6 +4016,29 @@ index 0000000000000000000000000000000000000000..8ebef203d1e2584aed61bd61a93e2314
+ public static int getTicketLevelFor(net.minecraft.world.level.chunk.ChunkStatus status) {
+ return net.minecraft.server.level.ChunkMap.MAX_VIEW_DISTANCE + net.minecraft.world.level.chunk.ChunkStatus.getDistance(status);
+ }
+
+ @NotNull
+ public static <T> List<T> copyListAndAdd(@NotNull final List<T> original,
+ @NotNull final T newElement) {
+ return ImmutableList.<T>builderWithExpectedSize(original.size() + 1)
+ .addAll(original)
+ .add(newElement)
+ .build();
+ }
+
+ @NotNull
+ public static <T> List<T> copyListAndRemoveIf(@NotNull final List<T> original,
+ @NotNull final Predicate<T> removalPredicate) {
+ final ImmutableList.Builder<T> builder = ImmutableList.builderWithExpectedSize(original.size());
+ for (int i = 0; i < original.size(); i++) {
+ final T value = original.get(i);
+ if (removalPredicate.test(value)) continue;
+
+ builder.add(value);
+ }
+
+ return builder.build();
+ }
+}
diff --git a/src/main/java/io/papermc/paper/util/StackWalkerUtil.java b/src/main/java/io/papermc/paper/util/StackWalkerUtil.java
new file mode 100644

Datei anzeigen

@ -546,7 +546,7 @@ index 0000000000000000000000000000000000000000..7ac27392a8647ef7d0dc78efe78703e9
+ @NotNull GameProfile buildGameProfile();
+}
diff --git a/src/main/java/io/papermc/paper/util/MCUtil.java b/src/main/java/io/papermc/paper/util/MCUtil.java
index 8ebef203d1e2584aed61bd61a93e231416eda749..36c0215a1ebc9372e5f355ecbe34fc1aaefd6903 100644
index 722dcae9ab65bcacb9fb89dfaa63715d87816476..c57e8b6458800fe9bb27050eecc42bd3e5cf5a15 100644
--- a/src/main/java/io/papermc/paper/util/MCUtil.java
+++ b/src/main/java/io/papermc/paper/util/MCUtil.java
@@ -1,5 +1,7 @@
@ -554,10 +554,10 @@ index 8ebef203d1e2584aed61bd61a93e231416eda749..36c0215a1ebc9372e5f355ecbe34fc1a
+import com.destroystokyo.paper.profile.CraftPlayerProfile;
+import com.destroystokyo.paper.profile.PlayerProfile;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import io.papermc.paper.math.BlockPosition;
import io.papermc.paper.math.FinePosition;
@@ -17,6 +19,7 @@ import net.minecraft.world.level.ClipContext;
@@ -18,6 +20,7 @@ import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import org.apache.commons.lang.exception.ExceptionUtils;
@ -565,7 +565,7 @@ index 8ebef203d1e2584aed61bd61a93e231416eda749..36c0215a1ebc9372e5f355ecbe34fc1a
import org.bukkit.Location;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.CraftWorld;
@@ -360,6 +363,10 @@ public final class MCUtil {
@@ -363,6 +366,10 @@ public final class MCUtil {
return run.get();
}

Datei anzeigen

@ -13,12 +13,12 @@ Shulkers) may need to be changed in order for it to re-save properly
No more crashing though.
diff --git a/src/main/java/io/papermc/paper/util/MCUtil.java b/src/main/java/io/papermc/paper/util/MCUtil.java
index 36c0215a1ebc9372e5f355ecbe34fc1aaefd6903..0d3ccf3ae219a3b24d17be03de8fd4906cb7235d 100644
index c57e8b6458800fe9bb27050eecc42bd3e5cf5a15..83c7b47e189a934345f6548df9b101cc8c501910 100644
--- a/src/main/java/io/papermc/paper/util/MCUtil.java
+++ b/src/main/java/io/papermc/paper/util/MCUtil.java
@@ -532,4 +532,19 @@ public final class MCUtil {
public static int getTicketLevelFor(net.minecraft.world.level.chunk.ChunkStatus status) {
return net.minecraft.server.level.ChunkMap.MAX_VIEW_DISTANCE + net.minecraft.world.level.chunk.ChunkStatus.getDistance(status);
@@ -558,4 +558,19 @@ public final class MCUtil {
return builder.build();
}
+
+ @Nullable

Datei anzeigen

@ -848,54 +848,6 @@ index fc83dde12957e575a4f1d4bee73c320bab95606f..ae430c36ed433e337dd92f197f1717fb
+ }
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java
index cc69f471c623c65251ccf7015499d8dbdb70ffad..a41a85ad89a177759c97d661a89b8b5dc419db1b 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java
@@ -89,6 +89,43 @@ public class CraftMushroomCow extends CraftCow implements MushroomCow {
this.getHandle().setVariant(net.minecraft.world.entity.animal.MushroomCow.MushroomType.values()[variant.ordinal()]);
}
+ // Paper start
+ @Override
+ public java.util.List<io.papermc.paper.potion.SuspiciousEffectEntry> getStewEffects() {
+ if (this.getHandle().stewEffects == null) {
+ return java.util.List.of();
+ }
+
+ java.util.List<io.papermc.paper.potion.SuspiciousEffectEntry> nmsPairs = new java.util.ArrayList<>(this.getHandle().stewEffects.size());
+ for (final net.minecraft.world.level.block.SuspiciousEffectHolder.EffectEntry effect : this.getHandle().stewEffects) {
+ nmsPairs.add(io.papermc.paper.potion.SuspiciousEffectEntry.create(
+ org.bukkit.craftbukkit.potion.CraftPotionEffectType.minecraftToBukkit(effect.effect()),
+ effect.duration()
+ ));
+ }
+
+ return java.util.Collections.unmodifiableList(nmsPairs);
+ }
+
+ @Override
+ public void setStewEffects(final java.util.List<io.papermc.paper.potion.SuspiciousEffectEntry> effects) {
+ if (effects.isEmpty()) {
+ this.getHandle().stewEffects = null;
+ return;
+ }
+
+ java.util.List<net.minecraft.world.level.block.SuspiciousEffectHolder.EffectEntry> nmsPairs = new java.util.ArrayList<>(effects.size());
+ for (final io.papermc.paper.potion.SuspiciousEffectEntry effect : effects) {
+ nmsPairs.add(new net.minecraft.world.level.block.SuspiciousEffectHolder.EffectEntry(
+ org.bukkit.craftbukkit.potion.CraftPotionEffectType.bukkitToMinecraft(effect.effect()),
+ effect.duration()
+ ));
+ }
+
+ this.getHandle().stewEffects = nmsPairs;
+ }
+ // Paper end
+
@Override
public String toString() {
return "CraftMushroomCow";
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPanda.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPanda.java
index 5467e4a74b70ff57b49d9e6bc686c493178f8511..01d104d91de9e1319d27e39d3f474318c7809486 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPanda.java

Datei anzeigen

@ -14610,10 +14610,10 @@ index cea9c098ade00ee87b8efc8164ab72f5279758f0..197224e31175252d8438a8df585bbb65
+ }
}
diff --git a/src/main/java/io/papermc/paper/util/MCUtil.java b/src/main/java/io/papermc/paper/util/MCUtil.java
index 0d3ccf3ae219a3b24d17be03de8fd4906cb7235d..850f75172e9efa72cabb8e5bd124b96a0b1a945f 100644
index 83c7b47e189a934345f6548df9b101cc8c501910..e028353e0261310afc42ca0454b723d9f1ffc131 100644
--- a/src/main/java/io/papermc/paper/util/MCUtil.java
+++ b/src/main/java/io/papermc/paper/util/MCUtil.java
@@ -6,17 +6,30 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder;
@@ -7,17 +7,30 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder;
import io.papermc.paper.math.BlockPosition;
import io.papermc.paper.math.FinePosition;
import io.papermc.paper.math.Position;
@ -14644,7 +14644,7 @@ index 0d3ccf3ae219a3b24d17be03de8fd4906cb7235d..850f75172e9efa72cabb8e5bd124b96a
import net.minecraft.world.phys.Vec3;
import org.apache.commons.lang.exception.ExceptionUtils;
import com.mojang.authlib.GameProfile;
@@ -28,8 +41,11 @@ import org.spigotmc.AsyncCatcher;
@@ -30,8 +43,11 @@ import org.spigotmc.AsyncCatcher;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -14656,7 +14656,7 @@ index 0d3ccf3ae219a3b24d17be03de8fd4906cb7235d..850f75172e9efa72cabb8e5bd124b96a
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.LinkedBlockingQueue;
@@ -529,6 +545,100 @@ public final class MCUtil {
@@ -532,6 +548,100 @@ public final class MCUtil {
}
}

Datei anzeigen

@ -0,0 +1,247 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
Date: Sun, 3 Mar 2024 19:43:40 +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/org/bukkit/craftbukkit/entity/CraftMushroomCow.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java
index b453a47cadbda2e22262bcdc5454c4c6cf5b2583..983e0cdbd1bd950807967a36cba49859fb956f31 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java
@@ -32,20 +32,32 @@ public class CraftMushroomCow extends CraftCow implements MushroomCow, io.paperm
return ImmutableList.of();
}
+ // Paper start - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
@Override
public boolean addEffectToNextStew(PotionEffect potionEffect, boolean overwrite) {
Preconditions.checkArgument(potionEffect != null, "PotionEffect cannot be null");
- MobEffectInstance minecraftPotionEffect = CraftPotionUtil.fromBukkit(potionEffect);
- if (!overwrite && this.hasEffectForNextStew(potionEffect.getType())) {
+ return addEffectToNextStew(io.papermc.paper.potion.SuspiciousEffectEntry.create(potionEffect.getType(), potionEffect.getDuration()), overwrite);
+ }
+
+ @Override
+ public boolean addEffectToNextStew(io.papermc.paper.potion.SuspiciousEffectEntry suspiciousEffectEntry, boolean overwrite) {
+ Preconditions.checkArgument(suspiciousEffectEntry != null, "SuspiciousEffectEntry cannot be null");
+ MobEffect minecraftPotionEffect = CraftPotionEffectType.bukkitToMinecraft(suspiciousEffectEntry.effect());
+ if (!overwrite && this.hasEffectForNextStew(suspiciousEffectEntry.effect())) {
return false;
}
+ SuspiciousEffectHolder.EffectEntry recordSuspiciousEffect = new SuspiciousEffectHolder.EffectEntry(minecraftPotionEffect, suspiciousEffectEntry.duration());
+ this.removeEffectFromNextStew(suspiciousEffectEntry.effect()); // Avoid duplicates of effects
+ // Paper start - fix modification of immutable stew effects list
if (this.getHandle().stewEffects == null) {
- this.getHandle().stewEffects = new ArrayList<>();
+ this.getHandle().stewEffects = List.of(recordSuspiciousEffect);
+ } else {
+ this.getHandle().stewEffects = io.papermc.paper.util.MCUtil.copyListAndAdd(this.getHandle().stewEffects, recordSuspiciousEffect);
}
- SuspiciousEffectHolder.EffectEntry recordSuspiciousEffect = new SuspiciousEffectHolder.EffectEntry(minecraftPotionEffect.getEffect(), minecraftPotionEffect.getDuration());
- this.removeEffectFromNextStew(potionEffect.getType()); // Avoid duplicates of effects
- return this.getHandle().stewEffects.add(recordSuspiciousEffect);
+ // Paper end - fix modification of immutable stew effects list
+ return true;
}
+ // Paper end - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
@Override
public boolean removeEffectFromNextStew(PotionEffectType potionEffectType) {
@@ -54,7 +66,21 @@ public class CraftMushroomCow extends CraftCow implements MushroomCow, io.paperm
return false;
}
MobEffect minecraftPotionEffectType = CraftPotionEffectType.bukkitToMinecraft(potionEffectType);
- return this.getHandle().stewEffects.removeIf(recordSuspiciousEffect -> recordSuspiciousEffect.effect().equals(minecraftPotionEffectType));
+ // Paper start - fix modification of immutable stew effects list
+ if (this.getHandle().stewEffects == null) return false;
+
+ final int oldSize = this.getHandle().stewEffects.size();
+ this.getHandle().stewEffects = io.papermc.paper.util.MCUtil.copyListAndRemoveIf(
+ this.getHandle().stewEffects, s -> java.util.Objects.equals(s.effect(), minecraftPotionEffectType)
+ );
+
+ final int newSize = this.getHandle().stewEffects.size();
+ if (newSize == 0) {
+ this.getHandle().stewEffects = null; // Null the empty list, mojang expect this
+ }
+
+ return oldSize != newSize; // Yield back if the size changed, implying an object was removed.
+ // Paper end - fix modification of immutable stew effects list
}
@Override
@@ -89,6 +115,43 @@ public class CraftMushroomCow extends CraftCow implements MushroomCow, io.paperm
this.getHandle().setVariant(net.minecraft.world.entity.animal.MushroomCow.MushroomType.values()[variant.ordinal()]);
}
+ // Paper start
+ @Override
+ public java.util.List<io.papermc.paper.potion.SuspiciousEffectEntry> getStewEffects() {
+ if (this.getHandle().stewEffects == null) {
+ return java.util.List.of();
+ }
+
+ java.util.List<io.papermc.paper.potion.SuspiciousEffectEntry> nmsPairs = new java.util.ArrayList<>(this.getHandle().stewEffects.size());
+ for (final net.minecraft.world.level.block.SuspiciousEffectHolder.EffectEntry effect : this.getHandle().stewEffects) {
+ nmsPairs.add(io.papermc.paper.potion.SuspiciousEffectEntry.create(
+ org.bukkit.craftbukkit.potion.CraftPotionEffectType.minecraftToBukkit(effect.effect()),
+ effect.duration()
+ ));
+ }
+
+ return java.util.Collections.unmodifiableList(nmsPairs);
+ }
+
+ @Override
+ public void setStewEffects(final java.util.List<io.papermc.paper.potion.SuspiciousEffectEntry> effects) {
+ if (effects.isEmpty()) {
+ this.getHandle().stewEffects = null;
+ return;
+ }
+
+ java.util.List<net.minecraft.world.level.block.SuspiciousEffectHolder.EffectEntry> nmsPairs = new java.util.ArrayList<>(effects.size());
+ for (final io.papermc.paper.potion.SuspiciousEffectEntry effect : effects) {
+ nmsPairs.add(new net.minecraft.world.level.block.SuspiciousEffectHolder.EffectEntry(
+ org.bukkit.craftbukkit.potion.CraftPotionEffectType.bukkitToMinecraft(effect.effect()),
+ effect.duration()
+ ));
+ }
+
+ this.getHandle().stewEffects = nmsPairs;
+ }
+ // Paper end
+
@Override
public String toString() {
return "CraftMushroomCow";
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSuspiciousStew.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSuspiciousStew.java
index 2c3b9f76067088efdc2250cdb5070df86e2dc0f5..243acae2c69dc46c02290ba103afc1549b618d85 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSuspiciousStew.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSuspiciousStew.java
@@ -24,7 +24,7 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
static final ItemMetaKey EFFECTS = new ItemMetaKey("effects", "effects");
static final ItemMetaKey ID = new ItemMetaKey("id", "id");
- private List<PotionEffect> customEffects;
+ private List<io.papermc.paper.potion.SuspiciousEffectEntry> customEffects; // Paper - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
CraftMetaSuspiciousStew(CraftMetaItem meta) {
super(meta);
@@ -57,7 +57,7 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
duration = net.minecraft.world.item.SuspiciousStewItem.DEFAULT_DURATION;
}
// Paper end start - default duration is 160
- this.customEffects.add(new PotionEffect(type, duration, 0));
+ this.customEffects.add(io.papermc.paper.potion.SuspiciousEffectEntry.create(type, duration)); // Paper - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
}
}
}
@@ -84,12 +84,14 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
ListTag effectList = new ListTag();
tag.put(CraftMetaSuspiciousStew.EFFECTS.NBT, effectList);
- for (PotionEffect effect : this.customEffects) {
+ // Paper start - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
+ for (io.papermc.paper.potion.SuspiciousEffectEntry effect : this.customEffects) {
CompoundTag effectData = new CompoundTag();
- effectData.putString(CraftMetaSuspiciousStew.ID.NBT, effect.getType().getKey().toString());
- if (effect.getDuration() != net.minecraft.world.item.SuspiciousStewItem.DEFAULT_DURATION) effectData.putInt(CraftMetaSuspiciousStew.DURATION.NBT, effect.getDuration()); // Paper - don't save duration if it's the default value
+ effectData.putString(CraftMetaSuspiciousStew.ID.NBT, effect.effect().getKey().toString());
+ if (effect.duration() != net.minecraft.world.item.SuspiciousStewItem.DEFAULT_DURATION) effectData.putInt(CraftMetaSuspiciousStew.DURATION.NBT, effect.duration()); // Paper - don't save duration if it's the default value
effectList.add(effectData);
}
+ // Paper end - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
}
}
@@ -124,7 +126,7 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
@Override
public List<PotionEffect> getCustomEffects() {
if (this.hasCustomEffects()) {
- return ImmutableList.copyOf(this.customEffects);
+ return this.customEffects.stream().map(suspiciousEffectEntry -> suspiciousEffectEntry.effect().createEffect(suspiciousEffectEntry.duration(), 0)).toList(); // Paper - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
}
return ImmutableList.of();
}
@@ -132,15 +134,21 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
@Override
public boolean addCustomEffect(PotionEffect effect, boolean overwrite) {
Preconditions.checkArgument(effect != null, "Potion effect cannot be null");
+ return addCustomEffect(io.papermc.paper.potion.SuspiciousEffectEntry.create(effect.getType(), effect.getDuration()), overwrite); // Paper - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
+ }
- int index = this.indexOfEffect(effect.getType());
+ // Paper start - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
+ @Override
+ public boolean addCustomEffect(final io.papermc.paper.potion.SuspiciousEffectEntry suspiciousEffectEntry, final boolean overwrite) {
+ Preconditions.checkArgument(suspiciousEffectEntry != null, "Suspicious effect entry cannot be null");
+ int index = this.indexOfEffect(suspiciousEffectEntry.effect());
if (index != -1) {
if (overwrite) {
- PotionEffect old = this.customEffects.get(index);
- if (old.getDuration() == effect.getDuration()) {
+ io.papermc.paper.potion.SuspiciousEffectEntry old = this.customEffects.get(index);
+ if (old.duration() == suspiciousEffectEntry.duration()) {
return false;
}
- this.customEffects.set(index, effect);
+ this.customEffects.set(index, suspiciousEffectEntry);
return true;
} else {
return false;
@@ -149,10 +157,11 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
if (this.customEffects == null) {
this.customEffects = new ArrayList<>();
}
- this.customEffects.add(effect);
+ this.customEffects.add(suspiciousEffectEntry);
return true;
}
}
+ // Paper end - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
@Override
public boolean removeCustomEffect(PotionEffectType type) {
@@ -163,10 +172,12 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
}
boolean changed = false;
- Iterator<PotionEffect> iterator = this.customEffects.iterator();
+ // Paper start - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
+ Iterator<io.papermc.paper.potion.SuspiciousEffectEntry> iterator = this.customEffects.iterator();
while (iterator.hasNext()) {
- PotionEffect effect = iterator.next();
- if (type.equals(effect.getType())) {
+ io.papermc.paper.potion.SuspiciousEffectEntry effect = iterator.next();
+ if (type.equals(effect.effect())) {
+ // Paper end - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
iterator.remove();
changed = true;
}
@@ -189,7 +200,7 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
}
for (int i = 0; i < this.customEffects.size(); i++) {
- if (this.customEffects.get(i).getType().equals(type)) {
+ if (this.customEffects.get(i).effect().equals(type)) { // Paper - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
return i;
}
}
@@ -234,7 +245,7 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
super.serialize(builder);
if (this.hasCustomEffects()) {
- builder.put(CraftMetaSuspiciousStew.EFFECTS.BUKKIT, ImmutableList.copyOf(this.customEffects));
+ builder.put(CraftMetaSuspiciousStew.EFFECTS.BUKKIT, ImmutableList.copyOf(com.google.common.collect.Lists.transform(this.customEffects, s -> new PotionEffect(s.effect(), s.duration(), 0)))); // Paper - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta - convert back to potion effect for bukkit legacy item serialisation to maintain backwards compatibility for the written format.
}
return builder;