很多日志都改成了中文
This commit is contained in:
parent
fb3892c3ad
commit
f21049b82c
@ -7,7 +7,7 @@ import java.nio.file.*;
|
||||
public class ModConfig {
|
||||
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||
private final Path configPath;
|
||||
private int webPort = 8080; // 默认端口
|
||||
private int webPort = 60048;
|
||||
|
||||
public ModConfig(Path configDir) {
|
||||
this.configPath = configDir.resolve("playertime-config.json");
|
||||
@ -26,7 +26,7 @@ public class ModConfig {
|
||||
webPort = json.get("webPort").getAsInt();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
PlayerTimeMod.LOGGER.error("Failed to load config", e);
|
||||
PlayerTimeMod.LOGGER.error("[在线时间] 加载配置失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ public class ModConfig {
|
||||
GSON.toJson(json, writer);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
PlayerTimeMod.LOGGER.error("Failed to save config", e);
|
||||
PlayerTimeMod.LOGGER.error("[在线时间] 保存配置失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,9 +28,9 @@ public class PlayerTimeMod implements ModInitializer {
|
||||
// 使用配置中的端口
|
||||
webServer = new WebServer(timeTracker, config.getWebPort());
|
||||
webServer.start();
|
||||
LOGGER.info("Web服务器在端口" + config.getWebPort()+ "启动");
|
||||
LOGGER.info("[在线时间] Web服务器在端口" + config.getWebPort()+ "启动");
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("无法启动Web服务器", e);
|
||||
LOGGER.error("[在线时间] 无法启动Web服务器", e);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -136,7 +136,7 @@ public class PlayerTimeTracker {
|
||||
playerData.put(uuid, GSON.fromJson(entry.getValue(), PlayerTimeData.class));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
PlayerTimeMod.LOGGER.error("无法加载玩家在线时间数据", e);
|
||||
PlayerTimeMod.LOGGER.error("[在线时间] 无法加载玩家在线时间数据", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,7 +149,7 @@ public class PlayerTimeTracker {
|
||||
try (Writer writer = Files.newBufferedWriter(dataFile)) {
|
||||
GSON.toJson(root, writer);
|
||||
} catch (Exception e) {
|
||||
PlayerTimeMod.LOGGER.error("无法保存玩家在线时间数据", e);
|
||||
PlayerTimeMod.LOGGER.error("[在线时间] 无法保存玩家在线时间数据", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,7 +176,7 @@ public class PlayerTimeTracker {
|
||||
try (Writer writer = Files.newBufferedWriter(dataFile)) {
|
||||
GSON.toJson(root, writer);
|
||||
} catch (Exception e) {
|
||||
PlayerTimeMod.LOGGER.error("无法保存" + uuid + "的在线时间数据", e);
|
||||
PlayerTimeMod.LOGGER.error("[在线时间] 无法保存" + uuid + "的在线时间数据", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public class WebServer {
|
||||
String response = new Gson().toJson(stats);
|
||||
sendResponse(exchange, 200, response.getBytes(), "application/json");
|
||||
} catch (Exception e) {
|
||||
PlayerTimeMod.LOGGER.error("Failed to get stats", e);
|
||||
PlayerTimeMod.LOGGER.error("[在线时间] 无法获得统计数据", e);
|
||||
sendResponse(exchange, 500, "Internal Server Error");
|
||||
}
|
||||
});
|
||||
@ -83,7 +83,7 @@ public class WebServer {
|
||||
|
||||
sendResponse(exchange, 200, buffer.toByteArray(), contentType);
|
||||
} catch (Exception e) {
|
||||
PlayerTimeMod.LOGGER.error("Failed to serve resource", e);
|
||||
PlayerTimeMod.LOGGER.error("[在线时间] 无法提供资源", e);
|
||||
sendResponse(exchange, 500, "Internal Server Error");
|
||||
}
|
||||
});
|
||||
|
@ -2,13 +2,10 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
const refreshBtn = document.getElementById('refresh-btn');
|
||||
const statsTable = document.getElementById('stats-table').getElementsByTagName('tbody')[0];
|
||||
|
||||
// 初始加载数据
|
||||
loadStats();
|
||||
|
||||
// 刷新按钮点击事件
|
||||
refreshBtn.addEventListener('click', loadStats);
|
||||
|
||||
// 加载统计数据
|
||||
function loadStats() {
|
||||
fetch('/api/stats')
|
||||
.then(response => response.json())
|
||||
@ -16,46 +13,38 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
updateTable(data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching stats:', error);
|
||||
alert('Failed to load player stats. Check console for details.');
|
||||
console.error('获取统计信息时出错:', error);
|
||||
alert('未能加载玩家统计信息。 检查控制台以获取详细信息');
|
||||
});
|
||||
}
|
||||
|
||||
// 更新表格数据
|
||||
function updateTable(statsData) {
|
||||
const statsTable = document.getElementById('stats-table').getElementsByTagName('tbody')[0];
|
||||
statsTable.innerHTML = '';
|
||||
|
||||
// 新数据格式是 { "玩家名": "统计信息", ... }
|
||||
Object.entries(statsData).forEach(([playerName, statString]) => {
|
||||
const row = statsTable.insertRow();
|
||||
|
||||
// 玩家名列
|
||||
const nameCell = row.insertCell(0);
|
||||
nameCell.textContent = playerName;
|
||||
|
||||
// 解析统计信息
|
||||
const stats = {};
|
||||
statString.split(" | ").forEach(part => {
|
||||
const [label, value] = part.split(": ");
|
||||
stats[label.trim()] = value;
|
||||
});
|
||||
|
||||
// 总时长列
|
||||
const totalCell = row.insertCell(1);
|
||||
totalCell.textContent = stats["总时长"];
|
||||
|
||||
// 30天列
|
||||
const thirtyCell = row.insertCell(2);
|
||||
thirtyCell.textContent = stats["30天"];
|
||||
|
||||
// 7天列
|
||||
const sevenCell = row.insertCell(3);
|
||||
sevenCell.textContent = stats["7天"];
|
||||
});
|
||||
}
|
||||
|
||||
// 辅助函数:将"Xh Ym"格式的时间转换为分钟数
|
||||
function parseTime(timeStr) {
|
||||
const [hPart, mPart] = timeStr.split(' ');
|
||||
const hours = parseInt(hPart.replace('h', ''));
|
||||
|
Loading…
x
Reference in New Issue
Block a user