yoni-mcscripts-lib
Version:
为 Minecraft Script API 中的部分接口创建了 wrapper,并提供简单的事件管理器和任务管理器,另附有一些便于代码编写的一些小工具。
26 lines (25 loc) • 751 B
JavaScript
import { MinecraftSystem } from "../basis.js";
export function WatchBird() {
if (hasInitiated)
return;
startWatchBird();
hasInitiated = true;
}
let hasInitiated = false;
const interruptRecord = [];
function startWatchBird() {
MinecraftSystem.beforeEvents.watchdogTerminate.subscribe(listenEvent);
}
function listenEvent(event) {
interruptRecord.unshift(Date.now());
if (interruptRecord.length >= 5) {
interruptRecord.length = 5;
let firstInterruptTime = interruptRecord[4];
let lastInterruptTime = interruptRecord[0];
if (lastInterruptTime - firstInterruptTime < 60 * 1000) {
console.error("WatchdogTerminate");
return;
}
}
event.cancel = true;
}