Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AntiBuild] Fix ender crystal breaking on 1.8 #6009

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading