Compare commits
120 Commits
@@ -9,10 +9,6 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: xmake-io/github-action-setup-xmake@v1
|
||||
|
||||
@@ -25,14 +21,8 @@ jobs:
|
||||
- run: |
|
||||
xmake -w -y
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }}
|
||||
path: |
|
||||
bin/DLL/
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: PDB
|
||||
path: |
|
||||
bin/PDB/
|
||||
bin/
|
||||
@@ -9,10 +9,6 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: xmake-io/github-action-setup-xmake@v1
|
||||
|
||||
@@ -25,17 +21,11 @@ jobs:
|
||||
- run: |
|
||||
xmake -w -y
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }}
|
||||
path: |
|
||||
bin/DLL/
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: PDB
|
||||
path: |
|
||||
bin/PDB/
|
||||
bin/
|
||||
|
||||
upload-to-release:
|
||||
needs:
|
||||
@@ -47,32 +37,23 @@ jobs:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Download Plugin
|
||||
uses: actions/download-artifact@v3
|
||||
- name: Download Mod
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }}
|
||||
path: release/Plugin/
|
||||
|
||||
- name: Download PDB
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: PDB
|
||||
path: release/PDB/
|
||||
path: artifact
|
||||
|
||||
- name: Copy additional files
|
||||
run: |
|
||||
cp LICENSE README.md release/Plugin/
|
||||
cp -v LICENSE README.md artifact/
|
||||
|
||||
- name: Archive release
|
||||
run: |
|
||||
cd release/Plugin
|
||||
zip -r ../${{ github.event.repository.name }}-windows-x64.zip *
|
||||
cd ..
|
||||
working-directory: artifact
|
||||
|
||||
- name: Create GitHub Release
|
||||
id: create_release
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
files: |
|
||||
release/${{ github.event.repository.name }}-windows-x64.zip
|
||||
release/PDB/${{ github.event.repository.name }}.pdb
|
||||
${{ github.event.repository.name }}-windows-x64.zip
|
||||
@@ -1,3 +0,0 @@
|
||||
[submodule "SDK-GMLIB"]
|
||||
path = SDK-GMLIB
|
||||
url = https://github.com/GroupMountain/SDK-GMLIB.git
|
||||
-1
Submodule SDK-GMLIB deleted from 710cc6e4c3
Vendored
+72
@@ -0,0 +1,72 @@
|
||||
export class PAPI {
|
||||
/** 注册一个玩家PAPI变量 */
|
||||
static registerPlayerPlaceholder(
|
||||
/** PAPI调用函数 */
|
||||
func: (
|
||||
/** 玩家对象 */
|
||||
player: Player,
|
||||
/** 变量参数 */
|
||||
param: null | object.<string, string>
|
||||
) => string,
|
||||
/** 插件名字 */
|
||||
pluginsName: string,
|
||||
/** PAPI变量 */
|
||||
PAPIName: string
|
||||
): boolean;
|
||||
|
||||
/** 注册一个服务器PAPI变量 */
|
||||
static registerServerPlaceholder(
|
||||
/** PAPI调用函数 */
|
||||
func: (
|
||||
/** 变量参数 */
|
||||
param: null | object.<string, string>
|
||||
) => string,
|
||||
/** 插件名字 */
|
||||
pluginsName: string,
|
||||
/** PAPI变量 */
|
||||
PAPIName: string
|
||||
): boolean;
|
||||
|
||||
/** 注册一个静态PAPI变量 */
|
||||
static registerStaticPlaceholder(
|
||||
/** PAPI调用函数 */
|
||||
func: () => string,
|
||||
/** 插件名字 */
|
||||
pluginsName: string,
|
||||
/** PAPI变量 */
|
||||
PAPIName: string,
|
||||
/** 更新时间 */
|
||||
UpdateInterval: number
|
||||
): boolean;
|
||||
|
||||
/** 获取一个服务器变量的值 */
|
||||
static getValue(
|
||||
/** PAPI名 */
|
||||
key: string
|
||||
): string;
|
||||
|
||||
/** 获取一个玩家变量的值 */
|
||||
static getValueByPlayer(
|
||||
/** PAPI名 */
|
||||
key: string,
|
||||
/** 玩家对象 */
|
||||
pl: Player
|
||||
): string;
|
||||
|
||||
/** 翻译带PAPI变量的字符串 */
|
||||
static translateString(
|
||||
/** 要翻译的字符串 */
|
||||
str: string,
|
||||
/** 玩家对象 */
|
||||
pl: Player | undefined
|
||||
): string;
|
||||
|
||||
/** 注销一个PAPI变量 */
|
||||
static unRegisterPlaceholder(
|
||||
/** PAPI名 */
|
||||
str: string
|
||||
): boolean;
|
||||
|
||||
/** 获取所有已注册的PAPI变量 */
|
||||
static getAllPAPI(): string[];
|
||||
}
|
||||
@@ -1,47 +1,117 @@
|
||||
const PlaceholderAPI = {
|
||||
/** 获取一个服务器变量的值 @type {function(string):string} */
|
||||
getValueAPI: ll.import("BEPlaceholderAPI", "GetValue"),
|
||||
/** 获取一个玩家变量的值 @type {function(string,Player):string} */
|
||||
getValueByPlayerAPI: ll.import("BEPlaceholderAPI", "GetValueWithPlayer"),
|
||||
/** 注册一个玩家变量 @type {function(string,string,string):boolean} */
|
||||
registerPlayerPlaceholderAPI: ll.import("BEPlaceholderAPI", "registerPlayerPlaceholder"),
|
||||
/** 注册一个服务器变量 @type {function(string,string,string):boolean} */
|
||||
registerServerPlaceholderAPI: ll.import("BEPlaceholderAPI", "registerServerPlaceholder"),
|
||||
/** 注册一个静态变量 @type {function(string,string,string,number):boolean} */
|
||||
registerStaticPlaceholderAPI: ll.import("BEPlaceholderAPI", "registerStaticPlaceholder"),
|
||||
/** 翻译包含PAPI服务器变量的字符串 @type {function(string):string} */
|
||||
translateStringAPI: ll.import("BEPlaceholderAPI", "translateString"),
|
||||
/** 翻译包含PAPI玩家变量的字符串 @type {function(string,Player):string} */
|
||||
translateStringWithPlayerAPI: ll.import("BEPlaceholderAPI", "translateStringWithPlayer"),
|
||||
/** 注销PAPI变量 @type {function(string):boolean} */
|
||||
unRegisterPlaceholderAPI: ll.import("BEPlaceholderAPI", "unRegisterPlaceholder"),
|
||||
/** 获取所有已注册的PAPI变量 @type {function():Array.<string>} */
|
||||
getAllPAPI: ll.import("BEPlaceholderAPI", "getAllPAPI")
|
||||
}
|
||||
|
||||
Function.prototype.getName = function () {
|
||||
return this.name || this.toString().match(/function\s*([^(]*)\(/)[1]
|
||||
Function.prototype.getName =
|
||||
/**
|
||||
* 获取函数名字
|
||||
* @returns {string}
|
||||
*/
|
||||
function () {
|
||||
return this.name || this.toString().match(/function\s*([^(]*)\(/)?.[1] || getStringHashCode(this.toString()).toString(16);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字符串哈希值
|
||||
* @param {string} str 字符串
|
||||
* @returns {number}
|
||||
*/
|
||||
function getStringHashCode(str) {
|
||||
let hash = 0, chr;
|
||||
if (str.length === 0) return hash;
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
chr = str.charCodeAt(i);
|
||||
hash = ((hash << 5) - hash) + chr;
|
||||
hash |= 0;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
/** PAPI变量类 */
|
||||
class PAPI {
|
||||
constructor() {
|
||||
throw new Error("Static class cannot be instantiated");
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册一个玩家PAPI变量
|
||||
* @param {function} func 变量调用的函数
|
||||
* @param {string} PluginName 插件名字
|
||||
* @param {string} PAPIName PAPI变量名
|
||||
* @returns {boolean} 是否注册成功
|
||||
*/
|
||||
static registerPlayerPlaceholder(func, PluginName, PAPIName) {
|
||||
ll.export(func, PluginName, func.getName());
|
||||
return PlaceholderAPI.registerPlayerPlaceholderAPI(PluginName, func.getName(), PAPIName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册一个服务器PAPI变量
|
||||
* @param {function} func 变量调用的函数
|
||||
* @param {string} PluginName 插件名字
|
||||
* @param {string} PAPIName PAPI变量名
|
||||
* @returns {boolean} 是否注册成功
|
||||
*/
|
||||
static registerServerPlaceholder(func, PluginName, PAPIName) {
|
||||
ll.export(func, PluginName, func.getName());
|
||||
return PlaceholderAPI.registerServerPlaceholderAPI(PluginName, func.getName(), PAPIName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册一个静态PAPI变量
|
||||
* @param {function} func 变量调用的函数
|
||||
* @param {string} PluginName 插件名字
|
||||
* @param {string} PAPIName PAPI变量名
|
||||
* @param {number} [UpdateInterval=50] 更新间隔
|
||||
* @returns {boolean} 是否注册成功
|
||||
*/
|
||||
static registerStaticPlaceholder(func, PluginName, PAPIName, UpdateInterval = 50) {
|
||||
ll.export(func, PluginName, func.getName());
|
||||
return PlaceholderAPI.registerStaticPlaceholderAPI(PluginName, func.getName(), PAPIName, UpdateInterval);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个服务器变量的值
|
||||
* @param {string} key PAPI变量名
|
||||
* @returns {string} 值
|
||||
*/
|
||||
static getValue(key) {
|
||||
return PlaceholderAPI.getValueAPI(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个玩家变量的值
|
||||
* @param {string} key PAPI变量名
|
||||
* @param {Player} pl 玩家对象
|
||||
* @returns {string} 值
|
||||
*/
|
||||
static getValueByPlayer(key, pl) {
|
||||
return PlaceholderAPI.getValueByPlayerAPI(key, pl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 翻译带PAPI变量的字符串
|
||||
* @param {string} str 字符串
|
||||
* @param {Player} pl 玩家对象
|
||||
* @returns {string} 翻译结果
|
||||
*/
|
||||
static translateString(str, pl = null) {
|
||||
if (pl) {
|
||||
return PlaceholderAPI.translateStringWithPlayerAPI(str, pl);
|
||||
@@ -49,10 +119,19 @@ class PAPI {
|
||||
return PlaceholderAPI.translateStringAPI(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注销一个PAPI变量
|
||||
* @param {string} str PAPI变量名
|
||||
* @returns {boolean} 是否注销成功
|
||||
*/
|
||||
static unRegisterPlaceholder(str) {
|
||||
return PlaceholderAPI.unRegisterPlaceholderAPI(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有已注册的PAPI变量
|
||||
* @returns {Array.<string>} 已注册的PAPI变量数组
|
||||
*/
|
||||
static getAllPAPI() {
|
||||
return PlaceholderAPI.getAllPAPI();
|
||||
}
|
||||
|
||||
Vendored
+894
@@ -0,0 +1,894 @@
|
||||
export namespace Event {
|
||||
/** 事件优先级 */
|
||||
export enum EventPriority {
|
||||
/** 最高 */
|
||||
Highest = 0,
|
||||
/** 高 */
|
||||
High = 100,
|
||||
/** 正常(推荐) */
|
||||
Normal = 200,
|
||||
/** 低 */
|
||||
Low = 300,
|
||||
/** 最低 */
|
||||
Lowest = 400
|
||||
}
|
||||
|
||||
/** 获取所有事件订阅 */
|
||||
export function getListener(): Record<string, number[]>;
|
||||
|
||||
/** 获取事件订阅列表 */
|
||||
export function getListener(
|
||||
/** 事件名 */
|
||||
eventName:
|
||||
"ll::ServerStoppingEvent"
|
||||
| "gmlib::ClientLoginAfterEvent"
|
||||
| "gmlib::WeatherUpdateBeforeEvent"
|
||||
| "gmlib::MobPickupItemBeforeEvent"
|
||||
| "gmlib::ItemActorSpawnBeforeEvent"
|
||||
| "gmlib::ItemActorSpawnAfterEvent"
|
||||
| "gmlib::ActorChangeDimensionBeforeEvent"
|
||||
| "gmlib::PlayerStopSleepBeforeEvent"
|
||||
| "gmlib::DeathMessageAfterEvent"
|
||||
| "gmlib::MobHurtAfterEvent"
|
||||
| "gmlib::EndermanTakeBlockBeforeEvent"
|
||||
| "gmlib::ActorChangeDimensionAfterEvent"
|
||||
| "gmlib::DragonRespawnBeforeEvent"
|
||||
| "gmlib::ProjectileCreateBeforeEvent"
|
||||
| "gmlib::ProjectileCreateAfterEvent"
|
||||
| "gmlib::SpawnWanderingTraderBeforeEvent"
|
||||
| "gmlib::HandleRequestActionBeforeEvent"
|
||||
| "gmlib::ContainerClosePacketSendAfterEvent"
|
||||
): number[];
|
||||
|
||||
/** 订阅事件是否存在 */
|
||||
export function hasListener(
|
||||
/** 事件ID */
|
||||
eventId: number
|
||||
): boolean;
|
||||
|
||||
/** 取消事件订阅 */
|
||||
export function removeListener(
|
||||
/** 事件ID */
|
||||
eventId: number
|
||||
): boolean;
|
||||
|
||||
/** 获取订阅事件优先级 */
|
||||
export function getListenerPriority(
|
||||
/** 事件ID */
|
||||
eventId: number
|
||||
): EventPriority | undefined;
|
||||
|
||||
/** 设置事件异常处理回调 */
|
||||
export function setErrorHanlerCallback(
|
||||
/** 回调 */
|
||||
callback: (
|
||||
/** 错误 */
|
||||
error: Error,
|
||||
/** 事件名 */
|
||||
eventName: string,
|
||||
/** 事件ID */
|
||||
eventId: number,
|
||||
/** 插件名 */
|
||||
pluginName: string
|
||||
) => void
|
||||
): boolean;
|
||||
|
||||
/** 监听事件(兼容旧版) */
|
||||
export function listen(
|
||||
/** 事件名 */
|
||||
eventName: "onServerStopping"
|
||||
| "onClientLogin"
|
||||
| "onWeatherChange"
|
||||
| "onMobPick"
|
||||
| "onItemTrySpawn"
|
||||
| "onItemSpawned"
|
||||
| "onEntityTryChangeDim"
|
||||
| "onLeaveBed"
|
||||
| "onDeathMessage"
|
||||
| "onMobHurted"
|
||||
| "onEndermanTake"
|
||||
| "onEntityChangeDim"
|
||||
| "onDragonRespawn"
|
||||
| "onProjectileTryCreate"
|
||||
| "onProjectileCreate"
|
||||
| "onSpawnWanderingTrader"
|
||||
| "onHandleRequestAction"
|
||||
| "onSendContainerClosePacket",
|
||||
/** 回调 */
|
||||
callback: Function
|
||||
): boolean;
|
||||
|
||||
/** 订阅事件 */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: string,
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: any[],
|
||||
/** 拦截事件 */
|
||||
cancel: () => void,
|
||||
/** 设置拦截状态 */
|
||||
setCancelled: (
|
||||
/** 是否拦截 */
|
||||
value: boolean
|
||||
) => void,
|
||||
/** 是否被拦截 */
|
||||
isCancelled: () => boolean,
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(服务器关闭事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "ll::ServerStoppingEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {},
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(客户端登录后事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::ClientLoginAfterEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {
|
||||
/** 玩家名 */
|
||||
0: string,
|
||||
/** 玩家uuid */
|
||||
1: string,
|
||||
/** 玩家服务端xuid */
|
||||
2: string,
|
||||
/** 玩家客户端xuid */
|
||||
3: string,
|
||||
},
|
||||
/** 拦截事件 */
|
||||
cancel: () => void,
|
||||
/** 设置拦截状态 */
|
||||
setCancelled: (
|
||||
/** 是否拦截 */
|
||||
value: boolean
|
||||
) => void,
|
||||
/** 是否被拦截 */
|
||||
isCancelled: () => boolean,
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(天气更新前事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::WeatherUpdateBeforeEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {
|
||||
/** 雨天等级 */
|
||||
0: number,
|
||||
/** 雨天时间(tick) */
|
||||
1: number,
|
||||
/** 暴雨等级 */
|
||||
2: number,
|
||||
/** 暴雨时间(tick) */
|
||||
3: number,
|
||||
},
|
||||
/** 拦截事件 */
|
||||
cancel: () => void,
|
||||
/** 设置拦截状态 */
|
||||
setCancelled: (
|
||||
/** 是否拦截 */
|
||||
value: boolean
|
||||
) => void,
|
||||
/** 是否被拦截 */
|
||||
isCancelled: () => boolean,
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(天气更新后事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::WeatherUpdateAfterEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {
|
||||
/** 雨天等级 */
|
||||
0: number,
|
||||
/** 雨天时间(tick) */
|
||||
1: number,
|
||||
/** 暴雨等级 */
|
||||
2: number,
|
||||
/** 暴雨时间(tick) */
|
||||
3: number,
|
||||
},
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(实体捡起物品前事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::MobPickupItemBeforeEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {
|
||||
/** 捡起物品的实体 */
|
||||
0: Entity,
|
||||
/** 掉落物 */
|
||||
1: Entity
|
||||
},
|
||||
/** 拦截事件 */
|
||||
cancel: () => void,
|
||||
/** 设置拦截状态 */
|
||||
setCancelled: (
|
||||
/** 是否拦截 */
|
||||
value: boolean
|
||||
) => void,
|
||||
/** 是否被拦截 */
|
||||
isCancelled: () => boolean,
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(实体捡起物品后事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::MobPickupItemAfterEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {
|
||||
/** 捡起物品的实体 */
|
||||
0: Entity,
|
||||
/** 掉落物 */
|
||||
1: Entity
|
||||
},
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(掉落物生成前事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::ItemActorSpawnBeforeEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {
|
||||
/** 物品 */
|
||||
0: Item,
|
||||
/** 生成坐标坐标 */
|
||||
1: FloatPos,
|
||||
/** 生成此物品主人的uniqueId (-1为不存在) */
|
||||
2: number
|
||||
},
|
||||
/** 拦截事件 */
|
||||
cancel: () => void,
|
||||
/** 设置拦截状态 */
|
||||
setCancelled: (
|
||||
/** 是否拦截 */
|
||||
value: boolean
|
||||
) => void,
|
||||
/** 是否被拦截 */
|
||||
isCancelled: () => boolean,
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(掉落物生成后事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::ItemActorSpawnAfterEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {
|
||||
/** 物品实体对象 */
|
||||
0: Entity,
|
||||
/** 生成坐标坐标 */
|
||||
1: FloatPos,
|
||||
/** 生成此物品主人的uniqueId (-1为不存在) */
|
||||
2: number
|
||||
},
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(实体切换维度前事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::ActorChangeDimensionBeforeEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {
|
||||
/** 切换维度的实体 */
|
||||
0: Entity,
|
||||
/** 前往的维度ID */
|
||||
1: number
|
||||
},
|
||||
/** 拦截事件 */
|
||||
cancel: () => void,
|
||||
/** 设置拦截状态 */
|
||||
setCancelled: (
|
||||
/** 是否拦截 */
|
||||
value: boolean
|
||||
) => void,
|
||||
/** 是否被拦截 */
|
||||
isCancelled: () => boolean,
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(事件切换维度后事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::ActorChangeDimensionAfterEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {
|
||||
/** 切换维度的实体 */
|
||||
0: Entity,
|
||||
/** 原来的维度ID */
|
||||
1: number,
|
||||
/** 前往的维度ID */
|
||||
2: number
|
||||
},
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(玩家开始睡觉前事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::PlayerStartSleepBeforeEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {
|
||||
/** 睡觉的玩家 */
|
||||
0: Player,
|
||||
/** 床的坐标 */
|
||||
1: IntPos
|
||||
},
|
||||
/** 拦截事件 */
|
||||
cancel: () => void,
|
||||
/** 设置拦截状态 */
|
||||
setCancelled: (
|
||||
/** 是否拦截 */
|
||||
value: boolean
|
||||
) => void,
|
||||
/** 是否被拦截 */
|
||||
isCancelled: () => boolean,
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(玩家开始睡觉后事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::PlayerStartSleepAfterEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {
|
||||
/** 睡觉的玩家 */
|
||||
0: Player,
|
||||
/** 床的坐标 */
|
||||
1: IntPos,
|
||||
/** 睡觉的结果 */
|
||||
2: number
|
||||
},
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(玩家停止睡觉前事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::PlayerStopSleepBeforeEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {
|
||||
/** 睡觉的玩家 */
|
||||
0: Player,
|
||||
/** forcefulWakeUp */
|
||||
1: boolean,
|
||||
/** updateLevelList */
|
||||
2: boolean
|
||||
},
|
||||
/** 拦截事件 */
|
||||
cancel: () => void,
|
||||
/** 设置拦截状态 */
|
||||
setCancelled: (
|
||||
/** 是否拦截 */
|
||||
value: boolean
|
||||
) => void,
|
||||
/** 是否被拦截 */
|
||||
isCancelled: () => boolean,
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(玩家停止睡觉后事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::PlayerStopSleepAfterEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {
|
||||
/** 睡觉的玩家 */
|
||||
0: Player,
|
||||
/** forcefulWakeUp */
|
||||
1: boolean,
|
||||
/** updateLevelList */
|
||||
2: boolean
|
||||
},
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(生成死亡消息后事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::DeathMessageAfterEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {
|
||||
/** 键名 */
|
||||
0: string,
|
||||
/** 翻译参数 */
|
||||
1: string[],
|
||||
/** 死亡的实体 */
|
||||
2: Entity
|
||||
},
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(实体受伤后事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::MobHurtAfterEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {
|
||||
/** 受伤的实体 */
|
||||
0: Entity,
|
||||
/** 伤害来源 */
|
||||
1: Entity,
|
||||
/** 伤害值 */
|
||||
2: number,
|
||||
/** 伤害类型 */
|
||||
3: DamageCause
|
||||
},
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(末影人搬运方块前事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::EndermanTakeBlockBeforeEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {
|
||||
/** 末影人实体 */
|
||||
0: Entity
|
||||
},
|
||||
/** 拦截事件 */
|
||||
cancel: () => void,
|
||||
/** 设置拦截状态 */
|
||||
setCancelled: (
|
||||
/** 是否拦截 */
|
||||
value: boolean
|
||||
) => void,
|
||||
/** 是否被拦截 */
|
||||
isCancelled: () => boolean,
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(末影龙复活前事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::DragonRespawnBeforeEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {},
|
||||
/** 拦截事件 */
|
||||
cancel: () => void,
|
||||
/** 设置拦截状态 */
|
||||
setCancelled: (
|
||||
/** 是否拦截 */
|
||||
value: boolean
|
||||
) => void,
|
||||
/** 是否被拦截 */
|
||||
isCancelled: () => boolean,
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(末影龙复活后事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::DragonRespawnAfterEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {
|
||||
/** 末影龙实体 */
|
||||
0: Entity
|
||||
},
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(投射物创建前事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::ProjectileCreateBeforeEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {
|
||||
/** 投射物实体 */
|
||||
0: Entity,
|
||||
/** 创建投射物实体的uniqueId */
|
||||
1: number
|
||||
},
|
||||
/** 拦截事件 */
|
||||
cancel: () => void,
|
||||
/** 设置拦截状态 */
|
||||
setCancelled: (
|
||||
/** 是否拦截 */
|
||||
value: boolean
|
||||
) => void,
|
||||
/** 是否被拦截 */
|
||||
isCancelled: () => boolean,
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(投射物创建后事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::ProjectileCreateAfterEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {
|
||||
/** 投射物实体 */
|
||||
0: Entity,
|
||||
/** 创建投射物实体的uniqueId */
|
||||
1: number
|
||||
},
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(生成流浪商人前事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::SpawnWanderingTraderBeforeEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {
|
||||
/** 出现的坐标 */
|
||||
0: IntPos
|
||||
},
|
||||
/** 拦截事件 */
|
||||
cancel: () => void,
|
||||
/** 设置拦截状态 */
|
||||
setCancelled: (
|
||||
/** 是否拦截 */
|
||||
value: boolean
|
||||
) => void,
|
||||
/** 是否被拦截 */
|
||||
isCancelled: () => boolean,
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(生成流浪商人后事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::SpawnWanderingTraderAfterEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {
|
||||
/** 出现的坐标 */
|
||||
0: IntPos
|
||||
},
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(处理物品请求前事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::HandleRequestActionBeforeEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {
|
||||
/** 请求的玩家 */
|
||||
0: Player,
|
||||
/** 请求类型 */
|
||||
1: string,
|
||||
/** 请求数量 */
|
||||
2: number,
|
||||
/** 请求原容器类型 */
|
||||
3: string,
|
||||
/** 请求原容器槽位 */
|
||||
4: number,
|
||||
/** 请求前往的容器类型 */
|
||||
5: string,
|
||||
/** 请求前往的槽位 */
|
||||
6: number
|
||||
},
|
||||
/** 拦截事件 */
|
||||
cancel: () => void,
|
||||
/** 设置拦截状态 */
|
||||
setCancelled: (
|
||||
/** 是否拦截 */
|
||||
value: boolean
|
||||
) => void,
|
||||
/** 是否被拦截 */
|
||||
isCancelled: () => boolean,
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(处理物品请求后事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::HandleRequestActionAfterEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {
|
||||
/** 请求的玩家 */
|
||||
0: Player,
|
||||
/** 请求类型 */
|
||||
1: string,
|
||||
/** 请求数量 */
|
||||
2: number,
|
||||
/** 请求原容器类型 */
|
||||
3: string,
|
||||
/** 请求原容器槽位 */
|
||||
4: number,
|
||||
/** 请求前往的容器类型 */
|
||||
5: string,
|
||||
/** 请求前往的槽位 */
|
||||
6: number
|
||||
},
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
|
||||
/** 订阅事件(玩家关闭容器后事件) */
|
||||
export function emplaceListener(
|
||||
/** 事件名 */
|
||||
eventName: "gmlib::ContainerClosePacketSendAfterEvent",
|
||||
/** 回调 */
|
||||
callback: (event: {
|
||||
/** 事件参数 */
|
||||
params: {
|
||||
/** 关闭的玩家 */
|
||||
0: Player,
|
||||
/** 容器会话ID */
|
||||
1: number,
|
||||
/** 由服务器关闭 */
|
||||
2: boolean
|
||||
},
|
||||
/** 获取事件ID */
|
||||
getId: () => number,
|
||||
/** 获取事件类型 */
|
||||
getEventType: () => string
|
||||
}) => void,
|
||||
/** 优先级 */
|
||||
priority?: Event.EventPriority,
|
||||
/** 插件名 */
|
||||
pluginName?: string
|
||||
): number;
|
||||
}
|
||||
+166
-25
@@ -1,29 +1,170 @@
|
||||
const CallEvent = ll.import("GMLIB_API", "callCustomEvent");
|
||||
|
||||
let NextEventId = 0;
|
||||
|
||||
function getNextEventId() {
|
||||
NextEventId++;
|
||||
return "GMLIB_Event_" + NextEventId;
|
||||
}
|
||||
|
||||
class Event {
|
||||
constructor() {
|
||||
throw new Error("Static class cannot be instantiated");
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
const getPluginName = () => {
|
||||
try {
|
||||
throw new Error("getPluginName");
|
||||
} catch (error) {
|
||||
return error.stack.trim().match(/plugins\\(.*)\\.*\.js:[0-9]+\)$/i)?.[1] || "Unknown";
|
||||
}
|
||||
|
||||
static listen(event, callback) {
|
||||
let eventId = getNextEventId();
|
||||
ll.export(callback, event, eventId);
|
||||
let result = CallEvent(event, eventId);
|
||||
if (!result) {
|
||||
logger.error(`Cannot listen event "${event}"!`);
|
||||
logger.error(`Event "${event}" No Found!`);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
Event
|
||||
Event: {
|
||||
/**
|
||||
* 事件订阅记录
|
||||
* 例如: {事件名: [事件ID, ...], ...}
|
||||
* @type {Object.<string, number[]>}
|
||||
*/
|
||||
mEventData: {},
|
||||
/**
|
||||
* 事件异常处理回调
|
||||
* @param {Error} error
|
||||
* @param {string} eventName
|
||||
* @param {number} eventID
|
||||
* @param {string} pluginName
|
||||
* @returns {void}
|
||||
*/
|
||||
mErrorHanlerCallback: (error, eventName, eventID, pluginName) => {
|
||||
logger.error(`Info: ${pluginName}-${eventName}-${eventID} Exception: ${error.message}\n${error.stack}`);
|
||||
},
|
||||
|
||||
/**
|
||||
* 监听事件(兼容旧版)
|
||||
* @param {string} eventName
|
||||
* @param {function} callback
|
||||
* @param {boolean}
|
||||
*/
|
||||
listen: function (eventName, callback) {
|
||||
try {
|
||||
if (typeof callback !== "function") return false;
|
||||
const eventReflection = {
|
||||
onServerStopping: "ll::ServerStoppingEvent",
|
||||
onClientLogin: "gmlib::ClientLoginAfterEvent",
|
||||
onWeatherChange: "gmlib::WeatherUpdateBeforeEvent",
|
||||
onMobPick: "gmlib::MobPickupItemBeforeEvent",
|
||||
onItemTrySpawn: "gmlib::ItemActorSpawnBeforeEvent",
|
||||
onItemSpawned: "gmlib::ItemActorSpawnAfterEvent",
|
||||
onEntityTryChangeDim: "gmlib::ActorChangeDimensionBeforeEvent",
|
||||
onLeaveBed: "gmlib::PlayerStopSleepBeforeEvent",
|
||||
onDeathMessage: "gmlib::DeathMessageAfterEvent",
|
||||
onMobHurted: "gmlib::MobHurtAfterEvent",
|
||||
onEndermanTake: "gmlib::EndermanTakeBlockBeforeEvent",
|
||||
onEntityChangeDim: "gmlib::ActorChangeDimensionAfterEvent",
|
||||
onDragonRespawn: "gmlib::DragonRespawnBeforeEvent",
|
||||
onProjectileTryCreate: "gmlib::ProjectileCreateBeforeEvent",
|
||||
onProjectileCreate: "gmlib::ProjectileCreateAfterEvent",
|
||||
onSpawnWanderingTrader: "gmlib::SpawnWanderingTraderBeforeEvent",
|
||||
onHandleRequestAction: "gmlib::HandleRequestActionBeforeEvent",
|
||||
onSendContainerClosePacket: "gmlib::ContainerClosePacketSendAfterEvent"
|
||||
};
|
||||
this.emplaceListener(eventReflection[eventName] ?? eventName, event => {
|
||||
const result = callback(...event.params);
|
||||
if (typeof (result) === "boolean" && !result) event.cancel();
|
||||
});
|
||||
return true;
|
||||
} catch { }
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* 订阅事件
|
||||
* @param {string} eventName
|
||||
* @param {function} callback
|
||||
* @param {number?} priority
|
||||
* @param {string?} pluginName
|
||||
* @returns {number}
|
||||
*/
|
||||
emplaceListener: function (eventName, callback, priority = this.EventPriority.Normal, pluginName = getPluginName()) {
|
||||
if (typeof callback !== "function") throw new Error("callback must be a function!");
|
||||
const /** @type {number} */ eventId = ll.imports("GMLIB_Event_API", "emplaceListener")(pluginName, eventName, priority);
|
||||
if (eventId === -1) throw new Error(`Event ${eventName} creation failed!`);
|
||||
ll.exports((...data) => {
|
||||
let /** @type {boolean} */ result = typeof (data.slice(-1)[0]) === "boolean" ? data.pop() : false;
|
||||
try {
|
||||
callback({
|
||||
params: data,
|
||||
cancel: () => result = true,
|
||||
setCancelled: (/** @type {boolean} */value) => { result = value; },
|
||||
isCancelled: () => result,
|
||||
getId: () => eventId,
|
||||
getEventType: () => eventName
|
||||
});
|
||||
} catch (error) {
|
||||
try {
|
||||
this.mErrorHanlerCallback(error, eventName, eventId, pluginName);
|
||||
} catch { }
|
||||
}
|
||||
return result;
|
||||
}, pluginName, eventName + "_" + eventId);
|
||||
(this.mEventData[eventName] ??= []).push(eventId);
|
||||
return eventId;
|
||||
},
|
||||
|
||||
/**
|
||||
* 取消事件订阅
|
||||
* @param {number} eventId
|
||||
* @param {boolean}
|
||||
*/
|
||||
removeListener: function (eventId) {
|
||||
const result = ll.imports("GMLIB_Event_API", "removeListener")(eventId);
|
||||
if (result) {
|
||||
for (let [eventName, eventIds] of Object.entries(this.mEventData)) {
|
||||
this.mEventData[eventName] = eventIds.filter(id => id !== eventId);
|
||||
if (this.mEventData[eventName].length === 0) delete this.mEventData[eventName];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
/**
|
||||
* 判断事件订阅是否存在
|
||||
* @param {number} eventId
|
||||
* @returns {boolean}
|
||||
*/
|
||||
hasListener: function (eventId) {
|
||||
return ll.imports("GMLIB_Event_API", "hasListener")(eventId);
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取订阅事件优先级
|
||||
* @param {number} eventId
|
||||
* @returns {number?}
|
||||
*/
|
||||
getListenerPriority: function (eventId) {
|
||||
const priority = ll.imports("GMLIB_Event_API", "getListenerPriority")(eventId);
|
||||
return priority === -1 ? undefined : priority;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取订阅事件列表
|
||||
* @param {string | undefined} eventName
|
||||
* @returns {number[] | Object.<string, number[]>}
|
||||
*/
|
||||
getListener: function (eventName) {
|
||||
return eventName === undefined ? this.mEventData : this.mEventData[eventName] ?? [];
|
||||
},
|
||||
|
||||
/**
|
||||
* 设置异常处理回调
|
||||
* @param {function(Error, string, number, string): void} callback
|
||||
* @returns {boolean}
|
||||
*/
|
||||
setErrorHanlerCallback: function (callback) {
|
||||
if (callback === undefined || typeof callback !== "function") return false;
|
||||
this.mErrorHanlerCallback = callback;
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* 事件优先级
|
||||
*/
|
||||
EventPriority: {
|
||||
Highest: 0,
|
||||
High: 100,
|
||||
Normal: 200,
|
||||
Low: 300,
|
||||
Lowest: 400
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,182 @@
|
||||
// // const getNextCallbackId = ll.import("GMLIB_FormAPI", "getNextFormCallbackId");
|
||||
|
||||
// class ServerSettingForm {
|
||||
// constructor() {
|
||||
// throw new Error("Static class cannot be instantiated");
|
||||
// }
|
||||
|
||||
// static getDefaultPriority() {
|
||||
// return ll.import("GMLIB_ServerSettingForm", "getDefaultPriority")();
|
||||
// }
|
||||
|
||||
// static hasTitle() {
|
||||
// return ll.import("GMLIB_ServerSettingForm", "hasTitle")();
|
||||
// }
|
||||
|
||||
// static getTitle() {
|
||||
// return ll.import("GMLIB_ServerSettingForm", "getTitle")();
|
||||
// }
|
||||
|
||||
// static setTitle(title, forceModify = false) {
|
||||
// return ll.import("GMLIB_ServerSettingForm", "setTitle")(title, forceModify);
|
||||
// }
|
||||
|
||||
// static hasIcon() {
|
||||
// return ll.import("GMLIB_ServerSettingForm", "hasIcon")();
|
||||
// }
|
||||
|
||||
// static getIconData() {
|
||||
// return hasIcon() ? ll.import("GMLIB_ServerSettingForm", "getIconData")() : null;
|
||||
// }
|
||||
|
||||
// static getIconType() {
|
||||
// return ll.import("GMLIB_ServerSettingForm", "getIconType")();
|
||||
// }
|
||||
|
||||
// static setIcon(data, type = 0, forceModify = false) {
|
||||
// return ll.import("GMLIB_ServerSettingForm", "setIcon")(data, type, forceModify);
|
||||
// }
|
||||
|
||||
// static addLabel(
|
||||
// text,
|
||||
// playerDetector = (pl) => { return true; },
|
||||
// priority = this.getDefaultPriority()
|
||||
// ) {
|
||||
// let detectorId = getNextCallbackId();
|
||||
// ll.export(playerDetector, "GMLIB_FORM_CALLBACK", detectorId);
|
||||
// return ll.import("GMLIB_ServerSettingForm", "addLabel")(text, detectorId, priority);
|
||||
// }
|
||||
|
||||
|
||||
// static addInput(
|
||||
// text,
|
||||
// placeholder,
|
||||
// defaultVal,
|
||||
// callback = (pl, input) => { },
|
||||
// playerDetector = (pl) => { return true; },
|
||||
// priority = this.getDefaultPriority()
|
||||
// ) {
|
||||
// let callbackId = getNextCallbackId();
|
||||
// ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
||||
// let detectorId = getNextCallbackId();
|
||||
// ll.export(playerDetector, "GMLIB_FORM_CALLBACK", detectorId);
|
||||
// return ll.import("GMLIB_ServerSettingForm", "addInput")(text, placeholder, defaultVal, callbackId, detectorId, priority);
|
||||
// }
|
||||
|
||||
// static addToggle(
|
||||
// text,
|
||||
// defaultVal = false,
|
||||
// callback = (pl, input) => { },
|
||||
// playerDetector = (pl) => { return true; },
|
||||
// priority = this.getDefaultPriority()
|
||||
// ) {
|
||||
// let callbackId = getNextCallbackId();
|
||||
// ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
||||
// let detectorId = getNextCallbackId();
|
||||
// ll.export(playerDetector, "GMLIB_FORM_CALLBACK", detectorId);
|
||||
// return ll.import("GMLIB_ServerSettingForm", "addToggle")(text, defaultVal, callbackId, detectorId, priority);
|
||||
// }
|
||||
|
||||
// static addDropdown(
|
||||
// text,
|
||||
// options,
|
||||
// defaultVal = 0,
|
||||
// callback = (pl, input) => { },
|
||||
// playerDetector = (pl) => { return true; },
|
||||
// priority = this.getDefaultPriority()
|
||||
// ) {
|
||||
// let callbackId = getNextCallbackId();
|
||||
// ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
||||
// let detectorId = getNextCallbackId();
|
||||
// ll.export(playerDetector, "GMLIB_FORM_CALLBACK", detectorId);
|
||||
// return ll.import("GMLIB_ServerSettingForm", "addDropdown")(text, options, defaultVal, callbackId, detectorId, priority);
|
||||
// }
|
||||
|
||||
// static addSlider(
|
||||
// text,
|
||||
// min,
|
||||
// max,
|
||||
// step = 0.0,
|
||||
// defaultVal = 0.0,
|
||||
// callback = (pl, input) => { },
|
||||
// playerDetector = (pl) => { return true; },
|
||||
// priority = this.getDefaultPriority()
|
||||
// ) {
|
||||
// let callbackId = getNextCallbackId();
|
||||
// ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
||||
// let detectorId = getNextCallbackId();
|
||||
// ll.export(playerDetector, "GMLIB_FORM_CALLBACK", detectorId);
|
||||
// return ll.import("GMLIB_ServerSettingForm", "addSlider")(text, min, max, step, defaultVal, callbackId, detectorId, priority);
|
||||
// }
|
||||
|
||||
// static addStepSlider(
|
||||
// text,
|
||||
// steps,
|
||||
// defaultVal = 0,
|
||||
// callback = (pl, input) => { },
|
||||
// playerDetector = (pl) => { return true; },
|
||||
// priority = this.getDefaultPriority()
|
||||
// ) {
|
||||
// let callbackId = getNextCallbackId();
|
||||
// ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
||||
// let detectorId = getNextCallbackId();
|
||||
// ll.export(playerDetector, "GMLIB_FORM_CALLBACK", detectorId);
|
||||
// return ll.import("GMLIB_ServerSettingForm", "addStepSlider")(text, steps, defaultVal, callbackId, detectorId, priority);
|
||||
// }
|
||||
|
||||
// static removeElement(id) {
|
||||
// return ll.import("GMLIB_ServerSettingForm", "removeElement")(id);
|
||||
// }
|
||||
// }
|
||||
|
||||
// class NpcDialogueForm {
|
||||
// constructor(npcName, sceneName, dialogue) {
|
||||
// this.mFormId = ll.import("GMLIB_NpcDialogueForm", "createForm")(npcName, sceneName, dialogue);
|
||||
// }
|
||||
|
||||
// addButton(button) {
|
||||
// return ll.import("GMLIB_NpcDialogueForm", "addButton")(this.mFormId, button);
|
||||
// }
|
||||
|
||||
// sendTo(pl, callback = (pl, index, type) => { }, free = true) {
|
||||
// let callbackId = getNextCallbackId();
|
||||
// ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
||||
// ll.import("GMLIB_NpcDialogueForm", "sendTo")(this.mFormId, pl, callbackId);
|
||||
// if (free) {
|
||||
// this.destroy();
|
||||
// }
|
||||
// }
|
||||
|
||||
// destroy() {
|
||||
// ll.import("GMLIB_NpcDialogueForm", "destroyForm")(this.mFormId);
|
||||
// }
|
||||
// }
|
||||
|
||||
// class ChestForm {
|
||||
// constructor(npcName, sceneName, dialogue) {
|
||||
// this.mFormId = ll.import("GMLIB_NpcDialogueForm", "createForm")(npcName, sceneName, dialogue);
|
||||
// }
|
||||
|
||||
// addButton(button) {
|
||||
// return ll.import("GMLIB_NpcDialogueForm", "addButton")(this.mFormId, button);
|
||||
// }
|
||||
|
||||
// sendTo(pl, free = true) {
|
||||
// //let callbackId = getNextCallbackId();
|
||||
// //ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
||||
// //ll.import("GMLIB_NpcDialogueForm", "sendTo")(this.mFormId, pl, callbackId);
|
||||
// //if (free) {
|
||||
// // this.destroy();
|
||||
// //}
|
||||
// }
|
||||
|
||||
// destroy() {
|
||||
// //ll.import("GMLIB_NpcDialogueForm", "destroyForm")(this.mFormId);
|
||||
// }
|
||||
// }
|
||||
|
||||
// module.exports = {
|
||||
// ServerSettingForm,
|
||||
// NpcDialogueForm,
|
||||
// ChestForm
|
||||
// };
|
||||
Vendored
+1856
File diff suppressed because it is too large
Load Diff
+2462
-86
File diff suppressed because it is too large
Load Diff
+2
-1
@@ -1,9 +1,10 @@
|
||||
{
|
||||
"name": "${pluginName}",
|
||||
"entry": "${pluginFile}",
|
||||
"version": "0.12.6",
|
||||
"version": "0.13.6",
|
||||
"author": "GroupMountain",
|
||||
"type": "native",
|
||||
"passive": true,
|
||||
"dependencies": [
|
||||
{
|
||||
"name": "GMLIB"
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
#include "Global.h"
|
||||
using namespace ll::hash_utils;
|
||||
|
||||
class LegacyScriptBinaryStreamManager {
|
||||
private:
|
||||
int64 mNextBinaryStreamId = 0;
|
||||
std::unordered_map<uint64, std::shared_ptr<GMLIB_BinaryStream>> mBinaryStream;
|
||||
|
||||
public:
|
||||
uint getNextId() { return mNextBinaryStreamId++; }
|
||||
|
||||
void cretateBinaryStream(uint id) { mBinaryStream[id] = std::make_shared<GMLIB_BinaryStream>(); }
|
||||
|
||||
uint64 copyBinaryStream(uint id) {
|
||||
auto nextId = getNextId();
|
||||
cretateBinaryStream(nextId);
|
||||
if(auto bs = getBinaryStream(nextId); bs !=nullptr){
|
||||
getBinaryStream(nextId)->mBuffer = getBinaryStream(id)->mBuffer;
|
||||
}
|
||||
return nextId;
|
||||
}
|
||||
|
||||
void removeBinaryStream(uint64 id) { mBinaryStream.erase(id); }
|
||||
|
||||
std::shared_ptr<GMLIB_BinaryStream> getBinaryStream(uint64 id) {
|
||||
return mBinaryStream.contains(id) ? mBinaryStream.at(id) : nullptr;
|
||||
}
|
||||
|
||||
public:
|
||||
static LegacyScriptBinaryStreamManager& getInstance() {
|
||||
static std::unique_ptr<LegacyScriptBinaryStreamManager> instance;
|
||||
if (!instance) instance = std::make_unique<LegacyScriptBinaryStreamManager>();
|
||||
return *instance;
|
||||
}
|
||||
};
|
||||
|
||||
#define BinaryStreamManager LegacyScriptBinaryStreamManager::getInstance()
|
||||
#define EXPORTAPI(funcName, type, fuc) \
|
||||
RemoteCall::exportAs("GMLIB_BinaryStream_API", funcName, [](uint64 id, type value) -> void { \
|
||||
auto bs = BinaryStreamManager.getBinaryStream(id); \
|
||||
if (bs != nullptr) fuc; \
|
||||
})
|
||||
|
||||
template <typename T>
|
||||
struct Info;
|
||||
template <typename T, typename R, typename A, typename... AS>
|
||||
struct Info<R (T::*)(A, AS...)> {
|
||||
using ArgT = A;
|
||||
};
|
||||
#define EXPORTAPI2(T) EXPORTAPI(#T, Info<decltype(&GMLIB_BinaryStream::T)>::ArgT, bs->T(value))
|
||||
|
||||
void Export_BinaryStream_API() {
|
||||
RemoteCall::exportAs("GMLIB_BinaryStream_API", "create", []() -> uint64 {
|
||||
auto id = BinaryStreamManager.getNextId();
|
||||
BinaryStreamManager.cretateBinaryStream(id);
|
||||
return id;
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_BinaryStream_API", "copy", [](uint64 id) -> uint64 {
|
||||
return BinaryStreamManager.copyBinaryStream(id);
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_BinaryStream_API", "reset", [](uint64 id) -> void {
|
||||
if (BinaryStreamManager.getBinaryStream(id) == nullptr) BinaryStreamManager.cretateBinaryStream(id);
|
||||
else BinaryStreamManager.getBinaryStream(id)->reset();
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_BinaryStream_API", "sendTo", [](uint64 id, Player* player) -> void {
|
||||
if (auto bs = BinaryStreamManager.getBinaryStream(id); bs != nullptr) bs->sendTo(*player);
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_BinaryStream_API", "destroy", [](uint64 id) -> void {
|
||||
BinaryStreamManager.removeBinaryStream(id);
|
||||
});
|
||||
EXPORTAPI("writePacketHeader", int, bs->writePacketHeader((MinecraftPacketIds)value));
|
||||
EXPORTAPI("writeUuid", std::string const&, bs->writeUuid(mce::UUID::fromString(value)));
|
||||
EXPORTAPI("writeItem", ItemStack*, bs->writeType(NetworkItemStackDescriptor(*value)));
|
||||
EXPORTAPI("writeString", std::string const&, bs->writeString(value));
|
||||
EXPORTAPI("writeCompoundTag", CompoundTag*, bs->writeCompoundTag(*value));
|
||||
EXPORTAPI2(writeBool);
|
||||
EXPORTAPI2(writeByte);
|
||||
EXPORTAPI2(writeDouble);
|
||||
EXPORTAPI2(writeFloat);
|
||||
EXPORTAPI2(writeSignedBigEndianInt);
|
||||
EXPORTAPI2(writeSignedInt);
|
||||
EXPORTAPI2(writeSignedInt64);
|
||||
EXPORTAPI2(writeSignedShort);
|
||||
EXPORTAPI2(writeUnsignedChar);
|
||||
EXPORTAPI2(writeUnsignedInt);
|
||||
EXPORTAPI2(writeUnsignedInt64);
|
||||
EXPORTAPI2(writeUnsignedShort);
|
||||
EXPORTAPI2(writeUnsignedVarInt);
|
||||
EXPORTAPI2(writeUnsignedVarInt64);
|
||||
EXPORTAPI2(writeVarInt);
|
||||
EXPORTAPI2(writeVarInt64);
|
||||
}
|
||||
+558
-263
File diff suppressed because it is too large
Load Diff
+16
-15
@@ -1,36 +1,37 @@
|
||||
#include "Entry.h"
|
||||
#include "Global.h"
|
||||
|
||||
ll::Logger logger(PLUGIN_NAME);
|
||||
namespace gmlib {
|
||||
|
||||
namespace GMLIB_LegacyRemoteCallApi {
|
||||
|
||||
std::unique_ptr<LRCA>& LRCA::getInstance() {
|
||||
static std::unique_ptr<LRCA> instance;
|
||||
LegacyRemoteCallApi& LegacyRemoteCallApi::getInstance() {
|
||||
static LegacyRemoteCallApi instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool LRCA::load() {
|
||||
bool LegacyRemoteCallApi::load() {
|
||||
Export_Legacy_GMLib_ModAPI();
|
||||
Export_Legacy_GMLib_ServerAPI();
|
||||
Export_Compatibility_API();
|
||||
ExportPAPI();
|
||||
Export_Event_API();
|
||||
logger.info("GMLIB-LegacyRemoteCallApi Loaded!");
|
||||
logger.info(
|
||||
Export_BinaryStream_API();
|
||||
// Export_Form_API();
|
||||
auto logger = ll::io::LoggerRegistry::getInstance().getOrCreate(PLUGIN_NAME);
|
||||
logger->info("GMLIB-LegacyRemoteCallApi Loaded!");
|
||||
logger->info(
|
||||
"Loaded Version: {} with {}",
|
||||
fmt::format(fg(fmt::color::pink), "GMLIB-" + GMLIB::Version::getLibVersionString()),
|
||||
fmt::format(fg(fmt::color::light_green), "GMLIB-LegacyRemoteCallApi-"+LIB_VERSION.asString())
|
||||
fmt::format(fg(fmt::color::light_green), "GMLIB-LegacyRemoteCallApi-" + LIB_VERSION.asString())
|
||||
);
|
||||
logger.info("Author: GroupMountain");
|
||||
logger.info("Repository: https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi");
|
||||
logger->info("Author: GroupMountain");
|
||||
logger->info("Repository: https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LRCA::enable() { return true; }
|
||||
bool LegacyRemoteCallApi::enable() { return true; }
|
||||
|
||||
bool LRCA::disable() { return true; }
|
||||
bool LegacyRemoteCallApi::disable() { return true; }
|
||||
|
||||
} // namespace GMLIB_LegacyRemoteCallApi
|
||||
} // namespace gmlib
|
||||
|
||||
LL_REGISTER_PLUGIN(GMLIB_LegacyRemoteCallApi::LRCA, GMLIB_LegacyRemoteCallApi::LRCA::getInstance());
|
||||
LL_REGISTER_MOD(gmlib::LegacyRemoteCallApi, gmlib::LegacyRemoteCallApi::getInstance());
|
||||
|
||||
+9
-9
@@ -1,17 +1,17 @@
|
||||
#pragma once
|
||||
#include <ll/api/plugin/NativePlugin.h>
|
||||
#include <ll/api/plugin/RegisterHelper.h>
|
||||
#include <ll/api/mod/NativeMod.h>
|
||||
#include <ll/api/mod/RegisterHelper.h>
|
||||
|
||||
namespace GMLIB_LegacyRemoteCallApi {
|
||||
namespace gmlib {
|
||||
|
||||
class LRCA {
|
||||
class LegacyRemoteCallApi {
|
||||
|
||||
public:
|
||||
static std::unique_ptr<LRCA>& getInstance();
|
||||
static LegacyRemoteCallApi& getInstance();
|
||||
|
||||
LRCA(ll::plugin::NativePlugin& self) : mSelf(self) {}
|
||||
LegacyRemoteCallApi() : mSelf(*ll::mod::NativeMod::current()) {}
|
||||
|
||||
[[nodiscard]] ll::plugin::NativePlugin& getSelf() const { return mSelf; }
|
||||
[[nodiscard]] ll::mod::NativeMod& getSelf() const { return mSelf; }
|
||||
|
||||
/// @return True if the plugin is loaded successfully.
|
||||
bool load();
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
// bool unload();
|
||||
|
||||
private:
|
||||
ll::plugin::NativePlugin& mSelf;
|
||||
ll::mod::NativeMod& mSelf;
|
||||
};
|
||||
|
||||
} // namespace GMLIB_LegacyRemoteCallApi
|
||||
} // namespace gmlib
|
||||
|
||||
+350
-192
@@ -1,201 +1,359 @@
|
||||
#include "Global.h"
|
||||
#include "ll/api/service/Bedrock.h"
|
||||
#include "ll/api/utils/ErrorUtils.h"
|
||||
using namespace ll::hash_utils;
|
||||
|
||||
class EventManager {
|
||||
private:
|
||||
std::unordered_map<ullong, ll::event::ListenerPtr> mEventIds;
|
||||
|
||||
public:
|
||||
static EventManager& getInstance() {
|
||||
static std::unique_ptr<EventManager> instance;
|
||||
if (!instance) instance = std::make_unique<EventManager>();
|
||||
return *instance;
|
||||
}
|
||||
|
||||
ullong getNextId() {
|
||||
auto id = mEventIds.size();
|
||||
mEventIds.emplace(id, nullptr);
|
||||
return id;
|
||||
}
|
||||
|
||||
bool addListener(ullong id, ll::event::ListenerPtr const& listener) {
|
||||
if (mEventIds.contains(id) && mEventIds[id]) return false;
|
||||
mEventIds[id] = listener;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool removeListener(ullong id) {
|
||||
if (ll::event::EventBus::getInstance().removeListener(mEventIds[id])) {
|
||||
ll::mod::NativeMod::current()->getLogger().warn("Removed listener with id {}", id);
|
||||
mEventIds[id] = nullptr;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hasListener(ullong id) { return mEventIds.contains(id) && mEventIds[id]; }
|
||||
|
||||
ll::event::ListenerPtr getListener(ullong id) { return mEventIds.contains(id) ? mEventIds[id] : nullptr; }
|
||||
};
|
||||
|
||||
#define REGISTER_EVENT_LISTEN(eventType, paramType, params, cancelFun, ...) \
|
||||
auto eventPtr = ll::event::EventBus::getInstance().emplaceListener<eventType>( \
|
||||
[pluginName, eventName, eventId](eventType& event) -> void { \
|
||||
if (!RemoteCall::hasFunc(pluginName, eventName + "_" + std::to_string(eventId))) { \
|
||||
EventManager::getInstance().removeListener(eventId); \
|
||||
return; \
|
||||
} \
|
||||
try { \
|
||||
__VA_ARGS__ \
|
||||
auto result = \
|
||||
RemoteCall::importAs<bool paramType>(pluginName, eventName + "_" + std::to_string(eventId)) \
|
||||
params; \
|
||||
cancelFun \
|
||||
} catch (...) {} \
|
||||
}, \
|
||||
ll::event::EventPriority(priority) \
|
||||
); \
|
||||
return eventId
|
||||
|
||||
void Export_Event_API() {
|
||||
auto eventBus = &ll::event::EventBus::getInstance();
|
||||
RemoteCall::exportAs("GMLIB_Event_API", "removeListener", [](ll::event::ListenerId eventId) -> bool {
|
||||
return EventManager::getInstance().removeListener(eventId);
|
||||
});
|
||||
|
||||
RemoteCall::exportAs("GMLIB_Event_API", "hasListener", [](ll::event::ListenerId eventId) -> bool {
|
||||
return EventManager::getInstance().hasListener(eventId);
|
||||
});
|
||||
|
||||
RemoteCall::exportAs("GMLIB_Event_API", "getListenerPriority", [](ll::event::ListenerId eventId) -> int {
|
||||
if (auto event = EventManager::getInstance().getListener(eventId); event != nullptr) {
|
||||
return (int)event->getPriority();
|
||||
}
|
||||
return -1;
|
||||
});
|
||||
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_API",
|
||||
"callCustomEvent",
|
||||
[eventBus](std::string const& eventName, std::string const& eventId) -> bool {
|
||||
if (RemoteCall::hasFunc(eventName, eventId)) {
|
||||
switch (doHash(eventName)) {
|
||||
case doHash("onClientLogin"): {
|
||||
auto Call = RemoteCall::importAs<bool(
|
||||
std::string const& realName,
|
||||
std::string const& uuid,
|
||||
std::string const& serverXuid,
|
||||
std::string const& clientXuid
|
||||
)>(eventName, eventId);
|
||||
eventBus->emplaceListener<GMLIB::Event::PacketEvent::ClientLoginAfterEvent>(
|
||||
[Call](GMLIB::Event::PacketEvent::ClientLoginAfterEvent& ev) {
|
||||
try {
|
||||
Call(
|
||||
ev.getRealName(),
|
||||
ev.getUuid().asString(),
|
||||
ev.getServerAuthXuid(),
|
||||
ev.getClientAuthXuid()
|
||||
);
|
||||
} catch (...) {}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onWeatherChange"): {
|
||||
auto Call =
|
||||
RemoteCall::importAs<bool(int lightningLevel, int rainLevel, int lightningLast, int rainLast)>(
|
||||
eventName,
|
||||
eventId
|
||||
);
|
||||
eventBus->emplaceListener<GMLIB::Event::LevelEvent::WeatherUpdateBeforeEvent>(
|
||||
[Call](GMLIB::Event::LevelEvent::WeatherUpdateBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(
|
||||
ev.getLightningLevel(),
|
||||
ev.getRainLevel(),
|
||||
ev.getLightningLastTick(),
|
||||
ev.getRainingLastTick()
|
||||
);
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onMobPick"): {
|
||||
auto Call = RemoteCall::importAs<bool(Actor * mob, Actor * item)>(eventName, eventId);
|
||||
eventBus->emplaceListener<GMLIB::Event::EntityEvent::MobPickupItemBeforeEvent>(
|
||||
[Call](GMLIB::Event::EntityEvent::MobPickupItemBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(&ev.self(), (Actor*)&ev.getItemActor());
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onItemTrySpawn"): {
|
||||
auto Call = RemoteCall::importAs<
|
||||
bool(const ItemStack* item, std::pair<Vec3, int> position, Actor* spawner)>(eventName, eventId);
|
||||
eventBus->emplaceListener<GMLIB::Event::EntityEvent::ItemActorSpawnBeforeEvent>(
|
||||
[Call](GMLIB::Event::EntityEvent::ItemActorSpawnBeforeEvent& ev) {
|
||||
auto pos = ev.getPosition();
|
||||
auto dimid = ev.getBlockSource().getDimensionId().id;
|
||||
std::pair<Vec3, int> lsePos = {pos, dimid};
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(&ev.getItem(), lsePos, ev.getSpawner());
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onItemSpawned"): {
|
||||
auto Call = RemoteCall::importAs<
|
||||
bool(const ItemStack* item, Actor* itemActor, std::pair<Vec3, int> position, Actor* spawner)>(
|
||||
eventName,
|
||||
eventId
|
||||
);
|
||||
eventBus->emplaceListener<GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent>(
|
||||
[Call](GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent& ev) {
|
||||
auto pos = ev.getPosition();
|
||||
auto dimid = ev.getBlockSource().getDimensionId().id;
|
||||
std::pair<Vec3, int> lsePos = {pos, dimid};
|
||||
try {
|
||||
Call(&ev.getItem(), (Actor*)&ev.getItemActor(), lsePos, ev.getSpawner());
|
||||
} catch (...) {}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onEntityChangeDim"): {
|
||||
auto Call = RemoteCall::importAs<bool(Actor * entity, int toDimId)>(eventName, eventId);
|
||||
eventBus->emplaceListener<GMLIB::Event::EntityEvent::ActorChangeDimensionBeforeEvent>(
|
||||
[Call](GMLIB::Event::EntityEvent::ActorChangeDimensionBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(&ev.self(), ev.getToDimensionId());
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onLeaveBed"): {
|
||||
auto Call = RemoteCall::importAs<bool(Player * pl)>(eventName, eventId);
|
||||
eventBus->emplaceListener<GMLIB::Event::PlayerEvent::PlayerStopSleepBeforeEvent>(
|
||||
[Call](GMLIB::Event::PlayerEvent::PlayerStopSleepBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(&ev.self());
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onDeathMessage"): {
|
||||
auto Call =
|
||||
RemoteCall::importAs<bool(std::string const& message, std::vector<std::string>, Actor* dead)>(
|
||||
eventName,
|
||||
eventId
|
||||
);
|
||||
eventBus->emplaceListener<GMLIB::Event::EntityEvent::DeathMessageAfterEvent>(
|
||||
[Call](GMLIB::Event::EntityEvent::DeathMessageAfterEvent& ev) {
|
||||
auto msg = ev.getDeathMessage();
|
||||
auto source = ev.getDamageSource();
|
||||
try {
|
||||
Call(msg.first, msg.second, &ev.self());
|
||||
} catch (...) {}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onMobHurted"): {
|
||||
auto Call = RemoteCall::importAs<bool(Actor * mob, Actor * source, float damage, int cause)>(
|
||||
eventName,
|
||||
eventId
|
||||
);
|
||||
eventBus->emplaceListener<GMLIB::Event::EntityEvent::MobHurtAfterEvent>(
|
||||
[Call](GMLIB::Event::EntityEvent::MobHurtAfterEvent& ev) {
|
||||
auto& damageSource = ev.getSource();
|
||||
Actor* source = nullptr;
|
||||
if (damageSource.isEntitySource()) {
|
||||
auto uniqueId = damageSource.getDamagingEntityUniqueID();
|
||||
source = ll::service::getLevel()->fetchEntity(uniqueId);
|
||||
if (source->getOwner()) {
|
||||
source = source->getOwner();
|
||||
}
|
||||
}
|
||||
try {
|
||||
Call(&ev.self(), source, ev.getDamage(), (int)damageSource.getCause());
|
||||
} catch (...) {}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onEndermanTake"): {
|
||||
auto Call = RemoteCall::importAs<bool(Actor * mob)>(eventName, eventId);
|
||||
eventBus->emplaceListener<GMLIB::Event::EntityEvent::EndermanTakeBlockBeforeEvent>(
|
||||
[Call](GMLIB::Event::EntityEvent::EndermanTakeBlockBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(&ev.self());
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
"GMLIB_Event_API",
|
||||
"emplaceListener",
|
||||
[](std::string const& pluginName, std::string const& eventName, int priority) -> llong {
|
||||
auto eventId = EventManager::getInstance().getNextId();
|
||||
switch (doHash(eventName)) {
|
||||
case doHash("ll::ServerStoppingEvent"): {
|
||||
REGISTER_EVENT_LISTEN(ll::event::ServerStoppingEvent, (), (), , );
|
||||
}
|
||||
return false;
|
||||
case doHash("gmlib::ClientLoginAfterEvent"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::PacketEvent::ClientLoginAfterEvent,
|
||||
(std::string const& realName,
|
||||
std::string const& uuid,
|
||||
std::string const& serverXuid,
|
||||
std::string const& clientXuid),
|
||||
(event.getRealName(),
|
||||
event.getUuid().asString(),
|
||||
event.getServerAuthXuid(),
|
||||
event.getClientAuthXuid()),
|
||||
if (result) event.disConnectClient();
|
||||
);
|
||||
}
|
||||
case doHash("gmlib::WeatherUpdateBeforeEvent"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::LevelEvent::WeatherUpdateBeforeEvent,
|
||||
(float rainLevel, int rainTime, float lightningLevel, int lightningTime, bool isCancelled),
|
||||
(event.getRainLevel(),
|
||||
event.getRainingLastTick(),
|
||||
event.getLightningLevel(),
|
||||
event.getLightningLastTick(),
|
||||
event.isCancelled()),
|
||||
event.setCancelled(result);
|
||||
);
|
||||
}
|
||||
case doHash("gmlib::WeatherUpdateAfterEvent"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::LevelEvent::WeatherUpdateAfterEvent,
|
||||
(float rainLevel, int rainTime, float lightningLevel, int lightningTime),
|
||||
(event.getRainLevel(),
|
||||
event.getRainingLastTick(),
|
||||
event.getLightningLevel(),
|
||||
event.getLightningLastTick()),
|
||||
,
|
||||
);
|
||||
}
|
||||
case doHash("gmlib::MobPickupItemBeforeEvent"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::EntityEvent::MobPickupItemBeforeEvent,
|
||||
(Actor * mob, Actor * item, bool isCancelled),
|
||||
(&event.self(), (Actor*)&event.getItemActor(), event.isCancelled()),
|
||||
event.setCancelled(result);
|
||||
);
|
||||
}
|
||||
case doHash("gmlib::MobPickupItemAfterEvent"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::EntityEvent::MobPickupItemAfterEvent,
|
||||
(Actor * mob, Actor * item),
|
||||
(&event.self(), (Actor*)&event.getItemActor()),
|
||||
,
|
||||
);
|
||||
}
|
||||
case doHash("gmlib::ItemActorSpawnBeforeEvent"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::EntityEvent::ItemActorSpawnBeforeEvent,
|
||||
(ItemStack * item, std::pair<Vec3, int> position, int64 spawnerUniqueId, bool isCancelled),
|
||||
(&event.getItem(),
|
||||
{event.getPosition(), event.getBlockSource().getDimensionId().id},
|
||||
event.getSpawner().has_value() ? event.getSpawner()->getOrCreateUniqueID().rawID : -1,
|
||||
event.isCancelled()),
|
||||
event.setCancelled(result);
|
||||
);
|
||||
}
|
||||
case doHash("gmlib::ItemActorSpawnAfterEvent"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent,
|
||||
(Actor * item, std::pair<Vec3, int> position, int64 spawnerUniqueId),
|
||||
(&event.self(),
|
||||
{event.getPosition(), event.getBlockSource().getDimensionId().id},
|
||||
event.getSpawner().has_value() ? event.getSpawner()->getOrCreateUniqueID().rawID : -1),
|
||||
,
|
||||
);
|
||||
}
|
||||
case doHash("gmlib::ActorChangeDimensionBeforeEvent"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::EntityEvent::ActorChangeDimensionBeforeEvent,
|
||||
(Actor * entity, int toDimId, bool isCancelled),
|
||||
(&event.self(), event.getToDimensionId(), event.isCancelled()),
|
||||
event.setCancelled(result);
|
||||
);
|
||||
}
|
||||
case doHash("gmlib::ActorChangeDimensionAfterEvent"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::EntityEvent::ActorChangeDimensionAfterEvent,
|
||||
(Actor * entity, int fromDimId, int toDimId),
|
||||
(&event.self(), event.getFromDimensionId(), event.getToDimensionId()),
|
||||
,
|
||||
);
|
||||
}
|
||||
case doHash("gmlib::PlayerStartSleepBeforeEvent"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::PlayerEvent::PlayerStartSleepBeforeEvent,
|
||||
(Player * entity, BlockPos pos, bool isCancelled),
|
||||
(&event.self(), event.getPosition(), event.isCancelled()),
|
||||
event.setCancelled(result);
|
||||
);
|
||||
}
|
||||
case doHash("gmlib::PlayerStartSleepAfterEvent"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::PlayerEvent::PlayerStartSleepAfterEvent,
|
||||
(Player * entity, BlockPos pos, int result),
|
||||
(&event.self(), event.getPosition(), (int)event.getResult()),
|
||||
,
|
||||
);
|
||||
}
|
||||
case doHash("gmlib::PlayerStopSleepBeforeEvent"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::PlayerEvent::PlayerStopSleepBeforeEvent,
|
||||
(Player * entity, bool forcefulWakeUp, bool updateLevelList, bool isCancelled),
|
||||
(&event.self(), event.isForcefulWakeUp(), event.isUpdateLevelList(), event.isCancelled()),
|
||||
event.setCancelled(result);
|
||||
);
|
||||
}
|
||||
case doHash("gmlib::PlayerStopSleepAfterEvent"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::PlayerEvent::PlayerStopSleepAfterEvent,
|
||||
(Player * entity, bool forcefulWakeUp, bool updateLevelList, bool),
|
||||
(&event.self(), event.isForcefulWakeUp(), event.isUpdateLevelList(), false),
|
||||
,
|
||||
);
|
||||
}
|
||||
case doHash("gmlib::DeathMessageAfterEvent"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::EntityEvent::DeathMessageAfterEvent,
|
||||
(std::string const& message, std::vector<std::string>, Actor* dead),
|
||||
(event.getDeathMessage().first, event.getDeathMessage().second, &event.self()),
|
||||
,
|
||||
);
|
||||
}
|
||||
case doHash("gmlib::MobHurtAfterEvent"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::EntityEvent::MobHurtAfterEvent,
|
||||
(Actor * mob, Actor * source, float damage, int cause),
|
||||
(&event.self(), source, -event.getDamage(), (int)damageSource.getCause()),
|
||||
,
|
||||
auto& damageSource = event.getSource();
|
||||
Actor* source = nullptr;
|
||||
if (damageSource.isEntitySource()) {
|
||||
auto uniqueId = damageSource.getDamagingEntityUniqueID();
|
||||
source = ll::service::getLevel()->fetchEntity(uniqueId, false);
|
||||
if (source->getOwner()) source = source->getOwner();
|
||||
}
|
||||
);
|
||||
}
|
||||
case doHash("gmlib::EndermanTakeBlockBeforeEvent"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::EntityEvent::EndermanTakeBlockBeforeEvent,
|
||||
(Actor * mob, bool isCancelled),
|
||||
(&event.self(), event.isCancelled()),
|
||||
event.setCancelled(result);
|
||||
);
|
||||
}
|
||||
case doHash("gmlib::DragonRespawnBeforeEvent"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::EntityEvent::DragonRespawnBeforeEvent,
|
||||
(bool isCancelled),
|
||||
(event.isCancelled()),
|
||||
event.setCancelled(result);
|
||||
);
|
||||
}
|
||||
case doHash("gmlib::DragonRespawnAfterEvent"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::EntityEvent::DragonRespawnAfterEvent,
|
||||
(Actor * mob),
|
||||
(event.getEnderDragon()),
|
||||
);
|
||||
}
|
||||
case doHash("gmlib::ProjectileCreateBeforeEvent"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::EntityEvent::ProjectileCreateBeforeEvent,
|
||||
(Actor * mob, int64 uniqueId, bool isCancelled),
|
||||
(&event.self(),
|
||||
event.getShooter() ? event.getShooter()->getOrCreateUniqueID().rawID : -1,
|
||||
event.isCancelled()),
|
||||
event.setCancelled(result);
|
||||
);
|
||||
}
|
||||
case doHash("gmlib::ProjectileCreateAfterEvent"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::EntityEvent::ProjectileCreateAfterEvent,
|
||||
(Actor * mob, int64 uniqueId),
|
||||
(&event.self(), event.getShooter() ? event.getShooter()->getOrCreateUniqueID().rawID : -1),
|
||||
);
|
||||
}
|
||||
case doHash("gmlib::SpawnWanderingTraderBeforeEvent"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::EntityEvent::SpawnWanderingTraderBeforeEvent,
|
||||
(std::pair<BlockPos, int> pos, bool isCancelled),
|
||||
({event.getPos(), event.getRegion().getDimensionId()}, event.isCancelled()),
|
||||
event.setCancelled(result);
|
||||
);
|
||||
}
|
||||
case doHash("gmlib::SpawnWanderingTraderAfterEvent"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::EntityEvent::SpawnWanderingTraderAfterEvent,
|
||||
(std::pair<BlockPos, int> pos),
|
||||
({event.getPos(), event.getRegion().getDimensionId()}),
|
||||
);
|
||||
}
|
||||
case doHash("gmlib::HandleRequestActionBeforeEvent"): {
|
||||
// clang-format off
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::PlayerEvent::HandleRequestActionBeforeEvent,
|
||||
(
|
||||
Player * player,
|
||||
std::string const& actionType,
|
||||
int count,
|
||||
std::string const& sourceContainerNetId,
|
||||
int sourceSlot,
|
||||
std::string const& destinationContainerNetId,
|
||||
int destinationSlot,
|
||||
bool isCancelled
|
||||
),
|
||||
(
|
||||
&event.self(),
|
||||
magic_enum::enum_name(requestAction.mActionType).data(),
|
||||
(int)requestAction.mAmount,
|
||||
magic_enum::enum_name(requestAction.mSrc->mFullContainerName.mName).data(),
|
||||
(int)requestAction.mSrc->mSlot,
|
||||
magic_enum::enum_name(requestAction.mDst->mFullContainerName.mName).data(),
|
||||
(int)requestAction.mDst->mSlot,
|
||||
event.isCancelled()
|
||||
),
|
||||
event.setCancelled(result);,
|
||||
auto& requestAction = (ItemStackRequestActionTransferBase&)event.getRequestAction();
|
||||
);
|
||||
// clang-format on
|
||||
}
|
||||
case doHash("gmlib::HandleRequestActionAfterEvent"): {
|
||||
// clang-format off
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::PlayerEvent::HandleRequestActionAfterEvent,
|
||||
(
|
||||
Player * player,
|
||||
std::string const& actionType,
|
||||
int count,
|
||||
std::string const& sourceContainerNetId,
|
||||
int sourceSlot,
|
||||
std::string const& destinationContainerNetId,
|
||||
int destinationSlot
|
||||
),
|
||||
(
|
||||
&event.self(),
|
||||
magic_enum::enum_name(requestAction.mActionType).data(),
|
||||
(int)requestAction.mAmount,
|
||||
magic_enum::enum_name(requestAction.mSrc->mFullContainerName.mName).data(),
|
||||
(int)requestAction.mSrc->mSlot,
|
||||
magic_enum::enum_name(requestAction.mDst->mFullContainerName.mName).data(),
|
||||
(int)requestAction.mDst->mSlot
|
||||
),
|
||||
,
|
||||
auto& requestAction = (ItemStackRequestActionTransferBase&)event.getRequestAction();
|
||||
);
|
||||
// clang-format on
|
||||
}
|
||||
case doHash("gmlib::ContainerClosePacketSendAfterEvent"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
GMLIB::Event::PacketEvent::ContainerClosePacketSendAfterEvent,
|
||||
(Player * player, int containerId, bool serverInitiatedClose, bool),
|
||||
(ll::service::getServerNetworkHandler()
|
||||
->_getServerPlayer(event.getNetworkIdentifier(), event.getPacket().mClientSubId),
|
||||
(int)event.getPacket().mContainerId,
|
||||
event.getPacket().mServerInitiatedClose,
|
||||
false),
|
||||
,
|
||||
);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
);
|
||||
}
|
||||
+288
@@ -0,0 +1,288 @@
|
||||
// #include "Global.h"
|
||||
|
||||
// using namespace ll::hash_utils;
|
||||
|
||||
// class LegacyScriptFormManager {
|
||||
// private:
|
||||
// int64 mNextFormCallbackId = 0;
|
||||
// int64 mNextFormId = 0;
|
||||
// std::unordered_map<int64, std::unique_ptr<gmlib::form::NpcDialogueForm>> mNpcDialogueForms;
|
||||
// // std::unordered_map<int64, std::unique_ptr<ChestForm>> mChestForms;
|
||||
|
||||
// public:
|
||||
// // std::string getNextFormCallbackId() {
|
||||
// // return "GMLIB_FormApi_" + std::to_string(mNextFormCallbackId++);
|
||||
// // }
|
||||
|
||||
// int64 getNextFormId() {
|
||||
// mNextFormId++;
|
||||
// return mNextFormId;
|
||||
// }
|
||||
|
||||
// int64 createNpcDialogueForm(std::string const& npcName, std::string const& sceneName, std::string const& dialogue) {
|
||||
// auto formId = LegacyScriptFormManager::getInstance().getNextFormId();
|
||||
// auto formPtr = std::make_unique<gmlib::form::NpcDialogueForm>(npcName, sceneName, dialogue);
|
||||
// mNpcDialogueForms[formId] = std::move(formPtr);
|
||||
// return formId;
|
||||
// }
|
||||
|
||||
// bool destroyNpcDialogueForm(int64 formId) {
|
||||
// if (mNpcDialogueForms.contains(formId)) {
|
||||
// mNpcDialogueForms.erase(formId);
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// optional_ref<gmlib::form::NpcDialogueForm> getNpcDialogueForm(int64 formId) {
|
||||
// if (mNpcDialogueForms.contains(formId)) {
|
||||
// return mNpcDialogueForms[formId].get();
|
||||
// }
|
||||
// return {};
|
||||
// }
|
||||
|
||||
// /*
|
||||
// int64 createChestForm(std::string const& npcName, std::string const& sceneName, std::string const& dialogue) {
|
||||
// auto formId = LegacyScriptFormManager::getInstance().getNextFormId();
|
||||
// auto formPtr = std::make_unique<ChestForm>(npcName, sceneName, dialogue);
|
||||
// mChestForms[formId] = std::move(formPtr);
|
||||
// return formId;
|
||||
// }
|
||||
|
||||
// bool destroyChestForm(int64 formId) {
|
||||
// if (mChestForms.contains(formId)) {
|
||||
// mChestForms.erase(formId);
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// optional_ref<ChestForm> getChestForm(int64 formId) {
|
||||
// if (mChestForms.contains(formId)) {
|
||||
// return mChestForms[formId].get();
|
||||
// }
|
||||
// return {};
|
||||
// }
|
||||
|
||||
// */
|
||||
// public:
|
||||
// static LegacyScriptFormManager& getInstance() {
|
||||
// static std::unique_ptr<LegacyScriptFormManager> instance;
|
||||
// if (!instance) {
|
||||
// instance = std::make_unique<LegacyScriptFormManager>();
|
||||
// }
|
||||
// return *instance;
|
||||
// }
|
||||
// };
|
||||
|
||||
// #define PLAYER_DETECROR \
|
||||
// [detectorId, result](::Player& pl) -> bool { \
|
||||
// try { \
|
||||
// if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", detectorId)) { \
|
||||
// auto const& detector = RemoteCall::importAs<bool(::Player*)>("GMLIB_FORM_CALLBACK", detectorId); \
|
||||
// return detector(&pl); \
|
||||
// } else { \
|
||||
// gmlib::form::ServerSettingForm::removeElement(result); \
|
||||
// } \
|
||||
// } catch (...) {} \
|
||||
// return false; \
|
||||
// }
|
||||
|
||||
// #define CALLBACK_TYPE(type) \
|
||||
// [callbackId, result](Player& pl, type data) { \
|
||||
// try { \
|
||||
// if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", callbackId)) { \
|
||||
// auto const& callback = RemoteCall::importAs<void(Player*, type)>("GMLIB_FORM_CALLBACK", callbackId); \
|
||||
// callback(&pl, data); \
|
||||
// } else { \
|
||||
// gmlib::form::ServerSettingForm::removeElement(result); \
|
||||
// } \
|
||||
// } catch (...) {} \
|
||||
// }
|
||||
|
||||
// #define CALLBACK_TYPE_NORMAL \
|
||||
// [callbackId](::Player& pl) { \
|
||||
// try { \
|
||||
// if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", callbackId)) { \
|
||||
// auto const& callback = RemoteCall::importAs<void(::Player*)>("GMLIB_FORM_CALLBACK", callbackId); \
|
||||
// callback(&pl); \
|
||||
// } \
|
||||
// } catch (...) {} \
|
||||
// }
|
||||
|
||||
|
||||
// void Export_Form_API() {
|
||||
// //////////////////////////////// Form Manager /////////////////////////////////
|
||||
// // RemoteCall::exportAs("GMLIB_FormAPI", "getNextFormCallbackId", []() -> std::string {
|
||||
// // return LegacyScriptFormManager::getInstance().getNextFormCallbackId();
|
||||
// // });
|
||||
// ////////////////////////////// ServerSettingForm //////////////////////////////
|
||||
// RemoteCall::exportAs("GMLIB_ServerSettingForm", "getDefaultPriority", []() -> int {
|
||||
// return gmlib::form::ServerSettingForm::getDefaultPriority();
|
||||
// });
|
||||
// RemoteCall::exportAs("GMLIB_ServerSettingForm", "hasTitle", []() -> bool { return gmlib::form::ServerSettingForm::hasTitle(); });
|
||||
// RemoteCall::exportAs("GMLIB_ServerSettingForm", "getTitle", []() -> std::string {
|
||||
// return gmlib::form::ServerSettingForm::getTitle();
|
||||
// });
|
||||
// RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "setTitle", [](std::string const& title, bool forceModify) -> bool {
|
||||
// return gmlib::form::ServerSettingForm::setTitle(title, forceModify);
|
||||
// });
|
||||
// RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "hasIcon", []() -> bool { return gmlib::form::ServerSettingForm::hasIcon(); });
|
||||
// RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "getIconData", []() -> std::string {
|
||||
// return gmlib::form::ServerSettingForm::getIconData().value_or("");
|
||||
// });
|
||||
// RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "getIconType", []() -> int {
|
||||
// return gmlib::form::ServerSettingForm::getIconType()
|
||||
// .transform([](gmlib::form::IconType&& type) -> int { return (int)type; })
|
||||
// .value_or(-1);
|
||||
// });
|
||||
// RemoteCall::exportAs(
|
||||
// "GMLIB_gmlib::form::ServerSettingForm",
|
||||
// "setIcon",
|
||||
// [](std::string const& title, uchar type, bool forceModify) -> bool {
|
||||
// return gmlib::form::ServerSettingForm::setIcon(title, gmlib::form::IconType(type), forceModify);
|
||||
// }
|
||||
// );
|
||||
// RemoteCall::exportAs(
|
||||
// "GMLIB_gmlib::form::ServerSettingForm",
|
||||
// "addLabel",
|
||||
// [](std::string const& text, std::string const& detectorId, int priority) -> uint {
|
||||
// uint result = gmlib::form::ServerSettingForm::addLabel(text, PLAYER_DETECROR, priority);
|
||||
// return result;
|
||||
// }
|
||||
// );
|
||||
// RemoteCall::exportAs(
|
||||
// "GMLIB_gmlib::form::ServerSettingForm",
|
||||
// "addInput",
|
||||
// [](std::string const& text,
|
||||
// std::string const& placeholder,
|
||||
// std::string const& defaultVal,
|
||||
// std::string const& callbackId,
|
||||
// std::string const& detectorId,
|
||||
// int priority) -> uint {
|
||||
// uint result = gmlib::form::ServerSettingForm::addInput(
|
||||
// text,
|
||||
// placeholder,
|
||||
// defaultVal,
|
||||
// CALLBACK_TYPE(std::string const&),
|
||||
// PLAYER_DETECROR,
|
||||
// priority
|
||||
// );
|
||||
// return result;
|
||||
// }
|
||||
// );
|
||||
// RemoteCall::exportAs(
|
||||
// "GMLIB_gmlib::form::ServerSettingForm",
|
||||
// "addToggle",
|
||||
// [](std::string const& text,
|
||||
// bool defaultVal,
|
||||
// std::string const& callbackId,
|
||||
// std::string const& detectorId,
|
||||
// int priority) -> uint {
|
||||
// uint result = gmlib::form::ServerSettingForm::addToggle(text, defaultVal, CALLBACK_TYPE(bool), PLAYER_DETECROR, priority);
|
||||
// return result;
|
||||
// }
|
||||
// );
|
||||
// RemoteCall::exportAs(
|
||||
// "GMLIB_gmlib::form::ServerSettingForm",
|
||||
// "addDropdown",
|
||||
// [](std::string const& text,
|
||||
// std::vector<std::string> options,
|
||||
// int64 defaultVal,
|
||||
// std::string const& callbackId,
|
||||
// std::string const& detectorId,
|
||||
// int priority) -> uint {
|
||||
// uint result = gmlib::form::ServerSettingForm::addDropdown(
|
||||
// text,
|
||||
// options,
|
||||
// defaultVal,
|
||||
// CALLBACK_TYPE(int64),
|
||||
// PLAYER_DETECROR,
|
||||
// priority
|
||||
// );
|
||||
// return result;
|
||||
// }
|
||||
// );
|
||||
// RemoteCall::exportAs(
|
||||
// "GMLIB_gmlib::form::ServerSettingForm",
|
||||
// "addSlider",
|
||||
// [](std::string const& text,
|
||||
// double min,
|
||||
// double max,
|
||||
// double step,
|
||||
// double defaultVal,
|
||||
// std::string const& callbackId,
|
||||
// std::string const& detectorId,
|
||||
// int priority) -> uint {
|
||||
// uint result = gmlib::form::ServerSettingForm::addSlider(
|
||||
// text,
|
||||
// min,
|
||||
// max,
|
||||
// step,
|
||||
// defaultVal,
|
||||
// CALLBACK_TYPE(double),
|
||||
// PLAYER_DETECROR,
|
||||
// priority
|
||||
// );
|
||||
// return result;
|
||||
// }
|
||||
// );
|
||||
// RemoteCall::exportAs(
|
||||
// "GMLIB_gmlib::form::ServerSettingForm",
|
||||
// "addStepSlider",
|
||||
// [](std::string const& text,
|
||||
// std::vector<std::string> steps,
|
||||
// int64 defaultVal,
|
||||
// std::string const& callbackId,
|
||||
// std::string const& detectorId,
|
||||
// int priority) -> uint {
|
||||
// uint result = gmlib::form::ServerSettingForm::addStepSlider(
|
||||
// text,
|
||||
// steps,
|
||||
// defaultVal,
|
||||
// CALLBACK_TYPE(int64),
|
||||
// PLAYER_DETECROR,
|
||||
// priority
|
||||
// );
|
||||
// return result;
|
||||
// }
|
||||
// );
|
||||
// RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "removeElement", [](uint id) -> bool {
|
||||
// return gmlib::form::ServerSettingForm::removeElement(id);
|
||||
// });
|
||||
// ////////////////////////////// NpcDialogueForm //////////////////////////////
|
||||
// RemoteCall::exportAs(
|
||||
// "GMLIB_NpcDialogueForm",
|
||||
// "createForm",
|
||||
// [](std::string const& npcName, std::string const& sceneName, std::string const& dialogue) -> int64 {
|
||||
// return LegacyScriptFormManager::getInstance().createNpcDialogueForm(npcName, sceneName, dialogue);
|
||||
// }
|
||||
// );
|
||||
// RemoteCall::exportAs("GMLIB_NpcDialogueForm", "destroyForm", [](int64 formId) -> bool {
|
||||
// return LegacyScriptFormManager::getInstance().destroyNpcDialogueForm(formId);
|
||||
// });
|
||||
// RemoteCall::exportAs(
|
||||
// "GMLIB_NpcDialogueForm",
|
||||
// "addButton",
|
||||
// [](int64 formId, std::string const& button, std::string const& callbackId) -> void {
|
||||
// if (auto formPtr = LegacyScriptFormManager::getInstance().getNpcDialogueForm(formId)) {
|
||||
// formPtr->addButton(button, CALLBACK_TYPE_NORMAL);
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
// RemoteCall::exportAs(
|
||||
// "GMLIB_NpcDialogueForm",
|
||||
// "onPlayerClose",
|
||||
// [](int64 formId, std::string const& callbackId) -> void {
|
||||
// if (auto formPtr = LegacyScriptFormManager::getInstance().getNpcDialogueForm(formId)) {
|
||||
// formPtr->onPlayerClose(CALLBACK_TYPE_NORMAL);
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
// RemoteCall::exportAs("GMLIB_NpcDialogueForm", "sendTo", [](int64 formId, ::Player* pl) -> void {
|
||||
// if (auto formPtr = LegacyScriptFormManager::getInstance().getNpcDialogueForm(formId)) {
|
||||
// formPtr->sendTo(*pl);
|
||||
// }
|
||||
// });
|
||||
// ////////////////////////////// ChestForm //////////////////////////////
|
||||
// }
|
||||
+6
-2
@@ -5,12 +5,16 @@
|
||||
|
||||
#define PLUGIN_NAME fmt::format(fg(fmt::color::light_green), "GMLIB-LRCA")
|
||||
|
||||
#define LIB_VERSION GMLIB::Version(0, 12, 6)
|
||||
#define LIB_VERSION_MAJOR 0
|
||||
#define LIB_VERSION_MINOR 13
|
||||
#define LIB_VERSION_PATCH 6
|
||||
|
||||
extern ll::Logger logger;
|
||||
#define LIB_VERSION GMLIB::Version(LIB_VERSION_MAJOR, LIB_VERSION_MINOR, LIB_VERSION_PATCH)
|
||||
|
||||
extern void Export_Legacy_GMLib_ModAPI();
|
||||
extern void Export_Legacy_GMLib_ServerAPI();
|
||||
extern void Export_Compatibility_API();
|
||||
extern void ExportPAPI();
|
||||
extern void Export_Event_API();
|
||||
extern void Export_BinaryStream_API();
|
||||
// extern void Export_Form_API();
|
||||
|
||||
+46
-66
@@ -3,13 +3,8 @@
|
||||
std::unordered_set<std::string> HardCodedKeys = {"AlwaysUnlocked", "PlayerHasManyItems", "PlayerInWater", "None"};
|
||||
|
||||
std::variant<std::string, std::vector<RecipeIngredient>> makeRecipeUnlockingKey(std::string const& key) {
|
||||
if (HardCodedKeys.count(key)) {
|
||||
return key;
|
||||
}
|
||||
std::vector<RecipeIngredient> result;
|
||||
auto item = RecipeIngredient(key, 0, 1);
|
||||
result.emplace_back(item);
|
||||
return result;
|
||||
if (HardCodedKeys.count(key)) return key;
|
||||
return std::vector<RecipeIngredient>({RecipeIngredient(key, 0, 1)});
|
||||
}
|
||||
|
||||
void Export_Legacy_GMLib_ModAPI() {
|
||||
@@ -22,18 +17,17 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
std::string const& result,
|
||||
int count,
|
||||
std::string const& unlock) -> void {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
if (!GMLIB_Level::getInstance().has_value()) return;
|
||||
std::vector<RecipeIngredient> types;
|
||||
for (auto ing : ingredients) {
|
||||
auto key = RecipeIngredient(ing, 0, 1);
|
||||
types.push_back(key);
|
||||
types.emplace_back(ing, 0, 1);
|
||||
}
|
||||
auto res = RecipeIngredient(result, 0, count);
|
||||
auto unl = makeRecipeUnlockingKey(unlock);
|
||||
GMLIB::Mod::JsonRecipe::registerShapelessCraftingTableRecipe(recipe_id, types, res, unl);
|
||||
GMLIB::Mod::JsonRecipe::registerShapelessCraftingTableRecipe(
|
||||
recipe_id,
|
||||
types,
|
||||
RecipeIngredient(result, 0, count),
|
||||
makeRecipeUnlockingKey(unlock)
|
||||
);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
@@ -45,18 +39,18 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
std::string const& result,
|
||||
int count,
|
||||
std::string const& unlock) -> void {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
if (!GMLIB_Level::getInstance().has_value()) return;
|
||||
std::vector<RecipeIngredient> types;
|
||||
for (auto ing : ingredients) {
|
||||
auto key = RecipeIngredient(ing, 0, 1);
|
||||
types.push_back(key);
|
||||
types.push_back(RecipeIngredient(ing, 0, 1));
|
||||
}
|
||||
auto res = RecipeIngredient(result, 0, count);
|
||||
auto unl = makeRecipeUnlockingKey(unlock);
|
||||
GMLIB::Mod::JsonRecipe::registerShapedCraftingTableRecipe(recipe_id, shape, types, res, unl);
|
||||
GMLIB::Mod::JsonRecipe::registerShapedCraftingTableRecipe(
|
||||
recipe_id,
|
||||
shape,
|
||||
types,
|
||||
RecipeIngredient(result, 0, count),
|
||||
makeRecipeUnlockingKey(unlock)
|
||||
);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
@@ -66,13 +60,13 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
std::string const& input,
|
||||
std::string const& output,
|
||||
std::vector<std::string> tags) -> void {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
auto inp = RecipeIngredient(input, 0, 1);
|
||||
auto outp = RecipeIngredient(output, 0, 1);
|
||||
GMLIB::Mod::JsonRecipe::registerFurnaceRecipe(recipe_id, inp, outp, tags);
|
||||
if (!GMLIB_Level::getInstance().has_value()) return;
|
||||
GMLIB::Mod::JsonRecipe::registerFurnaceRecipe(
|
||||
recipe_id,
|
||||
RecipeIngredient(input, 0, 1),
|
||||
RecipeIngredient(output, 0, 1),
|
||||
tags
|
||||
);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
@@ -80,12 +74,8 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
"registerBrewingMixRecipe",
|
||||
[](std::string const& recipe_id, std::string const& input, std::string const& output, std::string const& reagent
|
||||
) -> void {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
auto rea = RecipeIngredient(reagent, 0, 1);
|
||||
GMLIB::Mod::JsonRecipe::registerBrewingMixRecipe(recipe_id, input, output, rea);
|
||||
if (!GMLIB_Level::getInstance().has_value()) return;
|
||||
GMLIB::Mod::JsonRecipe::registerBrewingMixRecipe(recipe_id, input, output, RecipeIngredient(reagent, 0, 1));
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
@@ -93,14 +83,13 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
"registerBrewingContainerRecipe",
|
||||
[](std::string const& recipe_id, std::string const& input, std::string const& output, std::string const& reagent
|
||||
) -> void {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
auto inp = RecipeIngredient(input, 0, 1);
|
||||
auto outp = RecipeIngredient(output, 0, 1);
|
||||
auto rea = RecipeIngredient(reagent, 0, 1);
|
||||
GMLIB::Mod::JsonRecipe::registerBrewingContainerRecipe(recipe_id, inp, outp, rea);
|
||||
if (!GMLIB_Level::getInstance().has_value()) return;
|
||||
GMLIB::Mod::JsonRecipe::registerBrewingContainerRecipe(
|
||||
recipe_id,
|
||||
RecipeIngredient(input, 0, 1),
|
||||
RecipeIngredient(output, 0, 1),
|
||||
RecipeIngredient(reagent, 0, 1)
|
||||
);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
@@ -111,10 +100,7 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
std::string const& base,
|
||||
std::string const& addition,
|
||||
std::string const& result) -> void {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
if (!GMLIB_Level::getInstance().has_value()) return;
|
||||
GMLIB::Mod::JsonRecipe::registerSmithingTransformRecipe(
|
||||
recipe_id,
|
||||
smithing_template,
|
||||
@@ -131,10 +117,7 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
std::string const& smithing_template,
|
||||
std::string const& base,
|
||||
std::string const& addition) -> void {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
if (!GMLIB_Level::getInstance().has_value()) return;
|
||||
GMLIB::Mod::JsonRecipe::registerSmithingTrimRecipe(recipe_id, smithing_template, base, addition);
|
||||
}
|
||||
);
|
||||
@@ -147,13 +130,12 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
std::string const& output,
|
||||
int output_data,
|
||||
int output_count) -> void {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
auto inp = RecipeIngredient(input, 0, 1);
|
||||
auto outp = RecipeIngredient(output, 0, 1);
|
||||
GMLIB::Mod::JsonRecipe::registerStoneCutterRecipe(recipe_id, inp, outp);
|
||||
if (!GMLIB_Level::getInstance().has_value()) return;
|
||||
GMLIB::Mod::JsonRecipe::registerStoneCutterRecipe(
|
||||
recipe_id,
|
||||
RecipeIngredient(input, 0, 1),
|
||||
RecipeIngredient(output, 0, 1)
|
||||
);
|
||||
}
|
||||
);
|
||||
// 错误方块清理
|
||||
@@ -167,7 +149,7 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
if (set.contains((AllExperiments)experiment_id)) {
|
||||
GMLIB_Level::addExperimentsRequire((AllExperiments)experiment_id);
|
||||
} else {
|
||||
ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
|
||||
ll::io::LoggerRegistry::getInstance().getOrCreate("Server")->error("Experiment ID '{}' does not exist!", experiment_id);
|
||||
}
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ModAPI", "setExperimentEnabled", [](int experiment_id, bool value) -> void {
|
||||
@@ -176,7 +158,7 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
std::unordered_set<AllExperiments> set(list.begin(), list.end());
|
||||
if (set.contains((AllExperiments)experiment_id)) {
|
||||
GMLIB_Level::getInstance()->setExperimentEnabled(((AllExperiments)experiment_id), value);
|
||||
} else ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
|
||||
} else ll::io::LoggerRegistry::getInstance().getOrCreate("Server")->error("Experiment ID '{}' does not exist!", experiment_id);
|
||||
}
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ModAPI", "getExperimentEnabled", [](int experiment_id) -> bool {
|
||||
@@ -185,10 +167,8 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
std::unordered_set<AllExperiments> set(list.begin(), list.end());
|
||||
if (set.contains((AllExperiments)experiment_id)) {
|
||||
return GMLIB_Level::getInstance()->getExperimentEnabled(((AllExperiments)experiment_id));
|
||||
} else {
|
||||
ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
|
||||
return false;
|
||||
}
|
||||
ll::io::LoggerRegistry::getInstance().getOrCreate("Server")->error("Experiment ID '{}' does not exist!", experiment_id);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
+13
-12
@@ -1,6 +1,4 @@
|
||||
#include "GMLIB/Server/FakeListAPI.h"
|
||||
#include "Global.h"
|
||||
#include "mc/world/ActorUniqueID.h"
|
||||
|
||||
void Export_Legacy_GMLib_ServerAPI() {
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setEducationFeatureEnabled", []() -> void {
|
||||
@@ -17,10 +15,9 @@ void Export_Legacy_GMLib_ServerAPI() {
|
||||
GMLIB_Level::requireServerResourcePackAndAllowClientResourcePack();
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "getLevelName", []() -> std::string {
|
||||
if (auto level = GMLIB_Level::getInstance()) {
|
||||
return level->getLevelName();
|
||||
}
|
||||
return {};
|
||||
return GMLIB_Level::getInstance()
|
||||
.transform([](GMLIB_Level& level) -> std::string { return level.getLevelName(); })
|
||||
.value_or("");
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setLevelName", [](std::string const& name) -> void {
|
||||
if (auto level = GMLIB_Level::getInstance()) {
|
||||
@@ -28,10 +25,9 @@ void Export_Legacy_GMLib_ServerAPI() {
|
||||
}
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "getLevelSeed", []() -> std::string {
|
||||
if (auto level = GMLIB_Level::getInstance()) {
|
||||
return std::to_string(level->getSeed());
|
||||
}
|
||||
return {};
|
||||
return GMLIB_Level::getInstance()
|
||||
.transform([](GMLIB_Level& level) -> std::string { return std::to_string(level.getSeed()); })
|
||||
.value_or("");
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setFakeSeed", [](int64_t seed) -> void {
|
||||
return GMLIB_Level::setFakeSeed(seed);
|
||||
@@ -40,7 +36,7 @@ void Export_Legacy_GMLib_ServerAPI() {
|
||||
"GMLib_ServerAPI",
|
||||
"spawnEntity",
|
||||
[](std::pair<Vec3, int> pos, std::string const& name) -> Actor* {
|
||||
return GMLIB_Spawner::spawnEntity(pos.first, pos.second, name);
|
||||
return GMLIB_Spawner::spawnEntity(pos.first, pos.second, name).as_ptr();
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
@@ -48,7 +44,7 @@ void Export_Legacy_GMLib_ServerAPI() {
|
||||
"shootProjectile",
|
||||
[](Actor* owner, std::string const& name, float speed, float offset) -> Actor* {
|
||||
auto ac = (GMLIB_Actor*)owner;
|
||||
return ac->shootProjectile(name, speed, offset);
|
||||
return ac->shootProjectile(name, speed, offset).as_ptr();
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
@@ -73,4 +69,9 @@ void Export_Legacy_GMLib_ServerAPI() {
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "removeAllFakeList", []() -> void {
|
||||
return GMLIB::Server::FakeList::removeAllFakeLists();
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "getMaxPlayers", []() -> int {
|
||||
return GMLIB_Level::getInstance().transform(
|
||||
[](GMLIB_Level& level) -> int { return level.getMaxPlayerCount(); }
|
||||
).value_or(0);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@ bool isParameters(std::string const& str) {
|
||||
|
||||
std::string GetValue(std::string const& from) { return GMLIB::Server::PlaceholderAPI::getValue(from); }
|
||||
|
||||
std::string GetValueWithPlayer(std::string const& a1, std::string const& a2) {
|
||||
return GMLIB::Server::PlaceholderAPI::getValue(a1, ll::service::bedrock::getLevel()->getPlayer(a2));
|
||||
std::string GetValueWithPlayer(std::string const& key, Player* player) {
|
||||
return GMLIB::Server::PlaceholderAPI::getValue(key, player);
|
||||
}
|
||||
|
||||
bool registerPlayerPlaceholder(
|
||||
@@ -25,6 +25,7 @@ bool registerPlayerPlaceholder(
|
||||
std::string const& PAPIName
|
||||
) {
|
||||
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
||||
GMLIB::Server::PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
||||
if (isParameters(PAPIName)) {
|
||||
auto Call = RemoteCall::importAs<std::string(Player * pl, std::unordered_map<std::string, std::string>)>(
|
||||
PluginName,
|
||||
@@ -54,6 +55,7 @@ bool registerServerPlaceholder(
|
||||
std::string const& PAPIName
|
||||
) {
|
||||
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
||||
GMLIB::Server::PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
||||
if (isParameters(PAPIName)) {
|
||||
auto Call =
|
||||
RemoteCall::importAs<std::string(std::unordered_map<std::string, std::string>)>(PluginName, FuncName);
|
||||
@@ -78,6 +80,7 @@ bool registerStaticPlaceholder(
|
||||
int num
|
||||
) {
|
||||
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
||||
GMLIB::Server::PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
||||
if (isParameters(PAPIName)) {
|
||||
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
|
||||
if (num == -1) {
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"format_version": 2,
|
||||
"tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi",
|
||||
"version": "0.12.6",
|
||||
"version": "0.13.6",
|
||||
"info": {
|
||||
"name": "GMLIB-LegacyRemoteCallApi",
|
||||
"description": "Legacy RemoteCall API for GMLIB",
|
||||
@@ -14,9 +14,9 @@
|
||||
"library"
|
||||
]
|
||||
},
|
||||
"asset_url": "https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi/releases/download/v0.12.6/GMLIB-LegacyRemoteCallApi-windows-x64.zip",
|
||||
"asset_url": "https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi/releases/download/v0.13.6/GMLIB-LegacyRemoteCallApi-windows-x64.zip",
|
||||
"dependencies": {
|
||||
"github.com/GroupMountain/GMLIB": ">=0.12.4"
|
||||
"github.com/GroupMountain/GMLIB": ">=0.13.9"
|
||||
},
|
||||
"files": {
|
||||
"place": [
|
||||
|
||||
@@ -1,75 +1,44 @@
|
||||
add_rules("mode.debug", "mode.release")
|
||||
|
||||
add_repositories("liteldev-repo https://github.com/LiteLDev/xmake-repo.git")
|
||||
add_repositories("groupmountain-repo https://github.com/GroupMountain/xmake-repo.git")
|
||||
|
||||
if not has_config("vs_runtime") then
|
||||
set_runtimes("MD")
|
||||
end
|
||||
|
||||
-- Option 1: Use the latest version of LeviLamina released on GitHub.
|
||||
add_requires("levilamina")
|
||||
add_requires("legacyremotecall")
|
||||
add_requires("levilamina 1.0.0-rc.3", {configs = {target_type = "server"}})
|
||||
add_requires("legacyremotecall 0.9.0-rc.1")
|
||||
add_requires("gmlib 0.13.10")
|
||||
add_requires("levibuildscript 0.3.0")
|
||||
|
||||
-- Option 2: Use a specific version of LeviLamina released on GitHub.
|
||||
-- add_requires("levilamina x.x.x")
|
||||
|
||||
-- Option 3: Use the latest commit of LeviLamina on GitHub.
|
||||
-- -- Here, "develop" is the branch name. You can change it to any branch name you want.
|
||||
-- add_requires("levilamina develop")
|
||||
-- -- You can also use debug build of LeviLamina.
|
||||
-- -- add_requires("levilamina develop", {debug = true})
|
||||
-- package("levilamina")
|
||||
-- add_urls("https://github.com/LiteLDev/LeviLamina.git")
|
||||
|
||||
-- add_deps("ctre 3.8.1")
|
||||
-- add_deps("entt 3.12.2")
|
||||
-- add_deps("fmt 10.1.1")
|
||||
-- add_deps("gsl 4.0.0")
|
||||
-- add_deps("leveldb 1.23")
|
||||
-- add_deps("magic_enum 0.9.0")
|
||||
-- add_deps("nlohmann_json 3.11.2")
|
||||
-- add_deps("rapidjson 1.1.0")
|
||||
-- add_deps("pcg_cpp 1.0.0")
|
||||
-- add_deps("pfr 2.1.1")
|
||||
-- add_deps("preloader 1.4.0")
|
||||
-- add_deps("symbolprovider 1.1.0")
|
||||
|
||||
-- -- You may need to change this to the target BDS version of your choice.
|
||||
-- add_deps("bdslibrary 1.20.50.03")
|
||||
|
||||
-- on_install(function (package)
|
||||
-- import("package.tools.xmake").install(package)
|
||||
-- end)
|
||||
|
||||
target("GMLIB-LegacyRemoteCallApi") -- Change this to your plugin name.
|
||||
target("GMLIB-LegacyRemoteCallApi")
|
||||
add_cxflags(
|
||||
"/EHa",
|
||||
"/utf-8"
|
||||
)
|
||||
add_defines(
|
||||
"NOMINMAX",
|
||||
"UNICODE"
|
||||
"UNICODE",
|
||||
"_HAS_CXX17",
|
||||
"_HAS_CXX20",
|
||||
"_HAS_CXX23"
|
||||
)
|
||||
add_files(
|
||||
"src/**.cpp"
|
||||
)
|
||||
add_links(
|
||||
"SDK-GMLIB/Lib/GMLIB"
|
||||
)
|
||||
add_includedirs(
|
||||
"SDK-GMLIB",
|
||||
"src"
|
||||
)
|
||||
add_packages(
|
||||
"levilamina",
|
||||
"legacyremotecall"
|
||||
"legacyremotecall",
|
||||
"gmlib"
|
||||
)
|
||||
add_shflags(
|
||||
"/DELAYLOAD:bedrock_server.dll" -- Magic to import symbols from BDS
|
||||
)
|
||||
set_exceptions("none") -- To avoid conflicts with /EHa
|
||||
add_rules("@levibuildscript/linkrule")
|
||||
set_exceptions("none")
|
||||
set_kind("shared")
|
||||
set_languages("c++23")
|
||||
set_languages("cxx20")
|
||||
set_symbols("debug")
|
||||
|
||||
after_build(function (target)
|
||||
|
||||
Reference in New Issue
Block a user