Worked around bug with water potions causing errors.

This commit is contained in:
sk89q 2012-11-06 19:21:12 -08:00
parent 80a8ac9e98
commit d18fe6ffa0
3 changed files with 28 additions and 36 deletions

View File

@ -31,9 +31,6 @@
import org.bukkit.block.Block;
import org.bukkit.entity.*;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionType;
import java.util.List;
public class BukkitUtil {
@ -146,14 +143,13 @@ public static boolean isBlockWater(World world, int ox, int oy, int oz) {
}
/**
* Checks if the given potion is a vial of water
* Checks if the given potion is a vial of water.
*
* @param potion
* @param item the item to check
* @return true if it's a water vial
*/
public static boolean isWaterPotion(Potion potion) {
return potion.getType() == PotionType.WATER;
public static boolean isWaterPotion(ItemStack item) {
return (item.getDurability() & 0x3F) == 0;
}
/**

View File

@ -823,9 +823,8 @@ public void onBlockDispense(BlockDispenseEvent event) {
if (wcfg.blockPotions.size() > 0) {
ItemStack item = event.getItem();
if (item.getType() == Material.POTION) {
if (item.getType() == Material.POTION && !BukkitUtil.isWaterPotion(item)) {
Potion potion = Potion.fromItemStack(item);
if (!BukkitUtil.isWaterPotion(potion)) {
for (PotionEffect effect : potion.getEffects()) {
if (potion.isSplash() && wcfg.blockPotions.contains(effect.getType())) {
event.setCancelled(true);
@ -835,5 +834,4 @@ public void onBlockDispense(BlockDispenseEvent event) {
}
}
}
}
}

View File

@ -403,11 +403,10 @@ public void onPlayerInteract(PlayerInteractEvent event) {
if (wcfg.blockPotions.size() > 0) {
ItemStack item = event.getItem();
if (item != null && item.getType() == Material.POTION) {
if (item != null && item.getType() == Material.POTION && !BukkitUtil.isWaterPotion(item)) {
PotionEffect blockedEffect = null;
Potion potion = Potion.fromItemStack(item);
if (!BukkitUtil.isWaterPotion(potion)) {
for (PotionEffect effect : potion.getEffects()) {
if (wcfg.blockPotions.contains(effect.getType())) {
blockedEffect = effect;
@ -436,7 +435,6 @@ public void onPlayerInteract(PlayerInteractEvent event) {
}
}
}
}
/**
* Called when a player left clicks air.