Skip to content

Commit

Permalink
fixed bug where duplicate comments with leading whitespace were ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
nossr50 committed Jan 12, 2022
1 parent 5d2028b commit db0ae36
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -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>
Expand Down
25 changes: 23 additions & 2 deletions src/main/java/com/gmail/nossr50/config/BukkitConfig.java
Expand Up @@ -11,7 +11,9 @@
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;
Expand Down Expand Up @@ -149,7 +151,11 @@ private void purgeComments(boolean silentFail) {
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
Expand Down Expand Up @@ -189,4 +195,19 @@ private void purgeComments(boolean silentFail) {
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;
}
}

0 comments on commit db0ae36

Please sign in to comment.