125续15l-7i 修: 成书封页去文件名(整本直接协议全文)+findSemanticCut切点越界根治(只收i<limit句末)
Auto Release / build (push) Successful in 4m51s
Auto Release / build (push) Successful in 4m51s
This commit is contained in:
@@ -371,35 +371,23 @@ public class CustomScreenManager implements Listener {
|
|||||||
}
|
}
|
||||||
org.bukkit.inventory.meta.BookMeta bookMeta = (org.bukkit.inventory.meta.BookMeta) meta;
|
org.bukkit.inventory.meta.BookMeta bookMeta = (org.bukkit.inventory.meta.BookMeta) meta;
|
||||||
|
|
||||||
// ★ 15l-7f:封页标题 = 协议内容第一行(trim 后非空),兜底 fileName
|
// ★ 15l-7i(用户定调):封页不放文件名/标题,整本书直接是协议全文。
|
||||||
String firstLine = "";
|
// 封页 = 正文前 ~380 字(贪心填充),避免封页只有一行的稀疏感。
|
||||||
for (String line : content.split("\\n")) {
|
bookMeta.setTitle("§6用户协议");
|
||||||
String t = line.trim();
|
|
||||||
if (!t.isEmpty()) { firstLine = t; break; }
|
|
||||||
}
|
|
||||||
String displayTitle = firstLine.isEmpty() ? new File(fileName).getName() : firstLine;
|
|
||||||
|
|
||||||
bookMeta.setTitle("§6" + displayTitle);
|
|
||||||
bookMeta.setAuthor("Sdf1_login");
|
bookMeta.setAuthor("Sdf1_login");
|
||||||
|
|
||||||
String titleLine = displayTitle;
|
|
||||||
String body = content == null ? "" : content.trim();
|
String body = content == null ? "" : content.trim();
|
||||||
|
|
||||||
// 正文按行规整:去 markdown 残留、压缩空行
|
// 正文按行规整:去 markdown 残留、压缩空行
|
||||||
body = markdownToPlain(body);
|
body = markdownToPlain(body);
|
||||||
|
|
||||||
java.util.List<String> pages = new java.util.ArrayList<>();
|
java.util.List<String> pages = new java.util.ArrayList<>();
|
||||||
|
|
||||||
// ★ 15l-7 封页补肉:把标题和正文前 ~350 字合在封页,避免封页太空
|
// ★ 15l-7i 封页补肉:正文前 ~380 字直接进封页(不单独放标题行)
|
||||||
String cover = titleLine;
|
|
||||||
if (!body.isEmpty()) {
|
if (!body.isEmpty()) {
|
||||||
int target = 350;
|
int target = 380;
|
||||||
int consumed = Math.min(body.length(), target);
|
int consumed = Math.min(body.length(), target);
|
||||||
cover = titleLine + "\n\n" + body.substring(0, consumed).trim();
|
pages.add(body.substring(0, consumed));
|
||||||
body = body.substring(consumed).trim();
|
body = body.substring(consumed);
|
||||||
pages.add(cover);
|
|
||||||
} else {
|
|
||||||
pages.add(cover);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!body.isEmpty()) {
|
if (!body.isEmpty()) {
|
||||||
@@ -543,33 +531,28 @@ public class CustomScreenManager implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在 limit 以内找最佳语义截断点(。!?;、章节号、行首)。
|
* 在 limit 以内找最佳语义截断点(。!?;、行首)。
|
||||||
* ★ 15l-7 修复:best 初始化逻辑改为“找不到语义边界时退化按逗号/空格切,再退化硬切”。
|
* ★ 15l-7i 修复:从后往前扫时只接受 i < limit 的句末标点(避免 best 落在 limit 之后
|
||||||
|
* 导致切点越界、丢内容)。扫不到则退化按逗号/空格,再退化硬切 limit。
|
||||||
*/
|
*/
|
||||||
private int findSemanticCut(String s, int limit) {
|
private int findSemanticCut(String s, int limit) {
|
||||||
if (s.length() <= limit) return s.length();
|
if (s.length() <= limit) return s.length();
|
||||||
int best = -1;
|
int best = -1;
|
||||||
for (int i = s.length() - 1; i >= 0; i--) {
|
for (int i = s.length() - 1; i >= 0; i--) {
|
||||||
char c = s.charAt(i);
|
char c = s.charAt(i);
|
||||||
|
// 只接受 limit 以内的语义边界(旧 bug:i>=limit 的句末也被设为 best,越界)
|
||||||
|
if (i < limit) {
|
||||||
if (c == '。' || c == '!' || c == '?' || c == ';' || c == '\n') {
|
if (c == '。' || c == '!' || c == '?' || c == ';' || c == '\n') {
|
||||||
best = i + 1;
|
best = i + 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ((c >= '1' && c <= '9')) {
|
|
||||||
String rest = s.substring(i + 1, Math.min(i + 3, s.length()));
|
|
||||||
if (rest.startsWith("、") || rest.startsWith(" ") || rest.startsWith(".")) {
|
|
||||||
best = i + 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (i < limit && c == '\n') {
|
|
||||||
best = i + 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (best <= 0 || best > limit) {
|
if (best <= 0 || best > limit) {
|
||||||
// 找不到语义边界,退化为按空格/逗号切
|
// 退化:limit 以内找逗号/空格
|
||||||
for (int i = s.length() - 1; i >= 0; i--) {
|
for (int i = Math.min(s.length() - 1, limit - 1); i >= 0; i--) {
|
||||||
if (s.charAt(i) == ' ' || s.charAt(i) == ',' || s.charAt(i) == ',' || s.charAt(i) == '、') {
|
char c = s.charAt(i);
|
||||||
|
if (c == ',' || c == ',' || c == '、' || c == ' ' || c == '\n') {
|
||||||
best = i + 1;
|
best = i + 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user