Skip to content

Commit 1a4d75c

Browse files
JRoymdcfe
andauthored
[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>
1 parent 42121aa commit 1a4d75c

File tree

5 files changed

+38
-12
lines changed

5 files changed

+38
-12
lines changed

Essentials/src/main/java/com/earth2me/essentials/ISettings.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ public interface ISettings extends IConf {
103103

104104
List<Material> getProtectList(final String configName);
105105

106+
List<String> getProtectListRaw(final String configName);
107+
106108
boolean getProtectPreventSpawn(final String creatureName);
107109

108110
String getProtectString(final String configName);

Essentials/src/main/java/com/earth2me/essentials/Settings.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,14 +1091,23 @@ public boolean getProtectPreventSpawn(final String creatureName) {
10911091
}
10921092

10931093
@Override
1094-
public List<Material> getProtectList(final String configName) {
1095-
final List<Material> list = new ArrayList<>();
1094+
public List<String> getProtectListRaw(String configName) {
1095+
final List<String> list = new ArrayList<>();
10961096
for (String itemName : config.getString(configName, "").split(",")) {
10971097
itemName = itemName.trim();
10981098
if (itemName.isEmpty()) {
10991099
continue;
11001100
}
11011101

1102+
list.add(itemName);
1103+
}
1104+
return list;
1105+
}
1106+
1107+
@Override
1108+
public List<Material> getProtectList(final String configName) {
1109+
final List<Material> list = new ArrayList<>();
1110+
for (String itemName : getProtectListRaw(configName)) {
11021111
Material mat = EnumUtil.getMaterial(itemName.toUpperCase());
11031112

11041113
if (mat == null) {

EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuild.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ public boolean checkProtectionItems(final AntiBuildConfig list, final Material m
4545
return itemList != null && !itemList.isEmpty() && itemList.contains(mat);
4646
}
4747

48+
@Override
49+
public boolean checkProtectionItems(final AntiBuildConfig list, final String mat) {
50+
final List<String> protectList = ess.getEssentials().getSettings().getProtectListRaw(list.getConfigName());
51+
return protectList != null && !protectList.isEmpty() && protectList.contains(mat);
52+
}
53+
4854
@Override
4955
public EssentialsConnect getEssentialsConnect() {
5056
return ess;

EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.earth2me.essentials.antibuild;
22

33
import com.earth2me.essentials.User;
4+
import com.earth2me.essentials.utils.EnumUtil;
45
import com.earth2me.essentials.utils.VersionUtil;
56
import net.ess3.api.IEssentials;
67
import org.bukkit.Material;
@@ -274,29 +275,35 @@ public void onBlockEntityDamage(final EntityDamageByEntityEvent event) {
274275
} else if (event.getEntity() instanceof ArmorStand) {
275276
type = Material.ARMOR_STAND;
276277
} else if (event.getEntity() instanceof EnderCrystal) {
277-
type = Material.END_CRYSTAL;
278+
// There is no Material for Ender Crystals before 1.9.
279+
type = EnumUtil.getMaterial("END_CRYSTAL");
278280
} else {
279281
return;
280282
}
281283

282-
if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build") && !metaPermCheck(user, "break", type)) {
283-
if (ess.getSettings().warnOnBuildDisallow()) {
284-
user.sendTl("antiBuildBreak", type.toString());
284+
if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build")) {
285+
final boolean permCheck = type == null ? user.isAuthorized("essentials.build.break.END_CRYSTAL") : metaPermCheck(user, "break", type);
286+
if (!permCheck) {
287+
if (ess.getSettings().warnOnBuildDisallow()) {
288+
user.sendTl("antiBuildBreak", type != null ? type.toString() : "END_CRYSTAL");
289+
}
290+
event.setCancelled(true);
291+
return;
285292
}
286-
event.setCancelled(true);
287-
return;
288293
}
289294

290-
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_break, type) && !user.isAuthorized("essentials.protect.exemptbreak")) {
295+
final boolean blacklistCheck = type == null ? prot.checkProtectionItems(AntiBuildConfig.blacklist_break, "END_CRYSTAL") : prot.checkProtectionItems(AntiBuildConfig.blacklist_break, type);
296+
if (blacklistCheck && !user.isAuthorized("essentials.protect.exemptbreak")) {
291297
if (ess.getSettings().warnOnBuildDisallow()) {
292-
user.sendTl("antiBuildBreak", type.toString());
298+
user.sendTl("antiBuildBreak", type != null ? type.toString() : "END_CRYSTAL");
293299
}
294300
event.setCancelled(true);
295301
return;
296302
}
297303

298-
if (prot.checkProtectionItems(AntiBuildConfig.alert_on_break, type) && !user.isAuthorized("essentials.protect.alerts.notrigger")) {
299-
prot.getEssentialsConnect().alert(user, type.toString(), "alertBroke");
304+
final boolean alertCheck = type == null ? prot.checkProtectionItems(AntiBuildConfig.alert_on_break, "END_CRYSTAL") : prot.checkProtectionItems(AntiBuildConfig.alert_on_break, type);
305+
if (alertCheck && !user.isAuthorized("essentials.protect.alerts.notrigger")) {
306+
prot.getEssentialsConnect().alert(user, type != null ? type.toString() : "END_CRYSTAL", "alertBroke");
300307
}
301308
}
302309

EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/IAntiBuild.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
public interface IAntiBuild extends Plugin {
1010
boolean checkProtectionItems(final AntiBuildConfig list, final Material mat);
1111

12+
boolean checkProtectionItems(final AntiBuildConfig list, final String mat);
13+
1214
boolean getSettingBool(final AntiBuildConfig protectConfig);
1315

1416
EssentialsConnect getEssentialsConnect();

0 commit comments

Comments
 (0)