feat: refactor event API to use unique event names and remove NextEventId
This commit is contained in:
Vendored
+8
-8
@@ -13,7 +13,7 @@ declare class Event {
|
||||
) => boolean | void
|
||||
): boolean;
|
||||
|
||||
/** 客户端登录后事件(不可以拦截) */
|
||||
/** 客户端登录后事件 */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "onClientLogin",
|
||||
@@ -27,7 +27,7 @@ declare class Event {
|
||||
serverXuid: string,
|
||||
/** 玩家在客户端的xuid */
|
||||
clientXuid: string
|
||||
) => void
|
||||
) => bool
|
||||
): boolean;
|
||||
|
||||
/** 天气改变事件事件 */
|
||||
@@ -55,8 +55,8 @@ declare class Event {
|
||||
item: Item,
|
||||
/** 尝试生成的坐标对象 */
|
||||
pos: FloatPos,
|
||||
/** 创建掉落物的实体对象 */
|
||||
spawnerEntity: Entity
|
||||
/** 创建掉落物的实体uniqueId */
|
||||
spawnerUniqueId: number
|
||||
) => boolean | void
|
||||
): boolean;
|
||||
|
||||
@@ -72,15 +72,15 @@ declare class Event {
|
||||
entity: Entity,
|
||||
/** 实体生成的坐标 */
|
||||
pos: FloatPos,
|
||||
/** 创建掉落物的实体对象 */
|
||||
spawnerEntity: Entity
|
||||
/** 创建掉落物的实体uniqueId */
|
||||
spawnerUniqueId: number
|
||||
) => void
|
||||
): boolean;
|
||||
|
||||
/** 实体切换维度 */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "onEntityChangeDim",
|
||||
event: "onEntityTryChangeDim",
|
||||
/** 回调函数 */
|
||||
listener: (
|
||||
/** 切换维度的实体对象 */
|
||||
@@ -93,7 +93,7 @@ declare class Event {
|
||||
/** 实体切换维度后(不可拦截) */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "onEntityChangeDimAfter",
|
||||
event: "onEntityChangeDim",
|
||||
/** 回调函数 */
|
||||
listener: (
|
||||
/** 切换维度的实体对象 */
|
||||
|
||||
+1
-13
@@ -1,18 +1,6 @@
|
||||
/** 事件创建函数 @type {function(string,string):boolean} */
|
||||
const CallEvent = ll.import("GMLIB_API", "callCustomEvent");
|
||||
|
||||
/** 事件ID @type {number} */
|
||||
let NextEventId = 0;
|
||||
|
||||
/**
|
||||
* 获取事件ID标识名
|
||||
* @returns {string} 事件ID标识名
|
||||
*/
|
||||
function getNextEventId() {
|
||||
NextEventId++;
|
||||
return "GMLIB_Event_" + NextEventId;
|
||||
}
|
||||
|
||||
/** 事件类 */
|
||||
class Event {
|
||||
constructor() {
|
||||
@@ -26,7 +14,7 @@ class Event {
|
||||
* @returns {boolean} 是否创建成功
|
||||
*/
|
||||
static listen(event, callback) {
|
||||
let eventId = getNextEventId();
|
||||
let eventId = "GMLIB_Event_" + Math.random().toString(16).slice(2);
|
||||
ll.export(callback, event, eventId);
|
||||
let result = CallEvent(event, eventId);
|
||||
if (!result) {
|
||||
|
||||
Reference in New Issue
Block a user