Merge pull request #195 from magnusulf/master

Extended material facts
This commit is contained in:
Olof Larsson 2014-12-07 23:08:11 +01:00
commit 1eaf1cbfe5

View File

@ -38,6 +38,7 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile; import org.bukkit.entity.Projectile;
import org.bukkit.entity.ThrownPotion; import org.bukkit.entity.ThrownPotion;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
@ -554,6 +555,79 @@ public class MUtil
return isUnarmed((EntityDamageByEntityEvent)event); return isUnarmed((EntityDamageByEntityEvent)event);
} }
public static boolean isAxe(BlockBreakEvent event)
{
return isAxe(event.getPlayer().getItemInHand());
}
// Pickaxe
public static Set<Material> PICKAXE_MATERIALS = EnumSet.of(
Material.WOOD_PICKAXE,
Material.STONE_PICKAXE,
Material.IRON_PICKAXE,
Material.GOLD_PICKAXE,
Material.DIAMOND_PICKAXE
);
public static boolean isPickaxe(Material material)
{
return PICKAXE_MATERIALS.contains(material);
}
public static boolean isPickaxe(ItemStack item)
{
if (item == null) return false;
return isPickaxe(item.getType());
}
public static boolean isPickaxe(Entity entity)
{
if (entity == null) return false;
if (!(entity instanceof LivingEntity)) return false;
LivingEntity lentity = (LivingEntity)entity;
return isPickaxe(lentity.getEquipment().getItemInHand());
}
public static boolean isPickaxe(BlockBreakEvent event)
{
return isPickaxe(event.getPlayer().getItemInHand());
}
// Spade
public static Set<Material> SPADE_MATERIALS = EnumSet.of(
Material.WOOD_SPADE,
Material.STONE_SPADE,
Material.IRON_SPADE,
Material.GOLD_SPADE,
Material.DIAMOND_SPADE
);
public static boolean isSpade(Material material)
{
return SPADE_MATERIALS.contains(material);
}
public static boolean isSpade(ItemStack item)
{
if (item == null) return false;
return isSpade(item.getType());
}
public static boolean isSpade(Entity entity)
{
if (entity == null) return false;
if (!(entity instanceof LivingEntity)) return false;
LivingEntity lentity = (LivingEntity)entity;
return isSpade(lentity.getEquipment().getItemInHand());
}
public static boolean isSpade(BlockBreakEvent event)
{
return isSpade(event.getPlayer().getItemInHand());
}
// -------------------------------------------- // // -------------------------------------------- //
// EVENT DERP // EVENT DERP
// -------------------------------------------- // // -------------------------------------------- //