@@ -1,7 +1,7 @@
|
||||
package org.bukkit.potion;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.Collection;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -28,7 +28,7 @@ public class Potion {
|
||||
* @param type The potion type
|
||||
*/
|
||||
public Potion(@NotNull PotionType type) {
|
||||
Validate.notNull(type, "Null PotionType");
|
||||
Preconditions.checkArgument(type != null, "Null PotionType");
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ public class Potion {
|
||||
*/
|
||||
public Potion(@NotNull PotionType type, int level) {
|
||||
this(type);
|
||||
Validate.notNull(type, "Type cannot be null");
|
||||
Validate.isTrue(level > 0 && level < 3, "Level must be 1 or 2");
|
||||
Preconditions.checkArgument(type != null, "Type cannot be null");
|
||||
Preconditions.checkArgument(level > 0 && level < 3, "Level must be 1 or 2");
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
@@ -105,9 +105,9 @@ public class Potion {
|
||||
* @param to The itemstack to apply to
|
||||
*/
|
||||
public void apply(@NotNull ItemStack to) {
|
||||
Validate.notNull(to, "itemstack cannot be null");
|
||||
Validate.isTrue(to.hasItemMeta(), "given itemstack is not a potion");
|
||||
Validate.isTrue(to.getItemMeta() instanceof PotionMeta, "given itemstack is not a potion");
|
||||
Preconditions.checkArgument(to != null, "itemstack cannot be null");
|
||||
Preconditions.checkArgument(to.hasItemMeta(), "given itemstack is not a potion");
|
||||
Preconditions.checkArgument(to.getItemMeta() instanceof PotionMeta, "given itemstack is not a potion");
|
||||
PotionMeta meta = (PotionMeta) to.getItemMeta();
|
||||
meta.setBasePotionData(new PotionData(type, extended, level == 2));
|
||||
to.setItemMeta(meta);
|
||||
@@ -121,7 +121,7 @@ public class Potion {
|
||||
* @see LivingEntity#addPotionEffects(Collection)
|
||||
*/
|
||||
public void apply(@NotNull LivingEntity to) {
|
||||
Validate.notNull(to, "entity cannot be null");
|
||||
Preconditions.checkArgument(to != null, "entity cannot be null");
|
||||
to.addPotionEffects(getEffects());
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ public class Potion {
|
||||
* @param isExtended Whether the potion should have extended duration
|
||||
*/
|
||||
public void setHasExtendedDuration(boolean isExtended) {
|
||||
Validate.isTrue(type == null || !type.isInstant(), "Instant potions cannot be extended");
|
||||
Preconditions.checkArgument(type == null || !type.isInstant(), "Instant potions cannot be extended");
|
||||
extended = isExtended;
|
||||
}
|
||||
|
||||
@@ -233,8 +233,8 @@ public class Potion {
|
||||
* @param level The new level of this potion
|
||||
*/
|
||||
public void setLevel(int level) {
|
||||
Validate.notNull(this.type, "No-effect potions don't have a level.");
|
||||
Validate.isTrue(level > 0 && level <= 2, "Level must be between 1 and 2 for this potion");
|
||||
Preconditions.checkArgument(this.type != null, "No-effect potions don't have a level.");
|
||||
Preconditions.checkArgument(level > 0 && level <= 2, "Level must be between 1 and 2 for this potion");
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
@@ -354,7 +354,7 @@ public class Potion {
|
||||
|
||||
@NotNull
|
||||
public static Potion fromItemStack(@NotNull ItemStack item) {
|
||||
Validate.notNull(item, "item cannot be null");
|
||||
Preconditions.checkArgument(item != null, "item cannot be null");
|
||||
if (item.getType() != Material.POTION)
|
||||
throw new IllegalArgumentException("item is not a potion");
|
||||
return fromDamage(item.getDurability());
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.bukkit.potion;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class PotionData {
|
||||
@@ -20,10 +20,10 @@ public final class PotionData {
|
||||
* must be true
|
||||
*/
|
||||
public PotionData(@NotNull 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");
|
||||
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");
|
||||
this.type = type;
|
||||
this.extended = extended;
|
||||
this.upgraded = upgraded;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package org.bukkit.potion;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
@@ -44,7 +44,7 @@ public class PotionEffect implements ConfigurationSerializable {
|
||||
* @param icon the icon status, see {@link PotionEffect#hasIcon()}
|
||||
*/
|
||||
public PotionEffect(@NotNull PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles, boolean icon) {
|
||||
Validate.notNull(type, "effect type cannot be null");
|
||||
Preconditions.checkArgument(type != null, "effect type cannot be null");
|
||||
this.type = type;
|
||||
this.duration = duration;
|
||||
this.amplifier = amplifier;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package org.bukkit.potion;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.NamespacedKey;
|
||||
@@ -180,6 +180,11 @@ public abstract class PotionEffectType implements Keyed {
|
||||
*/
|
||||
public static final PotionEffectType HERO_OF_THE_VILLAGE = new PotionEffectTypeWrapper(32, "hero_of_the_village");
|
||||
|
||||
/**
|
||||
* Causes the player's vision to dim occasionally.
|
||||
*/
|
||||
public static final PotionEffectType DARKNESS = new PotionEffectTypeWrapper(33, "darkness");
|
||||
|
||||
private final int id;
|
||||
private final NamespacedKey key;
|
||||
|
||||
@@ -276,7 +281,7 @@ public abstract class PotionEffectType implements Keyed {
|
||||
return "PotionEffectType[" + id + ", " + getName() + "]";
|
||||
}
|
||||
|
||||
private static final PotionEffectType[] byId = new PotionEffectType[33];
|
||||
private static final PotionEffectType[] byId = new PotionEffectType[34];
|
||||
private static final Map<String, PotionEffectType> byName = new HashMap<String, PotionEffectType>();
|
||||
private static final Map<NamespacedKey, PotionEffectType> byKey = new HashMap<NamespacedKey, PotionEffectType>();
|
||||
// will break on updates.
|
||||
@@ -317,7 +322,7 @@ public abstract class PotionEffectType implements Keyed {
|
||||
*/
|
||||
@Nullable
|
||||
public static PotionEffectType getByName(@NotNull String name) {
|
||||
Validate.notNull(name, "name cannot be null");
|
||||
Preconditions.checkArgument(name != null, "name cannot be null");
|
||||
return byName.get(name.toLowerCase(java.util.Locale.ENGLISH));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user