fixed bug where duplicate comments with leading whitespace were ignored

This commit is contained in:
nossr50 2022-01-11 19:22:28 -08:00
parent 5d2028b5dc
commit db0ae36fa7
2 changed files with 24 additions and 3 deletions

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId>
<version>2.1.208</version>
<version>2.1.209-SNAPSHOT</version>
<name>mcMMO</name>
<url>https://github.com/mcMMO-Dev/mcMMO</url>
<scm>

View File

@ -11,7 +11,9 @@ import java.util.List;
import java.util.Set;
public abstract class BukkitConfig {
public static final String CURRENT_CONFIG_PATCH_VER = "ConfigPatchVersion: 1";
public static final String CONFIG_PATCH_PREFIX = "ConfigPatchVersion:";
public static final String CURRENT_CONFIG_PATCH_VER = "ConfigPatchVersion: 2";
public static final char COMMENT_PREFIX = '#';
protected final String fileName;
protected final File configFile;
protected YamlConfiguration config;
@ -149,7 +151,11 @@ public abstract class BukkitConfig {
break;
}
if (line.startsWith("#")) {
//Older version, don't append this line
if(line.startsWith(CONFIG_PATCH_PREFIX))
continue;
if (isFirstCharAsciiCharacter(line, COMMENT_PREFIX)) {
if(seenBefore.contains(line))
dupedLines++;
else
@ -189,4 +195,19 @@ public abstract class BukkitConfig {
ex.printStackTrace();
}
}
private boolean isFirstCharAsciiCharacter(String line, char character) {
if(line == null || line.isEmpty()) {
return true;
}
for(Character c : line.toCharArray()) {
if(c.equals(' '))
continue;
return c.equals(character);
}
return false;
}
}