From e2e053c8c1a2ad864f4fdc8dddd9b3b342faf398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=90=E6=B2=90=E5=91=80?= <163636894+zimuya4153@users.noreply.github.com> Date: Thu, 1 Aug 2024 20:54:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0onServerStopping=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/EventAPI-JS.d.ts | 8 ++++++++ lib/GMLIB_API-JS.js | 2 -- src/CompatibilityApi.cpp | 4 ---- src/EventAPI.cpp | 11 +++++++++++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/EventAPI-JS.d.ts b/lib/EventAPI-JS.d.ts index 0bfdb50..ec9c4ec 100644 --- a/lib/EventAPI-JS.d.ts +++ b/lib/EventAPI-JS.d.ts @@ -240,4 +240,12 @@ declare class Event { containerId: number ) => void ): boolean; + + /** 关闭服务器(不可拦截) */ + static listen( + /** 事件名 */ + event: "onServerStopping", + /** 回调函数 */ + listener: () => void + ): boolean; } \ No newline at end of file diff --git a/lib/GMLIB_API-JS.js b/lib/GMLIB_API-JS.js index 8e6cb3a..f9cf0c2 100644 --- a/lib/GMLIB_API-JS.js +++ b/lib/GMLIB_API-JS.js @@ -1,5 +1,3 @@ -/// - /** LRCA导出接口 */ const GMLIB_API = { /** 创建悬浮字 @type {function(FloatPos,string,boolean):number} */ diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index 9575c83..4ef3312 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -1,8 +1,4 @@ #include "Global.h" -#include "ll/api/service/Bedrock.h" -#include "magic_enum.hpp" -#include "mc/deps/core/string/HashedString.h" -#include "mc/world/effect/MobEffect.h" #include bool isInteger(const std::string& str) { diff --git a/src/EventAPI.cpp b/src/EventAPI.cpp index f129297..fe20805 100644 --- a/src/EventAPI.cpp +++ b/src/EventAPI.cpp @@ -314,6 +314,17 @@ void Export_Event_API() { ); return true; } + case doHash("onServerStopping"): { + auto Call = RemoteCall::importAs(eventName, eventId); + eventBus->emplaceListener( + [Call](ll::event::server::ServerStoppingEvent& ev) { + try { + Call(); + } catch (...) {} + } + ); + return true; + } default: return false; }