mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-06-26 06:14:42 +02:00
Support configuration for breaking time overrides.
This commit is contained in:
parent
1a8c292015
commit
6bf5b4c180
|
@ -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.
|
||||
|
|
|
@ -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<String>(), 785);
|
||||
set(ConfPaths.COMPATIBILITY_BLOCKS + ConfPaths.SUB_OVERRIDEFLAGS + "." + Material.SNOW.name().toLowerCase(), "default", 785);
|
||||
// Make blocks ign_passable+ground_height.
|
||||
|
|
|
@ -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<String, Object> entries = section.getValues(false);
|
||||
boolean hasErrors = false;
|
||||
|
|
Loading…
Reference in New Issue
Block a user