Updates signs with cross-version enum lookups

This commit is contained in:
md678685 2018-12-31 12:53:41 +00:00
parent 0114b5e4f6
commit 78fca9a67a
5 changed files with 25 additions and 24 deletions

View file

@ -1,6 +1,7 @@
package com.earth2me.essentials.signs;
import com.earth2me.essentials.*;
import com.earth2me.essentials.utils.EnumUtil;
import com.earth2me.essentials.utils.NumberUtil;
import net.ess3.api.IEssentials;
import net.ess3.api.MaxMoneyException;
@ -25,6 +26,7 @@ import static com.earth2me.essentials.I18n.tl;
public class EssentialsSign {
private static final Material SIGN_POST = EnumUtil.getMaterial("SIGN", "SIGN_POST");
private static final Set<Material> EMPTY_SET = new HashSet<Material>();
protected static final BigDecimal MINTRANSACTION = new BigDecimal("0.01");
protected transient final String signName;
@ -58,9 +60,7 @@ public class EssentialsSign {
sign.setLine(0, getSuccessName(ess));
}
return ret;
} catch (ChargeException ex) {
showError(ess, user.getSource(), ex, signName);
} catch (SignException ex) {
} catch (ChargeException | SignException ex) {
showError(ess, user.getSource(), ex, signName);
}
// Return true, so the player sees the wrong sign.
@ -115,9 +115,6 @@ public class EssentialsSign {
}
return onSignInteract(sign, user, getUsername(user), ess);
} catch (ChargeException ex) {
showError(ess, user.getSource(), ex, signName);
return false;
} catch (Exception ex) {
showError(ess, user.getSource(), ex, signName);
return false;
@ -161,9 +158,7 @@ public class EssentialsSign {
User user = ess.getUser(player);
try {
return onBlockPlace(block, user, getUsername(user), ess);
} catch (ChargeException ex) {
showError(ess, user.getSource(), ex, signName);
} catch (SignException ex) {
} catch (ChargeException | SignException ex) {
showError(ess, user.getSource(), ex, signName);
}
return false;
@ -173,9 +168,7 @@ public class EssentialsSign {
User user = ess.getUser(player);
try {
return onBlockInteract(block, user, getUsername(user), ess);
} catch (ChargeException ex) {
showError(ess, user.getSource(), ex, signName);
} catch (SignException ex) {
} catch (ChargeException | SignException ex) {
showError(ess, user.getSource(), ex, signName);
}
return false;
@ -213,7 +206,7 @@ public class EssentialsSign {
protected static boolean checkIfBlockBreaksSigns(final Block block) {
final Block sign = block.getRelative(BlockFace.UP);
if (sign.getType() == Material.SIGN && isValidSign(new BlockSign(sign))) {
if (sign.getType() == SIGN_POST && isValidSign(new BlockSign(sign))) {
return true;
}
final BlockFace[] directions = new BlockFace[]{BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};

View file

@ -2,6 +2,7 @@ package com.earth2me.essentials.signs;
import com.earth2me.essentials.I18n;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.EnumUtil;
import com.earth2me.essentials.utils.FormatUtil;
import net.ess3.api.IEssentials;
import net.ess3.api.MaxMoneyException;
@ -22,7 +23,7 @@ import java.util.logging.Logger;
public class SignBlockListener implements Listener {
private static final Logger LOGGER = Logger.getLogger("Essentials");
private static final Material WALL_SIGN = Material.WALL_SIGN;
private static final Material SIGN_POST = Material.SIGN;
private static final Material SIGN_POST = EnumUtil.getMaterial("SIGN", "SIGN_POST");
private final transient IEssentials ess;
public SignBlockListener(IEssentials ess) {

View file

@ -1,5 +1,6 @@
package com.earth2me.essentials.signs;
import com.earth2me.essentials.utils.EnumUtil;
import net.ess3.api.IEssentials;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -11,6 +12,8 @@ import org.bukkit.event.entity.EntityExplodeEvent;
public class SignEntityListener implements Listener {
private static final Material SIGN_POST = EnumUtil.getMaterial("SIGN", "SIGN_POST");
private final transient IEssentials ess;
public SignEntityListener(final IEssentials ess) {
@ -25,7 +28,7 @@ public class SignEntityListener implements Listener {
}
for (Block block : event.blockList()) {
if (((block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
if (((block.getType() == Material.WALL_SIGN || block.getType() == SIGN_POST) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
event.setCancelled(true);
return;
}
@ -46,7 +49,7 @@ public class SignEntityListener implements Listener {
}
final Block block = event.getBlock();
if (((block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
if (((block.getType() == Material.WALL_SIGN || block.getType() == SIGN_POST) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
event.setCancelled(true);
return;
}

View file

@ -1,5 +1,6 @@
package com.earth2me.essentials.signs;
import com.earth2me.essentials.utils.MaterialUtil;
import net.ess3.api.IEssentials;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -54,7 +55,7 @@ public class SignPlayerListener implements Listener {
}
final Material mat = block.getType();
if (mat == Material.SIGN || mat == Material.WALL_SIGN) {
if (MaterialUtil.isSign(mat)) {
final String csign = ((Sign) block.getState()).getLine(0);
for (EssentialsSign sign : ess.getSettings().enabledSigns()) {
if (csign.equalsIgnoreCase(sign.getSuccessName(ess))) {

View file

@ -4,7 +4,9 @@ import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.Trade.OverflowType;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.EnumUtil;
import com.earth2me.essentials.utils.FormatUtil;
import com.earth2me.essentials.utils.MaterialUtil;
import net.ess3.api.IEssentials;
import net.ess3.api.MaxMoneyException;
import org.bukkit.Location;
@ -21,13 +23,14 @@ import static com.earth2me.essentials.I18n.tl;
@Deprecated // This sign will be removed soon
public class SignProtection extends EssentialsSign {
private final transient Set<Material> protectedBlocks = EnumSet.noneOf(Material.class);
private final transient Set<Material> protectedBlocks = EnumUtil.getAllMatching(Material.class,
"CHEST",
"FURNACE",
"BURNING_FURNACE",
"DISPENSER");
public SignProtection() {
super("Protection");
protectedBlocks.add(Material.CHEST);
protectedBlocks.add(Material.FURNACE);
protectedBlocks.add(Material.DISPENSER);
}
@Override
@ -102,7 +105,7 @@ public class SignProtection extends EssentialsSign {
}
private SignProtectionState checkProtectionSign(final Block block, final User user, final String username) {
if (block.getType() == Material.SIGN || block.getType() == Material.WALL_SIGN) {
if (MaterialUtil.isSign(block.getType())) {
final BlockSign sign = new BlockSign(block);
if (sign.getLine(0).equals(this.getSuccessName())) { // TODO call getSuccessName(IEssentials)
return checkProtectionSign(sign, user, username);
@ -159,7 +162,7 @@ public class SignProtection extends EssentialsSign {
public boolean isBlockProtected(final Block block) {
final Block[] faces = getAdjacentBlocks(block);
for (Block b : faces) {
if (b.getType() == Material.SIGN || b.getType() == Material.WALL_SIGN) {
if (MaterialUtil.isSign(b.getType())) {
final Sign sign = (Sign) b.getState();
if (sign.getLine(0).equalsIgnoreCase("§1[Protection]")) {
return true;
@ -169,7 +172,7 @@ public class SignProtection extends EssentialsSign {
final Block[] faceChest = getAdjacentBlocks(b);
for (Block a : faceChest) {
if (a.getType() == Material.SIGN || a.getType() == Material.WALL_SIGN) {
if (MaterialUtil.isSign(a.getType())) {
final Sign sign = (Sign) a.getState();
if (sign.getLine(0).equalsIgnoreCase("§1[Protection]")) {
return true;