Add SIGNS and SPAWNER to MaterialUtil

This commit is contained in:
md678685 2018-12-09 13:47:22 +00:00
parent 3db3a272d5
commit 814e5a643e
2 changed files with 11 additions and 2 deletions

View file

@ -2,6 +2,7 @@ package com.earth2me.essentials;
import com.earth2me.essentials.utils.EnumUtil; import com.earth2me.essentials.utils.EnumUtil;
import com.earth2me.essentials.utils.LocationUtil; import com.earth2me.essentials.utils.LocationUtil;
import com.earth2me.essentials.utils.MaterialUtil;
import net.ess3.api.IEssentials; import net.ess3.api.IEssentials;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Material; import org.bukkit.Material;
@ -29,12 +30,12 @@ public class EssentialsBlockListener implements Listener {
// Do not rely on getItemInHand(); // Do not rely on getItemInHand();
// http://leaky.bukkit.org/issues/663 // http://leaky.bukkit.org/issues/663
final ItemStack is = LocationUtil.convertBlockToItem(event.getBlockPlaced()); final ItemStack is = LocationUtil.convertBlockToItem(event.getBlockPlaced());
if (is == null) { if (is == null) {
return; return;
} }
Material MOB_SPAWNER = EnumUtil.getMaterial("SPAWNER", "MOB_SPAWNER");
if (is.getType() == MOB_SPAWNER && event.getItemInHand() != null && event.getPlayer() != null && event.getItemInHand().getType() == MOB_SPAWNER) { if (is.getType() == MaterialUtil.SPAWNER && event.getItemInHand() != null && event.getPlayer() != null && event.getItemInHand().getType() == MaterialUtil.SPAWNER) {
final BlockState blockState = event.getBlockPlaced().getState(); final BlockState blockState = event.getBlockPlaced().getState();
if (blockState instanceof CreatureSpawner) { if (blockState instanceof CreatureSpawner) {
final CreatureSpawner spawner = (CreatureSpawner) blockState; final CreatureSpawner spawner = (CreatureSpawner) blockState;

View file

@ -16,6 +16,9 @@ public class MaterialUtil {
// includes TIPPED_ARROW which also has potion effects // includes TIPPED_ARROW which also has potion effects
private static final Set<Material> PLAYER_HEADS; private static final Set<Material> PLAYER_HEADS;
private static final Set<Material> POTIONS; private static final Set<Material> POTIONS;
private static final Set<Material> SIGNS;
public static final Material SPAWNER = EnumUtil.getMaterial("MOB_SPAWNER", "SPAWNER");
static { static {
@ -47,6 +50,7 @@ public class MaterialUtil {
POTIONS = EnumUtil.getAllMatching(Material.class, "POTION", "SPLASH_POTION", POTIONS = EnumUtil.getAllMatching(Material.class, "POTION", "SPLASH_POTION",
"LINGERING_POTION", "TIPPED_ARROW"); "LINGERING_POTION", "TIPPED_ARROW");
SIGNS = EnumUtil.getAllMatching(Material.class, "SIGN", "SIGN_POST", "WALL_SIGN");
} }
public static boolean isBed(Material material) { public static boolean isBed(Material material) {
@ -85,6 +89,10 @@ public class MaterialUtil {
return POTIONS.contains(material); return POTIONS.contains(material);
} }
public static boolean isSign(Material material) {
return SIGNS.contains(material);
}
public static boolean isSkull(Material material) { public static boolean isSkull(Material material) {
return isPlayerHead(material, -1) || isMobHead(material, -1); return isPlayerHead(material, -1) || isMobHead(material, -1);
} }