1 package org.bukkit.potion;
3 import java.util.Collection;
5 import org.apache.commons.lang.Validate;
6 import org.bukkit.Material;
7 import org.bukkit.entity.LivingEntity;
8 import org.bukkit.inventory.ItemStack;
10 import com.google.common.collect.ImmutableList;
16 private boolean extended =
false;
17 private boolean splash =
false;
18 private int level = 1;
19 private int name = -1;
40 @SuppressWarnings(
"javadoc")
43 this(type, tier ==
Tier.
TWO ? 2 : 1);
44 Validate.notNull(type,
"Type cannot be null");
48 @SuppressWarnings(
"javadoc")
55 @SuppressWarnings(
"javadoc")
59 this.extended = extended;
69 Validate.notNull(type,
"Type cannot be null");
70 Validate.isTrue(type !=
PotionType.
WATER,
"Water bottles don't have a level!");
71 Validate.isTrue(level > 0 && level < 3,
"Level must be 1 or 2");
100 this.extended = extended;
109 this.name = name & NAME_BIT;
110 if ((name & POTION_BIT) == 0) {
141 Validate.notNull(to,
"itemstack cannot be null");
154 Validate.notNull(to,
"entity cannot be null");
163 if (obj == null || getClass() != obj.getClass()) {
167 return extended == other.extended &&
splash == other.splash && level == other.level && type == other.type;
179 if (type == null)
return ImmutableList.<
PotionEffect>of();
222 final int prime = 31;
223 int result = prime + level;
224 result = prime * result + (extended ? 1231 : 1237);
225 result = prime * result + (
splash ? 1231 : 1237);
226 result = prime * result + ((type == null) ? 0 : type.hashCode());
246 Validate.isTrue(type == null || !type.
isInstant(),
"Instant potions cannot be extended");
247 extended = isExtended;
269 Validate.notNull(tier,
"tier cannot be null");
270 this.level = (tier ==
Tier.
TWO ? 2 : 1);
289 Validate.notNull(this.type,
"No-effect potions don't have a level.");
291 Validate.isTrue(level > 0 && level <= max,
"Level must be " + (max == 1 ?
"" :
"between 1 and ") + max +
" for this potion");
305 }
else if (type == null) {
307 damage = (short) (name == 0 ? 8192 : name);
309 damage = (short) (level - 1);
310 damage <<= TIER_SHIFT;
314 damage |= SPLASH_BIT;
317 damage |= EXTENDED_BIT;
338 private int damageBit;
350 if (tier.damageBit == damageBit)
359 private static final int EXTENDED_BIT = 0x40;
360 private static final int POTION_BIT = 0xF;
361 private static final int SPLASH_BIT = 0x4000;
362 private static final int TIER_BIT = 0x20;
363 private static final int TIER_SHIFT = 5;
364 private static final int NAME_BIT = 0x3F;
370 potion =
new Potion(damage & NAME_BIT);
372 int level = (damage & TIER_BIT) >> TIER_SHIFT;
374 potion =
new Potion(type, level);
376 if ((damage & SPLASH_BIT) > 0) {
377 potion = potion.splash();
379 if ((damage & EXTENDED_BIT) > 0) {
386 Validate.notNull(item,
"item cannot be null");
388 throw new IllegalArgumentException(
"item is not a potion");
409 throw new IllegalArgumentException(
"brewer can only be set internally");