Add Comments Option

This commit is contained in:
RayzsYT committed 2024-06-28 02:03:21 +02:00
1 parent 204dfa0b24
commit fdcdd325a6
1 file changed
+18 -3
@@ -31,8 +31,8 @@ public class ConfigUpdater {
}
}
public static int[] getSectionPositionByTarget(ConfigurationBuilder configurationBuilder, String targetPath) {
List<String> lines;
public static int[] getSectionPositionByTarget(ConfigurationBuilder configurationBuilder, String targetPath, boolean comments) {
List<String> lines = new LinkedList<>();
HashMap<Integer, String> hash = new HashMap<>();
int sections = 0;
@@ -91,7 +91,22 @@ public class ConfigUpdater {
position--;
} while (spaces != 0);
if(sectionPath.toString().equals(targetPath)) return new int[] { targetPath.contains(".") ? finalStartPos : finalEndPos, finalEndPos };
if(sectionPath.toString().equals(targetPath)) {
finalStartPos = targetPath.contains(".") ? finalStartPos : finalEndPos;
if(comments) {
int i;
for(i = finalStartPos; i > 0; i--) {
line = StringUtils.getLineText(lines, i);
if(line != null && !line.startsWith("#")) {
finalStartPos = i;
break;
}
}
}
return new int[] { finalStartPos, finalEndPos };
}
}
return new int[] {0, 0};