修复6项问题:#804菜单[玩家名]方括号占位符、#805 PVP装备选择宽限期防误遣返、#808收银台附魔书NBT重建、#809商店退货精确扣货
This commit is contained in:
@@ -3893,7 +3893,7 @@ public class Main extends JavaPlugin
|
||||
.replaceAll("\\{玩家名\\}", playerName)
|
||||
.replaceAll("%玩家名%", playerName)
|
||||
.replaceAll("<玩家名>", playerName)
|
||||
.replaceAll("\\[玩家名\\}", playerName)
|
||||
.replaceAll("\\[玩家名\\]", playerName)
|
||||
.replaceAll("\\(玩家名\\)", playerName);
|
||||
// ★ 根据权限类型选择执行身份
|
||||
if ("控制台".equals(permType) || "console".equalsIgnoreCase(permType)) {
|
||||
|
||||
@@ -82,6 +82,13 @@ public class PVPArenaManager implements Listener {
|
||||
/** 装备选择超时时间(秒):进入PVP后此时间内必须确认,否则自动遣返 */
|
||||
private static final long EQUIPMENT_SELECT_TIMEOUT_SECONDS = 60L;
|
||||
|
||||
/** 装备GUI打开后的宽限期(毫秒):此窗口内的关闭事件视为世界加载/过渡导致的瞬时误触,
|
||||
* 忽略遣返并在玩家当前未打开任何GUI时自动重开,让其能正常选装备(避免地图加载即被踢)。 */
|
||||
private static final long EQUIPMENT_SELECT_GRACE_MILLIS = 3000L;
|
||||
|
||||
/** 宽限期内自动重开次数上限(防极端情况下世界持续强制关闭GUI导致死循环) */
|
||||
private final Map<String, Integer> graceReopenCount = new ConcurrentHashMap<>();
|
||||
|
||||
// 待执行的"空场冷却删除世界"定时任务(有人重新进入时取消)
|
||||
private BukkitTask pendingDeleteTask = null;
|
||||
|
||||
@@ -655,6 +662,30 @@ public class PVPArenaManager implements Listener {
|
||||
// 程序内重开装备GUI(切换档位)导致的旧GUI关闭,忽略,不遣返
|
||||
if (guiReopening.remove(player.getName())) return;
|
||||
|
||||
// ★ 宽限期:GUI 刚打开后短时间内(世界加载/过渡导致的瞬时关闭)视为误触,
|
||||
// 忽略遣返,并在玩家当前未打开任何 GUI 时延迟自动重开,让其能正常选装备。
|
||||
Long openedAt = guiOpenedMillis.get(player.getName());
|
||||
if (openedAt != null
|
||||
&& System.currentTimeMillis() - openedAt < EQUIPMENT_SELECT_GRACE_MILLIS) {
|
||||
plugin.getLogger().info("[PVP] 玩家 " + player.getName()
|
||||
+ " 装备GUI在宽限期内关闭,疑似过渡误触,延迟自动重开");
|
||||
int cnt = graceReopenCount.getOrDefault(player.getName(), 0);
|
||||
if (cnt < 4) {
|
||||
graceReopenCount.put(player.getName(), cnt + 1);
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> {
|
||||
if (inPVPArena.contains(player.getName())
|
||||
&& !equipmentConfirmed.contains(player.getName())
|
||||
&& player.isOnline()
|
||||
&& (player.getOpenInventory() == null
|
||||
|| player.getOpenInventory().getType()
|
||||
== org.bukkit.event.inventory.InventoryType.CRAFTING)) {
|
||||
openEquipmentSelection(player);
|
||||
}
|
||||
}, 5L);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// ★★★ 核心改进:基于确定性状态判断,而非猜测关闭原因 ★★★
|
||||
//
|
||||
// 方案:检查玩家是否已选择了装备档位(selectedTier 有值)
|
||||
@@ -787,6 +818,7 @@ public class PVPArenaManager implements Listener {
|
||||
inPVPArena.remove(playerName);
|
||||
guiReopening.remove(playerName);
|
||||
guiOpenedMillis.remove(playerName);
|
||||
graceReopenCount.remove(playerName);
|
||||
selectedTier.remove(playerName);
|
||||
if (p != null && p.isOnline()) {
|
||||
p.closeInventory();
|
||||
@@ -842,6 +874,7 @@ public class PVPArenaManager implements Listener {
|
||||
inventoryBackups.remove(playerName);
|
||||
guiReopening.remove(playerName);
|
||||
guiOpenedMillis.remove(playerName);
|
||||
graceReopenCount.remove(playerName);
|
||||
selectedTier.remove(playerName);
|
||||
cancelKickTimeout(playerName);
|
||||
|
||||
@@ -964,6 +997,7 @@ public class PVPArenaManager implements Listener {
|
||||
equipmentConfirmed.remove(player.getName());
|
||||
guiReopening.remove(player.getName());
|
||||
guiOpenedMillis.remove(player.getName());
|
||||
graceReopenCount.remove(player.getName());
|
||||
selectedTier.remove(player.getName());
|
||||
cancelKickTimeout(player.getName());
|
||||
}
|
||||
@@ -1105,8 +1139,9 @@ public class PVPArenaManager implements Listener {
|
||||
* 打开装备选择GUI
|
||||
*/
|
||||
public void openEquipmentSelection(Player player) {
|
||||
// ★ 记录GUI打开时间(宽限期机制:此后5秒内的关闭事件不触发遣返)
|
||||
// ★ 记录GUI打开时间(宽限期机制:此后短时间内内的关闭事件不触发遣返)
|
||||
guiOpenedMillis.put(player.getName(), System.currentTimeMillis());
|
||||
graceReopenCount.put(player.getName(), 0);
|
||||
|
||||
Inventory gui = Bukkit.createInventory(null, 54, EQUIPMENT_GUI_TITLE);
|
||||
|
||||
|
||||
@@ -1621,6 +1621,23 @@ public class ShopManager implements Listener {
|
||||
item.getMaterial(), amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商品显示名智能推断并构建物品(用于收银台购物车按名称重建附魔书等带NBT物品)。
|
||||
* 当 PHP 购物车携带真实显示名(含附魔关键词)时,可绕过"按材质匹配取目录首个附魔书导致NBT丢失"的问题。
|
||||
*/
|
||||
public ItemStack getShopStackByName(String name, Material mat, int amount) {
|
||||
if (name == null || name.isEmpty()) {
|
||||
return new ItemStack(mat, amount);
|
||||
}
|
||||
ItemStack inferred = inferFromName(name, mat);
|
||||
if (inferred != null) {
|
||||
ItemStack copy = inferred.clone();
|
||||
copy.setAmount(amount);
|
||||
return copy;
|
||||
}
|
||||
return new ItemStack(mat, amount);
|
||||
}
|
||||
|
||||
// ===== 购买 =====
|
||||
|
||||
public boolean buyItem(Player p, ShopItem item,
|
||||
@@ -2090,9 +2107,12 @@ public class ShopManager implements Listener {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 普通:扣商品
|
||||
p.getInventory().removeItem(
|
||||
new ItemStack(rec.material, rec.amount));
|
||||
// 普通:扣商品(用实际发放的物品做精确匹配,避免带NBT/改名物品删不掉导致"退货不扣货")
|
||||
ShopItem si = findItemById(rec.itemId);
|
||||
ItemStack target = (si != null)
|
||||
? getShopStack(si, rec.amount)
|
||||
: new ItemStack(rec.material, rec.amount);
|
||||
p.getInventory().removeItem(target);
|
||||
}
|
||||
|
||||
// 退款:加债券
|
||||
|
||||
@@ -5931,8 +5931,8 @@ public class WebManager {
|
||||
String iid = it.has("item_id") ? it.get("item_id").getAsString() : "";
|
||||
int amt = it.has("amount") ? it.get("amount").getAsInt() : 0;
|
||||
if (!iid.isEmpty() && amt > 0) {
|
||||
entries.add(new CartEntry(iid, amt));
|
||||
String iname = it.has("name") ? it.get("name").getAsString() : iid;
|
||||
entries.add(new CartEntry(iid, amt, iname));
|
||||
int iprice = it.has("unit_price") ? it.get("unit_price").getAsInt() : 0;
|
||||
receiptItems.add(new OrderManager.OrderItem(iname, iid, iprice, iprice, amt));
|
||||
}
|
||||
@@ -5978,7 +5978,7 @@ public class WebManager {
|
||||
if ("shulker".equals(settlement)) {
|
||||
java.util.List<ItemStack> stacks = new java.util.ArrayList<>();
|
||||
for (CartEntry ce : entries) {
|
||||
ItemStack st = buildShopStack(ce.itemId, ce.amount);
|
||||
ItemStack st = buildShopStack(ce.itemId, ce.amount, ce.name);
|
||||
if (st != null) stacks.add(st);
|
||||
}
|
||||
java.util.List<ItemStack> boxes = packCartIntoShulkers(stacks, shulkerMat);
|
||||
@@ -6013,7 +6013,7 @@ public class WebManager {
|
||||
player.sendMessage("§6[商城] §f已打包为 §e" + boxes.size() + " §f个" + colorCn + "潜影盒(含小票书)");
|
||||
} else {
|
||||
for (CartEntry ce : entries) {
|
||||
dispatchItemByMaterialOrId(player, ce.itemId, ce.amount);
|
||||
dispatchItemByMaterialOrId(player, ce.itemId, ce.amount, ce.name);
|
||||
}
|
||||
}
|
||||
if ("cash".equals(payMode)) {
|
||||
@@ -6163,6 +6163,14 @@ public class WebManager {
|
||||
* 通过Material名称或商品ID发放商品(兼容PHP传Material名称的情况)
|
||||
*/
|
||||
private void dispatchItemByMaterialOrId(Player player, String itemId, int amount) {
|
||||
dispatchItemByMaterialOrId(player, itemId, amount, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发放单个商品(支持按购物车携带的真实显示名重建附魔书等带NBT物品)。
|
||||
* name 为 PHP 购物车携带的真实显示名(含附魔关键词),用于修正材质匹配取到裸附魔书的问题。
|
||||
*/
|
||||
private void dispatchItemByMaterialOrId(Player player, String itemId, int amount, String name) {
|
||||
try {
|
||||
plugin.getLogger().info("[Web交易] 发放商品(材料匹配): " + itemId + " x" + amount + " 给 " + player.getName());
|
||||
|
||||
@@ -6202,6 +6210,19 @@ public class WebManager {
|
||||
}
|
||||
}
|
||||
|
||||
// ★ 附魔书NBT修复:购物车携带真实显示名时,优先按名称重建附魔书,
|
||||
// 确保 enchantments NBT 正确。仅当按名称解析出带存储附魔的书时才覆盖。
|
||||
if (itemStack != null
|
||||
&& itemStack.getType() == org.bukkit.Material.ENCHANTED_BOOK
|
||||
&& name != null && !name.isEmpty()) {
|
||||
org.bukkit.inventory.ItemStack fromName = plugin.getShopManager().getShopStackByName(name, org.bukkit.Material.ENCHANTED_BOOK, amount);
|
||||
if (fromName != null
|
||||
&& fromName.getItemMeta() instanceof org.bukkit.inventory.meta.EnchantmentStorageMeta fesm
|
||||
&& !fesm.getStoredEnchants().isEmpty()) {
|
||||
itemStack = fromName;
|
||||
}
|
||||
}
|
||||
|
||||
if (itemStack != null) {
|
||||
java.util.HashMap<Integer, org.bukkit.inventory.ItemStack> leftover = player.getInventory().addItem(itemStack);
|
||||
if (!leftover.isEmpty()) {
|
||||
@@ -6272,16 +6293,22 @@ public class WebManager {
|
||||
private static class CartEntry {
|
||||
final String itemId;
|
||||
final int amount;
|
||||
final String name;
|
||||
CartEntry(String itemId, int amount) {
|
||||
this(itemId, amount, null);
|
||||
}
|
||||
CartEntry(String itemId, int amount, String name) {
|
||||
this.itemId = itemId;
|
||||
this.amount = amount;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过商品ID或Material名称构建商品ItemStack(不立即发放)
|
||||
* name 为 PHP 购物车携带的真实显示名(含附魔关键词),用于附魔书等带NBT物品按名称重建
|
||||
*/
|
||||
private ItemStack buildShopStack(String itemId, int amount) {
|
||||
private ItemStack buildShopStack(String itemId, int amount, String name) {
|
||||
if (plugin.getShopManager() == null) return null;
|
||||
ItemStack itemStack = null;
|
||||
try {
|
||||
@@ -6302,6 +6329,19 @@ public class WebManager {
|
||||
Sdf1_login.ShopItem shopItem = plugin.getShopManager().findItemById(itemId);
|
||||
if (shopItem != null) itemStack = plugin.getShopManager().getShopStack(shopItem, amount);
|
||||
}
|
||||
// ★ 附魔书NBT修复:购物车携带真实显示名时,优先按名称重建附魔书,
|
||||
// 确保 enchantments NBT 正确(避免按材质/ID 解析取到错误或无附魔的附魔书)。
|
||||
// 仅当按名称成功解析出带存储附魔的附魔书时才覆盖,否则保留原结果。
|
||||
if (itemStack != null
|
||||
&& itemStack.getType() == Material.ENCHANTED_BOOK
|
||||
&& name != null && !name.isEmpty()) {
|
||||
ItemStack fromName = plugin.getShopManager().getShopStackByName(name, Material.ENCHANTED_BOOK, amount);
|
||||
if (fromName != null
|
||||
&& fromName.getItemMeta() instanceof org.bukkit.inventory.meta.EnchantmentStorageMeta fesm
|
||||
&& !fesm.getStoredEnchants().isEmpty()) {
|
||||
itemStack = fromName;
|
||||
}
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user