Skip to content

Commit

Permalink
Add toggle for removing all enchants on blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreeam-qwq committed Sep 8, 2024
1 parent 5f62771 commit 00a77f2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/main/java/cn/dreeam/surf/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Config {
public static String prefix;

// Anti Illegal
public static boolean antiIllegalCheckIllegalBlockEnabled, checkIllegalDamageEnabled, checkIllegalPotionEnabled, stackedTotemRevertAsOneEnabled, antiIllegalDeleteIllegalsWhenFoundEnabled, antiIllegalCheckWhenPlayerJoinEnabled, antiIllegalCheckWhenHopperTransferEnabled, antiIllegalCheckWhenInventoryCloseEnabled, antiIllegalCheckWhenInventoryOpenEnabled, antiIllegalCheckWhenItemPickupEnabled;
public static boolean antiIllegalCheckIllegalBlockEnabled, antiIllegalCheckRemoveBlockEnchantsEnabled, checkIllegalDamageEnabled, checkIllegalPotionEnabled, stackedTotemRevertAsOneEnabled, antiIllegalDeleteIllegalsWhenFoundEnabled, antiIllegalCheckWhenPlayerJoinEnabled, antiIllegalCheckWhenHopperTransferEnabled, antiIllegalCheckWhenInventoryCloseEnabled, antiIllegalCheckWhenInventoryOpenEnabled, antiIllegalCheckWhenItemPickupEnabled;
public static String antiIllegalCheckIllegalBlockMessage, checkIllegalDamageMessage, checkIllegalPotionMessage;
public static List<String> antiIllegalIllegalBlockList, antiIllegalIllegalItemFlagList, antiIllegalIllegalEnchantList, antiIllegalIllegalAttributeModifierList;

Expand All @@ -37,7 +37,12 @@ public static void initConfig() {
prefix = Surf.configManager().getString("Prefix", "&6&l[&b&lSurf&6&l]&6 ", "Message prefix");

// Anti Illegal
antiIllegalCheckIllegalBlockEnabled = Surf.configManager().getBoolean("anti-illegal.check-illegal-block.enabled", true);
antiIllegalCheckIllegalBlockEnabled = Surf.configManager().getBoolean("anti-illegal.check-illegal-block.enabled", true, """
Should remove illegal blocks when placed
You can define illegal blocks in anti-illegal.checks.illegal-block-list""");
antiIllegalCheckRemoveBlockEnchantsEnabled = Surf.configManager().getBoolean("anti-illegal.check-illegal-block.remove-block-enchants", true, """
Whether remove all enchantments on blocks directly
Disable it to check illegal enchants for block like other normal items.""");
antiIllegalCheckIllegalBlockMessage = Surf.configManager().getString("anti-illegal.check-illegal-block.message", "&6You can not use this illegal block.");

checkIllegalDamageEnabled = Surf.configManager().getBoolean("check-illegal-damage.enabled", false);
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/cn/dreeam/surf/util/ItemUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import cn.dreeam.surf.config.Config;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.Inventory;
Expand Down Expand Up @@ -217,7 +216,19 @@ private static ItemStack cleanIllegals(ItemStack i) {
// Clean illegal Enchantment
Map<Enchantment, Integer> enchants = i.getEnchantments();
if (i.getType().isBlock()) {
enchants.keySet().forEach(i::removeEnchantment);
if (Config.antiIllegalCheckRemoveBlockEnchantsEnabled) {
// Directly remove enchs
enchants.keySet().forEach(i::removeEnchantment);
} else {
// Correct enchs
enchants.keySet().forEach(ench -> {
String key = ench.getKey().getKey();
int level = enchants.get(ench);
if (illegalEnchantsMap.containsKey(key) && illegalEnchantsMap.get(key) > 0 && level > illegalEnchantsMap.get(key)) {
i.addEnchantment(ench, ench.getMaxLevel());
}
});
}
} else {
enchants.keySet().forEach(ench -> {
if (ench.canEnchantItem(i)) {
Expand Down

0 comments on commit 00a77f2

Please sign in to comment.