mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-08 03:49:32 +01:00
Worked around bug with water potions causing errors.
This commit is contained in:
parent
80a8ac9e98
commit
d18fe6ffa0
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user