15m37 已签收玩家成书静默刷新: checkAndShowPending无待签收分支对已签收玩家重跑createBookItem, 替换背包旧成书书物品(不弹GUI不openBook不要求重签), 让玩家不管何时签收的都能按当前jar标准读出成书(如15m36链接补来源)
Auto Release / build (push) Successful in 5m1s
Auto Release / build (push) Successful in 5m1s
This commit is contained in:
@@ -169,6 +169,9 @@ public class CustomScreenManager implements Listener {
|
|||||||
String[] notiFiles = findPlayerPendingFiles(notiDir, name);
|
String[] notiFiles = findPlayerPendingFiles(notiDir, name);
|
||||||
|
|
||||||
if (agrFiles.length == 0 && notiFiles.length == 0) {
|
if (agrFiles.length == 0 && notiFiles.length == 0) {
|
||||||
|
// 15m37 静默刷新: 已签收玩家(无待签收)也按当前 jar 重新生成成书, 替换背包里的旧成书书物品,
|
||||||
|
// 让玩家"不管何时签收的都能按新标准读出来"。不弹GUI、不openBook、不要求重签, 仅静默刷新背包成书。
|
||||||
|
silentRefreshSignedBook(p, name, agrDir, ackDirAgr);
|
||||||
plugin.getLogger().info("[自定义屏幕] " + name + " 无待签收(全局协议=" + agrFiles.length + " 玩家通知=" + notiFiles.length + ")");
|
plugin.getLogger().info("[自定义屏幕] " + name + " 无待签收(全局协议=" + agrFiles.length + " 玩家通知=" + notiFiles.length + ")");
|
||||||
return; // 无待签收
|
return; // 无待签收
|
||||||
}
|
}
|
||||||
@@ -245,6 +248,48 @@ public class CustomScreenManager implements Listener {
|
|||||||
return pending.toArray(new String[0]);
|
return pending.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 15m37 静默刷新已签收玩家的成书: 扫 用户协议 目录, 对玩家已签收的 .md(回执存在)
|
||||||
|
* 按当前 jar 重新 createBookItem 生成新成书, 替换玩家背包里的旧成书书物品。
|
||||||
|
* 不弹GUI、不openBook、不要求重签 —— 让玩家"不管何时签收的都能按新标准读出来"。
|
||||||
|
* 仅当背包里已有同类成书书物品时替换(避免往满背包塞新书打扰玩家)。
|
||||||
|
*/
|
||||||
|
private void silentRefreshSignedBook(Player p, String name, File agrDir, File ackDir) {
|
||||||
|
if (agrDir == null || !agrDir.exists() || !agrDir.isDirectory()) return;
|
||||||
|
File[] files = agrDir.listFiles((d, n) -> n.endsWith(".md"));
|
||||||
|
if (files == null || files.length == 0) return;
|
||||||
|
// 回执: 玩家名.md 存在=已签收
|
||||||
|
File ackFile = new File(ackDir, name + ".md");
|
||||||
|
if (!ackFile.exists() || ackFile.length() == 0) return; // 未签收, 走正常弹窗路径, 不在此刷新
|
||||||
|
|
||||||
|
// 已签收: 重新生成新成书
|
||||||
|
for (File f : files) {
|
||||||
|
String content;
|
||||||
|
try {
|
||||||
|
content = new String(Files.readAllBytes(f.toPath()));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String displayContent = stripJsonBlock(content);
|
||||||
|
try {
|
||||||
|
ItemStack newBook = createBookItem(displayContent, f.getName());
|
||||||
|
if (newBook == null || newBook.getType() != Material.WRITTEN_BOOK) continue;
|
||||||
|
// 背包里找旧成书书物品(WRITTEN_BOOK)替换为新书; 找不到旧书则不动(避免塞满背包)
|
||||||
|
org.bukkit.inventory.Inventory inv = p.getInventory();
|
||||||
|
int oldIdx = -1;
|
||||||
|
for (int i = 0; i < inv.getStorageContents().length; i++) {
|
||||||
|
ItemStack it = inv.getItem(i);
|
||||||
|
if (it != null && it.getType() == Material.WRITTEN_BOOK) { oldIdx = i; break; }
|
||||||
|
}
|
||||||
|
if (oldIdx >= 0) {
|
||||||
|
inv.setItem(oldIdx, newBook);
|
||||||
|
p.updateInventory();
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
break; // 一个全局协议足够
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 玩家通知:按 {玩家名}.*.md 匹配,签收回执 = 原文件名。
|
* 玩家通知:按 {玩家名}.*.md 匹配,签收回执 = 原文件名。
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user