diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java index 1e34ae47..b74b86a5 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java @@ -44,6 +44,7 @@ public abstract class ConfPaths { public static final String SUB_MODSPRINT = "modsprint"; /** No trailing dot! */ public static final String SUB_OVERRIDEFLAGS = "overrideflags"; + public static final String SUB_BREAKINGTIME = "breakingtime"; public static final String SUB_SPEED = "speed"; public static final String SUB_VERTICAL = "vertical"; public static final String SUB_VERTICALSPEED = "verticalspeed"; // Phase out. diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java index 9b46e2fc..92483d10 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java @@ -616,6 +616,7 @@ public class DefaultConfig extends ConfigFile { set(ConfPaths.COMPATIBILITY_EXEMPTIONS_REMOVE_LEAVE, true, 785); set(ConfPaths.COMPATIBILITY_SERVER_CBDEDICATED_ENABLE, true, 785); set(ConfPaths.COMPATIBILITY_SERVER_CBREFLECT_ENABLE, true, 785); + set(ConfPaths.COMPATIBILITY_BLOCKS + ConfPaths.SUB_BREAKINGTIME + ".IRON_BLOCK:PICKAXE:DIAMOND:12", 1); set(ConfPaths.COMPATIBILITY_BLOCKS + ConfPaths.SUB_ALLOWINSTANTBREAK, new LinkedList(), 785); set(ConfPaths.COMPATIBILITY_BLOCKS + ConfPaths.SUB_OVERRIDEFLAGS + "." + Material.SNOW.name().toLowerCase(), "default", 785); // Make blocks ign_passable+ground_height. diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/map/BlockProperties.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/map/BlockProperties.java index e1673097..2164498c 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/map/BlockProperties.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/map/BlockProperties.java @@ -427,6 +427,30 @@ public class BlockProperties { return efficiency; } + /** + * Add properties defined in a (config line of) string. + * + * @param def + * @return + * @throws All sorts of exceptions (number format, enum constants, runtime). + */ + public BlockBreakKey fromString(String def) { + String[] parts = def.split(":"); + // First fully parse: + if (parts.length != 4) { + throw new IllegalArgumentException("Accept key definition with 4 parts only, input: " + def); + } + Material blockType = Material.matchMaterial(parts[0]); + ToolType toolType = ToolType.valueOf(parts[1].toUpperCase()); + MaterialBase materialBase = MaterialBase.valueOf(parts[2].toUpperCase()); + int efficiency = Integer.parseInt(parts[3]); + return this + .blockType(blockType) + .toolType(toolType) + .materialBase(materialBase) + .efficiency(efficiency); + } + @Override public int hashCode() { // TODO: ... @@ -3086,6 +3110,19 @@ public class BlockProperties { */ public static void applyConfig(final RawConfigFile config, final String pathPrefix) { + // Breaking time overrides for specific side conditions. + ConfigurationSection section = config.getConfigurationSection(pathPrefix + ConfPaths.SUB_BREAKINGTIME); + for (final String input : section.getKeys(false)) { + try { + BlockProperties.setBreakingTimeOverride(new BlockBreakKey().fromString(input.trim()), + section.getLong(input)); + } + catch (Exception e) { + StaticLog.logWarning("Bad breaking time override (" + pathPrefix + ConfPaths.SUB_BREAKINGTIME + "): " + input); + StaticLog.logWarning(e); + } + } + // Allow instant breaking. for (final String input : config.getStringList(pathPrefix + ConfPaths.SUB_ALLOWINSTANTBREAK)) { final Material id = RawConfigFile.parseMaterial(input); @@ -3098,7 +3135,7 @@ public class BlockProperties { } // Override block flags. - ConfigurationSection section = config.getConfigurationSection(pathPrefix + ConfPaths.SUB_OVERRIDEFLAGS); + section = config.getConfigurationSection(pathPrefix + ConfPaths.SUB_OVERRIDEFLAGS); if (section != null) { final Map entries = section.getValues(false); boolean hasErrors = false;