This repository was archived by the owner on Feb 3, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathBDSLM.js
More file actions
115 lines (107 loc) · 3.94 KB
/
Copy pathBDSLM.js
File metadata and controls
115 lines (107 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
var nginxConf = `
events {
multi_accept on;
}
http {
server {
listen port;
listen [::]:port;
server_name example.com;
root ../unmined-web/;
index unmined.index.html;
}
}`
configure = JSON.parse(File.readFrom("./plugins/BDSLM/config.json"))
function GetServerProperties() {
let serverProperties = {};
propertiesFile = File.readFrom("./server.properties").replace("\r", "").split(/\n/); // 读入server.properties并且分割每一行
propertiesFile.forEach((item, _index) => {
if (item && item.replace(" ", "").indexOf("#") != 0) {
out = item.trim().split("="); // 以等号分割一行properties项,并去除两侧可能出现的等号
serverProperties[out[0].trim()] = out[1].trim(); // 将各项存入serverProperties
}
});
return serverProperties;
}
function RendMap() {
let serverProperties = GetServerProperties();
let zoomin = configure["mapRender"]["maxZoomLevel"];
let zoomout = configure["mapRender"]["minZoomLevel"];
log("启动地图渲染进程……");
system.cmd("start .\\plugins\\BDSLM\\unmined\\unmined-cli.exe web render --world=\"./worlds/" + serverProperties["level-name"] + "\" --output=\"./plugins/BDSLM/unmined-web/\" --imageformat=webp -c --zoomin=" + zoomin + " --zoomout=" + zoomout, function GetRendMapResult(_exitcode, _output) { });
setTimeout(applyConf, 10000);
}
function applyConf() {
log("应用配置文件……");
changeWebTitle();
addMarkers();
}
function changeWebTitle() {
if (configure["webserver"]["mapTitle"] != "default") {
File.writeTo("./plugins/BDSLM/unmined-web/unmined.index.html", File.readFrom("./plugins/BDSLM/unmined-web/unmined.index.html").replaceAll("UnminedMapProperties.worldName", '"' + configure["webserver"]["mapTitle"] + '"'));
}
}
function addMarkers() {
let markers = JSON.parse(File.readFrom("./plugins/BDSLM/markers.json"));
let writeOut = {};
writeOut["isEnabled"] = true;
writeOut["markers"] = [];
markers.forEach((item, _index) => {
item["image"] = "custom.pin.png";
item["imageAnchor"] = ["0.5", 1];
item["imageScale"] = "0.3";
item["textColor"] = "red";
item["offsetX"] = 0;
item["offsetY"] = 20;
item["font"] = "bold 20px Calibri,sans serif";
writeOut["markers"].push(item);
});
writeOut = "UnminedCustomMarkers = " + data.toJson(writeOut, 4);
File.writeTo("./plugins/BDSLM/unmined-web/custom.markers.js", writeOut);
}
function startNginxWebserver() {
let port = configure["webserver"]["port"];
File.writeTo("./plugins/BDSLM/nginx/conf/nginx.conf", nginxConf.replaceAll("port", port));
log("启动nginx……");
system.cmd(".\\plugins\\BDSLM\\nginx\\nginx.exe -s stop -p ./plugins/BDSLM/nginx/", function GetRendMapResult(_exitcode, _output) {
system.cmd(".\\plugins\\BDSLM\\nginx\\nginx -p ./plugins/BDSLM/nginx/", function GetRendMapResult(_exitcode, _output) { });
});
}
/*
function autoRendInit() {
if (!isMapHolding) {
log("地图挂起中……安全起见,准备阶段不能将地图挂起。等待10秒重试……");
setTimeout(autoRenderInit, 10000);
}
else {
log("挂起地图,准备更新渲染");
mc.runcmdEx("save hold");
autoRend();
}
}
function autoRend() {
if (isMapHolding) {
log("地图已挂起,开始渲染。");
RendMap();
setTimeout(() => {
mc.runcmdEx("save resume");
log("恢复地图");
}, 10000);
}
else {
log("等待地图挂起……");
setTimeout(autoRenderInit, 10000);
}
}
function isMapHolding() {
mc.runcmdEx("save query").output.indexOf("Data saved.");
}
*/
function Init() {
if (configure["autoRend"]["enable"]) {
setInterval(RendMap, configure["autoRend"]["cycle"] * 60 * 1000);
}
RendMap();
startNginxWebserver();
}
Init();