mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-05 07:57:59 +01:00
Use MaterialUtil to check signs
This commit is contained in:
parent
af4cfd3fe9
commit
d282462547
@ -2,6 +2,7 @@ package com.earth2me.essentials.signs;
|
|||||||
|
|
||||||
import com.earth2me.essentials.*;
|
import com.earth2me.essentials.*;
|
||||||
import com.earth2me.essentials.utils.EnumUtil;
|
import com.earth2me.essentials.utils.EnumUtil;
|
||||||
|
import com.earth2me.essentials.utils.MaterialUtil;
|
||||||
import com.earth2me.essentials.utils.NumberUtil;
|
import com.earth2me.essentials.utils.NumberUtil;
|
||||||
import net.ess3.api.IEssentials;
|
import net.ess3.api.IEssentials;
|
||||||
import net.ess3.api.MaxMoneyException;
|
import net.ess3.api.MaxMoneyException;
|
||||||
@ -26,7 +27,6 @@ import static com.earth2me.essentials.I18n.tl;
|
|||||||
|
|
||||||
|
|
||||||
public class EssentialsSign {
|
public class EssentialsSign {
|
||||||
private static final Material SIGN_POST = EnumUtil.getMaterial("SIGN", "SIGN_POST");
|
|
||||||
private static final Set<Material> EMPTY_SET = new HashSet<Material>();
|
private static final Set<Material> EMPTY_SET = new HashSet<Material>();
|
||||||
protected static final BigDecimal MINTRANSACTION = new BigDecimal("0.01");
|
protected static final BigDecimal MINTRANSACTION = new BigDecimal("0.01");
|
||||||
protected transient final String signName;
|
protected transient final String signName;
|
||||||
@ -206,13 +206,13 @@ public class EssentialsSign {
|
|||||||
|
|
||||||
protected static boolean checkIfBlockBreaksSigns(final Block block) {
|
protected static boolean checkIfBlockBreaksSigns(final Block block) {
|
||||||
final Block sign = block.getRelative(BlockFace.UP);
|
final Block sign = block.getRelative(BlockFace.UP);
|
||||||
if (sign.getType() == SIGN_POST && isValidSign(new BlockSign(sign))) {
|
if (MaterialUtil.isSignPost(sign.getType()) && isValidSign(new BlockSign(sign))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final BlockFace[] directions = new BlockFace[]{BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};
|
final BlockFace[] directions = new BlockFace[]{BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};
|
||||||
for (BlockFace blockFace : directions) {
|
for (BlockFace blockFace : directions) {
|
||||||
final Block signblock = block.getRelative(blockFace);
|
final Block signblock = block.getRelative(blockFace);
|
||||||
if (signblock.getType() == Material.WALL_SIGN) {
|
if (MaterialUtil.isWallSign(signblock.getType())) {
|
||||||
try {
|
try {
|
||||||
final org.bukkit.material.Sign signMat = (org.bukkit.material.Sign) signblock.getState().getData();
|
final org.bukkit.material.Sign signMat = (org.bukkit.material.Sign) signblock.getState().getData();
|
||||||
if (signMat != null && signMat.getFacing() == blockFace && isValidSign(new BlockSign(signblock))) {
|
if (signMat != null && signMat.getFacing() == blockFace && isValidSign(new BlockSign(signblock))) {
|
||||||
|
@ -4,6 +4,7 @@ import com.earth2me.essentials.I18n;
|
|||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import com.earth2me.essentials.utils.EnumUtil;
|
import com.earth2me.essentials.utils.EnumUtil;
|
||||||
import com.earth2me.essentials.utils.FormatUtil;
|
import com.earth2me.essentials.utils.FormatUtil;
|
||||||
|
import com.earth2me.essentials.utils.MaterialUtil;
|
||||||
import net.ess3.api.IEssentials;
|
import net.ess3.api.IEssentials;
|
||||||
import net.ess3.api.MaxMoneyException;
|
import net.ess3.api.MaxMoneyException;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -22,8 +23,6 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
public class SignBlockListener implements Listener {
|
public class SignBlockListener implements Listener {
|
||||||
private static final Logger LOGGER = Logger.getLogger("Essentials");
|
private static final Logger LOGGER = Logger.getLogger("Essentials");
|
||||||
private static final Material WALL_SIGN = Material.WALL_SIGN;
|
|
||||||
private static final Material SIGN_POST = EnumUtil.getMaterial("SIGN", "SIGN_POST");
|
|
||||||
private final transient IEssentials ess;
|
private final transient IEssentials ess;
|
||||||
|
|
||||||
public SignBlockListener(IEssentials ess) {
|
public SignBlockListener(IEssentials ess) {
|
||||||
@ -55,7 +54,7 @@ public class SignBlockListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Material mat = block.getType();
|
final Material mat = block.getType();
|
||||||
if (mat == SIGN_POST || mat == WALL_SIGN) {
|
if (MaterialUtil.isSign(mat)) {
|
||||||
final Sign csign = (Sign) block.getState();
|
final Sign csign = (Sign) block.getState();
|
||||||
|
|
||||||
for (EssentialsSign sign : ess.getSettings().enabledSigns()) {
|
for (EssentialsSign sign : ess.getSettings().enabledSigns()) {
|
||||||
@ -143,12 +142,12 @@ public class SignBlockListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Block against = event.getBlockAgainst();
|
final Block against = event.getBlockAgainst();
|
||||||
if ((against.getType() == WALL_SIGN || against.getType() == SIGN_POST) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(against))) {
|
if (MaterialUtil.isSign(against.getType()) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(against))) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Block block = event.getBlock();
|
final Block block = event.getBlock();
|
||||||
if (block.getType() == WALL_SIGN || block.getType() == SIGN_POST) {
|
if (MaterialUtil.isSign(block.getType())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (EssentialsSign sign : ess.getSettings().enabledSigns()) {
|
for (EssentialsSign sign : ess.getSettings().enabledSigns()) {
|
||||||
@ -167,7 +166,7 @@ public class SignBlockListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Block block = event.getBlock();
|
final Block block = event.getBlock();
|
||||||
if (((block.getType() == WALL_SIGN || block.getType() == SIGN_POST) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
|
if ((MaterialUtil.isSign(block.getType()) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -187,7 +186,7 @@ public class SignBlockListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Block block = event.getBlock();
|
final Block block = event.getBlock();
|
||||||
if (((block.getType() == WALL_SIGN || block.getType() == SIGN_POST) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
|
if ((MaterialUtil.isSign(block.getType()) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -207,7 +206,7 @@ public class SignBlockListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Block block : event.getBlocks()) {
|
for (Block block : event.getBlocks()) {
|
||||||
if (((block.getType() == WALL_SIGN || block.getType() == SIGN_POST) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
|
if ((MaterialUtil.isSign(block.getType()) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -232,7 +231,7 @@ public class SignBlockListener implements Listener {
|
|||||||
final Block[] affectedBlocks = new Block[]{pistonBaseBlock, pistonBaseBlock.getRelative(event.getDirection()), event.getRetractLocation().getBlock()};
|
final Block[] affectedBlocks = new Block[]{pistonBaseBlock, pistonBaseBlock.getRelative(event.getDirection()), event.getRetractLocation().getBlock()};
|
||||||
|
|
||||||
for (Block block : affectedBlocks) {
|
for (Block block : affectedBlocks) {
|
||||||
if (((block.getType() == WALL_SIGN || block.getType() == SIGN_POST) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
|
if ((MaterialUtil.isSign(block.getType()) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.earth2me.essentials.signs;
|
package com.earth2me.essentials.signs;
|
||||||
|
|
||||||
import com.earth2me.essentials.utils.EnumUtil;
|
import com.earth2me.essentials.utils.EnumUtil;
|
||||||
|
import com.earth2me.essentials.utils.MaterialUtil;
|
||||||
import net.ess3.api.IEssentials;
|
import net.ess3.api.IEssentials;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -13,7 +14,6 @@ import org.bukkit.event.entity.EntityExplodeEvent;
|
|||||||
|
|
||||||
public class SignEntityListener implements Listener {
|
public class SignEntityListener implements Listener {
|
||||||
|
|
||||||
private static final Material SIGN_POST = EnumUtil.getMaterial("SIGN", "SIGN_POST");
|
|
||||||
private final transient IEssentials ess;
|
private final transient IEssentials ess;
|
||||||
|
|
||||||
public SignEntityListener(final IEssentials ess) {
|
public SignEntityListener(final IEssentials ess) {
|
||||||
@ -28,7 +28,7 @@ public class SignEntityListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Block block : event.blockList()) {
|
for (Block block : event.blockList()) {
|
||||||
if (((block.getType() == Material.WALL_SIGN || block.getType() == SIGN_POST) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
|
if ((MaterialUtil.isSign(block.getType()) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ public class SignEntityListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Block block = event.getBlock();
|
final Block block = event.getBlock();
|
||||||
if (((block.getType() == Material.WALL_SIGN || block.getType() == SIGN_POST) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
|
if ((MaterialUtil.isSign(block.getType()) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ public class SignProtection extends EssentialsSign {
|
|||||||
final Block sign = entry.getKey().getBlock();
|
final Block sign = entry.getKey().getBlock();
|
||||||
if (!hasAdjacentBlock(sign, block)) {
|
if (!hasAdjacentBlock(sign, block)) {
|
||||||
block.setType(Material.AIR);
|
block.setType(Material.AIR);
|
||||||
final Trade trade = new Trade(new ItemStack(Material.SIGN, 1), ess);
|
final Trade trade = new Trade(new ItemStack(sign.getType(), 1), ess);
|
||||||
trade.pay(player, OverflowType.DROP);
|
trade.pay(player, OverflowType.DROP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.earth2me.essentials.utils;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.DyeColor;
|
import org.bukkit.DyeColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Registry;
|
||||||
import org.bukkit.material.MaterialData;
|
import org.bukkit.material.MaterialData;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
@ -21,7 +22,8 @@ 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;
|
private static final Set<Material> SIGN_POSTS;
|
||||||
|
private static final Set<Material> WALL_SIGNS;
|
||||||
|
|
||||||
public static final Material SPAWNER = EnumUtil.getMaterial("MOB_SPAWNER", "SPAWNER");
|
public static final Material SPAWNER = EnumUtil.getMaterial("MOB_SPAWNER", "SPAWNER");
|
||||||
|
|
||||||
@ -55,7 +57,14 @@ 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");
|
SIGN_POSTS = EnumUtil.getAllMatching(Material.class, "SIGN", "SIGN_POST",
|
||||||
|
"ACACIA_SIGN", "BIRCH_SIGN",
|
||||||
|
"DARK_OAK_SIGN", "JUNGLE_SIGN",
|
||||||
|
"OAK_SIGN", "SPRUCE_SIGN");
|
||||||
|
|
||||||
|
WALL_SIGNS = EnumUtil.getAllMatching(Material.class, "WALL_SIGN",
|
||||||
|
"ACACIA_WALL_SIGN", "BIRCH_WALL_SIGN", "DARK_OAK_WALL_SIGN", "JUNGLE_WALL_SIGN",
|
||||||
|
"OAK_WALL_SIGN", "SPRUCE_WALL_SIGN");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isBed(Material material) {
|
public static boolean isBed(Material material) {
|
||||||
@ -94,8 +103,16 @@ public class MaterialUtil {
|
|||||||
return POTIONS.contains(material);
|
return POTIONS.contains(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isSignPost(Material material) {
|
||||||
|
return SIGN_POSTS.contains(material);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isWallSign(Material material) {
|
||||||
|
return WALL_SIGNS.contains(material);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isSign(Material material) {
|
public static boolean isSign(Material material) {
|
||||||
return SIGNS.contains(material);
|
return isSignPost(material) || isWallSign(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSkull(Material material) {
|
public static boolean isSkull(Material material) {
|
||||||
@ -108,7 +125,7 @@ public class MaterialUtil {
|
|||||||
try {
|
try {
|
||||||
return Bukkit.getUnsafe().fromLegacy(new MaterialData(material, damage));
|
return Bukkit.getUnsafe().fromLegacy(new MaterialData(material, damage));
|
||||||
} catch (NoSuchMethodError error) {
|
} catch (NoSuchMethodError error) {
|
||||||
return material;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user