修复垃圾站取回后SN lore丢失:取回改用DB原始存档还原,补挂SN行,背包满掉落防吞
Check Source / check (push) Successful in 4s
Auto Release / build (push) Successful in 2m4s
Simple Test / test (push) Successful in 2s
Test Env / test (push) Successful in 1s

This commit is contained in:
youpaishidifu
2026-10-02 11:45:01 +08:00
parent 4d34606d8e
commit 9cf9fd745c
2 changed files with 84 additions and 14 deletions
@@ -519,6 +519,38 @@ public class GarbageManager {
}
}
/**
* 取回前按 id 读原始存档(含原 lore 与 PDC)。
* GUI 展示副本的 lore 已被覆盖成
* 「ID/点击取出」,取回必须用这个还原,
* 否则 §8SN 行与物品说明 lore 会丢。
*
* @param id items 表主键
* @return 原始物品;读不到返回 null
*/
public ItemStack fetchItem(int id) {
try {
PreparedStatement ps = db.prepareStatement(
"SELECT item_data, amount FROM items "
+ "WHERE id=?");
ps.setInt(1, id);
ResultSet rs = ps.executeQuery();
ItemStack result = null;
if (rs.next()) {
result = base64ToStack(
rs.getString("item_data"));
if (result != null) {
result.setAmount(rs.getInt("amount"));
}
}
rs.close();
ps.close();
return result;
} catch (Exception e) {
return null;
}
}
public int getItemCount() {
try {
Statement st = db.createStatement();
+52 -14
View File
@@ -4573,28 +4573,66 @@ public class Main extends JavaPlugin
int dbId =
Integer.parseInt(
numStr);
// ★ 取回必须用 DB 原始存档:GUI 展示
// 副本的 lore 已被覆盖成「ID/点击取出
// 」,直接给玩家会抹掉 §8SN 行。
ItemStack original =
garbage.fetchItem(dbId);
if (garbage.removeItem(
dbId)) {
ItemStack give =
inSlot.clone();
ItemMeta gm =
give.getItemMeta();
if (gm == null)
gm = Bukkit
.getItemFactory()
.getItemMeta(
give
.getType());
gm.setLore(null);
give.setItemMeta(gm);
ItemStack give;
if (original != null) {
give = original;
} else {
// 兜底:存档读不到时退回展示
// 副本,剥掉展示行
give = inSlot.clone();
ItemMeta gm =
give.getItemMeta();
if (gm == null)
gm = Bukkit
.getItemFactory()
.getItemMeta(
give
.getType());
gm.setLore(null);
give.setItemMeta(gm);
}
// ★ SN 物品确保 §8SN 行在位(PDC 是
// 真值来源,lore 只是展示)
if (getSnManager() != null) {
String gsn =
getSnManager()
.readSn(give);
String gtype =
gsn == null
? null
: getSnManager()
.detectType(give);
if (gsn != null
&& gtype != null)
getSnManager()
.writeSn(
give,
gsn,
gtype);
}
java.util.Map<Integer,
ItemStack> left =
p.getInventory()
.addItem(give);
// 背包满 → 掉脚下,绝不吞物品
// (DB 已删,此处不能直接丢弃)
if (left != null
&& !left.isEmpty()) {
p.getWorld()
.dropItemNaturally(
p.getLocation(),
give);
}
// ★ SN 物品取回 → 回到本人身上,
// 脱离管控的 12 小时计时清零
if ((left == null || left.isEmpty())
&& getSnManager() != null) {
if (getSnManager() != null) {
getSnManager()
.onRecovered(give, p);
}