UNPKG

yoni-mcscripts-lib

Version:

为 Minecraft Script API 中的部分接口创建了 wrapper,并提供简单的事件管理器和任务管理器,另附有一些便于代码编写的一些小工具。

35 lines (25 loc) 853 B
import { MinecraftSystem, Minecraft } from "../basis.js"; export function WatchBird(){ if (hasInitiated) return; startWatchBird(); hasInitiated = true; } let hasInitiated: boolean = false; const interruptRecord: number[] = []; function startWatchBird(){ MinecraftSystem.beforeEvents.watchdogTerminate.subscribe(listenEvent); } function listenEvent(event: Minecraft.WatchdogTerminateBeforeEvent){ 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; }