测试版

This commit is contained in:
yaohunya 2024-07-23 21:26:30 +08:00
parent 6db1f114d5
commit 7d069aea91
4 changed files with 15 additions and 10 deletions

View File

@ -7,6 +7,7 @@ import me.Demon.BlockWars.Manager.MinerOperate;
import me.Demon.BlockWars.Util.BossBarUtil;
import me.Demon.BlockWars.Util.ComputeBlock;
import me.Demon.BlockWars.Util.GameUtil;
import me.Demon.BlockWars.api.BlockWarsAPI;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.boss.BarColor;
@ -73,10 +74,10 @@ public class GameData {
int a = this.totalBlockAmount;
int b = this.completeBlockGoal;
double percent = (double) a / (double) b;
System.out.println("[调试 - 进度] 填充进度: "+a+" b = "+b);
// System.out.println("[调试 - 进度] 填充进度: "+a+" b = "+b);
String percentShow = String.format("%.2f", (percent * 100));
bossBar2.setTitle("§6填充进度: §f"+a+"/"+b+" §9("+percentShow+"%)");
System.out.println("[调试 - 进度] 填充进度: "+percent);
// System.out.println("[调试 - 进度] 填充进度: "+percent);
BossBarUtil.setBarProgress(bossBar2,percent);
BossBarUtil.setBarColor(bossBar2,percent);
}
@ -116,6 +117,7 @@ public class GameData {
GameUtil.loadSchematics("miner_11x11"); // 初始化矿区模板
MinerOperate.initializeMinerSize(); // 初始化矿区大小
updateBossBar();
refreshBlockRgionList(16); // 拆分矿区
}
/*
* 初始化主播游戏参数: 生命值物品栏BossBar当前位置

View File

@ -4,6 +4,7 @@ import cn.hamster3.cdapi.CDTimeAPI;
import me.Demon.BlockWars.Game.Region;
import me.Demon.BlockWars.Main;
import me.Demon.BlockWars.Util.GameUtil;
import me.Demon.BlockWars.api.BlockWarsAPI;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
@ -165,6 +166,7 @@ public class GameListener implements Listener {
}
return;
}
long startTime = System.currentTimeMillis(); // 记录开始时间
Location location = block.getLocation();
int indexY = location.getBlockY();
for (int y = (int) region.getMin().getY(); y < indexY; y++) {
@ -195,6 +197,9 @@ public class GameListener implements Listener {
a++;
}
GameUtil.refreshPlayerHandStack(p);
long endTime = System.currentTimeMillis(); // 记录结束时间
long duration = endTime - startTime; // 计算耗时
System.out.println("[调试 - 快速] 本次搭建总计耗时 " + duration + " ms");
}else{
if(sounds_butt) {
p.playSound(p.getLocation(), Sound.BLOCK_AMETHYST_BLOCK_PLACE, 1.0F, 1.0F);

View File

@ -13,7 +13,7 @@ import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
public static boolean Debug = true;
public static boolean Debug = false;
public static Main plugin;
public static GameData gameData;
public static ConfigYml configYml;

View File

@ -19,23 +19,21 @@ import java.util.concurrent.atomic.AtomicInteger;
public class ComputeBlock {
public static int getCompleteBlockAmount(List<BlockRegion> blockRegionList){
System.out.println("[调试 - 统计] 本次统计拆分异步区块 " + blockRegionList.size() + "");
AtomicInteger totalBlockAmount = new AtomicInteger(0);
for (BlockRegion blockRegion : blockRegionList) {
CompletableFuture.runAsync(() -> {
long startTime = System.currentTimeMillis(); // 记录开始时间
int minX = blockRegion.getMinX();
int maxX = blockRegion.getMaxX();
CuboidRegion cuboidRegion = getCuboidRegion(minX,maxX);
int airCount = countAirBlocks(cuboidRegion); // 计算 AIR 方块数量
totalBlockAmount.addAndGet(airCount); // 线程安全地累加 AIR 方块数量
if(Main.Debug) {
long endTime = System.currentTimeMillis(); // 记录结束时间
long duration = endTime - startTime; // 计算耗时
System.out.println("[调试 - 统计] 本次统计所有方块总计耗时 " + duration + " ms");
}
System.out.println("Air count for region: " + airCount); // 调试信息
System.out.println("[调试 - 统计] 编号区块方块数量: "+totalBlockAmount.toString());
});
}
return totalBlockAmount.intValue();
System.out.println("[调试 - 统计] 总计方块数量: "+totalBlockAmount.toString());
return Integer.parseInt(totalBlockAmount.toString());
}
public static int countAirBlocks(CuboidRegion cuboidRegion) {