diff --git a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java index eedc49e01db..c39c6975bdb 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java @@ -103,6 +103,8 @@ public interface ISettings extends IConf { List getProtectList(final String configName); + List getProtectListRaw(final String configName); + boolean getProtectPreventSpawn(final String creatureName); String getProtectString(final String configName); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Settings.java b/Essentials/src/main/java/com/earth2me/essentials/Settings.java index 4f490d5841a..938738e2432 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Settings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Settings.java @@ -1091,14 +1091,23 @@ public boolean getProtectPreventSpawn(final String creatureName) { } @Override - public List getProtectList(final String configName) { - final List list = new ArrayList<>(); + public List getProtectListRaw(String configName) { + final List list = new ArrayList<>(); for (String itemName : config.getString(configName, "").split(",")) { itemName = itemName.trim(); if (itemName.isEmpty()) { continue; } + list.add(itemName); + } + return list; + } + + @Override + public List getProtectList(final String configName) { + final List list = new ArrayList<>(); + for (String itemName : getProtectListRaw(configName)) { Material mat = EnumUtil.getMaterial(itemName.toUpperCase()); if (mat == null) { diff --git a/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuild.java b/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuild.java index 54ec55aefd0..34f91007341 100644 --- a/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuild.java +++ b/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuild.java @@ -45,6 +45,12 @@ public boolean checkProtectionItems(final AntiBuildConfig list, final Material m return itemList != null && !itemList.isEmpty() && itemList.contains(mat); } + @Override + public boolean checkProtectionItems(final AntiBuildConfig list, final String mat) { + final List protectList = ess.getEssentials().getSettings().getProtectListRaw(list.getConfigName()); + return protectList != null && !protectList.isEmpty() && protectList.contains(mat); + } + @Override public EssentialsConnect getEssentialsConnect() { return ess; diff --git a/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java b/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java index 667ad808f6f..bd48746e939 100644 --- a/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java +++ b/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.antibuild; import com.earth2me.essentials.User; +import com.earth2me.essentials.utils.EnumUtil; import com.earth2me.essentials.utils.VersionUtil; import net.ess3.api.IEssentials; import org.bukkit.Material; @@ -274,29 +275,33 @@ public void onBlockEntityDamage(final EntityDamageByEntityEvent event) { } else if (event.getEntity() instanceof ArmorStand) { type = Material.ARMOR_STAND; } else if (event.getEntity() instanceof EnderCrystal) { - type = Material.END_CRYSTAL; + // There is no Material for Ender Crystals before 1.9. + type = EnumUtil.getMaterial("END_CRYSTAL"); } else { return; } - if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build") && !metaPermCheck(user, "break", type)) { + final boolean permCheck = type == null ? user.isAuthorized("essentials.build.break.END_CRYSTAL") : metaPermCheck(user, "break", type); + if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build") && !permCheck) { if (ess.getSettings().warnOnBuildDisallow()) { - user.sendTl("antiBuildBreak", type.toString()); + user.sendTl("antiBuildBreak", type != null ? type.toString() : "END_CRYSTAL"); } event.setCancelled(true); return; } - if (prot.checkProtectionItems(AntiBuildConfig.blacklist_break, type) && !user.isAuthorized("essentials.protect.exemptbreak")) { + final boolean blacklistCheck = type == null ? prot.checkProtectionItems(AntiBuildConfig.blacklist_break, "END_CRYSTAL") : prot.checkProtectionItems(AntiBuildConfig.blacklist_break, type); + if (blacklistCheck && !user.isAuthorized("essentials.protect.exemptbreak")) { if (ess.getSettings().warnOnBuildDisallow()) { - user.sendTl("antiBuildBreak", type.toString()); + user.sendTl("antiBuildBreak", type != null ? type.toString() : "END_CRYSTAL"); } event.setCancelled(true); return; } - if (prot.checkProtectionItems(AntiBuildConfig.alert_on_break, type) && !user.isAuthorized("essentials.protect.alerts.notrigger")) { - prot.getEssentialsConnect().alert(user, type.toString(), "alertBroke"); + final boolean alertCheck = type == null ? prot.checkProtectionItems(AntiBuildConfig.alert_on_break, "END_CRYSTAL") : prot.checkProtectionItems(AntiBuildConfig.alert_on_break, type); + if (alertCheck && !user.isAuthorized("essentials.protect.alerts.notrigger")) { + prot.getEssentialsConnect().alert(user, type != null ? type.toString() : "END_CRYSTAL", "alertBroke"); } } diff --git a/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/IAntiBuild.java b/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/IAntiBuild.java index 81aa7d3cbf5..ec3ca45a010 100644 --- a/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/IAntiBuild.java +++ b/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/IAntiBuild.java @@ -9,6 +9,8 @@ public interface IAntiBuild extends Plugin { boolean checkProtectionItems(final AntiBuildConfig list, final Material mat); + boolean checkProtectionItems(final AntiBuildConfig list, final String mat); + boolean getSettingBool(final AntiBuildConfig protectConfig); EssentialsConnect getEssentialsConnect();