diff options
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/bukkit/Material.java | 8 | ||||
-rw-r--r-- | src/main/java/org/bukkit/World.java | 14 | ||||
-rw-r--r-- | src/main/java/org/bukkit/entity/AreaEffectCloud.java | 64 | ||||
-rw-r--r-- | src/main/java/org/bukkit/entity/EntityType.java | 8 | ||||
-rw-r--r-- | src/main/java/org/bukkit/entity/LingeringPotion.java | 6 | ||||
-rw-r--r-- | src/main/java/org/bukkit/entity/SplashPotion.java | 6 | ||||
-rw-r--r-- | src/main/java/org/bukkit/entity/ThrownPotion.java | 8 | ||||
-rw-r--r-- | src/main/java/org/bukkit/entity/TippedArrow.java | 77 | ||||
-rw-r--r-- | src/main/java/org/bukkit/inventory/meta/PotionMeta.java | 33 | ||||
-rw-r--r-- | src/main/java/org/bukkit/potion/Potion.java | 145 | ||||
-rw-r--r-- | src/main/java/org/bukkit/potion/PotionBrewer.java | 11 | ||||
-rw-r--r-- | src/main/java/org/bukkit/potion/PotionData.java | 64 | ||||
-rw-r--r-- | src/main/java/org/bukkit/potion/PotionEffect.java | 2 | ||||
-rw-r--r-- | src/main/java/org/bukkit/potion/PotionEffectType.java | 2 | ||||
-rw-r--r-- | src/main/java/org/bukkit/potion/PotionType.java | 101 |
15 files changed, 407 insertions, 142 deletions
diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java index d44a61b7..1886c2e1 100644 --- a/src/main/java/org/bukkit/Material.java +++ b/src/main/java/org/bukkit/Material.java @@ -402,9 +402,6 @@ public enum Material { GHAST_TEAR(370), GOLD_NUGGET(371), NETHER_STALK(372), - /** - * @see Potion - */ POTION(373, 1, MaterialData.class), GLASS_BOTTLE(374), SPIDER_EYE(375), @@ -473,10 +470,7 @@ public enum Material { SPLASH_POTION(438, 1), SPECTRAL_ARROW(439), TIPPED_ARROW(440), - /** - * @see Potion - */ - LINGERING_POTION(441, 1, MaterialData.class), + LINGERING_POTION(441, 1), SHIELD(442, 1, 336), ELYTRA(443, 1), BOAT_SPRUCE(444, 1), diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java index 58f44313..1e150d10 100644 --- a/src/main/java/org/bukkit/World.java +++ b/src/main/java/org/bukkit/World.java @@ -319,6 +319,20 @@ public interface World extends PluginMessageRecipient, Metadatable { public Arrow spawnArrow(Location location, Vector direction, float speed, float spread); /** + * Creates an arrow entity of the given class at the given {@link Location} + * + * @param <T> type of arrow to spawn + * @param location Location to spawn the arrow + * @param direction Direction to shoot the arrow in + * @param speed Speed of the arrow. A recommend speed is 0.6 + * @param spread Spread of the arrow. A recommend spread is 12 + * @param clazz the Entity class for the arrow + * {@link org.bukkit.entity.SpectralArrow},{@link org.bukkit.entity.Arrow},{@link org.bukkit.entity.TippedArrow} + * @return Arrow entity spawned as a result of this method + */ + public <T extends Arrow> T spawnArrow(Location location, Vector direction, float speed, float spread, Class<T> clazz); + + /** * Creates a tree at the given {@link Location} * * @param location Location to spawn the tree diff --git a/src/main/java/org/bukkit/entity/AreaEffectCloud.java b/src/main/java/org/bukkit/entity/AreaEffectCloud.java index 5b880f4b..c9d04db7 100644 --- a/src/main/java/org/bukkit/entity/AreaEffectCloud.java +++ b/src/main/java/org/bukkit/entity/AreaEffectCloud.java @@ -2,9 +2,10 @@ package org.bukkit.entity; import java.util.List; import org.bukkit.Color; -import org.bukkit.Effect; import org.bukkit.Particle; +import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; /** * Represents an area effect cloud which will imbue a potion effect onto @@ -71,6 +72,7 @@ public interface AreaEffectCloud extends Entity { * @param duration duration on use delta */ void setDurationOnUse(int duration); + /** * Gets the initial radius of the cloud. * @@ -130,33 +132,67 @@ public interface AreaEffectCloud extends Entity { void setParticle(Particle particle); /** - * Get a copy of all effects which can be applied by this cloud. No - * guarantees are made about the nature of the returned list. + * Sets the underlying potion data + * + * @param data PotionData to set the base potion state to + */ + void setBasePotionData(PotionData data); + + /** + * Returns the potion data about the base potion + * + * @return a PotionData object + */ + PotionData getBasePotionData(); + + /** + * Checks for the presence of custom potion effects. + * + * @return true if custom potion effects are applied + */ + boolean hasCustomEffects(); + + /** + * Gets an immutable list containing all custom potion effects applied to + * this cloud. + * <p> + * Plugins should check that hasCustomEffects() returns true before calling + * this method. * - * @return the list of all effects + * @return the immutable list of custom potion effects */ - List<PotionEffect> getEffects(); + List<PotionEffect> getCustomEffects(); /** - * Add an effect which can be applied by this cloud. + * Adds a custom potion effect to this cloud. * - * @param effect the effect to add + * @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 effect was added as a result of this call */ - void addEffect(PotionEffect effect); + boolean addCustomEffect(PotionEffect effect, boolean overwrite); /** - * Remove an effect from this cloud. + * Removes a custom potion effect from this cloud. * - * @param effect the effect to remove + * @param type the potion effect type to remove + * @return true if the an effect was removed as a result of this call */ - void removeEffect(PotionEffect effect); + boolean removeCustomEffect(PotionEffectType type); /** - * Set the effects of this cloud. Will remove all existing effects. + * Checks for a specific custom potion effect type on this cloud. * - * @param effects the new effects to set + * @param type the potion effect type to check for + * @return true if the potion has this effect + */ + boolean hasCustomEffect(PotionEffectType type); + + /** + * Removes all custom potion effects from this cloud. */ - void setEffects(List<PotionEffect> effects); + void clearCustomEffects(); /** * Gets the color of this cloud. Will be applied as a tint to its particles. diff --git a/src/main/java/org/bukkit/entity/EntityType.java b/src/main/java/org/bukkit/entity/EntityType.java index 25b70bf8..27c3c9ae 100644 --- a/src/main/java/org/bukkit/entity/EntityType.java +++ b/src/main/java/org/bukkit/entity/EntityType.java @@ -173,9 +173,13 @@ public enum EntityType { ENDER_CRYSTAL("EnderCrystal", EnderCrystal.class, 200), // These don't have an entity ID in nms.EntityTypes. /** - * A flying splash potion. + * A flying splash potion */ - SPLASH_POTION(null, ThrownPotion.class, -1, false), + SPLASH_POTION(null, SplashPotion.class, -1, false), + /** + * A flying lingering potion + */ + LINGERING_POTION(null, LingeringPotion.class, -1, false), AREA_EFFECT_CLOUD(null, AreaEffectCloud.class, -1), /** * A flying chicken egg. diff --git a/src/main/java/org/bukkit/entity/LingeringPotion.java b/src/main/java/org/bukkit/entity/LingeringPotion.java new file mode 100644 index 00000000..5aca7cb8 --- /dev/null +++ b/src/main/java/org/bukkit/entity/LingeringPotion.java @@ -0,0 +1,6 @@ +package org.bukkit.entity; + +/** + * Represents a thrown lingering potion bottle + */ +public interface LingeringPotion extends ThrownPotion { } diff --git a/src/main/java/org/bukkit/entity/SplashPotion.java b/src/main/java/org/bukkit/entity/SplashPotion.java new file mode 100644 index 00000000..2a210254 --- /dev/null +++ b/src/main/java/org/bukkit/entity/SplashPotion.java @@ -0,0 +1,6 @@ +package org.bukkit.entity; + +/** + * Represents a thrown splash potion bottle + */ +public interface SplashPotion extends ThrownPotion { } diff --git a/src/main/java/org/bukkit/entity/ThrownPotion.java b/src/main/java/org/bukkit/entity/ThrownPotion.java index 8b382db3..81dcecb8 100644 --- a/src/main/java/org/bukkit/entity/ThrownPotion.java +++ b/src/main/java/org/bukkit/entity/ThrownPotion.java @@ -20,8 +20,8 @@ public interface ThrownPotion extends Projectile { /** * Returns a copy of the ItemStack for this thrown potion. * <p> - * Altering this copy will not alter the thrown potion directly. If you - * want to alter the thrown potion, you must use the {@link + * Altering this copy will not alter the thrown potion directly. If you want + * to alter the thrown potion, you must use the {@link * #setItem(ItemStack) setItemStack} method. * * @return A copy of the ItemStack for this thrown potion. @@ -31,7 +31,9 @@ public interface ThrownPotion extends Projectile { /** * Set the ItemStack for this thrown potion. * <p> - * The ItemStack must be a potion, otherwise an exception is thrown. + * The ItemStack must be of type {@link org.bukkit.Material#SPLASH_POTION} + * or {@link org.bukkit.Material#LINGERING_POTION}, otherwise an exception + * is thrown. * * @param item New ItemStack */ diff --git a/src/main/java/org/bukkit/entity/TippedArrow.java b/src/main/java/org/bukkit/entity/TippedArrow.java index 3ef2c783..86666173 100644 --- a/src/main/java/org/bukkit/entity/TippedArrow.java +++ b/src/main/java/org/bukkit/entity/TippedArrow.java @@ -1,3 +1,78 @@ package org.bukkit.entity; -public interface TippedArrow extends Arrow {} +import java.util.List; + +import org.bukkit.potion.PotionData; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public interface TippedArrow extends Arrow { + + /** + * Sets the underlying potion data + * + * @param data PotionData to set the base potion state to + */ + void setBasePotionData(PotionData data); + + /** + * Returns the potion data about the base potion + * + * @return a PotionData object + */ + PotionData getBasePotionData(); + + /** + * Checks for the presence of custom potion effects. + * + * @return true if custom potion effects are applied + */ + boolean hasCustomEffects(); + + /** + * Gets an immutable list containing all custom potion effects applied to + * this arrow. + * <p> + * Plugins should check that hasCustomEffects() returns true before calling + * this method. + * + * @return the immutable list of custom potion effects + */ + List<PotionEffect> getCustomEffects(); + + /** + * Adds a custom potion effect to this arrow. + * + * @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 effect was added as a result of this call + */ + boolean addCustomEffect(PotionEffect effect, boolean overwrite); + + /** + * Removes a custom potion effect from this arrow. + * + * @param type the potion effect type to remove + * @return true if the an effect was removed as a result of this call + * @throws IllegalArgumentException if this operation would leave the Arrow + * in a state with no Custom Effects and PotionType.UNCRAFTABLE + */ + boolean removeCustomEffect(PotionEffectType type); + + /** + * Checks for a specific custom potion effect type on this arrow. + * + * @param type the potion effect type to check for + * @return true if the potion has this effect + */ + boolean hasCustomEffect(PotionEffectType type); + + /** + * Removes all custom potion effects from this arrow. + * + * @throws IllegalArgumentException if this operation would leave the Arrow + * in a state with no Custom Effects and PotionType.UNCRAFTABLE + */ + void clearCustomEffects(); +} diff --git a/src/main/java/org/bukkit/inventory/meta/PotionMeta.java b/src/main/java/org/bukkit/inventory/meta/PotionMeta.java index 8dca9830..1ebf066e 100644 --- a/src/main/java/org/bukkit/inventory/meta/PotionMeta.java +++ b/src/main/java/org/bukkit/inventory/meta/PotionMeta.java @@ -1,17 +1,32 @@ package org.bukkit.inventory.meta; -import org.bukkit.Material; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import org.bukkit.potion.PotionData; +import org.bukkit.potion.PotionType; import java.util.List; /** - * Represents a potion ({@link Material#POTION}) that can have custom effects. + * Represents a potion or item that can have custom effects. */ public interface PotionMeta extends ItemMeta { /** + * Sets the underlying potion data + * + * @param data PotionData to set the base potion state to + */ + void setBasePotionData(PotionData data); + + /** + * Returns the potion data about the base potion + * + * @return a PotionData object + */ + PotionData getBasePotionData(); + + /** * Checks for the presence of custom potion effects. * * @return true if custom potion effects are applied @@ -22,8 +37,8 @@ public interface PotionMeta extends ItemMeta { * Gets an immutable list containing all custom potion effects applied to * this potion. * <p> - * Plugins should check that hasCustomEffects() returns true before - * calling this method. + * Plugins should check that hasCustomEffects() returns true before calling + * this method. * * @return the immutable list of custom potion effects */ @@ -34,7 +49,7 @@ public interface PotionMeta extends ItemMeta { * * @param effect the potion effect to add * @param overwrite true if any existing effect of the same type should be - * overwritten + * overwritten * @return true if the potion meta changed as a result of this call */ boolean addCustomEffect(PotionEffect effect, boolean overwrite); @@ -49,7 +64,7 @@ public interface PotionMeta extends ItemMeta { /** * Checks for a specific custom potion effect type on this potion. - * + * * @param type the potion effect type to check for * @return true if the potion has this effect */ @@ -58,12 +73,13 @@ public interface PotionMeta extends ItemMeta { /** * Moves a potion effect to the top of the potion effect list. * <p> - * This causes the client to display the potion effect in the potion's - * name. + * This causes the client to display the potion effect in the potion's name. * * @param type the potion effect type to move * @return true if the potion meta changed as a result of this call + * @deprecated use {@link #setType(PotionType)} */ + @Deprecated boolean setMainEffect(PotionEffectType type); /** @@ -73,5 +89,6 @@ public interface PotionMeta extends ItemMeta { */ boolean clearCustomEffects(); + @Override PotionMeta clone(); } diff --git a/src/main/java/org/bukkit/potion/Potion.java b/src/main/java/org/bukkit/potion/Potion.java index 36f2f1ad..b702b7a6 100644 --- a/src/main/java/org/bukkit/potion/Potion.java +++ b/src/main/java/org/bukkit/potion/Potion.java @@ -6,17 +6,17 @@ import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.entity.LivingEntity; import org.bukkit.inventory.ItemStack; - -import com.google.common.collect.ImmutableList; +import org.bukkit.inventory.meta.PotionMeta; /** - * Represents a minecraft potion + * Potion Adapter for pre-1.9 data values + * see @PotionMeta for 1.9+ */ +@Deprecated public class Potion { private boolean extended = false; private boolean splash = false; private int level = 1; - private int name = -1; private PotionType type; /** @@ -29,20 +29,13 @@ public class Potion { * @see #Potion(int) */ public Potion(PotionType type) { + Validate.notNull(type, "Null PotionType"); this.type = type; - if (type != null) { - this.name = type.getDamageValue(); - } - if (type == null || type == PotionType.WATER) { - this.level = 0; - } } /** - * @param type the type of the potion - * @param tier the tier of the potion * @deprecated In favour of {@link #Potion(PotionType, int)} - */ + */ @Deprecated public Potion(PotionType type, Tier tier) { this(type, tier == Tier.TWO ? 2 : 1); @@ -50,9 +43,6 @@ public class Potion { } /** - * @param type the type of the potion - * @param tier the tier of the potion - * @param splash whether the potion is a splash potion * @deprecated In favour of {@link #Potion(PotionType, int, boolean)} */ @Deprecated @@ -61,10 +51,6 @@ public class Potion { } /** - * @param type the type of the potion - * @param tier the tier of the potion - * @param splash whether the potion is a splash potion - * @param extended whether the potion has an extended duration * @deprecated In favour of {@link #Potion(PotionType, int, boolean, * boolean)} */ @@ -83,7 +69,6 @@ public class Potion { public Potion(PotionType type, int level) { this(type); Validate.notNull(type, "Type cannot be null"); - Validate.isTrue(type != PotionType.WATER, "Water bottles don't have a level!"); Validate.isTrue(level > 0 && level < 3, "Level must be 1 or 2"); this.level = level; } @@ -120,17 +105,11 @@ public class Potion { } /** - * Create a potion with a specific name. - * - * @param name The name index (0-63) + * @Deprecated */ + @Deprecated public Potion(int name) { - this(PotionType.getByDamageValue(name & POTION_BIT)); - this.name = name & NAME_BIT; - if ((name & POTION_BIT) == 0) { - // If it's 0 it would've become PotionType.WATER, but it should actually be mundane potion - this.type = null; - } + this(PotionType.WATER); } /** @@ -161,8 +140,11 @@ public class Potion { */ public void apply(ItemStack to) { Validate.notNull(to, "itemstack cannot be null"); - Validate.isTrue(to.getType() == Material.POTION, "given itemstack is not a potion"); - to.setDurability(toDamageValue()); + Validate.isTrue(to.hasItemMeta(), "given itemstack is not a potion"); + Validate.isTrue(to.getItemMeta() instanceof PotionMeta, "given itemstack is not a potion"); + PotionMeta meta = (PotionMeta) to.getItemMeta(); + meta.setBasePotionData(new PotionData(type, level == 2, extended)); + to.setItemMeta(meta); } /** @@ -198,8 +180,7 @@ public class Potion { * @return The effects that this potion applies */ public Collection<PotionEffect> getEffects() { - if (type == null) return ImmutableList.<PotionEffect>of(); - return getBrewer().getEffectsFromDamage(toDamageValue()); + return getBrewer().getEffects(type, level == 2, extended); } /** @@ -215,6 +196,7 @@ public class Potion { * Returns the {@link Tier} of this potion. * * @return The tier of this potion + * @deprecated */ @Deprecated public Tier getTier() { @@ -307,8 +289,7 @@ public class Potion { */ public void setLevel(int level) { Validate.notNull(this.type, "No-effect potions don't have a level."); - int max = type.getMaxLevel(); - Validate.isTrue(level > 0 && level <= max, "Level must be " + (max == 1 ? "" : "between 1 and ") + max + " for this potion"); + Validate.isTrue(level > 0 && level <= 2, "Level must be between 1 and 2 for this potion"); this.level = level; } @@ -317,28 +298,11 @@ public class Potion { * item stacks. * * @return The damage value of this potion - * @deprecated Magic value + * @deprecated Non-functional */ @Deprecated public short toDamageValue() { - short damage; - if (type == PotionType.WATER) { - return 0; - } else if (type == null) { - // Without this, mundanePotion.toDamageValue() would return 0 - damage = (short) (name == 0 ? 8192 : name); - } else { - damage = (short) (level - 1); - damage <<= TIER_SHIFT; - damage |= (short) type.getDamageValue(); - } - if (splash) { - damage |= SPLASH_BIT; - } - if (extended) { - damage |= EXTENDED_BIT; - } - return damage; + return 0; } /** @@ -349,7 +313,17 @@ public class Potion { * @return The created ItemStack */ public ItemStack toItemStack(int amount) { - return new ItemStack(Material.POTION, amount, toDamageValue()); + Material material; + if (isSplash()) { + material = Material.SPLASH_POTION; + } else { + material = Material.POTION; + } + ItemStack itemStack = new ItemStack(material, amount); + PotionMeta meta = (PotionMeta) itemStack.getItemMeta(); + meta.setBasePotionData(new PotionData(type, level == 2, extended)); + itemStack.setItemMeta(meta); + return itemStack; } @Deprecated @@ -383,20 +357,63 @@ public class Potion { private static final int SPLASH_BIT = 0x4000; private static final int TIER_BIT = 0x20; private static final int TIER_SHIFT = 5; - private static final int NAME_BIT = 0x3F; /** * * @param damage the damage value * @return the produced potion - * @deprecated Magic value */ - @Deprecated public static Potion fromDamage(int damage) { - PotionType type = PotionType.getByDamageValue(damage & POTION_BIT); + PotionType type; + switch (damage & POTION_BIT) { + case 0: + type = PotionType.WATER; + break; + case 1: + type = PotionType.REGEN; + break; + case 2: + type = PotionType.SPEED; + break; + case 3: + type = PotionType.FIRE_RESISTANCE; + break; + case 4: + type = PotionType.POISON; + break; + case 5: + type = PotionType.INSTANT_HEAL; + break; + case 6: + type = PotionType.NIGHT_VISION; + break; + case 8: + type = PotionType.WEAKNESS; + break; + case 9: + type = PotionType.STRENGTH; + break; + case 10: + type = PotionType.SLOWNESS; + break; + case 11: + type = PotionType.JUMP; + break; + case 12: + type = PotionType.INSTANT_DAMAGE; + break; + case 13: + type = PotionType.WATER_BREATHING; + break; + case 14: + type = PotionType.INVISIBILITY; + break; + default: + type = PotionType.WATER; + } Potion potion; if (type == null || type == PotionType.WATER) { - potion = new Potion(damage & NAME_BIT); + potion = new Potion(PotionType.WATER); } else { int level = (damage & TIER_BIT) >> TIER_SHIFT; level++; @@ -405,7 +422,7 @@ public class Potion { if ((damage & SPLASH_BIT) > 0) { potion = potion.splash(); } - if ((type == null || !type.isInstant()) && (damage & EXTENDED_BIT) > 0) { + if ((damage & EXTENDED_BIT) > 0) { potion = potion.extend(); } return potion; @@ -442,10 +459,10 @@ public class Potion { /** * * @return the name id - * @deprecated Magic value + * @deprecated Non-functional */ @Deprecated public int getNameId() { - return name; + return 0; } } diff --git a/src/main/java/org/bukkit/potion/PotionBrewer.java b/src/main/java/org/bukkit/potion/PotionBrewer.java index 52755170..40f8d12b 100644 --- a/src/main/java/org/bukkit/potion/PotionBrewer.java +++ b/src/main/java/org/bukkit/potion/PotionBrewer.java @@ -24,8 +24,17 @@ public interface PotionBrewer { * * @param damage The data value of the potion * @return The list of effects - * @deprecated Magic value + * @deprecated Non-Functional */ @Deprecated public Collection<PotionEffect> getEffectsFromDamage(int damage); + + /** + * Returns a collection of {@link PotionEffect} that would be applied from + * a potion with the given type. + * + * @param type The type of the potion + * @return The list of effects + */ + public Collection<PotionEffect> getEffects(PotionType type, boolean upgraded, boolean extended); } diff --git a/src/main/java/org/bukkit/potion/PotionData.java b/src/main/java/org/bukkit/potion/PotionData.java new file mode 100644 index 00000000..7e9ce38a --- /dev/null +++ b/src/main/java/org/bukkit/potion/PotionData.java @@ -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; + } +} diff --git a/src/main/java/org/bukkit/potion/PotionEffect.java b/src/main/java/org/bukkit/potion/PotionEffect.java index 6d25e673..03221bf8 100644 --- a/src/main/java/org/bukkit/potion/PotionEffect.java +++ b/src/main/java/org/bukkit/potion/PotionEffect.java @@ -62,7 +62,7 @@ public class PotionEffect implements ConfigurationSerializable { * @param particles the particle status, see {@link PotionEffect#hasParticles()} */ public PotionEffect(PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles) { - this(type, duration, amplifier, ambient, true, null); + this(type, duration, amplifier, ambient, particles, null); } /** diff --git a/src/main/java/org/bukkit/potion/PotionEffectType.java b/src/main/java/org/bukkit/potion/PotionEffectType.java index aa17528f..c62b168a 100644 --- a/src/main/java/org/bukkit/potion/PotionEffectType.java +++ b/src/main/java/org/bukkit/potion/PotionEffectType.java @@ -162,7 +162,7 @@ public abstract class PotionEffectType { * @return a resulting potion effect */ public PotionEffect createEffect(int duration, int amplifier) { - return Potion.getBrewer().createEffect(this, duration, amplifier); + return new PotionEffect(this, isInstant() ? 1 : (int) (duration * getDurationModifier()), amplifier); } /** diff --git a/src/main/java/org/bukkit/potion/PotionType.java b/src/main/java/org/bukkit/potion/PotionType.java index 29e53ef2..95f238a3 100644 --- a/src/main/java/org/bukkit/potion/PotionType.java +++ b/src/main/java/org/bukkit/potion/PotionType.java @@ -1,73 +1,94 @@ package org.bukkit.potion; +/** + * This enum reflects and matches each potion state that can be obtained from + * the Creative mode inventory + */ public enum PotionType { - WATER(0, null, 0), - REGEN(1, PotionEffectType.REGENERATION, 2), - SPEED(2, PotionEffectType.SPEED, 2), - FIRE_RESISTANCE(3, PotionEffectType.FIRE_RESISTANCE, 1), - POISON(4, PotionEffectType.POISON, 2), - INSTANT_HEAL(5, PotionEffectType.HEAL, 2), - NIGHT_VISION(6, PotionEffectType.NIGHT_VISION, 1), - WEAKNESS(8, PotionEffectType.WEAKNESS, 1), - STRENGTH(9, PotionEffectType.INCREASE_DAMAGE, 2), - SLOWNESS(10, PotionEffectType.SLOW, 1), - JUMP(11, PotionEffectType.JUMP, 2), - INSTANT_DAMAGE(12, PotionEffectType.HARM, 2), - WATER_BREATHING(13, PotionEffectType.WATER_BREATHING, 1), - INVISIBILITY(14, PotionEffectType.INVISIBILITY, 1), - /** - * @deprecated not representable with a damage value! - */ - @Deprecated - LUCK(-1, PotionEffectType.LUCK, 1), + UNCRAFTABLE(null, false, false), + WATER(null, false, false), + MUNDANE(null, false, false), + THICK(null, false, false), + AWKWARD(null, false, false), + NIGHT_VISION(PotionEffectType.NIGHT_VISION, false, true), + INVISIBILITY(PotionEffectType.INVISIBILITY, false, true), + JUMP(PotionEffectType.JUMP, true, true), + FIRE_RESISTANCE(PotionEffectType.FIRE_RESISTANCE, false, true), + SPEED(PotionEffectType.SPEED, true, true), + SLOWNESS(PotionEffectType.SLOW, false, true), + WATER_BREATHING(PotionEffectType.WATER_BREATHING, false, true), + INSTANT_HEAL(PotionEffectType.HEAL, true, false), + INSTANT_DAMAGE(PotionEffectType.HARM, true, false), + POISON(PotionEffectType.POISON, true, true), + REGEN(PotionEffectType.REGENERATION, true, true), + STRENGTH(PotionEffectType.INCREASE_DAMAGE, true, true), + WEAKNESS(PotionEffectType.WEAKNESS, false, true), + LUCK(PotionEffectType.LUCK, false, false); ; - private final int damageValue, maxLevel; private final PotionEffectType effect; + private final boolean upgradeable; + private final boolean extendable; - PotionType(int damageValue, PotionEffectType effect, int maxLevel) { - this.damageValue = damageValue; + PotionType(PotionEffectType effect, boolean upgradeable, boolean extendable) { this.effect = effect; - this.maxLevel = maxLevel; + this.upgradeable = upgradeable; + this.extendable = extendable; } public PotionEffectType getEffectType() { return effect; } + public boolean isInstant() { + return effect != null && effect.isInstant(); + } + /** - * - * @return the damage value - * @deprecated Magic value + * Checks if the potion type has an upgraded state. + * This refers to whether or not the potion type can be Tier 2, + * such as Potion of Fire Resistance II. + * + * @return true if the potion type can be upgraded; + */ + public boolean isUpgradeable() { + return upgradeable; + } + + /** + * Checks if the potion type has an extended state. + * This refers to the extended duration potions + * + * @return true if the potion type can be extended + */ + public boolean isExtendable() { + return extendable; + } + + /** + * @deprecated Non-functional */ @Deprecated public int getDamageValue() { - return damageValue; + return 0; } public int getMaxLevel() { - return maxLevel; - } - - public boolean isInstant() { - return effect == null ? true : effect.isInstant(); + return upgradeable ? 2 : 1; } /** - * - * @param damage the damage value - * @return the matching potion type or null - * @deprecated Magic value + * @deprecated Non-functional */ @Deprecated public static PotionType getByDamageValue(int damage) { - for (PotionType type : PotionType.values()) { - if (type.damageValue == damage) - return type; - } return null; } + /** + * @deprecated Misleading + */ + @Deprecated public static PotionType getByEffect(PotionEffectType effectType) { if (effectType == null) return WATER; |