1.0.1:Fix bug:[21:01:10 INFO]: [PBL] §a========================================

[21:01:10 INFO]: [PBL] §ePlayerBlockLife v1.0.1-1.20.4 已启用
              [21:01:10 INFO]: [PBL] §e作者: [YourName]
              [21:01:10 INFO]: [PBL] §a========================================
This commit is contained in:
xiaobai
2026-02-13 22:03:17 +08:00
parent f899540449
commit 8b502459b0
10 changed files with 737 additions and 138 deletions

View File

@@ -34,32 +34,43 @@ public class PlayerBlockManager {
}
/**
* 为玩家设置生命方块
* 为玩家设置生命方块(兼容旧方法)
*/
public boolean setLifeBlocks(Player player, Location center) {
ConfigManager config = plugin.getConfigManager();
int blockAmount = config.getBlocksPerPlayer();
int spreadRange = config.getSpreadRange();
boolean requireOpenSky = config.isRequireOpenSky();
int maxAttempts = config.getMaxAttempts();
return generateLifeBlocksForPlayer(player, blockAmount, spreadRange, requireOpenSky, maxAttempts);
}
/**
* 为玩家生成生命方块(新方法,支持自动生成)
*/
public boolean generateLifeBlocksForPlayer(Player player, int blockAmount, int spreadRange, boolean requireOpenSky, int maxAttempts) {
UUID playerId = player.getUniqueId();
String playerName = player.getName();
// 检查是否已有生命方块
if (hasLifeBlocks(playerId)) {
player.sendMessage("§c你已经有生命方块了");
player.sendMessage("§e使用 /checklifeblocks 查看位置");
return false;
}
// 检查玩家皮肤是否已加载
if (!skinManager.isSkinLoaded(playerId)) {
player.sendMessage("§e你的皮肤正在加载中请稍候...");
player.sendMessage("§7(如果长时间未加载完成,请重新加入服务器)");
return false;
}
List<Location> blocks = new ArrayList<>();
int blocksPlaced = 0;
int attempts = 0;
// 尝试在中心周围生成5个方块
for (int attempt = 0; attempt < 20 && blocksPlaced < 5; attempt++) {
Location blockLoc = findSuitableLocation(center);
// 尝试生成指定数量的方块
while (blocksPlaced < blockAmount && attempts < maxAttempts) {
Location blockLoc = findSurfaceLocation(player.getLocation(), spreadRange, requireOpenSky);
attempts++;
if (blockLoc != null && placePlayerHead(blockLoc, playerId, playerName)) {
blocks.add(blockLoc);
@@ -74,22 +85,70 @@ public class PlayerBlockManager {
if (blocksPlaced > 0) {
playerBlocks.put(playerId, blocks);
saveData();
player.sendMessage("§a========================================");
player.sendMessage("§a成功生成 §e" + blocksPlaced + " §a个生命方块");
player.sendMessage("§6方块使用了你的皮肤头像");
player.sendMessage("§c⚠ 警告: 方块被挖光时,你将死亡!");
player.sendMessage("§7使用 /checklifeblocks 查看方块位置");
player.sendMessage("§a========================================");
return true;
} else {
player.sendMessage("§c无法生成生命方块");
player.sendMessage("§7请确保周围有足够的空间至少5个可放置位置");
return false;
}
}
/**
* 寻找地表位置(上方无方块覆盖)
*/
private Location findSurfaceLocation(Location center, int spreadRange, boolean requireOpenSky) {
for (int i = 0; i < 10; i++) {
int x = random.nextInt(spreadRange * 2 + 1) - spreadRange;
int z = random.nextInt(spreadRange * 2 + 1) - spreadRange;
// 从中心点上方开始向下寻找地表
Location testLoc = center.clone().add(x, 10, z);
World world = testLoc.getWorld();
if (world == null) continue;
// 向下寻找第一个非空气方块
Block groundBlock = null;
for (int y = 10; y > world.getMinHeight(); y--) {
testLoc.setY(y);
Block block = testLoc.getBlock();
if (!block.getType().isAir()) {
groundBlock = block;
break;
}
}
if (groundBlock == null) continue;
// 检查地表方块上方位置
Location surfaceLoc = groundBlock.getLocation().add(0, 1, 0);
Block surfaceBlock = surfaceLoc.getBlock();
// 检查是否已有方块
if (blockOwners.containsKey(surfaceLoc)) {
continue;
}
// 检查地表方块是否合适
if (!isSuitableLocation(surfaceLoc)) {
continue;
}
// 如果需要上方无方块覆盖,检查上方
if (requireOpenSky) {
boolean hasCover = false;
for (int y = 1; y <= 5; y++) {
Block aboveBlock = surfaceLoc.clone().add(0, y, 0).getBlock();
if (!aboveBlock.getType().isAir()) {
hasCover = true;
break;
}
}
if (hasCover) continue;
}
return surfaceLoc;
}
return null;
}
/**
* 寻找合适的位置
*/