mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-08 16:12:18 -07:00
@@ -8,6 +8,7 @@ import java.io.Reader;
|
|||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@@ -80,7 +81,7 @@ public class YamlConfiguration extends FileConfiguration {
|
|||||||
node.setEndComments(getCommentLines(options().getFooter(), CommentType.BLOCK));
|
node.setEndComments(getCommentLines(options().getFooter(), CommentType.BLOCK));
|
||||||
|
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
if (node.getEndComments().isEmpty() && node.getEndComments().isEmpty() && node.getValue().isEmpty()) {
|
if (node.getBlockComments().isEmpty() && node.getEndComments().isEmpty() && node.getValue().isEmpty()) {
|
||||||
writer.write("");
|
writer.write("");
|
||||||
} else {
|
} else {
|
||||||
if (node.getValue().isEmpty()) {
|
if (node.getValue().isEmpty()) {
|
||||||
@@ -231,16 +232,23 @@ public class YamlConfiguration extends FileConfiguration {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the empty line at the end of the header that separates the header
|
* Removes the empty line at the end of the header that separates the header
|
||||||
* from further comments.
|
* from further comments. Also removes all empty header starts (backwards
|
||||||
|
* compat).
|
||||||
*
|
*
|
||||||
* @param header The list of heading comments
|
* @param header The list of heading comments
|
||||||
* @return The modified list
|
* @return The modified list
|
||||||
*/
|
*/
|
||||||
private List<String> loadHeader(List<String> header) {
|
private List<String> loadHeader(List<String> header) {
|
||||||
ArrayList<String> list = new ArrayList<String>(header);
|
LinkedList<String> list = new LinkedList<>(header);
|
||||||
if (list.size() != 0) {
|
|
||||||
list.remove(list.size() - 1);
|
if (!list.isEmpty()) {
|
||||||
|
list.removeLast();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (!list.isEmpty() && list.peek() == null) {
|
||||||
|
list.remove();
|
||||||
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,10 +260,12 @@ public class YamlConfiguration extends FileConfiguration {
|
|||||||
* @return The modified list
|
* @return The modified list
|
||||||
*/
|
*/
|
||||||
private List<String> saveHeader(List<String> header) {
|
private List<String> saveHeader(List<String> header) {
|
||||||
ArrayList<String> list = new ArrayList<String>(header);
|
LinkedList<String> list = new LinkedList<>(header);
|
||||||
if (list.size() != 0) {
|
|
||||||
|
if (!list.isEmpty()) {
|
||||||
list.add(null);
|
list.add(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -163,4 +163,15 @@ public class YamlConfigurationTest extends FileConfigurationTest {
|
|||||||
String result = config.saveToString();
|
String result = config.saveToString();
|
||||||
assertEquals(data, result);
|
assertEquals(data, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnlyHeader() {
|
||||||
|
YamlConfiguration config = getConfig();
|
||||||
|
config.options().header("# Test");
|
||||||
|
|
||||||
|
String result = config.saveToString();
|
||||||
|
String expected = "# # Test\n\n{}\n";
|
||||||
|
|
||||||
|
assertEquals(expected, result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user