Skip to content

Commit

Permalink
[AntiBuild] Fix ender crystal breaking on 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
JRoy committed Jan 13, 2025
1 parent 667b0f7 commit 3c73ee6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public interface ISettings extends IConf {

List<Material> getProtectList(final String configName);

List<String> getProtectListRaw(final String configName);

boolean getProtectPreventSpawn(final String creatureName);

String getProtectString(final String configName);
Expand Down
13 changes: 11 additions & 2 deletions Essentials/src/main/java/com/earth2me/essentials/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -1091,14 +1091,23 @@ public boolean getProtectPreventSpawn(final String creatureName) {
}

@Override
public List<Material> getProtectList(final String configName) {
final List<Material> list = new ArrayList<>();
public List<String> getProtectListRaw(String configName) {
final List<String> 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<Material> getProtectList(final String configName) {
final List<Material> list = new ArrayList<>();
for (String itemName : getProtectListRaw(configName)) {
Material mat = EnumUtil.getMaterial(itemName.toUpperCase());

if (mat == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> protectList = ess.getEssentials().getSettings().getProtectListRaw(list.getConfigName());
return protectList != null && !protectList.isEmpty() && protectList.contains(mat);
}

@Override
public EssentialsConnect getEssentialsConnect() {
return ess;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 3c73ee6

Please sign in to comment.