Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.potion.Potion Class Reference

Classes

enum  Tier
 

Public Member Functions

 Potion (PotionType type)
 
 Potion (PotionType type, Tier tier)
 
 Potion (PotionType type, Tier tier, boolean splash)
 
 Potion (PotionType type, Tier tier, boolean splash, boolean extended)
 
 Potion (PotionType type, int level)
 
 Potion (PotionType type, int level, boolean splash)
 
 Potion (PotionType type, int level, boolean splash, boolean extended)
 
 Potion (int name)
 
Potion splash ()
 
Potion extend ()
 
void apply (ItemStack to)
 
void apply (LivingEntity to)
 
boolean equals (Object obj)
 
Collection< PotionEffectgetEffects ()
 
int getLevel ()
 
Tier getTier ()
 
PotionType getType ()
 
boolean hasExtendedDuration ()
 
int hashCode ()
 
boolean isSplash ()
 
void setHasExtendedDuration (boolean isExtended)
 
void setSplash (boolean isSplash)
 
void setTier (Tier tier)
 
void setType (PotionType type)
 
void setLevel (int level)
 
short toDamageValue ()
 
ItemStack toItemStack (int amount)
 
int getNameId ()
 

Static Public Member Functions

static Potion fromDamage (int damage)
 
static Potion fromItemStack (ItemStack item)
 
static PotionBrewer getBrewer ()
 
static void setPotionBrewer (PotionBrewer other)
 

Detailed Description

Represents a minecraft potion

Definition at line 15 of file Potion.java.

Constructor & Destructor Documentation

org.bukkit.potion.Potion.Potion ( PotionType  type)

Construct a new potion of the given type. Unless the type is PotionType#WATER, it will be level one, without extended duration. Don't use this constructor to create a no-effect potion other than water bottle.

Parameters
typeThe potion type
See also
Potion(int)

Definition at line 31 of file Potion.java.

References org.bukkit.potion.PotionType.getDamageValue().

Referenced by org.bukkit.potion.Potion.fromDamage().

31  {
32  this.type = type;
33  if (type != null) {
34  this.name = type.getDamageValue();
35  }
36  if (type == null || type == PotionType.WATER) {
37  this.level = 0;
38  }
39  }
org.bukkit.potion.Potion.Potion ( PotionType  type,
Tier  tier 
)
Deprecated:
In favour of Potion(PotionType, int)

Definition at line 46 of file Potion.java.

46  {
47  this(type, tier == Tier.TWO ? 2 : 1);
48  Validate.notNull(type, "Type cannot be null");
49  }
org.bukkit.potion.Potion.Potion ( PotionType  type,
Tier  tier,
boolean  splash 
)
Deprecated:
In favour of Potion(PotionType, int, boolean)

Definition at line 56 of file Potion.java.

References org.bukkit.potion.Potion.splash().

56  {
57  this(type, tier == Tier.TWO ? 2 : 1, splash);
58  }
org.bukkit.potion.Potion.Potion ( PotionType  type,
Tier  tier,
boolean  splash,
boolean  extended 
)
Deprecated:
In favour of int, boolean, boolean)

Definition at line 66 of file Potion.java.

References org.bukkit.potion.Potion.splash().

66  {
67  this(type, tier, splash);
68  this.extended = extended;
69  }
org.bukkit.potion.Potion.Potion ( PotionType  type,
int  level 
)

Create a new potion of the given type and level.

Parameters
typeThe type of potion.
levelThe potion's level.

Definition at line 77 of file Potion.java.

77  {
78  this(type);
79  Validate.notNull(type, "Type cannot be null");
80  Validate.isTrue(type != PotionType.WATER, "Water bottles don't have a level!");
81  Validate.isTrue(level > 0 && level < 3, "Level must be 1 or 2");
82  this.level = level;
83  }
org.bukkit.potion.Potion.Potion ( PotionType  type,
int  level,
boolean  splash 
)

Create a new potion of the given type and level.

Parameters
typeThe type of potion.
levelThe potion's level.
splashWhether it is a splash potion.
Deprecated:
In favour of using Potion(PotionType) with splash().

Definition at line 95 of file Potion.java.

References org.bukkit.potion.Potion.splash().

95  {
96  this(type, level);
97  this.splash = splash;
98  }
org.bukkit.potion.Potion.Potion ( PotionType  type,
int  level,
boolean  splash,
boolean  extended 
)

Create a new potion of the given type and level.

Parameters
typeThe type of potion.
levelThe potion's level.
splashWhether it is a splash potion.
extendedWhether it has an extended duration.
Deprecated:
In favour of using Potion(PotionType) with extend() and possibly splash().

Definition at line 111 of file Potion.java.

References org.bukkit.potion.Potion.splash().

111  {
112  this(type, level, splash);
113  this.extended = extended;
114  }
org.bukkit.potion.Potion.Potion ( int  name)

Create a potion with a specific name.

Parameters
nameThe name index (0-63)

Definition at line 121 of file Potion.java.

References org.bukkit.potion.PotionType.getByDamageValue().

121  {
122  this(PotionType.getByDamageValue(name & POTION_BIT));
123  this.name = name & NAME_BIT;
124  if ((name & POTION_BIT) == 0) {
125  // If it's 0 it would've become PotionType.WATER, but it should actually be mundane potion
126  this.type = null;
127  }
128  }

Member Function Documentation

void org.bukkit.potion.Potion.apply ( ItemStack  to)

Applies the effects of this potion to the given ItemStack. The ItemStack must be a potion.

Parameters
toThe itemstack to apply to

Definition at line 156 of file Potion.java.

References org.bukkit.inventory.ItemStack.getType(), org.bukkit.Material.POTION, org.bukkit.inventory.ItemStack.setDurability(), and org.bukkit.potion.Potion.toDamageValue().

156  {
157  Validate.notNull(to, "itemstack cannot be null");
158  Validate.isTrue(to.getType() == Material.POTION, "given itemstack is not a potion");
159  to.setDurability(toDamageValue());
160  }
void org.bukkit.potion.Potion.apply ( LivingEntity  to)

Applies the effects that would be applied by this potion to the given LivingEntity.

See also
LivingEntity::addPotionEffects(Collection)
Parameters
toThe entity to apply the effects to

Definition at line 169 of file Potion.java.

References org.bukkit.entity.LivingEntity.addPotionEffects(), and org.bukkit.potion.Potion.getEffects().

169  {
170  Validate.notNull(to, "entity cannot be null");
171  to.addPotionEffects(getEffects());
172  }
Collection< PotionEffect > getEffects()
Definition: Potion.java:194
Potion org.bukkit.potion.Potion.extend ( )

Chain this to the constructor to extend the potion's duration.

Returns
The potion.

Definition at line 145 of file Potion.java.

References org.bukkit.potion.Potion.setHasExtendedDuration().

Referenced by org.bukkit.potion.Potion.fromDamage().

145  {
147  return this;
148  }
void setHasExtendedDuration(boolean isExtended)
Definition: Potion.java:261
static Potion org.bukkit.potion.Potion.fromDamage ( int  damage)
static
Deprecated:
Magic value

Definition at line 387 of file Potion.java.

References org.bukkit.potion.Potion.extend(), org.bukkit.potion.PotionType.getByDamageValue(), and org.bukkit.potion.Potion.Potion().

387  {
388  PotionType type = PotionType.getByDamageValue(damage & POTION_BIT);
389  Potion potion;
390  if (type == null || (type == PotionType.WATER && damage != 0)) {
391  potion = new Potion(damage & NAME_BIT);
392  } else {
393  int level = (damage & TIER_BIT) >> TIER_SHIFT;
394  level++;
395  potion = new Potion(type, level);
396  }
397  if ((damage & SPLASH_BIT) > 0) {
398  potion = potion.splash();
399  }
400  if ((damage & EXTENDED_BIT) > 0) {
401  potion = potion.extend();
402  }
403  return potion;
404  }
Potion(PotionType type)
Definition: Potion.java:31
static PotionType getByDamageValue(int damage)
Definition: PotionType.java:54
static PotionBrewer org.bukkit.potion.Potion.getBrewer ( )
static

Returns an instance of PotionBrewer.

Returns
An instance of PotionBrewer

Definition at line 418 of file Potion.java.

Referenced by org.bukkit.potion.PotionEffectType.createEffect(), and org.bukkit.potion.Potion.getEffects().

418  {
419  return brewer;
420  }
Collection<PotionEffect> org.bukkit.potion.Potion.getEffects ( )

Returns a collection of PotionEffects that this Potion would confer upon a LivingEntity.

See also
PotionBrewer::getEffectsFromDamage(int)
Potion::toDamageValue()
Returns
The effects that this potion applies

Definition at line 194 of file Potion.java.

References org.bukkit.potion.Potion.getBrewer(), org.bukkit.potion.PotionBrewer.getEffectsFromDamage(), and org.bukkit.potion.Potion.toDamageValue().

Referenced by org.bukkit.potion.Potion.apply().

194  {
195  if (type == null) return ImmutableList.<PotionEffect>of();
197  }
Collection< PotionEffect > getEffectsFromDamage(int damage)
static PotionBrewer getBrewer()
Definition: Potion.java:418
int org.bukkit.potion.Potion.getLevel ( )

Returns the level of this potion.

Returns
The level of this potion

Definition at line 204 of file Potion.java.

204  {
205  return level;
206  }
int org.bukkit.potion.Potion.getNameId ( )
Deprecated:
Magic value

Definition at line 439 of file Potion.java.

439  {
440  return name;
441  }
Tier org.bukkit.potion.Potion.getTier ( )

Returns the Tier of this potion.

Returns
The tier of this potion

Definition at line 214 of file Potion.java.

214  {
215  return level == 2 ? Tier.TWO : Tier.ONE;
216  }
PotionType org.bukkit.potion.Potion.getType ( )

Returns the PotionType of this potion.

Returns
The type of this potion

Definition at line 223 of file Potion.java.

223  {
224  return type;
225  }
boolean org.bukkit.potion.Potion.hasExtendedDuration ( )

Returns whether this potion has an extended duration.

Returns
Whether this potion has extended duration

Definition at line 232 of file Potion.java.

232  {
233  return extended;
234  }
boolean org.bukkit.potion.Potion.isSplash ( )

Returns whether this potion is a splash potion.

Returns
Whether this is a splash potion

Definition at line 251 of file Potion.java.

References org.bukkit.potion.Potion.splash().

Referenced by org.bukkit.potion.Potion.setSplash().

251  {
252  return splash;
253  }
void org.bukkit.potion.Potion.setHasExtendedDuration ( boolean  isExtended)

Set whether this potion has extended duration. This will cause the potion to have roughly 8/3 more duration than a regular potion.

Parameters
isExtendedWhether the potion should have extended duration

Definition at line 261 of file Potion.java.

Referenced by org.bukkit.potion.Potion.extend().

261  {
262  Validate.isTrue(type == null || !type.isInstant(), "Instant potions cannot be extended");
263  extended = isExtended;
264  }
void org.bukkit.potion.Potion.setLevel ( int  level)

Sets the level of this potion.

Parameters
levelThe new level of this potion

Definition at line 302 of file Potion.java.

302  {
303  Validate.notNull(this.type, "No-effect potions don't have a level.");
304  int max = type.getMaxLevel();
305  Validate.isTrue(level > 0 && level <= max, "Level must be " + (max == 1 ? "" : "between 1 and ") + max + " for this potion");
306  this.level = level;
307  }
static void org.bukkit.potion.Potion.setPotionBrewer ( PotionBrewer  other)
static

Sets the current instance of PotionBrewer. Generally not to be used from within a plugin.

Parameters
otherThe new PotionBrewer

Definition at line 428 of file Potion.java.

428  {
429  if (brewer != null)
430  throw new IllegalArgumentException("brewer can only be set internally");
431  brewer = other;
432  }
void org.bukkit.potion.Potion.setSplash ( boolean  isSplash)

Sets whether this potion is a splash potion. Splash potions can be thrown for a radius effect.

Parameters
isSplashWhether this is a splash potion

Definition at line 272 of file Potion.java.

References org.bukkit.potion.Potion.isSplash().

Referenced by org.bukkit.potion.Potion.splash().

272  {
273  splash = isSplash;
274  }
void org.bukkit.potion.Potion.setTier ( Tier  tier)

Sets the Tier of this potion.

Parameters
tierThe new tier of this potion
Deprecated:
In favour of setLevel(int)

Definition at line 283 of file Potion.java.

283  {
284  Validate.notNull(tier, "tier cannot be null");
285  this.level = (tier == Tier.TWO ? 2 : 1);
286  }
void org.bukkit.potion.Potion.setType ( PotionType  type)

Sets the PotionType of this potion.

Parameters
typeThe new type of this potion

Definition at line 293 of file Potion.java.

293  {
294  this.type = type;
295  }
Potion org.bukkit.potion.Potion.splash ( )

Chain this to the constructor to make the potion a splash potion.

Returns
The potion.

Definition at line 135 of file Potion.java.

References org.bukkit.potion.Potion.setSplash().

Referenced by org.bukkit.potion.Potion.isSplash(), and org.bukkit.potion.Potion.Potion().

135  {
136  setSplash(true);
137  return this;
138  }
void setSplash(boolean isSplash)
Definition: Potion.java:272
short org.bukkit.potion.Potion.toDamageValue ( )

Converts this potion to a valid potion damage short, usable for potion item stacks.

Returns
The damage value of this potion
Deprecated:
Magic value

Definition at line 317 of file Potion.java.

References org.bukkit.potion.PotionType.getDamageValue().

Referenced by org.bukkit.potion.Potion.apply(), org.bukkit.potion.Potion.getEffects(), and org.bukkit.potion.Potion.toItemStack().

317  {
318  short damage;
319  if (type == PotionType.WATER) {
320  return 0;
321  } else if (type == null) {
322  // Without this, mundanePotion.toDamageValue() would return 0
323  damage = (short) (name == 0 ? 8192 : name);
324  } else {
325  damage = (short) (level - 1);
326  damage <<= TIER_SHIFT;
327  damage |= (short) type.getDamageValue();
328  }
329  if (splash) {
330  damage |= SPLASH_BIT;
331  }
332  if (extended) {
333  damage |= EXTENDED_BIT;
334  }
335  return damage;
336  }
ItemStack org.bukkit.potion.Potion.toItemStack ( int  amount)

Converts this potion to an ItemStack with the specified amount and a correct damage value.

Parameters
amountThe amount of the ItemStack
Returns
The created ItemStack

Definition at line 345 of file Potion.java.

References org.bukkit.Material.POTION, and org.bukkit.potion.Potion.toDamageValue().

345  {
346  return new ItemStack(Material.POTION, amount, toDamageValue());
347  }

The documentation for this class was generated from the following file: