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,14 +823,12 @@ 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);
return;
}
for (PotionEffect effect : potion.getEffects()) {
if (potion.isSplash() && wcfg.blockPotions.contains(effect.getType())) {
event.setCancelled(true);
return;
}
}
}

View File

@ -403,36 +403,34 @@ 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;
break;
}
for (PotionEffect effect : potion.getEffects()) {
if (wcfg.blockPotions.contains(effect.getType())) {
blockedEffect = effect;
break;
}
}
if (blockedEffect != null) {
if (plugin.hasPermission(player, "worldguard.override.potions")) {
if (potion.isSplash() && wcfg.blockPotionsAlways) {
player.sendMessage(ChatColor.RED + "Sorry, potions with " +
blockedEffect.getType().getName() + " can't be thrown, " +
"even if you have a permission to bypass it, " +
"due to limitations (and because overly-reliable potion blocking is on).");
event.setUseItemInHand(Result.DENY);
return;
}
} else {
player.sendMessage(ChatColor.RED + "Sorry, potions with "
+ blockedEffect.getType().getName() + " are presently disabled.");
if (blockedEffect != null) {
if (plugin.hasPermission(player, "worldguard.override.potions")) {
if (potion.isSplash() && wcfg.blockPotionsAlways) {
player.sendMessage(ChatColor.RED + "Sorry, potions with " +
blockedEffect.getType().getName() + " can't be thrown, " +
"even if you have a permission to bypass it, " +
"due to limitations (and because overly-reliable potion blocking is on).");
event.setUseItemInHand(Result.DENY);
return;
}
} else {
player.sendMessage(ChatColor.RED + "Sorry, potions with "
+ blockedEffect.getType().getName() + " are presently disabled.");
event.setUseItemInHand(Result.DENY);
return;
}
}
}
}