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.block.Block;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionType;
import java.util.List; import java.util.List;
public class BukkitUtil { 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 * @return true if it's a water vial
*/ */
public static boolean isWaterPotion(Potion potion) { public static boolean isWaterPotion(ItemStack item) {
return (item.getDurability() & 0x3F) == 0;
return potion.getType() == PotionType.WATER;
} }
/** /**

View File

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

View File

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