Skip to content

Commit

Permalink
JSON book bugfix
Browse files Browse the repository at this point in the history
Might only work on 1.20.3+ needs testing on older versions.
  • Loading branch information
RockinChaos committed Dec 10, 2023
1 parent 00c64f3 commit 7547181
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/main/java/me/RockinChaos/itemjoin/item/ItemDesigner.java
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,8 @@ private void setJSONBookPages(final ItemMap itemMap) {
for (String pageString : pagesSection.getKeys(false)) {
List<String> pageList = itemMap.getNodeLocation().getStringList(".pages." + pageString);
rawPages.add(pageList);
StringBuilder textBuilder = new StringBuilder("[\"\"");
StringBuilder textBuilder = new StringBuilder("{\"text\":\"\",\"extra\":[");
boolean firstIn = true;
for (String string : pageList) {
Map<Integer, String> JSONBuilder = new HashMap<>();
String formatLine = string.replace("\n", "\\n");
Expand Down Expand Up @@ -554,15 +555,22 @@ private void setJSONBookPages(final ItemMap itemMap) {
}
}
}
textBuilder.append("}," + "{\"text\":\"\\n\",\"color\":\"reset\"}");
textBuilder.append("},{\"text\":\"\\n\"}");
firstIn = false;
}
} else if (formatLine.contains("raw:")) {
textBuilder.append(formatLine.replace("raw: ", "").replace("raw:", "").replace("[\"\"", "").replace("\"bold\":false}]", "\"bold\":false}").replace("\"bold\":true}]", "\"bold\":true}")).append(",").append("{\"text\":\"\\n\",\"color\":\"reset\"}");
String format = (!firstIn ? "," : "") + formatLine.replace("raw: ", "").replace("raw:", "").replace("[\"\",", "").replace("[\"\"", "").replace("\"bold\":false}]", "\"bold\":false}").replace("\"bold\":true}]", "\"bold\":true}");
if (format.endsWith("]")) {
format = StringUtils.replaceLast(format, "]", "");
}
textBuilder.append(format).append(",{\"text\":\"\\n\"}");
firstIn = false;
} else {
textBuilder.append("," + "{\"text\":\"").append(formatLine).append("\"}").append(",").append("{\"text\":\"\\n\",\"color\":\"reset\"}");
textBuilder.append(!firstIn ? "," : "").append("{\"text\":\"").append(formatLine).append("\"},{\"text\":\"\\n\"}");
firstIn = false;
}
}
JSONPages.add(textBuilder + "]");
JSONPages.add(textBuilder + "]}");
}
itemMap.setPages(JSONPages);
itemMap.setListPages(rawPages);
Expand Down

0 comments on commit 7547181

Please sign in to comment.