[AntiBuild] Fix ender crystal breaking on 1.8 (#6009)

Ugly fix but it works for now...

Fixes #4418

---------

Co-authored-by: MD <1917406+mdcfe@users.noreply.github.com>
This commit is contained in:
Josh Roy 2025-02-02 09:14:21 -05:00 committed by GitHub
parent 42121aa4be
commit 1a4d75ced7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 41 additions and 15 deletions

View File

@ -103,6 +103,8 @@ public interface ISettings extends IConf {
List<Material> getProtectList(final String configName); List<Material> getProtectList(final String configName);
List<String> getProtectListRaw(final String configName);
boolean getProtectPreventSpawn(final String creatureName); boolean getProtectPreventSpawn(final String creatureName);
String getProtectString(final String configName); String getProtectString(final String configName);

View File

@ -1091,14 +1091,23 @@ public class Settings implements net.ess3.api.ISettings {
} }
@Override @Override
public List<Material> getProtectList(final String configName) { public List<String> getProtectListRaw(String configName) {
final List<Material> list = new ArrayList<>(); final List<String> list = new ArrayList<>();
for (String itemName : config.getString(configName, "").split(",")) { for (String itemName : config.getString(configName, "").split(",")) {
itemName = itemName.trim(); itemName = itemName.trim();
if (itemName.isEmpty()) { if (itemName.isEmpty()) {
continue; continue;
} }
list.add(itemName);
}
return list;
}
@Override
public List<Material> getProtectList(final String configName) {
final List<Material> list = new ArrayList<>();
for (String itemName : getProtectListRaw(configName)) {
Material mat = EnumUtil.getMaterial(itemName.toUpperCase()); Material mat = EnumUtil.getMaterial(itemName.toUpperCase());
if (mat == null) { if (mat == null) {

View File

@ -45,6 +45,12 @@ public class EssentialsAntiBuild extends JavaPlugin implements IAntiBuild {
return itemList != null && !itemList.isEmpty() && itemList.contains(mat); return itemList != null && !itemList.isEmpty() && itemList.contains(mat);
} }
@Override
public boolean checkProtectionItems(final AntiBuildConfig list, final String mat) {
final List<String> protectList = ess.getEssentials().getSettings().getProtectListRaw(list.getConfigName());
return protectList != null && !protectList.isEmpty() && protectList.contains(mat);
}
@Override @Override
public EssentialsConnect getEssentialsConnect() { public EssentialsConnect getEssentialsConnect() {
return ess; return ess;

View File

@ -1,6 +1,7 @@
package com.earth2me.essentials.antibuild; package com.earth2me.essentials.antibuild;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.EnumUtil;
import com.earth2me.essentials.utils.VersionUtil; import com.earth2me.essentials.utils.VersionUtil;
import net.ess3.api.IEssentials; import net.ess3.api.IEssentials;
import org.bukkit.Material; import org.bukkit.Material;
@ -274,29 +275,35 @@ public class EssentialsAntiBuildListener implements Listener {
} else if (event.getEntity() instanceof ArmorStand) { } else if (event.getEntity() instanceof ArmorStand) {
type = Material.ARMOR_STAND; type = Material.ARMOR_STAND;
} else if (event.getEntity() instanceof EnderCrystal) { } 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 { } else {
return; return;
} }
if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build") && !metaPermCheck(user, "break", type)) { if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build")) {
final boolean permCheck = type == null ? user.isAuthorized("essentials.build.break.END_CRYSTAL") : metaPermCheck(user, "break", type);
if (!permCheck) {
if (ess.getSettings().warnOnBuildDisallow()) {
user.sendTl("antiBuildBreak", type != null ? type.toString() : "END_CRYSTAL");
}
event.setCancelled(true);
return;
}
}
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()) { if (ess.getSettings().warnOnBuildDisallow()) {
user.sendTl("antiBuildBreak", type.toString()); user.sendTl("antiBuildBreak", type != null ? type.toString() : "END_CRYSTAL");
} }
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_break, type) && !user.isAuthorized("essentials.protect.exemptbreak")) { final boolean alertCheck = type == null ? prot.checkProtectionItems(AntiBuildConfig.alert_on_break, "END_CRYSTAL") : prot.checkProtectionItems(AntiBuildConfig.alert_on_break, type);
if (ess.getSettings().warnOnBuildDisallow()) { if (alertCheck && !user.isAuthorized("essentials.protect.alerts.notrigger")) {
user.sendTl("antiBuildBreak", type.toString()); prot.getEssentialsConnect().alert(user, type != null ? type.toString() : "END_CRYSTAL", "alertBroke");
}
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");
} }
} }

View File

@ -9,6 +9,8 @@ import java.util.Map;
public interface IAntiBuild extends Plugin { public interface IAntiBuild extends Plugin {
boolean checkProtectionItems(final AntiBuildConfig list, final Material mat); boolean checkProtectionItems(final AntiBuildConfig list, final Material mat);
boolean checkProtectionItems(final AntiBuildConfig list, final String mat);
boolean getSettingBool(final AntiBuildConfig protectConfig); boolean getSettingBool(final AntiBuildConfig protectConfig);
EssentialsConnect getEssentialsConnect(); EssentialsConnect getEssentialsConnect();