SPIGOT-1638 / SPIGOT-1673: Rework Potions API

By: t00thpick1 <t00thpick1dirko@gmail.com>
This commit is contained in:
Bukkit/Spigot
2016-03-02 20:45:27 -05:00
parent a7e0658387
commit 949890d29d
16 changed files with 407 additions and 312 deletions

View File

@@ -0,0 +1,64 @@
package org.bukkit.potion;
import org.apache.commons.lang.Validate;
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(PotionType type, boolean extended, boolean upgraded) {
Validate.notNull(type, "Potion Type must not be null");
Validate.isTrue(!upgraded || type.isUpgradeable(), "Potion Type is not upgradable");
Validate.isTrue(!extended || type.isExtendable(), "Potion Type is not extendable");
Validate.isTrue(!upgraded || !extended, "Potion cannot be both extended and upgraded");
this.type = type;
this.extended = extended;
this.upgraded = upgraded;
}
public PotionData(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
*/
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;
}
}