mirror of
https://github.com/PaperMC/Paper.git
synced 2025-02-17 10:41:41 +01:00
Largely restore deprecated PotionData API
By: md_5 <git@md-5.net>
This commit is contained in:
parent
d8b68e62df
commit
26f4f1cf7d
4 changed files with 153 additions and 0 deletions
paper-api/src/main/java/org/bukkit
|
@ -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 {
|
|||
*/
|
||||
<T> 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
|
||||
*
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
93
paper-api/src/main/java/org/bukkit/potion/PotionData.java
Normal file
93
paper-api/src/main/java/org/bukkit/potion/PotionData.java
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue