第17轮修复4问题:①PVP模板世界改为懒加载(从onEnable移除,首次/pvp join时按需生成,消除启动卡50秒)②修复模板不存在导致无法加入PVP(ensurePVPTemplates先创建成功再加列表+复制前校验目录存在+递归重试)③confirmTransaction改同步调用+本地confirmedTxIds去重+PHP超时60s→3600s三管齐下修复重启重复发货bug;PHP端pull_pending_transactions不再选中processing状态交易
This commit is contained in:
@@ -516,8 +516,7 @@ public class Main extends JavaPlugin
|
|||||||
.registerEvents(pvPArenaManager, this);
|
.registerEvents(pvPArenaManager, this);
|
||||||
// 确保PVP世界存在
|
// 确保PVP世界存在
|
||||||
pvPArenaManager.ensurePVPWorldExists();
|
pvPArenaManager.ensurePVPWorldExists();
|
||||||
// 预生成PVP模板世界池(首次启动生成并存盘;之后仅校验,避免开战时实时生成地形卡服)
|
// PVP模板世界改为懒加载:首次 /pvp join 时按需创建(不再启动时同步生成,避免拖慢启动50秒)
|
||||||
pvPArenaManager.ensurePVPTemplates();
|
|
||||||
|
|
||||||
// 13 ====cypay债券====
|
// 13 ====cypay债券====
|
||||||
// 债券系统(独立DB)
|
// 债券系统(独立DB)
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ public class PVPArenaManager implements Listener {
|
|||||||
private World createPVPWorld() {
|
private World createPVPWorld() {
|
||||||
long t0 = System.currentTimeMillis();
|
long t0 = System.currentTimeMillis();
|
||||||
|
|
||||||
// 确保模板世界已就绪(首次生成,之后仅校验;生成在启动阶段完成,不卡服)
|
// 确保模板世界已就绪(懒加载:首次 /pvp join 时按需生成,不拖慢启动)
|
||||||
ensurePVPTemplates();
|
ensurePVPTemplates();
|
||||||
if (pvpTemplateNames.isEmpty()) {
|
if (pvpTemplateNames.isEmpty()) {
|
||||||
plugin.getLogger().severe("[PVP] 模板世界初始化失败,无法创建竞技场");
|
plugin.getLogger().severe("[PVP] 模板世界初始化失败,无法创建竞技场");
|
||||||
@@ -282,6 +282,18 @@ public class PVPArenaManager implements Listener {
|
|||||||
String tpl = pvpTemplateNames.get(worldSeedRandom.nextInt(pvpTemplateNames.size()));
|
String tpl = pvpTemplateNames.get(worldSeedRandom.nextInt(pvpTemplateNames.size()));
|
||||||
File tplFolder = new File(Bukkit.getWorldContainer(), tpl);
|
File tplFolder = new File(Bukkit.getWorldContainer(), tpl);
|
||||||
|
|
||||||
|
// ★ 安全检查:确认模板目录确实存在(防止外部删除或卸载后目录丢失)
|
||||||
|
if (!tplFolder.exists()) {
|
||||||
|
plugin.getLogger().warning("[PVP] 模板 " + tpl + " 目录不存在,从列表移除并重试");
|
||||||
|
pvpTemplateNames.remove(tpl);
|
||||||
|
if (pvpTemplateNames.isEmpty()) {
|
||||||
|
plugin.getLogger().severe("[PVP] 所有模板世界均不可用,无法创建竞技场");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// 递归重试(换一个模板)
|
||||||
|
return createPVPWorld();
|
||||||
|
}
|
||||||
|
|
||||||
// 随机新世界名(彻底绕开旧目录残留冲突)
|
// 随机新世界名(彻底绕开旧目录残留冲突)
|
||||||
deleteWorldFolderIfExists(pvpWorldName);
|
deleteWorldFolderIfExists(pvpWorldName);
|
||||||
this.pvpWorldName = PVP_WORLD_NAME + "_" + Long.toUnsignedString(worldSeedRandom.nextLong());
|
this.pvpWorldName = PVP_WORLD_NAME + "_" + Long.toUnsignedString(worldSeedRandom.nextLong());
|
||||||
@@ -322,9 +334,9 @@ public class PVPArenaManager implements Listener {
|
|||||||
if (!pvpTemplateNames.isEmpty()) return;
|
if (!pvpTemplateNames.isEmpty()) return;
|
||||||
for (int i = 0; i < PVP_TEMPLATE_POOL; i++) {
|
for (int i = 0; i < PVP_TEMPLATE_POOL; i++) {
|
||||||
String tpl = "pvp_tpl_" + i;
|
String tpl = "pvp_tpl_" + i;
|
||||||
pvpTemplateNames.add(tpl);
|
|
||||||
File folder = new File(Bukkit.getWorldContainer(), tpl);
|
File folder = new File(Bukkit.getWorldContainer(), tpl);
|
||||||
if (folder.exists()) {
|
if (folder.exists()) {
|
||||||
|
pvpTemplateNames.add(tpl); // ★ 仅在目录确认存在时才加入可用列表
|
||||||
plugin.getLogger().info("[PVP] 模板世界 " + tpl + " 已存在,跳过生成");
|
plugin.getLogger().info("[PVP] 模板世界 " + tpl + " 已存在,跳过生成");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -333,16 +345,22 @@ public class PVPArenaManager implements Listener {
|
|||||||
c.environment(World.Environment.NORMAL);
|
c.environment(World.Environment.NORMAL);
|
||||||
c.type(WorldType.NORMAL);
|
c.type(WorldType.NORMAL);
|
||||||
c.seed(seed);
|
c.seed(seed);
|
||||||
plugin.getLogger().info("[PVP] 首次生成模板世界 " + tpl + " 种子=" + seed + "(启动阶段,不卡服)");
|
plugin.getLogger().info("[PVP] 首次生成模板世界 " + tpl + " 种子=" + seed + "(懒加载,/pvp join 时触发)");
|
||||||
World w = Bukkit.createWorld(c);
|
World w = Bukkit.createWorld(c);
|
||||||
if (w == null) {
|
if (w == null) {
|
||||||
plugin.getLogger().severe("[PVP] 模板世界 " + tpl + " 生成失败");
|
plugin.getLogger().severe("[PVP] 模板世界 " + tpl + " 生成失败,该模板将不可用");
|
||||||
continue;
|
continue; // ★ 不加入 pvpTemplateNames,不会被选中复制
|
||||||
}
|
}
|
||||||
preGenerateSpawnChunksSync(w, 4);
|
preGenerateSpawnChunksSync(w, 4);
|
||||||
reapplyWorldRules(w);
|
reapplyWorldRules(w);
|
||||||
Bukkit.unloadWorld(w, true);
|
Bukkit.unloadWorld(w, true);
|
||||||
|
// ★ 卸载后再次确认目录仍存在(某些配置下 unloadWorld 可能删除目录)
|
||||||
|
if (folder.exists()) {
|
||||||
|
pvpTemplateNames.add(tpl);
|
||||||
plugin.getLogger().info("[PVP] 模板世界 " + tpl + " 已生成并存盘");
|
plugin.getLogger().info("[PVP] 模板世界 " + tpl + " 已生成并存盘");
|
||||||
|
} else {
|
||||||
|
plugin.getLogger().severe("[PVP] 模板世界 " + tpl + " 卸载后目录消失,该模板将不可用");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1204,6 +1204,9 @@ public class WebManager {
|
|||||||
private volatile long lastTransactionPullTime = 0;
|
private volatile long lastTransactionPullTime = 0;
|
||||||
private static final long MIN_PULL_INTERVAL_MS = 5000; // 最小拉取间隔5秒,防止过于频繁
|
private static final long MIN_PULL_INTERVAL_MS = 5000; // 最小拉取间隔5秒,防止过于频繁
|
||||||
|
|
||||||
|
// ★ 本轮会话已确认的交易ID集合(防止重启后异步confirm未完成导致PHP回退processing→pending从而重复发货)
|
||||||
|
private final java.util.Set<String> confirmedTxIds = java.util.concurrent.ConcurrentHashMap.newKeySet();
|
||||||
|
|
||||||
private void requestImmediateTransactionPull() {
|
private void requestImmediateTransactionPull() {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
if (now - lastTransactionPullTime < MIN_PULL_INTERVAL_MS) {
|
if (now - lastTransactionPullTime < MIN_PULL_INTERVAL_MS) {
|
||||||
@@ -5844,6 +5847,13 @@ public class WebManager {
|
|||||||
* 处理Web交易
|
* 处理Web交易
|
||||||
*/
|
*/
|
||||||
private void processWebTransaction(String txId, String playerName, String type, int amount, String detail) {
|
private void processWebTransaction(String txId, String playerName, String type, int amount, String detail) {
|
||||||
|
// ★ 去重检查:本会话已确认的交易不再重复处理(防止重启后PHP回退processing→pending导致重复发货)
|
||||||
|
if (confirmedTxIds.contains(txId)) {
|
||||||
|
plugin.getLogger().info("[Web交易] 跳过已确认交易: ID=" + txId + "(本会话已处理,可能PHP端confirm未持久化)");
|
||||||
|
confirmTransaction(txId); // 重新确认一次,确保PHP状态一致
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
plugin.getLogger().info("[Web交易] 处理交易: ID=" + txId + ", 玩家=" + playerName + ", 类型=" + type + ", 金额=" + amount + ", 详情=" + detail);
|
plugin.getLogger().info("[Web交易] 处理交易: ID=" + txId + ", 玩家=" + playerName + ", 类型=" + type + ", 金额=" + amount + ", 详情=" + detail);
|
||||||
boolean txSuccess = false;
|
boolean txSuccess = false;
|
||||||
String errorMsg = "";
|
String errorMsg = "";
|
||||||
@@ -6408,23 +6418,19 @@ public class WebManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 确认交易已处理
|
* 确认交易已处理(同步调用,确保PHP收到确认后才返回,防止重启后重复发货)
|
||||||
*/
|
*/
|
||||||
private void confirmTransaction(String txId) {
|
private void confirmTransaction(String txId) {
|
||||||
new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
|
confirmedTxIds.add(txId); // ★ 先标记本地已确认(即使HTTP失败也不会重复处理)
|
||||||
String bodyJson = "{\"tx_id\":\"" + txId + "\"}";
|
String bodyJson = "{\"tx_id\":\"" + txId + "\"}";
|
||||||
String postUrl = webBaseUrl + "/api/sync.php?action=confirm_transaction&secret="
|
String postUrl = webBaseUrl + "/api/sync.php?action=confirm_transaction&secret="
|
||||||
+ java.net.URLEncoder.encode(secretKey, "UTF-8");
|
+ java.net.URLEncoder.encode(secretKey, "UTF-8");
|
||||||
doPost(postUrl, bodyJson);
|
doPost(postUrl, bodyJson);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 静默处理
|
plugin.getLogger().warning("[Web交易] 确认交易 " + txId + " 失败(已标记本地已确认,不会重复处理): " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.runTaskAsynchronously(plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 拉取Web端修改的商品库存
|
* 拉取Web端修改的商品库存
|
||||||
|
|||||||
Reference in New Issue
Block a user