修复: PVP世界改FLAT+噪声圆形岛根除方形切割区块丢失 + 商城目录定时全量同步给PHP + 装备GUI响应优化(延迟20->5tick)
This commit is contained in:
@@ -254,78 +254,51 @@ public class PVPArenaManager implements Listener {
|
|||||||
* - 最多用 3 个不同种子尝试,只要找到一个出生点周围有正常陆地(score≥2)就接受
|
* - 最多用 3 个不同种子尝试,只要找到一个出生点周围有正常陆地(score≥2)就接受
|
||||||
* - 全部 3 次都是海洋 → 在最后一个世界上强制改造出生点区域为陆地平台
|
* - 全部 3 次都是海洋 → 在最后一个世界上强制改造出生点区域为陆地平台
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* 创建全新PVP世界 — FLAT 世界 + 手写噪声地形(圆形自然竞技岛,无四方形切割)
|
||||||
|
*
|
||||||
|
* ★ 2026-07-07 重构:抛弃 NORMAL 随机地形(易出海洋/虚空导致小平台)
|
||||||
|
* 与 forceTerraformSpawnArea 的 81x81 四方形草地岛(明显的方形切割边界)。
|
||||||
|
* 改用 FLAT 世界(基础为实心连续地形,杜绝虚空与区块丢失),
|
||||||
|
* 再用手写噪声生成器 generatePVPTerrain 生成半径 48 的圆形起伏竞技岛,
|
||||||
|
* 边缘自然衰减入周围平地,观感自然、加载迅速、永远有合格陆地。
|
||||||
|
*/
|
||||||
private void createPVPWorld() {
|
private void createPVPWorld() {
|
||||||
final int MAX_RETRIES = 3; // 最多尝试 3 个不同种子
|
long seed = worldSeedRandom.nextLong();
|
||||||
World pvpWorld = null;
|
plugin.getLogger().info("[PVP] 创建PVP世界 (FLAT+噪声地形 seed=" + seed + ")");
|
||||||
Location spawnLoc = null;
|
|
||||||
long seed = 0;
|
|
||||||
|
|
||||||
for (int attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
// 清理上次残留世界,确保是全新世界
|
||||||
seed = worldSeedRandom.nextLong();
|
File existing = new File(Bukkit.getWorldContainer(), PVP_WORLD_NAME);
|
||||||
plugin.getLogger().info("[PVP] 创建PVP世界 (第" + attempt + "/" + MAX_RETRIES + "次尝试, seed=" + seed + ")");
|
if (existing.exists()) moveWorldToTrash(existing);
|
||||||
|
|
||||||
// 清理上次尝试的世界(如果有)
|
// FLAT 世界:基础为实心连续地形,彻底消除虚空/区块丢失
|
||||||
if (pvpWorld != null) {
|
WorldCreator creator = new WorldCreator(PVP_WORLD_NAME);
|
||||||
try { Bukkit.unloadWorld(pvpWorld, false); } catch (Exception ignored) {}
|
creator.environment(World.Environment.NORMAL);
|
||||||
File worldDir = new File(Bukkit.getWorldContainer(), PVP_WORLD_NAME);
|
creator.type(WorldType.FLAT);
|
||||||
moveWorldToTrash(worldDir);
|
creator.seed(seed);
|
||||||
}
|
|
||||||
|
|
||||||
// 自然主世界地形
|
World pvpWorld = creator.createWorld();
|
||||||
WorldCreator creator = new WorldCreator(PVP_WORLD_NAME);
|
|
||||||
creator.environment(World.Environment.NORMAL);
|
|
||||||
creator.type(WorldType.NORMAL);
|
|
||||||
creator.seed(seed);
|
|
||||||
|
|
||||||
pvpWorld = creator.createWorld();
|
|
||||||
if (pvpWorld == null) {
|
|
||||||
plugin.getLogger().severe("[PVP] 无法创建PVP竞技场世界!(第" + attempt + "次)");
|
|
||||||
continue; // 试下一个种子
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置基本规则
|
|
||||||
pvpWorld.setPVP(true);
|
|
||||||
pvpWorld.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
|
|
||||||
pvpWorld.setGameRule(GameRule.DO_WEATHER_CYCLE, false);
|
|
||||||
pvpWorld.setTime(6000);
|
|
||||||
|
|
||||||
// ★ 扩大预生成半径到12个区块(384格),覆盖更大范围确保地形完整
|
|
||||||
preGenerateSpawnChunks(pvpWorld, 12);
|
|
||||||
spawnLoc = findSafeSpawn(pvpWorld);
|
|
||||||
|
|
||||||
if (spawnLoc != null && lastSpawnLandScore >= 2) {
|
|
||||||
// ✅ 找到合格陆地,接受这个世界
|
|
||||||
pvpWorld.setSpawnLocation(spawnLoc.getBlockX(), spawnLoc.getBlockY(), spawnLoc.getBlockZ());
|
|
||||||
plugin.getLogger().info("[PVP] ✅ 已创建PVP竞技场世界(自然主世界陆地地形 seed=" + seed + "): "
|
|
||||||
+ PVP_WORLD_NAME + " 出生点=(" + spawnLoc.getBlockX() + "," + spawnLoc.getBlockY() + "," + spawnLoc.getBlockZ()
|
|
||||||
+ ") 质量=" + lastSpawnLandScore);
|
|
||||||
return; // 成功,直接返回
|
|
||||||
}
|
|
||||||
|
|
||||||
// ❌ 质量不够(海洋/虚空)→ 记录日志后重试
|
|
||||||
String reason = (spawnLoc == null) ? "findSafeSpawn=null(疑似虚空)" : ("质量分=" + lastSpawnLandScore + "(海洋/孤岛)");
|
|
||||||
plugin.getLogger().warning("[PVP] ⚠️ 第" + attempt + "次种子出生点不合格(" + reason + "),将重试新种子...");
|
|
||||||
}
|
|
||||||
|
|
||||||
// ===== 全部重试都失败 → 在最后一个世界上强制造陆 =====
|
|
||||||
if (pvpWorld == null) {
|
if (pvpWorld == null) {
|
||||||
plugin.getLogger().severe("[PVP] " + MAX_RETRIES + "次创建全部失败!");
|
plugin.getLogger().severe("[PVP] 无法创建PVP竞技场世界!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getLogger().warning("[PVP] " + MAX_RETRIES + "次尝试均未找到合格陆地,在当前世界强制改造出生点区域...");
|
pvpWorld.setPVP(true);
|
||||||
|
pvpWorld.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
|
||||||
|
pvpWorld.setGameRule(GameRule.DO_WEATHER_CYCLE, false);
|
||||||
|
pvpWorld.setTime(6000);
|
||||||
|
pvpWorld.setKeepSpawnInMemory(true);
|
||||||
|
|
||||||
if (spawnLoc != null) {
|
// ★ 手写噪声地形:在原点周边生成圆形竞技岛(半径 48 格)
|
||||||
pvpWorld.setSpawnLocation(spawnLoc.getBlockX(), spawnLoc.getBlockY(), spawnLoc.getBlockZ());
|
generatePVPTerrain(pvpWorld, seed);
|
||||||
} else {
|
// 立即落盘,确保手写地形持久化、不被后续自动保存覆盖
|
||||||
pvpWorld.setSpawnLocation(0, 64, 0);
|
try { pvpWorld.save(); } catch (Exception ignored) {}
|
||||||
}
|
|
||||||
|
|
||||||
// ★ 强制造陆:在出生点周围 81x81 范围内铺成草地平原(比 20x20 保底平台大得多,且避免与保底平台并存)
|
// 出生点固定在世界原点上方地形顶部
|
||||||
forceTerraformSpawnArea(pvpWorld);
|
int groundY = getTopSolidY(pvpWorld, 0, 0);
|
||||||
|
pvpWorld.setSpawnLocation(0, groundY + 1, 0);
|
||||||
plugin.getLogger().info("[PVP] 已创建PVP竞技场世界(强制改造地形 seed=" + seed + "): " + PVP_WORLD_NAME
|
plugin.getLogger().info("[PVP] ✅ 已创建PVP竞技场世界(噪声地形 seed=" + seed
|
||||||
+ " 出生点已强制造陆");
|
+ ") 出生点=(0," + (groundY + 1) + ",0)");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -720,6 +693,17 @@ public class PVPArenaManager implements Listener {
|
|||||||
plugin.getLogger().warning("[PVP] 已生成保底出生平台: 中心(0," + (centerY+1) + ",0), 范围20x20");
|
plugin.getLogger().warning("[PVP] 已生成保底出生平台: 中心(0," + (centerY+1) + ",0), 范围20x20");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定列从顶部向下的第一个非空气、非流体方块 Y 坐标(用于确定出生点地形高度)
|
||||||
|
*/
|
||||||
|
private int getTopSolidY(World world, int x, int z) {
|
||||||
|
for (int y = 255; y >= 1; y--) {
|
||||||
|
Material t = world.getBlockAt(x, y, z).getType();
|
||||||
|
if (!t.isAir() && t != Material.WATER && t != Material.LAVA) return y;
|
||||||
|
}
|
||||||
|
return 64;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ★ 强制造陆(最后兜底):当连续多个随机种子都生成海洋/虚空时,
|
* ★ 强制造陆(最后兜底):当连续多个随机种子都生成海洋/虚空时,
|
||||||
* 在出生点周围强制改造出一块自然主世界风格的开阔陆地
|
* 在出生点周围强制改造出一块自然主世界风格的开阔陆地
|
||||||
@@ -1578,7 +1562,7 @@ public class PVPArenaManager implements Listener {
|
|||||||
&& player.getWorld().getName().equals(PVP_WORLD_NAME)) {
|
&& player.getWorld().getName().equals(PVP_WORLD_NAME)) {
|
||||||
onPlayerEnterPVPWorld(player);
|
onPlayerEnterPVPWorld(player);
|
||||||
}
|
}
|
||||||
}, 20L);
|
}, 5L);
|
||||||
|
|
||||||
player.sendMessage("§a§l正在前往PVP竞技场...");
|
player.sendMessage("§a§l正在前往PVP竞技场...");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ import org.bukkit.util.io.BukkitObjectOutputStream;
|
|||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -2099,6 +2101,44 @@ public class ShopManager implements Listener {
|
|||||||
return categories;
|
return categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将游戏内完整商品目录序列化为 JSON(供定时同步到 PHP Web 端)
|
||||||
|
*
|
||||||
|
* 结构:
|
||||||
|
* {
|
||||||
|
* "categories": [
|
||||||
|
* { "name":"分类名", "file":"文件名.md",
|
||||||
|
* "items":[ { "id":"...", "display_name":"...", "material":"DIAMOND",
|
||||||
|
* "buy_price":100, "sell_price":50 }, ... ] },
|
||||||
|
* ...
|
||||||
|
* ]
|
||||||
|
* }
|
||||||
|
* 注意:仅同步目录结构(分类/商品/价格),库存由 PHP 端动态管理,不在本 JSON 中覆盖。
|
||||||
|
*/
|
||||||
|
public String buildCatalogJson() {
|
||||||
|
JsonArray cats = new JsonArray();
|
||||||
|
for (ShopCategory cat : categories) {
|
||||||
|
JsonObject catObj = new JsonObject();
|
||||||
|
catObj.addProperty("name", cat.getName());
|
||||||
|
catObj.addProperty("file", cat.getFileName());
|
||||||
|
JsonArray items = new JsonArray();
|
||||||
|
for (ShopItem it : cat.getItems()) {
|
||||||
|
JsonObject itObj = new JsonObject();
|
||||||
|
itObj.addProperty("id", it.getId());
|
||||||
|
itObj.addProperty("display_name", it.getDisplayName());
|
||||||
|
itObj.addProperty("material", it.getMaterial() == null ? "STONE" : it.getMaterial().name());
|
||||||
|
itObj.addProperty("buy_price", it.getBuyPrice());
|
||||||
|
itObj.addProperty("sell_price", it.getSellPrice());
|
||||||
|
items.add(itObj);
|
||||||
|
}
|
||||||
|
catObj.add("items", items);
|
||||||
|
cats.add(catObj);
|
||||||
|
}
|
||||||
|
JsonObject root = new JsonObject();
|
||||||
|
root.add("categories", cats);
|
||||||
|
return root.toString();
|
||||||
|
}
|
||||||
|
|
||||||
// ===== 命令处理 =====
|
// ===== 命令处理 =====
|
||||||
|
|
||||||
public boolean handleCommand(
|
public boolean handleCommand(
|
||||||
@@ -2120,6 +2160,12 @@ public class ShopManager implements Listener {
|
|||||||
s.sendMessage("§a商店已重载,共 "
|
s.sendMessage("§a商店已重载,共 "
|
||||||
+ categories.size()
|
+ categories.size()
|
||||||
+ " 个分类");
|
+ " 个分类");
|
||||||
|
// ★ 重载后立即把最新目录异步同步到 PHP(游戏内增删分类/商品 → Web 端镜像)
|
||||||
|
if (plugin.webManager != null) {
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override public void run() { plugin.webManager.pushShopCatalog(); }
|
||||||
|
}.runTaskAsynchronously(plugin);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -900,6 +900,8 @@ public class WebManager {
|
|||||||
try { Thread.sleep(6000 + (long)(Math.random() * 8000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(6000 + (long)(Math.random() * 8000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("首次-syncShopData", () -> syncShopData());
|
submitNormalDbTask("首次-syncShopData", () -> syncShopData());
|
||||||
try { Thread.sleep(6000 + (long)(Math.random() * 8000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(6000 + (long)(Math.random() * 8000)); } catch (InterruptedException ignored) {}
|
||||||
|
submitNormalDbTask("首次-pushShopCatalog", () -> pushShopCatalog());
|
||||||
|
try { Thread.sleep(6000 + (long)(Math.random() * 8000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("首次-syncBondBalances", () -> syncBondBalances());
|
submitNormalDbTask("首次-syncBondBalances", () -> syncBondBalances());
|
||||||
try { Thread.sleep(6000 + (long)(Math.random() * 8000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(6000 + (long)(Math.random() * 8000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("首次-syncBondTransactions", () -> syncBondTransactions());
|
submitNormalDbTask("首次-syncBondTransactions", () -> syncBondTransactions());
|
||||||
@@ -1409,6 +1411,7 @@ public class WebManager {
|
|||||||
try { Thread.sleep(6000 + (long)(Math.random() * 8000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(6000 + (long)(Math.random() * 8000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("周期-pullShopPrices", () -> pullShopPrices());
|
submitNormalDbTask("周期-pullShopPrices", () -> pullShopPrices());
|
||||||
submitNormalDbTask("周期-pullShopConfig", () -> pullShopConfig());
|
submitNormalDbTask("周期-pullShopConfig", () -> pullShopConfig());
|
||||||
|
submitNormalDbTask("周期-pushShopCatalog", () -> pushShopCatalog());
|
||||||
try { Thread.sleep(6000 + (long)(Math.random() * 8000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(6000 + (long)(Math.random() * 8000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("周期-pullBondChanges", () -> pullBondChanges());
|
submitNormalDbTask("周期-pullBondChanges", () -> pullBondChanges());
|
||||||
try { Thread.sleep(6000 + (long)(Math.random() * 8000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(6000 + (long)(Math.random() * 8000)); } catch (InterruptedException ignored) {}
|
||||||
@@ -6615,6 +6618,28 @@ public class WebManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 推送游戏内完整商品目录到 PHP(商城定时同步:游戏内增删分类/商品 → Web 端镜像)
|
||||||
|
* 安全护栏:目录为空时不推送,避免误清空 PHP 端商品表。
|
||||||
|
*/
|
||||||
|
public void pushShopCatalog() {
|
||||||
|
try {
|
||||||
|
ShopManager sm = plugin.getShopManager();
|
||||||
|
if (sm == null || sm.getCategories().isEmpty()) {
|
||||||
|
plugin.getLogger().info("[商品同步] 游戏内目录为空,跳过推送(防止误清空PHP)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String json = sm.buildCatalogJson();
|
||||||
|
String urlStr = webBaseUrl + "/api/sync.php?action=set_shop_catalog&secret="
|
||||||
|
+ java.net.URLEncoder.encode(secretKey, "UTF-8");
|
||||||
|
String resp = doPost(urlStr, json);
|
||||||
|
plugin.getLogger().info("[商品同步] 已推送游戏内商品目录到PHP"
|
||||||
|
+ (resp != null ? " 响应:" + resp : "(无响应)"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.getLogger().warning("[商品同步] 推送商品目录失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清除PHP端的管理员价格标记
|
* 清除PHP端的管理员价格标记
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user