Skip to content

Commit

Permalink
Fixed inline comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mikigal committed Feb 9, 2024
1 parent adf42d2 commit 7f11bc9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.MD
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ maven {
url = 'https://repo.mikigal.pl/releases'
}
compile group: 'pl.mikigal', name: 'ConfigAPI', version: '1.2.4'
compile group: 'pl.mikigal', name: 'ConfigAPI', version: '1.2.5'
```

#### Maven
Expand All @@ -34,7 +34,7 @@ compile group: 'pl.mikigal', name: 'ConfigAPI', version: '1.2.4'
<dependency>
<groupId>pl.mikigal</groupId>
<artifactId>ConfigAPI</artifactId>
<version>1.2.4</version>
<version>1.2.5</version>
<scope>compile</scope>
</dependency>
```
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'pl.mikigal'
version '1.2.4'
version '1.2.5'

publishing {
repositories {
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/pl/mikigal/config/BukkitConfiguration.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.file.YamlRepresenter;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import pl.mikigal.config.annotation.Comment;
import pl.mikigal.config.exception.InvalidConfigException;
import pl.mikigal.config.exception.MissingSerializerException;
Expand Down Expand Up @@ -112,6 +110,8 @@ public Object get(String path) {
*/
@Override
public String saveToString() {
this.overrideMaxLineWidth();

String yaml = super.saveToString();

List<String> lines = new ArrayList<>();
Expand Down Expand Up @@ -208,6 +208,21 @@ private void copyDefaultConfig() {
}
}

/**
* Set SnakeYaml's max line width to max Integer value.
* Required for inline comments
*/
private void overrideMaxLineWidth() {
try {
Field yamlOptionsField = YamlConfiguration.class.getDeclaredField("yamlOptions");
yamlOptionsField.setAccessible(true);
DumperOptions yamlOptions = (DumperOptions) yamlOptionsField.get(this);
yamlOptions.setWidth(Integer.MAX_VALUE);
} catch (Exception e) {
throw new RuntimeException("Could not set max YAML line width", e);
}
}

/**
* Add value to cache for optimization, to do not parse it every time user want to access it
* @param path path in config
Expand Down

0 comments on commit 7f11bc9

Please sign in to comment.