Compare commits
148 Commits
@@ -9,12 +9,10 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: xmake-io/github-action-setup-xmake@v1
|
||||
with:
|
||||
xmake-version: "2.9.3"
|
||||
|
||||
- run: |
|
||||
xmake repo -u
|
||||
|
||||
@@ -9,12 +9,10 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: xmake-io/github-action-setup-xmake@v1
|
||||
with:
|
||||
xmake-version: "2.9.3"
|
||||
|
||||
- run: |
|
||||
xmake repo -u
|
||||
|
||||
@@ -15,3 +15,4 @@ build/
|
||||
/.xmake
|
||||
/CMakeLists.txt
|
||||
/bin
|
||||
.cache/clangd/index
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
[submodule "SDK-GMLIB"]
|
||||
path = SDK-GMLIB
|
||||
url = https://github.com/GroupMountain/SDK-GMLIB.git
|
||||
@@ -5,6 +5,5 @@ Legacy RemoteCall API for GMLIB. Only for legacy LSE plugin compatibility.
|
||||
- 本模块是 `GMLIB` 的 `Legacy RemoteCall API` 模块,是为LL2的LLSE插件的兼容性保留。
|
||||
- 通过本模块,可以使LSE插件调用 `GMLIB` 内部的API。
|
||||
|
||||
# 注意事项
|
||||
- 本模块仅为兼容性保留模块,仅保留过去的接口以保留兼容性。
|
||||
- 本模块不会提供 `GMLIB` 在迁移到 `LeviLamina` 后新开发的接口。
|
||||
# 开发文档
|
||||
- https://groupmountain.github.io/Documentation/
|
||||
|
||||
-1
Submodule SDK-GMLIB deleted from 9935ed4063
Vendored
+72
@@ -0,0 +1,72 @@
|
||||
declare 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
+251
@@ -0,0 +1,251 @@
|
||||
/** 事件监听接口 */
|
||||
declare class Event {
|
||||
/** 生物捡起物品 */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "onMobDie",
|
||||
/** 监听函数 */
|
||||
listener: (
|
||||
/** 尝试捡起物品的实体对象 */
|
||||
entity: Entity,
|
||||
/** 掉落物实体对象 */
|
||||
itemEntity: Entity
|
||||
) => boolean | void
|
||||
): boolean;
|
||||
|
||||
/** 客户端登录后事件(不可以拦截) */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "onClientLogin",
|
||||
/** 监听函数 */
|
||||
listener: (
|
||||
/** 玩家的游戏名字 */
|
||||
realName: string,
|
||||
/** 玩家的uuid */
|
||||
uuid: string,
|
||||
/** 玩家在服务端的xuid */
|
||||
serverXuid: string,
|
||||
/** 玩家在客户端的xuid */
|
||||
clientXuid: string
|
||||
) => void
|
||||
): boolean;
|
||||
|
||||
/** 天气改变事件事件 */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "onWeatherChange",
|
||||
/** 监听函数 */
|
||||
listener: (
|
||||
/** 雷暴天气等级 */
|
||||
lightningLevel: number,
|
||||
/** 雨天天气等级 */
|
||||
rainLevel: number,
|
||||
/** 雷暴持续时间(刻) */
|
||||
lightningLastTick: number,
|
||||
/** 雨天持续时间(刻) */
|
||||
rainingLastTick: number
|
||||
) => boolean | void
|
||||
): boolean;
|
||||
|
||||
/** 掉落物尝试生成 */
|
||||
static listen(
|
||||
event: "onItemTrySpawn",
|
||||
listener: (
|
||||
/** 物品对象 */
|
||||
item: Item,
|
||||
/** 尝试生成的坐标对象 */
|
||||
pos: FloatPos,
|
||||
/** 创建掉落物的实体uniqueId */
|
||||
spawnerUniqueId: number
|
||||
) => boolean | void
|
||||
): boolean;
|
||||
|
||||
/** 掉落物生成完毕(不可以拦截) */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "onItemSpawned",
|
||||
/** 回调函数 */
|
||||
listener: (
|
||||
/** 物品对象 */
|
||||
item: Item,
|
||||
/** 掉落物实体对象 */
|
||||
entity: Entity,
|
||||
/** 实体生成的坐标 */
|
||||
pos: FloatPos,
|
||||
/** 创建掉落物的实体uniqueId */
|
||||
spawnerUniqueId: number
|
||||
) => void
|
||||
): boolean;
|
||||
|
||||
/** 实体切换维度 */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "onEntityTryChangeDim",
|
||||
/** 回调函数 */
|
||||
listener: (
|
||||
/** 切换维度的实体对象 */
|
||||
entity: Entity,
|
||||
/** 前往到的维度ID */
|
||||
dimid: number
|
||||
) => boolean | void
|
||||
): boolean;
|
||||
|
||||
/** 实体切换维度后(不可拦截) */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "onEntityChangeDim",
|
||||
/** 回调函数 */
|
||||
listener: (
|
||||
/** 切换维度的实体对象 */
|
||||
entity: Entity,
|
||||
/** 前往到的维度ID */
|
||||
fromDimid: number
|
||||
) => void
|
||||
): boolean;
|
||||
|
||||
/** 玩家下床 */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "onLeaveBed",
|
||||
/** 回调函数 */
|
||||
listener: (
|
||||
/** 下床的玩家对象 */
|
||||
player: Player
|
||||
) => boolean | void
|
||||
): boolean;
|
||||
|
||||
/** 触发死亡信息(不可以拦截) */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "onDeathMessage",
|
||||
/** 回调函数 */
|
||||
listener: (
|
||||
/** 死亡信息键名 */
|
||||
deathMsgKey: string,
|
||||
/** 死亡信息翻译参数 */
|
||||
deathMsgParams: string[],
|
||||
/** 死亡实体的实体对象 */
|
||||
entity: Entity
|
||||
) => void
|
||||
): boolean;
|
||||
|
||||
/** 实体受伤后事件 */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "onMobHurted",
|
||||
/** 回调函数 */
|
||||
listener: (
|
||||
/** 受伤的实体对象 */
|
||||
entity: Entity,
|
||||
/** 造成伤害的实体对象 */
|
||||
source: Entity,
|
||||
/** 伤害值 */
|
||||
damage: number,
|
||||
/** 伤害类型 */
|
||||
cause: number
|
||||
) => void
|
||||
): boolean;
|
||||
|
||||
/** 末影人搬起方块 */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "onEndermanTake",
|
||||
/** 回调函数 */
|
||||
listener: (
|
||||
/** 末影人实体对象 */
|
||||
entity: Entity
|
||||
) => boolean | void
|
||||
): boolean;
|
||||
|
||||
/** 末影龙重生事件 */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "onDragonRespawn",
|
||||
/** 回调函数 */
|
||||
listener: (
|
||||
/** 末影龙重生后的UniqueID */
|
||||
uniqueID: number
|
||||
) => boolean | void
|
||||
): boolean;
|
||||
|
||||
/** 弹射物实体尝试创建 */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "onProjectileTryCreate",
|
||||
/** 回调函数 */
|
||||
listener: (
|
||||
/** 弹射物实体对象 */
|
||||
entity: Entity,
|
||||
/** 创建弹射的实体的uniqueID */
|
||||
uniqueId: number
|
||||
) => boolean | void
|
||||
): boolean;
|
||||
|
||||
/** 弹射物实体成功后(不可拦截) */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "onProjectileCreate",
|
||||
/** 回调函数 */
|
||||
listener: (
|
||||
/** 弹射物实体对象 */
|
||||
entity: Entity,
|
||||
/** 创建弹射的实体的uniqueID */
|
||||
uniqueId: number
|
||||
) => void
|
||||
): boolean;
|
||||
|
||||
/** 生成流浪商人 */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "onSpawnWanderingTrader",
|
||||
/** 回调函数 */
|
||||
listener: (
|
||||
/** 生成的坐标 */
|
||||
pos: IntPos
|
||||
) => boolean | void
|
||||
): boolean;
|
||||
|
||||
/** 处理物品请求 */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "onHandleRequestAction",
|
||||
/** 回调函数 */
|
||||
listener: (
|
||||
/** 请求玩家 */
|
||||
player: Player,
|
||||
/** 请求类型 */
|
||||
actionType: string,
|
||||
/** 请求数量 */
|
||||
count: number,
|
||||
/** 第一个格子的容器类型 */
|
||||
sourceContainerNetId: string,
|
||||
/** 第一个格子的槽位 */
|
||||
sourceSlot: number,
|
||||
/** 第二个格子的容器类型 */
|
||||
destinationContainerNetId: string,
|
||||
/** 第二个格子的槽位 */
|
||||
destinationSlot: number
|
||||
) => boolean | void
|
||||
): boolean;
|
||||
|
||||
/** 发送容器关闭数据包后(不可拦截) */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "onSendContainerClosePacket",
|
||||
/** 回调函数 */
|
||||
listener: (
|
||||
/** 要被关闭的玩家 */
|
||||
player: Player,
|
||||
/** 容器ID */
|
||||
containerId: number
|
||||
) => void
|
||||
): boolean;
|
||||
|
||||
/** 关闭服务器(不可拦截) */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "onServerStopping",
|
||||
/** 回调函数 */
|
||||
listener: () => void
|
||||
): boolean;
|
||||
}
|
||||
+15
-16
@@ -1,29 +1,28 @@
|
||||
const CallEvent = ll.import("GMLIB_API", "callCustomEvent");
|
||||
|
||||
let NextEventId = 0;
|
||||
|
||||
function getNextEventId() {
|
||||
NextEventId++;
|
||||
return "GMLIB_Event_" + NextEventId;
|
||||
}
|
||||
/** 事件创建函数 @type {function(string,string):boolean} */
|
||||
const CallEvent = ll.import("GMLIB_Event_API", "callCustomEvent");
|
||||
/** 获取事件ID函数 @type {function():string} */
|
||||
const getNextEventId = ll.import("GMLIB_Event_API", "getNextScriptEventId");
|
||||
|
||||
/** 事件类 */
|
||||
class Event {
|
||||
constructor() {
|
||||
throw new Error("Static class cannot be instantiated");
|
||||
}
|
||||
constructor() { throw new Error("Static class cannot be instantiated"); }
|
||||
|
||||
/**
|
||||
* 监听事件
|
||||
* @param {string} event 事件名称
|
||||
* @param {function} callback 回调
|
||||
* @returns {boolean} 是否创建成功
|
||||
*/
|
||||
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!`);
|
||||
logger.error(`Cannot listen event "${event}" !`);
|
||||
logger.error(`GMLIB Script Event "${event}" does not exist !`);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Event
|
||||
};
|
||||
module.exports = { Event };
|
||||
@@ -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
+1678
File diff suppressed because it is too large
Load Diff
+2573
-139
File diff suppressed because it is too large
Load Diff
+3
-1
@@ -1,8 +1,10 @@
|
||||
{
|
||||
"name": "${pluginName}",
|
||||
"entry": "${pluginFile}",
|
||||
"version": "0.9.4",
|
||||
"version": "0.13.3",
|
||||
"author": "GroupMountain",
|
||||
"type": "native",
|
||||
"passive": true,
|
||||
"dependencies": [
|
||||
{
|
||||
"name": "GMLIB"
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
#include "Global.h"
|
||||
using namespace ll::hash_utils;
|
||||
|
||||
class LegacyScriptBinaryStreamManager {
|
||||
private:
|
||||
int64 mNextBinaryStreamId = 0;
|
||||
std::unordered_map<uint64, std::shared_ptr<gmlib::network::BinaryStream>> mBinaryStream;
|
||||
|
||||
public:
|
||||
uint getNextId() { return mNextBinaryStreamId++; }
|
||||
|
||||
void cretateBinaryStream(uint id) { mBinaryStream[id] = std::make_shared<gmlib::network::BinaryStream>(); }
|
||||
|
||||
void removeBinaryStream(uint64 id) { mBinaryStream.erase(id); }
|
||||
|
||||
std::shared_ptr<gmlib::network::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::network::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", "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);
|
||||
}
|
||||
+749
-278
File diff suppressed because it is too large
Load Diff
+15
-9
@@ -3,30 +3,36 @@
|
||||
|
||||
ll::Logger logger(PLUGIN_NAME);
|
||||
|
||||
namespace GMLIB_LegacyRemoteCallApi {
|
||||
namespace gmlib {
|
||||
|
||||
std::unique_ptr<LRCA>& LRCA::getInstance() {
|
||||
static std::unique_ptr<LRCA> instance;
|
||||
std::unique_ptr<LegacyRemoteCallApi>& LegacyRemoteCallApi::getInstance() {
|
||||
static std::unique_ptr<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();
|
||||
Export_BinaryStream_API();
|
||||
Export_Form_API();
|
||||
logger.info("GMLIB-LegacyRemoteCallApi Loaded!");
|
||||
logger.info("Version: {}", LIB_VERSION.asString());
|
||||
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())
|
||||
);
|
||||
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 std::unique_ptr<LegacyRemoteCallApi>& getInstance();
|
||||
|
||||
LRCA(ll::plugin::NativePlugin& self) : mSelf(self) {}
|
||||
LegacyRemoteCallApi(ll::mod::NativeMod& self) : mSelf(self) {}
|
||||
|
||||
[[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
|
||||
|
||||
+239
-152
@@ -1,162 +1,249 @@
|
||||
#include "Global.h"
|
||||
using namespace ll::hash_utils;
|
||||
|
||||
class LegacyScriptEventManager {
|
||||
private:
|
||||
int64 mNextEventId = 0;
|
||||
std::unordered_map<uint64, ll::event::ListenerPtr> mEventListeners;
|
||||
|
||||
public:
|
||||
std::string getNextEventId() {
|
||||
mNextEventId++;
|
||||
return "GMLIB_EVENT_" + std::to_string(mNextEventId);
|
||||
}
|
||||
|
||||
void emplaceListener(std::string const& scriptEventId, ll::event::ListenerPtr listenerPtr) {
|
||||
mEventListeners[doHash(scriptEventId)] = std::move(listenerPtr);
|
||||
}
|
||||
|
||||
void removeListener(std::string const& scriptEventId) {
|
||||
ll::event::EventBus::getInstance().removeListener(mEventListeners[doHash(scriptEventId)]);
|
||||
mEventListeners.erase(doHash(scriptEventId));
|
||||
}
|
||||
|
||||
public:
|
||||
static LegacyScriptEventManager& getInstance() {
|
||||
static std::unique_ptr<LegacyScriptEventManager> instance;
|
||||
if (!instance) {
|
||||
instance = std::make_unique<LegacyScriptEventManager>();
|
||||
}
|
||||
return *instance;
|
||||
}
|
||||
};
|
||||
|
||||
#define REGISTER_EVENT_LISTEN(eventType, callFunction, eventParams, cancelFunction, otherFunction) \
|
||||
eventManager.emplaceListener( \
|
||||
eventId, \
|
||||
eventBus.emplaceListener<eventType>([eventName, eventId, &eventBus, &eventManager](eventType& ev) -> void { \
|
||||
if (!RemoteCall::hasFunc(eventName, eventId)) { \
|
||||
eventManager.removeListener(eventId); \
|
||||
return; \
|
||||
} \
|
||||
bool result = true; \
|
||||
try { \
|
||||
otherFunction; \
|
||||
result = RemoteCall::importAs<bool callFunction>(eventName, eventId) eventParams; \
|
||||
} catch (...) {} \
|
||||
if (!result) cancelFunction; \
|
||||
}) \
|
||||
); \
|
||||
return true;
|
||||
|
||||
void Export_Event_API() {
|
||||
auto eventBus = &ll::event::EventBus::getInstance();
|
||||
RemoteCall::exportAs("GMLIB_Event_API", "getNextScriptEventId", []() -> std::string {
|
||||
return LegacyScriptEventManager::getInstance().getNextEventId();
|
||||
});
|
||||
auto& eventBus = ll::event::EventBus::getInstance();
|
||||
auto& eventManager = LegacyScriptEventManager::getInstance();
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_API",
|
||||
"GMLIB_Event_API",
|
||||
"callCustomEvent",
|
||||
[eventBus](std::string eventName, std::string eventId) -> bool {
|
||||
if (RemoteCall::hasFunc(eventName, eventId)) {
|
||||
switch (doHash(eventName)) {
|
||||
case doHash("onClientLogin"): {
|
||||
auto Call = RemoteCall::importAs<
|
||||
bool(std::string realName, std::string uuid, std::string serverXuid, std::string 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("onTextSend"): {
|
||||
auto Call = RemoteCall::importAs<bool(std::string author, std::string message)>(eventName, eventId);
|
||||
eventBus->emplaceListener<GMLIB::Event::PacketEvent::TextPacketSendBeforeEvent>(
|
||||
[Call](GMLIB::Event::PacketEvent::TextPacketSendBeforeEvent& ev) {
|
||||
auto pkt = ev.getPacket();
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(pkt.mAuthor, pkt.mMessage);
|
||||
} 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 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;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
[&eventBus, &eventManager](std::string const& eventName, std::string const& eventId) -> bool {
|
||||
if (!RemoteCall::hasFunc(eventName, eventId)) return false;
|
||||
switch (doHash(eventName)) {
|
||||
case doHash("onClientLogin"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::packet::ClientLoginAfterEvent,
|
||||
(std::string const& realName,
|
||||
std::string const& uuid,
|
||||
std::string const& serverXuid,
|
||||
std::string const& clientXuid),
|
||||
(ev.getRealName(), ev.getUuid().asString(), ev.getServerAuthXuid(), ev.getClientAuthXuid()),
|
||||
logger.error("Event \"onClientLogin\" cannot be intercepted"),
|
||||
)
|
||||
}
|
||||
case doHash("onWeatherChange"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::level::WeatherUpdateBeforeEvent,
|
||||
(int lightningLevel, int rainLevel, int lightningLast, int rainLast),
|
||||
(ev.getLightningLevel(), ev.getRainLevel(), ev.getLightningLastTick(), ev.getRainingLastTick()),
|
||||
ev.cancel(),
|
||||
)
|
||||
}
|
||||
case doHash("onMobPick"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::entity::MobPickupItemBeforeEvent,
|
||||
(Actor * mob, Actor * item),
|
||||
(&ev.self(), (Actor*)&ev.getItemActor()),
|
||||
ev.cancel(),
|
||||
)
|
||||
}
|
||||
case doHash("onItemTrySpawn"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::entity::ItemActorSpawnBeforeEvent,
|
||||
(const ItemStack* item, std::pair<Vec3, int> position, int64 spawnerUniqueId),
|
||||
(&ev.getItem(),
|
||||
{ev.getPosition(), ev.getBlockSource().getDimensionId().id},
|
||||
ev.getSpawner().has_value() ? ev.getSpawner()->getOrCreateUniqueID().id : -1),
|
||||
ev.cancel(),
|
||||
)
|
||||
}
|
||||
case doHash("onItemSpawned"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::entity::ItemActorSpawnAfterEvent,
|
||||
(const ItemStack* item, Actor* itemActor, std::pair<Vec3, int> position, int64 spawnerUniqueId),
|
||||
(&ev.getItem(),
|
||||
(Actor*)&ev.getItemActor(),
|
||||
{ev.getPosition(), ev.getBlockSource().getDimensionId().id},
|
||||
ev.getSpawner().has_value() ? ev.getSpawner()->getOrCreateUniqueID().id : -1),
|
||||
logger.error("Event \"onItemSpawned\" cannot be intercepted"),
|
||||
)
|
||||
}
|
||||
case doHash("onEntityTryChangeDim"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::entity::ActorChangeDimensionBeforeEvent,
|
||||
(Actor * entity, int toDimId),
|
||||
(&ev.self(), ev.getToDimensionId()),
|
||||
ev.cancel(),
|
||||
)
|
||||
}
|
||||
case doHash("onLeaveBed"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::player::PlayerStopSleepBeforeEvent,
|
||||
(Player * pl),
|
||||
(&ev.self()),
|
||||
ev.cancel(),
|
||||
)
|
||||
}
|
||||
case doHash("onDeathMessage"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::entity::DeathMessageAfterEvent,
|
||||
(std::string const& message, std::vector<std::string>, Actor* dead),
|
||||
(ev.getDeathMessage().first, ev.getDeathMessage().second, &ev.self()),
|
||||
logger.error("Event \"onDeathMessage\" cannot be intercepted"),
|
||||
)
|
||||
}
|
||||
case doHash("onMobHurted"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::entity::MobHurtAfterEvent,
|
||||
(Actor * mob, Actor * source, float damage, int cause),
|
||||
(&ev.self(), source, ev.getDamage(), (int)damageSource.getCause()),
|
||||
logger.error("Event \"onMobHurted\" cannot be intercepted"),
|
||||
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();
|
||||
}
|
||||
)
|
||||
}
|
||||
case doHash("onEndermanTake"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::entity::EndermanTakeBlockBeforeEvent,
|
||||
(Actor * mob),
|
||||
(&ev.self()),
|
||||
ev.cancel(),
|
||||
)
|
||||
}
|
||||
case doHash("onEntityChangeDim"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::entity::ActorChangeDimensionAfterEvent,
|
||||
(Actor * mob, int fromDimId),
|
||||
(&ev.self(), ev.getFromDimensionId()),
|
||||
logger.error("Event \"onEntityChangeDim\" cannot be intercepted"),
|
||||
)
|
||||
}
|
||||
case doHash("onDragonRespawn"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::entity::DragonRespawnBeforeEvent,
|
||||
(int64 enderDragonUniqueID),
|
||||
(ev.getEnderDragon().id),
|
||||
ev.cancel(),
|
||||
)
|
||||
}
|
||||
case doHash("onProjectileTryCreate"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::entity::ProjectileCreateBeforeEvent,
|
||||
(Actor * mob, int64 uniqueId),
|
||||
(&ev.self(), ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1),
|
||||
ev.cancel(),
|
||||
)
|
||||
}
|
||||
case doHash("onProjectileCreate"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::entity::ProjectileCreateAfterEvent,
|
||||
(Actor * mob, int64 uniqueId),
|
||||
(&ev.self(), ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1),
|
||||
logger.error("Event \"onProjectileCreate\" cannot be intercepted"),
|
||||
)
|
||||
}
|
||||
case doHash("onSpawnWanderingTrader"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::entity::SpawnWanderingTraderBeforeEvent,
|
||||
(std::pair<BlockPos, int> pos),
|
||||
({ev.getPos(), ev.getRegion().getDimensionId()}),
|
||||
ev.cancel(),
|
||||
)
|
||||
}
|
||||
case doHash("onHandleRequestAction"): {
|
||||
// clang-format off
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::player::HandleRequestActionBeforeEvent,
|
||||
(
|
||||
Player * player,
|
||||
std::string const& actionType,
|
||||
int count,
|
||||
std::string const& sourceContainerNetId,
|
||||
int sourceSlot,
|
||||
std::string const& destinationContainerNetId,
|
||||
int destinationSlot
|
||||
),
|
||||
(
|
||||
(Player*)&ev.self(),
|
||||
magic_enum::enum_name(requestAction.mActionType).data(),
|
||||
(int)requestAction.mAmount,
|
||||
magic_enum::enum_name(requestAction.mSrc.mOpenContainerNetId).data(),
|
||||
(int)requestAction.mSrc.mSlot,
|
||||
magic_enum::enum_name(requestAction.mDst.mOpenContainerNetId).data(),
|
||||
(int)requestAction.mDst.mSlot
|
||||
),
|
||||
ev.cancel(),
|
||||
auto& requestAction = (ItemStackRequestActionTransferBase&)ev.getRequestAction();
|
||||
)
|
||||
// clang-format on
|
||||
}
|
||||
case doHash("onSendContainerClosePacket"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::packet::ContainerClosePacketSendAfterEvent,
|
||||
(Player * player, int ContainerNetId),
|
||||
(ev.getServerNetworkHandler()
|
||||
.getServerPlayer(ev.getNetworkIdentifier(), ev.getPacket().mClientSubId),
|
||||
(int)ev.getPacket().mContainerId),
|
||||
logger.error("Event \"onSendContainerClosePacket\" cannot be intercepted"),
|
||||
)
|
||||
}
|
||||
case doHash("onServerStopping"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
ll::event::server::ServerStoppingEvent,
|
||||
(),
|
||||
(),
|
||||
logger.error("Event \"onServerStopping\" cannot be intercepted"),
|
||||
)
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
);
|
||||
}
|
||||
+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 //////////////////////////////
|
||||
}
|
||||
+10
-3
@@ -1,10 +1,15 @@
|
||||
#pragma once
|
||||
#include <include_all.h>
|
||||
#include <headers/include_all.h>
|
||||
|
||||
#include <RemoteCallAPI.h>
|
||||
|
||||
#define PLUGIN_NAME "GMLIB-LRCA"
|
||||
#define LIB_VERSION SemVersion(0, 9, 4, "", "")
|
||||
#define PLUGIN_NAME fmt::format(fg(fmt::color::light_green), "GMLIB-LRCA")
|
||||
|
||||
#define LIB_VERSION_MAJOR 0
|
||||
#define LIB_VERSION_MINOR 13
|
||||
#define LIB_VERSION_PATCH 3
|
||||
|
||||
#define LIB_VERSION gmlib::Version(LIB_VERSION_MAJOR, LIB_VERSION_MINOR, LIB_VERSION_PATCH)
|
||||
|
||||
extern ll::Logger logger;
|
||||
|
||||
@@ -13,3 +18,5 @@ 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();
|
||||
|
||||
+106
-105
@@ -2,14 +2,9 @@
|
||||
|
||||
std::unordered_set<std::string> HardCodedKeys = {"AlwaysUnlocked", "PlayerHasManyItems", "PlayerInWater", "None"};
|
||||
|
||||
std::variant<std::string, std::vector<RecipeIngredient>> makeRecipeUnlockingKey(std::string& key) {
|
||||
if (HardCodedKeys.count(key)) {
|
||||
return key;
|
||||
}
|
||||
std::vector<RecipeIngredient> result;
|
||||
auto item = RecipeIngredient(key, 0, 1);
|
||||
result.emplace_back(item);
|
||||
return result;
|
||||
std::variant<std::string, std::vector<RecipeIngredient>> makeRecipeUnlockingKey(std::string const& key) {
|
||||
if (HardCodedKeys.count(key)) return key;
|
||||
return std::vector<RecipeIngredient>({RecipeIngredient(key, 0, 1)});
|
||||
}
|
||||
|
||||
void Export_Legacy_GMLib_ModAPI() {
|
||||
@@ -17,100 +12,101 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
RemoteCall::exportAs(
|
||||
"GMLib_ModAPI",
|
||||
"registerShapelessRecipe",
|
||||
[](std::string recipe_id,
|
||||
[](std::string const& recipe_id,
|
||||
std::vector<std::string> ingredients,
|
||||
std::string result,
|
||||
std::string const& result,
|
||||
int count,
|
||||
std::string unlock) -> void {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
std::string const& unlock) -> void {
|
||||
if (!gmlib::world::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::recipe::JsonRecipeRegistry::registerShapelessCraftingTableRecipe(
|
||||
recipe_id,
|
||||
types,
|
||||
RecipeIngredient(result, 0, count),
|
||||
makeRecipeUnlockingKey(unlock)
|
||||
);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLib_ModAPI",
|
||||
"registerShapedRecipe",
|
||||
[](std::string recipe_id,
|
||||
[](std::string const& recipe_id,
|
||||
std::vector<std::string> shape,
|
||||
std::vector<std::string> ingredients,
|
||||
std::string result,
|
||||
std::string const& result,
|
||||
int count,
|
||||
std::string unlock) -> void {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
std::string const& unlock) -> void {
|
||||
if (!gmlib::world::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::recipe::JsonRecipeRegistry::registerShapedCraftingTableRecipe(
|
||||
recipe_id,
|
||||
shape,
|
||||
types,
|
||||
RecipeIngredient(result, 0, count),
|
||||
makeRecipeUnlockingKey(unlock)
|
||||
);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLib_ModAPI",
|
||||
"registerFurnaceRecipe",
|
||||
[](std::string recipe_id, std::string input, std::string 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);
|
||||
[](std::string const& recipe_id,
|
||||
std::string const& input,
|
||||
std::string const& output,
|
||||
std::vector<std::string> tags) -> void {
|
||||
if (!gmlib::world::Level::getInstance().has_value()) return;
|
||||
gmlib::mod::recipe::JsonRecipeRegistry::registerFurnaceRecipe(
|
||||
recipe_id,
|
||||
RecipeIngredient(input, 0, 1),
|
||||
RecipeIngredient(output, 0, 1),
|
||||
tags
|
||||
);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLib_ModAPI",
|
||||
"registerBrewingMixRecipe",
|
||||
[](std::string recipe_id, std::string input, std::string output, std::string 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);
|
||||
[](std::string const& recipe_id, std::string const& input, std::string const& output, std::string const& reagent
|
||||
) -> void {
|
||||
if (!gmlib::world::Level::getInstance().has_value()) return;
|
||||
gmlib::mod::recipe::JsonRecipeRegistry::registerBrewingMixRecipe(
|
||||
recipe_id,
|
||||
input,
|
||||
output,
|
||||
RecipeIngredient(reagent, 0, 1)
|
||||
);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLib_ModAPI",
|
||||
"registerBrewingContainerRecipe",
|
||||
[](std::string recipe_id, std::string input, std::string output, std::string 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);
|
||||
[](std::string const& recipe_id, std::string const& input, std::string const& output, std::string const& reagent
|
||||
) -> void {
|
||||
if (!gmlib::world::Level::getInstance().has_value()) return;
|
||||
gmlib::mod::recipe::JsonRecipeRegistry::registerBrewingContainerRecipe(
|
||||
recipe_id,
|
||||
RecipeIngredient(input, 0, 1),
|
||||
RecipeIngredient(output, 0, 1),
|
||||
RecipeIngredient(reagent, 0, 1)
|
||||
);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLib_ModAPI",
|
||||
"registerSmithingTransformRecipe",
|
||||
[](std::string recipe_id,
|
||||
std::string smithing_template,
|
||||
std::string base,
|
||||
std::string addition,
|
||||
std::string result) -> void {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
GMLIB::Mod::JsonRecipe::registerSmithingTransformRecipe(
|
||||
[](std::string const& recipe_id,
|
||||
std::string const& smithing_template,
|
||||
std::string const& base,
|
||||
std::string const& addition,
|
||||
std::string const& result) -> void {
|
||||
if (!gmlib::world::Level::getInstance().has_value()) return;
|
||||
gmlib::mod::recipe::JsonRecipeRegistry::registerSmithingTransformRecipe(
|
||||
recipe_id,
|
||||
smithing_template,
|
||||
base,
|
||||
@@ -122,66 +118,71 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
RemoteCall::exportAs(
|
||||
"GMLib_ModAPI",
|
||||
"registerSmithingTrimRecipe",
|
||||
[](std::string recipe_id, std::string smithing_template, std::string base, std::string addition) -> void {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
GMLIB::Mod::JsonRecipe::registerSmithingTrimRecipe(recipe_id, smithing_template, base, addition);
|
||||
[](std::string const& recipe_id,
|
||||
std::string const& smithing_template,
|
||||
std::string const& base,
|
||||
std::string const& addition) -> void {
|
||||
if (!gmlib::world::Level::getInstance().has_value()) return;
|
||||
gmlib::mod::recipe::JsonRecipeRegistry::registerSmithingTrimRecipe(
|
||||
recipe_id,
|
||||
smithing_template,
|
||||
base,
|
||||
addition
|
||||
);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLib_ModAPI",
|
||||
"registerStoneCutterRecipe",
|
||||
[](std::string recipe_id,
|
||||
std::string input,
|
||||
int input_data,
|
||||
std::string 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);
|
||||
[](std::string const& recipe_id,
|
||||
std::string const& input,
|
||||
int input_data,
|
||||
std::string const& output,
|
||||
int output_data,
|
||||
int output_count) -> void {
|
||||
if (!gmlib::world::Level::getInstance().has_value()) return;
|
||||
gmlib::mod::recipe::JsonRecipeRegistry::registerStoneCutterRecipe(
|
||||
recipe_id,
|
||||
RecipeIngredient(input, 0, 1),
|
||||
RecipeIngredient(output, 0, 1)
|
||||
);
|
||||
}
|
||||
);
|
||||
// 错误方块清理
|
||||
RemoteCall::exportAs("GMLib_ModAPI", "setUnknownBlockCleaner", []() -> void {
|
||||
GMLIB::Mod::VanillaFix::setAutoCleanUnknownBlockEnabled();
|
||||
gmlib::tools::VanillaFix::setAutoCleanUnknownBlockEnabled();
|
||||
});
|
||||
// 实验性
|
||||
RemoteCall::exportAs("GMLib_ModAPI", "registerExperimentsRequire", [](int experiment_id) -> void {
|
||||
auto map = GMLIB_Level::getAllExperiments();
|
||||
if (map.count(experiment_id)) {
|
||||
GMLIB_Level::addExperimentsRequire((AllExperiments)experiment_id);
|
||||
auto list = gmlib::world::Level::getAllExperiments();
|
||||
std::unordered_set<AllExperiments> set(list.begin(), list.end());
|
||||
if (set.contains((AllExperiments)experiment_id)) {
|
||||
gmlib::world::Level::addExperimentsRequire((AllExperiments)experiment_id);
|
||||
} else {
|
||||
ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
|
||||
}
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ModAPI", "setExperimentEnabled", [](int experiment_id, bool value) -> void {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
if (gmlib::world::Level::getInstance()) {
|
||||
auto list = gmlib::world::Level::getAllExperiments();
|
||||
std::unordered_set<AllExperiments> set(list.begin(), list.end());
|
||||
if (set.contains((AllExperiments)experiment_id)) {
|
||||
gmlib::world::Level::getInstance()->setExperimentEnabled(((AllExperiments)experiment_id), value);
|
||||
} else ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
|
||||
}
|
||||
auto map = GMLIB_Level::getAllExperiments();
|
||||
if (map.count(experiment_id)) {
|
||||
GMLIB_Level::getInstance()->setExperimentEnabled(((AllExperiments)experiment_id), value);
|
||||
} else ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ModAPI", "getExperimentEnabled", [](int experiment_id) -> bool {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return false;
|
||||
}
|
||||
auto map = GMLIB_Level::getAllExperiments();
|
||||
if (map.count(experiment_id)) {
|
||||
return GMLIB_Level::getInstance()->getExperimentEnabled(((AllExperiments)experiment_id));
|
||||
} else {
|
||||
if (gmlib::world::Level::getInstance()) {
|
||||
auto list = gmlib::world::Level::getAllExperiments();
|
||||
std::unordered_set<AllExperiments> set(list.begin(), list.end());
|
||||
if (set.contains((AllExperiments)experiment_id)) {
|
||||
return gmlib::world::Level::getInstance()->getExperimentEnabled(((AllExperiments)experiment_id));
|
||||
}
|
||||
ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ModAPI", "setFixI18nEnabled", []() -> void {
|
||||
gmlib::tools::VanillaFix::setFixI18nEnabled();
|
||||
});
|
||||
}
|
||||
+51
-24
@@ -2,51 +2,78 @@
|
||||
|
||||
void Export_Legacy_GMLib_ServerAPI() {
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setEducationFeatureEnabled", []() -> void {
|
||||
GMLIB_Level::addEducationEditionRequired();
|
||||
gmlib::world::Level::tryEnableEducationEdition();
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "registerAbilityCommand", []() -> void {
|
||||
GMLIB_Level::forceEnableAbilityCommand();
|
||||
gmlib::world::Level::tryRegisterAbilityCommand();
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setEnableAchievement", []() -> void {
|
||||
GMLIB_Level::setForceAchievementsEnabled();
|
||||
gmlib::world::Level::setForceAchievementsEnabled();
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setForceTrustSkins", []() -> void {
|
||||
gmlib::world::Level::trustAllSkins();
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "enableCoResourcePack", []() -> void {
|
||||
gmlib::world::Level::requireServerResourcePackAndAllowClientResourcePack();
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setForceTrustSkins", []() -> void { GMLIB_Level::setForceTrustSkin(); });
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "enableCoResourcePack", []() -> void { GMLIB_Level::setCoResourcePack(); });
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "getLevelName", []() -> std::string {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return "";
|
||||
}
|
||||
return level->getLevelName();
|
||||
return gmlib::world::Level::getInstance()
|
||||
.transform([](gmlib::world::Level& level) -> std::string { return level.getLevelName(); })
|
||||
.value_or("");
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setLevelName", [](std::string name) -> void {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setLevelName", [](std::string const& name) -> void {
|
||||
if (auto level = gmlib::world::Level::getInstance()) {
|
||||
level->setLevelName(name);
|
||||
}
|
||||
return level->setLevelName(name);
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "getLevelSeed", []() -> std::string {
|
||||
return gmlib::world::Level::getInstance()
|
||||
.transform([](gmlib::world::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);
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "spawnEntity", [](std::pair<Vec3, int> pos, std::string name) -> Actor* {
|
||||
return GMLIB_Spawner::spawnEntity(pos.first, pos.second, name);
|
||||
return gmlib::world::Level::setFakeSeed(seed);
|
||||
});
|
||||
RemoteCall::exportAs(
|
||||
"GMLib_ServerAPI",
|
||||
"spawnEntity",
|
||||
[](std::pair<Vec3, int> pos, std::string const& name) -> Actor* {
|
||||
return gmlib::world::Spawner::spawnEntity(pos.first, pos.second, name).as_ptr();
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLib_ServerAPI",
|
||||
"shootProjectile",
|
||||
[](Actor* owner, std::string name, float speed, float offset) -> Actor* {
|
||||
auto ac = (GMLIB_Actor*)owner;
|
||||
return ac->shootProjectile(name, speed, offset);
|
||||
[](Actor* owner, std::string const& name, float speed, float offset) -> Actor* {
|
||||
auto ac = (gmlib::world::Actor*)owner;
|
||||
return ac->shootProjectile(name, speed, offset).as_ptr();
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLib_ServerAPI",
|
||||
"throwEntity",
|
||||
[](Actor* owner, Actor* actor, float speed, float offset) -> bool {
|
||||
auto ac = (GMLIB_Actor*)owner;
|
||||
return ac->throwEntity(actor, speed, offset);
|
||||
auto ac = (gmlib::world::Actor*)owner;
|
||||
return ac->throwEntity(*actor, speed, offset);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "PlayerToEntity", [](Player* player) -> Actor* { return (Actor*)player; });
|
||||
RemoteCall::exportAs(
|
||||
"GMLib_ServerAPI",
|
||||
"addFakeList",
|
||||
[](const std::string& name, const std::string& xuid) -> bool {
|
||||
return gmlib::tools::FakeList::addFakeList(name, xuid, ActorUniqueID(-1));
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "removeFakeList", [](const std::string& nameOrXuid) -> bool {
|
||||
return gmlib::tools::FakeList::removeFakeList(nameOrXuid);
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "removeAllFakeList", []() -> void {
|
||||
return gmlib::tools::FakeList::removeAllFakeLists();
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "getMaxPlayers", []() -> int {
|
||||
return gmlib::world::Level::getInstance()
|
||||
.transform([](gmlib::world::Level& level) -> int { return level.getMaxPlayerCount(); })
|
||||
.value_or(0);
|
||||
});
|
||||
}
|
||||
+66
-33
@@ -3,10 +3,20 @@
|
||||
|
||||
namespace PAPIRemoteCall {
|
||||
|
||||
std::string GetValue(std::string const& from) { return GMLIB::Server::PlaceholderAPI::getValue(from); }
|
||||
std::string removeBrackets(std::string a1) {
|
||||
a1.erase(a1.find_last_not_of("%") + 1);
|
||||
return a1;
|
||||
}
|
||||
|
||||
std::string GetValueWithPlayer(std::string const& a1, std::string const& a2) {
|
||||
return GMLIB::Server::PlaceholderAPI::getValue(a1, ll::service::bedrock::getLevel()->getPlayer(a2));
|
||||
bool isParameters(std::string const& str) {
|
||||
std::regex reg("[<]([^<>]+)[>]");
|
||||
return std::regex_search(removeBrackets(str), reg);
|
||||
}
|
||||
|
||||
std::string GetValue(std::string const& from) { return gmlib::tools::PlaceholderAPI::getValue(from); }
|
||||
|
||||
std::string GetValueWithPlayer(std::string const& key, Player* player) {
|
||||
return gmlib::tools::PlaceholderAPI::getValue(key, player);
|
||||
}
|
||||
|
||||
bool registerPlayerPlaceholder(
|
||||
@@ -15,12 +25,25 @@ bool registerPlayerPlaceholder(
|
||||
std::string const& PAPIName
|
||||
) {
|
||||
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
||||
auto Call = RemoteCall::importAs<std::string(Player * pl)>(PluginName, FuncName);
|
||||
GMLIB::Server::PlaceholderAPI::registerPlayerPlaceholder(
|
||||
PAPIName,
|
||||
[Call](Player* sp) { return Call(sp); },
|
||||
PluginName
|
||||
);
|
||||
gmlib::tools::PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
||||
if (isParameters(PAPIName)) {
|
||||
auto Call = RemoteCall::importAs<std::string(Player * pl, std::unordered_map<std::string, std::string>)>(
|
||||
PluginName,
|
||||
FuncName
|
||||
);
|
||||
gmlib::tools::PlaceholderAPI::registerPlayerPlaceholder(
|
||||
PAPIName,
|
||||
[Call](Player* sp, std::unordered_map<std::string, std::string> map) { return Call(sp, map); },
|
||||
PluginName
|
||||
);
|
||||
} else {
|
||||
auto Call = RemoteCall::importAs<std::string(Player * pl)>(PluginName, FuncName);
|
||||
gmlib::tools::PlaceholderAPI::registerPlayerPlaceholder(
|
||||
PAPIName,
|
||||
[Call](Player* sp) { return Call(sp); },
|
||||
PluginName
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -32,12 +55,19 @@ bool registerServerPlaceholder(
|
||||
std::string const& PAPIName
|
||||
) {
|
||||
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
||||
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
|
||||
GMLIB::Server::PlaceholderAPI::registerServerPlaceholder(
|
||||
PAPIName,
|
||||
[Call]() { return Call(); },
|
||||
PluginName
|
||||
);
|
||||
gmlib::tools::PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
||||
if (isParameters(PAPIName)) {
|
||||
auto Call =
|
||||
RemoteCall::importAs<std::string(std::unordered_map<std::string, std::string>)>(PluginName, FuncName);
|
||||
gmlib::tools::PlaceholderAPI::registerServerPlaceholder(
|
||||
PAPIName,
|
||||
[Call](std::unordered_map<std::string, std::string> map) { return Call(map); },
|
||||
PluginName
|
||||
);
|
||||
} else {
|
||||
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
|
||||
gmlib::tools::PlaceholderAPI::registerServerPlaceholder(PAPIName, [Call]() { return Call(); }, PluginName);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -50,20 +80,23 @@ bool registerStaticPlaceholder(
|
||||
int num
|
||||
) {
|
||||
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
||||
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
|
||||
if (num == -1) {
|
||||
GMLIB::Server::PlaceholderAPI::registerStaticPlaceholder(
|
||||
PAPIName,
|
||||
[Call] { return Call(); },
|
||||
PluginName
|
||||
);
|
||||
} else {
|
||||
GMLIB::Server::PlaceholderAPI::registerStaticPlaceholder(
|
||||
PAPIName,
|
||||
num,
|
||||
[Call] { return Call(); },
|
||||
PluginName
|
||||
);
|
||||
gmlib::tools::PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
||||
if (isParameters(PAPIName)) {
|
||||
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
|
||||
if (num == -1) {
|
||||
gmlib::tools::PlaceholderAPI::registerStaticPlaceholder(
|
||||
PAPIName,
|
||||
[Call] { return Call(); },
|
||||
PluginName
|
||||
);
|
||||
} else {
|
||||
gmlib::tools::PlaceholderAPI::registerStaticPlaceholder(
|
||||
PAPIName,
|
||||
num,
|
||||
[Call] { return Call(); },
|
||||
PluginName
|
||||
);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -71,14 +104,14 @@ bool registerStaticPlaceholder(
|
||||
}
|
||||
|
||||
std::string translateStringWithPlayer(std::string const& str, Player* pl) {
|
||||
return GMLIB::Server::PlaceholderAPI::translateString(str, pl);
|
||||
return gmlib::tools::PlaceholderAPI::translateString(str, pl);
|
||||
}
|
||||
|
||||
std::string translateString(std::string const& str) { return GMLIB::Server::PlaceholderAPI::translateString(str); }
|
||||
std::string translateString(std::string const& str) { return gmlib::tools::PlaceholderAPI::translateString(str); }
|
||||
|
||||
bool unRegisterPlaceholder(std::string const& str) { return GMLIB::Server::PlaceholderAPI::unRegisterPlaceholder(str); }
|
||||
bool unRegisterPlaceholder(std::string const& str) { return gmlib::tools::PlaceholderAPI::unregisterPlaceholder(str); }
|
||||
|
||||
std::vector<std::string> getAllPAPI() { return GMLIB::Server::PlaceholderAPI::getAllPAPI(); }
|
||||
std::vector<std::string> getAllPAPI() { return gmlib::tools::PlaceholderAPI::getAllPAPI(); }
|
||||
|
||||
} // namespace PAPIRemoteCall
|
||||
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"format_version": 2,
|
||||
"tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi",
|
||||
"version": "0.9.4",
|
||||
"version": "0.13.3",
|
||||
"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.9.4/GMLIB-LegacyRemoteCallApi-windows-x64.zip",
|
||||
"asset_url": "https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi/releases/download/v0.13.3/GMLIB-LegacyRemoteCallApi-windows-x64.zip",
|
||||
"dependencies": {
|
||||
"github.com/GroupMountain/GMLIB": ">=0.9.6"
|
||||
"github.com/GroupMountain/GMLIB": ">=0.13.0"
|
||||
},
|
||||
"files": {
|
||||
"place": [
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
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("levilaminalibrary")
|
||||
add_requires("legacyremotecall")
|
||||
add_requires("gmlib")
|
||||
|
||||
-- Option 2: Use a specific version of LeviLamina released on GitHub.
|
||||
-- add_requires("levilamina x.x.x")
|
||||
@@ -53,16 +55,13 @@ target("GMLIB-LegacyRemoteCallApi") -- Change this to your plugin name.
|
||||
add_files(
|
||||
"src/**.cpp"
|
||||
)
|
||||
add_links(
|
||||
"SDK-GMLIB/Lib/GMLIB"
|
||||
)
|
||||
add_includedirs(
|
||||
"SDK-GMLIB",
|
||||
"src"
|
||||
)
|
||||
add_packages(
|
||||
"levilamina",
|
||||
"legacyremotecall"
|
||||
"levilaminalibrary",
|
||||
"legacyremotecall",
|
||||
"gmlib"
|
||||
)
|
||||
add_shflags(
|
||||
"/DELAYLOAD:bedrock_server.dll" -- Magic to import symbols from BDS
|
||||
|
||||
Reference in New Issue
Block a user