From 0a031a0a925bdb6700967bb80fbc1daafce08c3a Mon Sep 17 00:00:00 2001 From: asofold Date: Wed, 20 Feb 2013 22:09:31 +0100 Subject: [PATCH] [BLEEDING] Add hidden config option to override block flags. This allows to override arbitrary blocks block-flags. --- .../nocheatplus/config/RootConfPaths.java | 1 + .../utilities/BlockProperties.java | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/config/RootConfPaths.java b/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/config/RootConfPaths.java index f3ae7c81..11a1ac55 100644 --- a/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/config/RootConfPaths.java +++ b/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/config/RootConfPaths.java @@ -11,5 +11,6 @@ public class RootConfPaths { // Sub-paths that are used with different path prefixes potentially. public static final String SUB_IGNOREPASSABLE = "ignorepassable"; public static final String SUB_ALLOWINSTANTBREAK = "allowinstantbreak"; + public static final String SUB_OVERRIDEFLAGS = "overrideflags"; } diff --git a/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/utilities/BlockProperties.java b/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/utilities/BlockProperties.java index d720ac12..464cb9c9 100644 --- a/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/utilities/BlockProperties.java +++ b/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/utilities/BlockProperties.java @@ -9,11 +9,13 @@ import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -671,6 +673,7 @@ public class BlockProperties { * Convenience method to parse a flag. * @param input * @return + * @throws InputMismatchException if failed to parse. */ public static long parseFlag(final String input){ final String ucInput = input.toUpperCase(); @@ -1253,6 +1256,48 @@ public class BlockProperties { setBlockProps(id, instantType); } } + + // Override block flags. + ConfigurationSection section = config.getConfigurationSection(pathPrefix + RootConfPaths.SUB_OVERRIDEFLAGS); + if (section != null){ + final Map entries = section.getValues(false); + boolean hasErrors = false; + for (final Entry entry : entries.entrySet()){ + final String key = entry.getKey(); + final Integer id = RawConfigFile.parseTypeId(key); + if (id == null || id < 0 || id >= 4096){ + LogUtil.logWarning("[NoCheatplus] Bad block id (" + pathPrefix + RootConfPaths.SUB_OVERRIDEFLAGS + "): " + key); + continue; + } + final Object obj = entry.getValue(); + if (!(obj instanceof String)){ + LogUtil.logWarning("[NoCheatplus] Bad flags at " + pathPrefix + RootConfPaths.SUB_OVERRIDEFLAGS + " for key: " + key); + hasErrors = true; + continue; + } + final Collection split = StringUtil.split((String) obj, ' ', ',', '/', '|', ';', '\t'); + long flags = 0; + boolean error = false; + for (final String input : split){ + if (input.isEmpty()) continue; + try{ + flags |= parseFlag(input); + } catch(InputMismatchException e){ + LogUtil.logWarning("[NoCheatplus] Bad flag at " + pathPrefix + RootConfPaths.SUB_OVERRIDEFLAGS + " for key " + key + " (skip setting flags for this block): " + input); + error = true; + hasErrors = true; + break; + } + } + if (error){ + continue; + } + blockFlags[id] = flags; + } + if (hasErrors){ + LogUtil.logInfo("[NoCheatPlus] Overriding block-flags was not entirely successful, all available flags: \n" + StringUtil.join(flagNameMap.values(), "|")); + } + } } // /**