diff --git a/paper-api/src/main/java/org/bukkit/entity/AreaEffectCloud.java b/paper-api/src/main/java/org/bukkit/entity/AreaEffectCloud.java index 3c65da551a..1df234d653 100644 --- a/paper-api/src/main/java/org/bukkit/entity/AreaEffectCloud.java +++ b/paper-api/src/main/java/org/bukkit/entity/AreaEffectCloud.java @@ -3,6 +3,7 @@ package org.bukkit.entity; import java.util.List; import org.bukkit.Color; import org.bukkit.Particle; +import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionType; @@ -145,6 +146,25 @@ public interface AreaEffectCloud extends Entity { */ void setParticle(@NotNull Particle particle, @Nullable T data); + /** + * Sets the underlying potion data + * + * @param data PotionData to set the base potion state to + * @deprecated Upgraded / extended potions are now their own {@link PotionType} use {@link #setBasePotionType} instead. + */ + @Deprecated + void setBasePotionData(@Nullable PotionData data); + + /** + * Returns the potion data about the base potion + * + * @return a PotionData object + * @deprecated Upgraded / extended potions are now their own {@link PotionType} use {@link #getBasePotionType()} instead. + */ + @Nullable + @Deprecated + PotionData getBasePotionData(); + /** * Sets the underlying potion type * diff --git a/paper-api/src/main/java/org/bukkit/entity/Arrow.java b/paper-api/src/main/java/org/bukkit/entity/Arrow.java index bd1116adc8..a1615334ca 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Arrow.java +++ b/paper-api/src/main/java/org/bukkit/entity/Arrow.java @@ -2,6 +2,7 @@ package org.bukkit.entity; import java.util.List; import org.bukkit.Color; +import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionType; @@ -10,6 +11,25 @@ import org.jetbrains.annotations.Nullable; public interface Arrow extends AbstractArrow { + /** + * Sets the underlying potion data + * + * @param data PotionData to set the base potion state to + * @deprecated Upgraded / extended potions are now their own {@link PotionType} use {@link #setBasePotionType} instead. + */ + @Deprecated + void setBasePotionData(@Nullable PotionData data); + + /** + * Returns the potion data about the base potion + * + * @return a PotionData object + * @deprecated Upgraded / extended potions are now their own {@link PotionType} use {@link #getBasePotionType()} instead. + */ + @Nullable + @Deprecated + PotionData getBasePotionData(); + /** * Sets the underlying potion type * diff --git a/paper-api/src/main/java/org/bukkit/inventory/meta/PotionMeta.java b/paper-api/src/main/java/org/bukkit/inventory/meta/PotionMeta.java index d5b6d347b2..02e7c3adf1 100644 --- a/paper-api/src/main/java/org/bukkit/inventory/meta/PotionMeta.java +++ b/paper-api/src/main/java/org/bukkit/inventory/meta/PotionMeta.java @@ -2,6 +2,7 @@ package org.bukkit.inventory.meta; import java.util.List; import org.bukkit.Color; +import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionType; @@ -13,6 +14,25 @@ import org.jetbrains.annotations.Nullable; */ public interface PotionMeta extends ItemMeta { + /** + * Sets the underlying potion data + * + * @param data PotionData to set the base potion state to + * @deprecated Upgraded / extended potions are now their own {@link PotionType} use {@link #setBasePotionType} instead. + */ + @Deprecated + void setBasePotionData(@Nullable PotionData data); + + /** + * Returns the potion data about the base potion + * + * @return a PotionData object + * @deprecated Upgraded / extended potions are now their own {@link PotionType} use {@link #getBasePotionType()} instead. + */ + @Nullable + @Deprecated + PotionData getBasePotionData(); + /** * Sets the underlying potion type * diff --git a/paper-api/src/main/java/org/bukkit/potion/PotionData.java b/paper-api/src/main/java/org/bukkit/potion/PotionData.java new file mode 100644 index 0000000000..ee6d07fb3e --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/potion/PotionData.java @@ -0,0 +1,93 @@ +package org.bukkit.potion; + +import com.google.common.base.Preconditions; +import org.jetbrains.annotations.NotNull; + +/** + * @deprecated Upgraded / extended potions are now their own {@link PotionType} use them instead. + */ +@Deprecated(forRemoval = true) +public final class PotionData { + + private final PotionType type; + private final boolean extended; + private final boolean upgraded; + + /** + * Instantiates a final PotionData object to contain information about a + * Potion + * + * @param type the type of the Potion + * @param extended whether the potion is extended PotionType#isExtendable() + * must be true + * @param upgraded whether the potion is upgraded PotionType#isUpgradable() + * must be true + */ + public PotionData(@NotNull PotionType type, boolean extended, boolean upgraded) { + Preconditions.checkArgument(type != null, "Potion Type must not be null"); + Preconditions.checkArgument(!upgraded || type.isUpgradeable(), "Potion Type is not upgradable"); + Preconditions.checkArgument(!extended || type.isExtendable(), "Potion Type is not extendable"); + Preconditions.checkArgument(!upgraded || !extended, "Potion cannot be both extended and upgraded"); + Preconditions.checkArgument(!type.getKey().getKey().startsWith("strong_"), "Strong potion type cannot be used directly, got %s", type.getKey()); + Preconditions.checkArgument(!type.getKey().getKey().startsWith("long_"), "Extended potion type cannot be used directly, got %s", type.getKey()); + this.type = type; + this.extended = extended; + this.upgraded = upgraded; + } + + public PotionData(@NotNull PotionType type) { + this(type, false, false); + } + + /** + * Gets the type of the potion, Type matches up with each kind of craftable + * potion + * + * @return the potion type + */ + @NotNull + public PotionType getType() { + return type; + } + + /** + * Checks if the potion is in an upgraded state. This refers to whether or + * not the potion is Tier 2, such as Potion of Fire Resistance II. + * + * @return true if the potion is upgraded; + */ + public boolean isUpgraded() { + return upgraded; + } + + /** + * Checks if the potion is in an extended state. This refers to the extended + * duration potions + * + * @return true if the potion is extended + */ + public boolean isExtended() { + return extended; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 23 * hash + (this.type != null ? this.type.hashCode() : 0); + hash = 23 * hash + (this.extended ? 1 : 0); + hash = 23 * hash + (this.upgraded ? 1 : 0); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + PotionData other = (PotionData) obj; + return (this.upgraded == other.upgraded) && (this.extended == other.extended) && (this.type == other.type); + } +}