Compare commits

...

71 Commits

21 changed files with 4355 additions and 375 deletions
+2 -4
View File
@@ -9,12 +9,10 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v2 uses: actions/checkout@v2
with:
submodules: recursive
- uses: actions/checkout@v4
- uses: xmake-io/github-action-setup-xmake@v1 - uses: xmake-io/github-action-setup-xmake@v1
with:
xmake-version: "2.9.3"
- run: | - run: |
xmake repo -u xmake repo -u
+2 -4
View File
@@ -9,12 +9,10 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v2 uses: actions/checkout@v2
with:
submodules: recursive
- uses: actions/checkout@v4
- uses: xmake-io/github-action-setup-xmake@v1 - uses: xmake-io/github-action-setup-xmake@v1
with:
xmake-version: "2.9.3"
- run: | - run: |
xmake repo -u xmake repo -u
-3
View File
@@ -1,3 +0,0 @@
[submodule "SDK-GMLIB"]
path = SDK-GMLIB
url = https://github.com/GroupMountain/SDK-GMLIB.git
Submodule SDK-GMLIB deleted from 710cc6e4c3
+72
View File
@@ -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[];
}
+81 -2
View File
@@ -1,47 +1,117 @@
const PlaceholderAPI = { const PlaceholderAPI = {
/** 获取一个服务器变量的值 @type {function(string):string} */
getValueAPI: ll.import("BEPlaceholderAPI", "GetValue"), getValueAPI: ll.import("BEPlaceholderAPI", "GetValue"),
/** 获取一个玩家变量的值 @type {function(string,Player):string} */
getValueByPlayerAPI: ll.import("BEPlaceholderAPI", "GetValueWithPlayer"), getValueByPlayerAPI: ll.import("BEPlaceholderAPI", "GetValueWithPlayer"),
/** 注册一个玩家变量 @type {function(string,string,string):boolean} */
registerPlayerPlaceholderAPI: ll.import("BEPlaceholderAPI", "registerPlayerPlaceholder"), registerPlayerPlaceholderAPI: ll.import("BEPlaceholderAPI", "registerPlayerPlaceholder"),
/** 注册一个服务器变量 @type {function(string,string,string):boolean} */
registerServerPlaceholderAPI: ll.import("BEPlaceholderAPI", "registerServerPlaceholder"), registerServerPlaceholderAPI: ll.import("BEPlaceholderAPI", "registerServerPlaceholder"),
/** 注册一个静态变量 @type {function(string,string,string,number):boolean} */
registerStaticPlaceholderAPI: ll.import("BEPlaceholderAPI", "registerStaticPlaceholder"), registerStaticPlaceholderAPI: ll.import("BEPlaceholderAPI", "registerStaticPlaceholder"),
/** 翻译包含PAPI服务器变量的字符串 @type {function(string):string} */
translateStringAPI: ll.import("BEPlaceholderAPI", "translateString"), translateStringAPI: ll.import("BEPlaceholderAPI", "translateString"),
/** 翻译包含PAPI玩家变量的字符串 @type {function(string,Player):string} */
translateStringWithPlayerAPI: ll.import("BEPlaceholderAPI", "translateStringWithPlayer"), translateStringWithPlayerAPI: ll.import("BEPlaceholderAPI", "translateStringWithPlayer"),
/** 注销PAPI变量 @type {function(string):boolean} */
unRegisterPlaceholderAPI: ll.import("BEPlaceholderAPI", "unRegisterPlaceholder"), unRegisterPlaceholderAPI: ll.import("BEPlaceholderAPI", "unRegisterPlaceholder"),
/** 获取所有已注册的PAPI变量 @type {function():Array.<string>} */
getAllPAPI: ll.import("BEPlaceholderAPI", "getAllPAPI") getAllPAPI: ll.import("BEPlaceholderAPI", "getAllPAPI")
} }
Function.prototype.getName = function () { Function.prototype.getName =
return this.name || this.toString().match(/function\s*([^(]*)\(/)[1] /**
* 获取函数名字
* @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 { class PAPI {
constructor() { constructor() {
throw new Error("Static class cannot be instantiated"); 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) { static registerPlayerPlaceholder(func, PluginName, PAPIName) {
ll.export(func, PluginName, func.getName()); ll.export(func, PluginName, func.getName());
return PlaceholderAPI.registerPlayerPlaceholderAPI(PluginName, func.getName(), PAPIName); 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) { static registerServerPlaceholder(func, PluginName, PAPIName) {
ll.export(func, PluginName, func.getName()); ll.export(func, PluginName, func.getName());
return PlaceholderAPI.registerServerPlaceholderAPI(PluginName, func.getName(), PAPIName); 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) { static registerStaticPlaceholder(func, PluginName, PAPIName, UpdateInterval = 50) {
ll.export(func, PluginName, func.getName()); ll.export(func, PluginName, func.getName());
return PlaceholderAPI.registerStaticPlaceholderAPI(PluginName, func.getName(), PAPIName, UpdateInterval); return PlaceholderAPI.registerStaticPlaceholderAPI(PluginName, func.getName(), PAPIName, UpdateInterval);
} }
/**
* 获取一个服务器变量的值
* @param {string} key PAPI变量名
* @returns {string} 值
*/
static getValue(key) { static getValue(key) {
return PlaceholderAPI.getValueAPI(key); return PlaceholderAPI.getValueAPI(key);
} }
/**
* 获取一个玩家变量的值
* @param {string} key PAPI变量名
* @param {Player} pl 玩家对象
* @returns {string} 值
*/
static getValueByPlayer(key, pl) { static getValueByPlayer(key, pl) {
return PlaceholderAPI.getValueByPlayerAPI(key, pl); return PlaceholderAPI.getValueByPlayerAPI(key, pl);
} }
/**
* 翻译带PAPI变量的字符串
* @param {string} str 字符串
* @param {Player} pl 玩家对象
* @returns {string} 翻译结果
*/
static translateString(str, pl = null) { static translateString(str, pl = null) {
if (pl) { if (pl) {
return PlaceholderAPI.translateStringWithPlayerAPI(str, pl); return PlaceholderAPI.translateStringWithPlayerAPI(str, pl);
@@ -49,10 +119,19 @@ class PAPI {
return PlaceholderAPI.translateStringAPI(str); return PlaceholderAPI.translateStringAPI(str);
} }
/**
* 注销一个PAPI变量
* @param {string} str PAPI变量名
* @returns {boolean} 是否注销成功
*/
static unRegisterPlaceholder(str) { static unRegisterPlaceholder(str) {
return PlaceholderAPI.unRegisterPlaceholderAPI(str); return PlaceholderAPI.unRegisterPlaceholderAPI(str);
} }
/**
* 获取所有已注册的PAPI变量
* @returns {Array.<string>} 已注册的PAPI变量数组
*/
static getAllPAPI() { static getAllPAPI() {
return PlaceholderAPI.getAllPAPI(); return PlaceholderAPI.getAllPAPI();
} }
+251
View File
@@ -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,
/** 创建掉落物的实体对象 */
spawnerEntity: Entity
) => boolean | void
): boolean;
/** 掉落物生成完毕(不可以拦截) */
static listen(
/** 事件名 */
event: "onItemSpawned",
/** 回调函数 */
listener: (
/** 物品对象 */
item: Item,
/** 掉落物实体对象 */
entity: Entity,
/** 实体生成的坐标 */
pos: FloatPos,
/** 创建掉落物的实体对象 */
spawnerEntity: Entity
) => void
): boolean;
/** 实体切换维度 */
static listen(
/** 事件名 */
event: "onEntityChangeDim",
/** 回调函数 */
listener: (
/** 切换维度的实体对象 */
entity: Entity,
/** 前往到的维度ID */
dimid: number
) => boolean | void
): boolean;
/** 实体切换维度后(不可拦截) */
static listen(
/** 事件名 */
event: "onEntityChangeDimAfter",
/** 回调函数 */
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;
}
+13
View File
@@ -1,17 +1,30 @@
/** 事件创建函数 @type {function(string,string):boolean} */
const CallEvent = ll.import("GMLIB_API", "callCustomEvent"); const CallEvent = ll.import("GMLIB_API", "callCustomEvent");
/** 事件ID @type {number} */
let NextEventId = 0; let NextEventId = 0;
/**
* 获取事件ID标识名
* @returns {string} 事件ID标识名
*/
function getNextEventId() { function getNextEventId() {
NextEventId++; NextEventId++;
return "GMLIB_Event_" + NextEventId; return "GMLIB_Event_" + NextEventId;
} }
/** 事件类 */
class Event { class Event {
constructor() { constructor() {
throw new Error("Static class cannot be instantiated"); throw new Error("Static class cannot be instantiated");
} }
/**
* 监听事件
* @param {string} event 事件名称
* @param {function} callback 回调
* @returns {boolean} 是否创建成功
*/
static listen(event, callback) { static listen(event, callback) {
let eventId = getNextEventId(); let eventId = getNextEventId();
ll.export(callback, event, eventId); ll.export(callback, event, eventId);
+1373
View File
File diff suppressed because it is too large Load Diff
+1784 -86
View File
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -1,9 +1,10 @@
{ {
"name": "${pluginName}", "name": "${pluginName}",
"entry": "${pluginFile}", "entry": "${pluginFile}",
"version": "0.12.6", "version": "0.13.2",
"author": "GroupMountain", "author": "GroupMountain",
"type": "native", "type": "native",
"passive": true,
"dependencies": [ "dependencies": [
{ {
"name": "GMLIB" "name": "GMLIB"
+382 -27
View File
@@ -1,5 +1,6 @@
#include "Global.h" #include "Global.h"
#include <regex> #include <regex>
#include <vector>
bool isInteger(const std::string& str) { bool isInteger(const std::string& str) {
std::regex pattern("^[+-]?\\d+$"); std::regex pattern("^[+-]?\\d+$");
@@ -19,10 +20,10 @@ void Export_Compatibility_API() {
if (!level) { if (!level) {
return false; return false;
} }
return GMLIB::Mod::CustomRecipe::unregisterRecipe(id); return CustomRecipe::unregisterRecipe(id);
}); });
RemoteCall::exportAs("GMLIB_API", "setCustomPackPath", [](std::string const& path) -> void { RemoteCall::exportAs("GMLIB_API", "setCustomPackPath", [](std::string const& path) -> void {
GMLIB::Mod::CustomPacks::addCustomPackPath(path); CustomPacks::addCustomPackPath(path);
}); });
RemoteCall::exportAs("GMLIB_API", "getServerMspt", []() -> float { RemoteCall::exportAs("GMLIB_API", "getServerMspt", []() -> float {
auto level = GMLIB_Level::getInstance(); auto level = GMLIB_Level::getInstance();
@@ -96,70 +97,71 @@ void Export_Compatibility_API() {
"GMLIB_API", "GMLIB_API",
"createFloatingText", "createFloatingText",
[](std::pair<Vec3, int> pos, std::string const& text, bool papi) -> int { [](std::pair<Vec3, int> pos, std::string const& text, bool papi) -> int {
auto ft = std::make_shared<GMLIB::Server::StaticFloatingText>(text, pos.first, pos.second, papi); auto& manager = FloatingTextManager::getInstance();
GMLIB::Server::FloatingTextManager::getInstance().add(ft); auto ft = manager.createStatic(text, pos.first, pos.second, papi);
manager.add(ft);
return ft->getRuntimeID(); return ft->getRuntimeID();
} }
); );
RemoteCall::exportAs("GMLIB_API", "setFloatingTextData", [](int id, std::string const& text) -> bool { RemoteCall::exportAs("GMLIB_API", "setFloatingTextData", [](int id, std::string const& text) -> bool {
if (auto ft = GMLIB::Server::FloatingTextManager::getInstance().getFloatingText(id)) { if (auto ft = FloatingTextManager::getInstance().getFloatingText(id)) {
ft->setText(text); ft->setText(text);
return true; return true;
} }
return false; return false;
}); });
RemoteCall::exportAs("GMLIB_API", "deleteFloatingText", [](int id) -> bool { RemoteCall::exportAs("GMLIB_API", "deleteFloatingText", [](int id) -> bool {
return GMLIB::Server::FloatingTextManager::getInstance().remove(id); return FloatingTextManager::getInstance().remove(id);
}); });
RemoteCall::exportAs("GMLIB_API", "sendFloatingTextToPlayer", [](int id, Player* pl) -> bool { RemoteCall::exportAs("GMLIB_API", "sendFloatingTextToPlayer", [](int id, Player* pl) -> bool {
if (auto ft = GMLIB::Server::FloatingTextManager::getInstance().getFloatingText(id)) { if (auto ft = FloatingTextManager::getInstance().getFloatingText(id)) {
ft->sendTo(*pl); ft->sendTo(*pl);
return true; return true;
} }
return false; return false;
}); });
RemoteCall::exportAs("GMLIB_API", "sendFloatingText", [](int id) -> bool { RemoteCall::exportAs("GMLIB_API", "sendFloatingText", [](int id) -> bool {
if (auto ft = GMLIB::Server::FloatingTextManager::getInstance().getFloatingText(id)) { if (auto ft = FloatingTextManager::getInstance().getFloatingText(id)) {
ft->sendToClients(); ft->sendToClients();
return true; return true;
} }
return false; return false;
}); });
RemoteCall::exportAs("GMLIB_API", "removeFloatingTextFromPlayer", [](int id, Player* pl) -> bool { RemoteCall::exportAs("GMLIB_API", "removeFloatingTextFromPlayer", [](int id, Player* pl) -> bool {
if (auto ft = GMLIB::Server::FloatingTextManager::getInstance().getFloatingText(id)) { if (auto ft = FloatingTextManager::getInstance().getFloatingText(id)) {
ft->removeFrom(*pl); ft->removeFrom(*pl);
return true; return true;
} }
return false; return false;
}); });
RemoteCall::exportAs("GMLIB_API", "removeFloatingText", [](int id) -> bool { RemoteCall::exportAs("GMLIB_API", "removeFloatingText", [](int id) -> bool {
if (auto ft = GMLIB::Server::FloatingTextManager::getInstance().getFloatingText(id)) { if (auto ft = FloatingTextManager::getInstance().getFloatingText(id)) {
ft->removeFromClients(); ft->removeFromClients();
return true; return true;
} }
return false; return false;
}); });
RemoteCall::exportAs("GMLIB_API", "updateClientFloatingTextData", [](int id, Player* pl) -> bool { RemoteCall::exportAs("GMLIB_API", "updateClientFloatingTextData", [](int id, Player* pl) -> bool {
if (auto ft = GMLIB::Server::FloatingTextManager::getInstance().getFloatingText(id)) { if (auto ft = FloatingTextManager::getInstance().getFloatingText(id)) {
ft->update(*pl); ft->update(*pl);
return true; return true;
} }
return false; return false;
}); });
RemoteCall::exportAs("GMLIB_API", "updateAllClientsFloatingTextData", [](int id) -> bool { RemoteCall::exportAs("GMLIB_API", "updateAllClientsFloatingTextData", [](int id) -> bool {
if (auto ft = GMLIB::Server::FloatingTextManager::getInstance().getFloatingText(id)) { if (auto ft = FloatingTextManager::getInstance().getFloatingText(id)) {
ft->updateClients(); ft->updateClients();
return true; return true;
} }
return false; return false;
}); });
RemoteCall::exportAs("GMLIB_API", "isVersionMatched", [](int a, int b, int c) -> bool { RemoteCall::exportAs("GMLIB_API", "isVersionMatched", [](int a, int b, int c) -> bool {
auto version = GMLIB::Version(a, b, c, "", ""); auto version = Version(a, b, c, "", "");
return LIB_VERSION >= version; return LIB_VERSION >= version;
}); });
RemoteCall::exportAs("GMLIB_API", "getVersion_LRCA", []() -> std::string { return LIB_VERSION.asString(); }); RemoteCall::exportAs("GMLIB_API", "getVersion_LRCA", []() -> std::string { return LIB_VERSION.asString(); });
RemoteCall::exportAs("GMLIB_API", "getVersion_GMLIB", []() -> std::string { RemoteCall::exportAs("GMLIB_API", "getVersion_GMLIB", []() -> std::string {
return GMLIB::Version::getLibVersionString(); return Version::getLibVersionString();
}); });
RemoteCall::exportAs( RemoteCall::exportAs(
"GMLIB_API", "GMLIB_API",
@@ -198,7 +200,8 @@ void Export_Compatibility_API() {
RemoteCall::exportAs( RemoteCall::exportAs(
"GMLIB_API", "GMLIB_API",
"updateOrCreateLanguageFile", "updateOrCreateLanguageFile",
[](std::string const& code, std::string const& lang, std::string const& path) -> void { [](std::string const& code, std::unordered_map<std::string, std::string> lang, std::string const& path
) -> void {
if (GMLIB_Level::getInstance()) { if (GMLIB_Level::getInstance()) {
I18nAPI::updateOrCreateLanguageFile(path, code, lang); I18nAPI::updateOrCreateLanguageFile(path, code, lang);
} }
@@ -508,8 +511,7 @@ void Export_Compatibility_API() {
} }
); );
RemoteCall::exportAs("GMLIB_API", "getPlayerFromUuid", [](std::string const& uuid) -> Player* { RemoteCall::exportAs("GMLIB_API", "getPlayerFromUuid", [](std::string const& uuid) -> Player* {
auto uid = mce::UUID::fromString(uuid); return ll::service::getLevel()->getPlayer(mce::UUID::fromString(uuid));
return ll::service::getLevel()->getPlayer(uuid);
}); });
RemoteCall::exportAs("GMLIB_API", "getPlayerFromUniqueId", [](std::string const& uniqueId) -> Actor* { RemoteCall::exportAs("GMLIB_API", "getPlayerFromUniqueId", [](std::string const& uniqueId) -> Actor* {
auto auid = parseScriptUniqueID(uniqueId); auto auid = parseScriptUniqueID(uniqueId);
@@ -554,32 +556,32 @@ void Export_Compatibility_API() {
); );
RemoteCall::exportAs("GMLIB_API", "getXuidByUuid", [](std::string const& uuid) -> std::string { RemoteCall::exportAs("GMLIB_API", "getXuidByUuid", [](std::string const& uuid) -> std::string {
auto uid = mce::UUID::fromString(uuid); auto uid = mce::UUID::fromString(uuid);
auto result = GMLIB::UserCache::getXuidByUuid(uid); auto result = UserCache::getXuidByUuid(uid);
return result ? result.value() : ""; return result ? result.value() : "";
}); });
RemoteCall::exportAs("GMLIB_API", "getNameByUuid", [](std::string const& uuid) -> std::string { RemoteCall::exportAs("GMLIB_API", "getNameByUuid", [](std::string const& uuid) -> std::string {
auto uid = mce::UUID::fromString(uuid); auto uid = mce::UUID::fromString(uuid);
auto result = GMLIB::UserCache::getNameByUuid(uid); auto result = UserCache::getNameByUuid(uid);
return result ? result.value() : ""; return result ? result.value() : "";
}); });
RemoteCall::exportAs("GMLIB_API", "getUuidByXuid", [](std::string const& xuid) -> std::string { RemoteCall::exportAs("GMLIB_API", "getUuidByXuid", [](std::string const& xuid) -> std::string {
auto result = GMLIB::UserCache::getUuidByXuid(xuid); auto result = UserCache::getUuidByXuid(xuid);
return result ? result.value().asString() : ""; return result ? result.value().asString() : "";
}); });
RemoteCall::exportAs("GMLIB_API", "getNameByXuid", [](std::string const& xuid) -> std::string { RemoteCall::exportAs("GMLIB_API", "getNameByXuid", [](std::string const& xuid) -> std::string {
auto result = GMLIB::UserCache::getNameByXuid(xuid); auto result = UserCache::getNameByXuid(xuid);
return result ? result.value() : ""; return result ? result.value() : "";
}); });
RemoteCall::exportAs("GMLIB_API", "getXuidByName", [](std::string const& name) -> std::string { RemoteCall::exportAs("GMLIB_API", "getXuidByName", [](std::string const& name) -> std::string {
auto result = GMLIB::UserCache::getXuidByName(name); auto result = UserCache::getXuidByName(name);
return result ? result.value() : ""; return result ? result.value() : "";
}); });
RemoteCall::exportAs("GMLIB_API", "getUuidByName", [](std::string const& name) -> std::string { RemoteCall::exportAs("GMLIB_API", "getUuidByName", [](std::string const& name) -> std::string {
auto result = GMLIB::UserCache::getUuidByName(name); auto result = UserCache::getUuidByName(name);
return result ? result.value().asString() : ""; return result ? result.value().asString() : "";
}); });
RemoteCall::exportAs("GMLIB_API", "getUuidByName", [](std::string const& name) -> std::string { RemoteCall::exportAs("GMLIB_API", "getUuidByName", [](std::string const& name) -> std::string {
auto result = GMLIB::UserCache::getUuidByName(name); auto result = UserCache::getUuidByName(name);
return result ? result.value().asString() : ""; return result ? result.value().asString() : "";
}); });
RemoteCall::exportAs( RemoteCall::exportAs(
@@ -587,7 +589,7 @@ void Export_Compatibility_API() {
"getAllPlayerInfo", "getAllPlayerInfo",
[]() -> std::vector<std::unordered_map<std::string, std::string>> { []() -> std::vector<std::unordered_map<std::string, std::string>> {
std::vector<std::unordered_map<std::string, std::string>> result; std::vector<std::unordered_map<std::string, std::string>> result;
GMLIB::UserCache::forEach([&result](const GMLIB::UserCache::UserCacheEntry& entry) { UserCache::forEach([&result](const UserCache::UserCacheEntry& entry) {
std::unordered_map<std::string, std::string> info; std::unordered_map<std::string, std::string> info;
info["Name"] = entry.mName; info["Name"] = entry.mName;
info["Xuid"] = entry.mXuid; info["Xuid"] = entry.mXuid;
@@ -597,10 +599,363 @@ void Export_Compatibility_API() {
return result; return result;
} }
); );
RemoteCall::exportAs("GMLIB_API", "getBlockRuntimeId", [](std::string const& blockName) -> uint { RemoteCall::exportAs("GMLIB_API", "getBlockRuntimeId", [](std::string const& blockName, short legacyData) -> uint {
if (auto block = Block::tryGetFromRegistry(blockName)) { if (auto block = Block::tryGetFromRegistry(blockName, legacyData)) {
return block->getRuntimeId(); return block->getRuntimeId();
} }
return 0; return 0;
}); });
RemoteCall::exportAs("GMLIB_API", "getBlockTranslateKey", [](Block const* block) -> std::string {
return block->buildDescriptionId();
});
RemoteCall::exportAs("GMLIB_API", "getItemTranslateKey", [](ItemStack* item) -> std::string {
return item->getDescriptionId();
});
RemoteCall::exportAs("GMLIB_API", "getEntityTranslateKey", [](Actor* entity) -> std::string {
return entity->getEntityLocNameString();
});
RemoteCall::exportAs(
"GMLIB_API",
"readNbtFromFile",
[](std::string const& path, bool isBinary) -> std::unique_ptr<CompoundTag> {
if (auto nbt = GMLIB_CompoundTag::readFromFile(path, isBinary)) {
return std::make_unique<CompoundTag>(nbt.value());
}
return nullptr;
}
);
RemoteCall::exportAs(
"GMLIB_API",
"saveNbtToFile",
[](std::string const& path, CompoundTag* nbt, bool isBinary) -> bool {
return GMLIB_CompoundTag::saveToFile(path, *nbt, isBinary);
}
);
RemoteCall::exportAs("GMLIB_API", "getBlockDestroySpeed", [](Block const* block) -> float {
return block->getDestroySpeed();
});
RemoteCall::exportAs("GMLIB_API", "getDestroyBlockSpeed", [](ItemStack const* item, Block const* block) -> float {
return item->getDestroySpeed(*block);
});
RemoteCall::exportAs(
"GMLIB_API",
"playerDestroyBlock",
[](Block const* block, std::pair<BlockPos, int> pos, Player* player) -> void {
return block->playerDestroy(*player, pos.first);
}
);
RemoteCall::exportAs("GMLIB_API", "itemCanDestroyBlock", [](ItemStack const* item, Block const* block) -> bool {
return item->canDestroy(block);
});
RemoteCall::exportAs("GMLIB_API", "itemCanDestroyInCreative", [](ItemStack const* item) -> bool {
if (auto itemDef = item->getItem()) {
return itemDef->canDestroyInCreative();
}
return false;
});
RemoteCall::exportAs("GMLIB_API", "itemCanDestroySpecial", [](ItemStack const* item, Block const* block) -> bool {
return item->canDestroySpecial(*block);
});
RemoteCall::exportAs("GMLIB_API", "blockCanDropWithAnyTool", [](Block const* block) -> bool {
return block->canDropWithAnyTool();
});
RemoteCall::exportAs("GMLIB_API", "blockIsAlwaysDestroyable", [](Block const* block) -> bool {
return block->getMaterial().isAlwaysDestroyable();
});
RemoteCall::exportAs(
"GMLIB_API",
"blockPlayerWillDestroy",
[](Block const* block, Player* player, std::pair<BlockPos, int> pos) -> bool {
return block->playerWillDestroy(*player, pos.first);
}
);
RemoteCall::exportAs("GMLIB_API", "playerAttack", [](Player* player, Actor* entity) -> bool {
return player->attack(*entity, ActorDamageCause::EntityAttack);
});
RemoteCall::exportAs("GMLIB_API", "playerPullInEntity", [](Player* player, Actor* entity) -> bool {
return player->pullInEntity(*entity);
});
RemoteCall::exportAs("GMLIB_API", "getBlockTranslateKeyFromName", [](std::string const& blockName) -> std::string {
if (auto block = Block::tryGetFromRegistry(blockName)) {
return block->buildDescriptionId();
}
return "tile.unknown.name";
});
RemoteCall::exportAs(
"GMLIB_API",
"getBlockLightEmission",
[](std::string const& blockName, short legacyData) -> char {
if (auto block = Block::tryGetFromRegistry(blockName, legacyData)) {
return (char)block->getLightEmission().value;
}
return -1;
}
);
RemoteCall::exportAs(
"GMLIB_API",
"getGameRules",
[]() -> std::vector<std::unordered_map<std::string, std::string>> {
auto gameRules = ll::service::getLevel()->getGameRules().getRules();
std::vector<std::unordered_map<std::string, std::string>> result;
for (auto& gameRule : gameRules) {
std::unordered_map<std::string, std::string> data;
data["Name"] = gameRule.getName();
switch (gameRule.getType()) {
case GameRule::Type::Bool:
data["Type"] = "Bool";
data["Value"] = std::to_string(gameRule.getBool());
break;
case GameRule::Type::Float:
data["Type"] = "Float";
data["Value"] = std::to_string(gameRule.getFloat());
break;
case GameRule::Type::Int:
data["Type"] = "Int";
data["Value"] = std::to_string(gameRule.getInt());
break;
case GameRule::Type::Invalid:
break;
}
result.push_back(data);
}
return result;
}
);
RemoteCall::exportAs("GMLIB_API", "getLegalEnchants", [](ItemStack const* item) -> std::vector<std::string> {
std::vector<int> enchants = EnchantUtils::getLegalEnchants(item->getItem());
std::vector<std::string> result;
for (auto& enchant : enchants) {
result.push_back(Enchant::getEnchant((Enchant::Type)enchant)->getStringId());
}
return result;
});
RemoteCall::exportAs("GMLIB_API", "getEnchantTypeNameFromId", [](int id) -> std::string {
if (auto enchant = Enchant::getEnchant((Enchant::Type)id)) {
return std::string(enchant->getStringId());
}
return "";
});
RemoteCall::exportAs(
"GMLIB_API",
"applyEnchant",
[](ItemStack const* item, std::string const& typeName, int level, bool allowNonVanilla) -> bool {
return EnchantUtils::applyEnchant(
*(const_cast<ItemStack*>(item)),
Enchant::getEnchantTypeFromName(HashedString(typeName)),
level,
allowNonVanilla
);
}
);
RemoteCall::exportAs("GMLIB_API", "removeEnchants", [](ItemStack const* item) -> void {
EnchantUtils::removeEnchants((ItemStack&)*item);
});
RemoteCall::exportAs("GMLIB_API", "hasEnchant", [](ItemStack const* item, std::string const& typeName) -> bool {
return EnchantUtils::hasEnchant(
Enchant::getEnchantTypeFromName(HashedString(typeName)),
*(const_cast<ItemStack*>(item))
);
});
RemoteCall::exportAs("GMLIB_API", "getEnchantLevel", [](ItemStack const* item, std::string const& typeName) -> int {
return EnchantUtils::getEnchantLevel(
Enchant::getEnchantTypeFromName(HashedString(typeName)),
*(const_cast<ItemStack*>(item))
);
});
RemoteCall::exportAs(
"GMLIB_API",
"getEnchantNameAndLevel",
[](std::string const& typeName, int level) -> std::string {
return EnchantUtils::getEnchantNameAndLevel(Enchant::getEnchantTypeFromName(HashedString(typeName)), level);
}
);
RemoteCall::exportAs(
"GMLIB_API",
"dropPlayerItem",
[](Player* player, ItemStack const* item, bool randomly) -> bool { return player->drop(*item, randomly); }
);
RemoteCall::exportAs("GMLIB_API", "getPlayerRuntimeId", [](Player* player) -> uint64 {
return player->getRuntimeID().id;
});
RemoteCall::exportAs("GMLIB_API", "getEntityRuntimeId", [](Actor* entity) -> uint64 {
return entity->getRuntimeID().id;
});
RemoteCall::exportAs("GMLIB_API", "getEntityNameTag", [](Actor* entity) -> std::string {
return entity->getNameTag();
});
RemoteCall::exportAs("GMLIB_API", "ItemisUnbreakable", [](ItemStack const* item) -> bool {
return ((GMLIB_ItemStack*)item)->isUnbreakable();
});
RemoteCall::exportAs("GMLIB_API", "setItemUnbreakable", [](ItemStack const* item, bool value) -> void {
((GMLIB_ItemStack*)item)->setUnbreakable(value);
});
RemoteCall::exportAs("GMLIB_API", "getItemShouldKeepOnDeath", [](ItemStack const* item) -> bool {
return ((GMLIB_ItemStack*)item)->getShouldKeepOnDeath();
});
RemoteCall::exportAs("GMLIB_API", "setItemShouldKeepOnDeath", [](ItemStack const* item, bool value) -> void {
((GMLIB_ItemStack*)item)->setShouldKeepOnDeath(value);
});
RemoteCall::exportAs("GMLIB_API", "getItemLockMode", [](ItemStack const* item) -> int {
return (int)((GMLIB_ItemStack*)item)->getItemLockMode();
});
RemoteCall::exportAs("GMLIB_API", "setItemLockMode", [](ItemStack const* item, int value) -> void {
((GMLIB_ItemStack*)item)->setItemLockMode((ItemLockMode)value);
});
RemoteCall::exportAs("GMLIB_API", "getItemRepairCost", [](ItemStack const* item) -> int {
return item->getBaseRepairCost();
});
RemoteCall::exportAs("GMLIB_API", "setItemRepairCost", [](ItemStack const* item, int cost) -> void {
(*(const_cast<ItemStack*>(item))).setRepairCost(cost);
});
RemoteCall::exportAs("GMLIB_API", "getItemCanDestroy", [](ItemStack const* item) -> std::vector<std::string> {
std::vector<std::string> result = {};
for (auto& block : ((GMLIB_ItemStack*)item)->getCanDestroy()) {
result.push_back(block->getTypeName());
}
return result;
});
RemoteCall::exportAs(
"GMLIB_API",
"setItemCanDestroy",
[](ItemStack const* item, std::vector<std::string> blocks) -> void {
((GMLIB_ItemStack*)item)->setCanDestroy(blocks);
}
);
RemoteCall::exportAs("GMLIB_API", "getItemCanPlaceOn", [](ItemStack const* item) -> std::vector<std::string> {
std::vector<std::string> result = {};
for (auto& block : ((GMLIB_ItemStack*)item)->getCanPlaceOn()) {
result.push_back(block->getTypeName());
}
return result;
});
RemoteCall::exportAs(
"GMLIB_API",
"setItemCanPlaceOn",
[](ItemStack const* item, std::vector<std::string> blocks) -> void {
((GMLIB_ItemStack*)item)->setCanPlaceOn(blocks);
}
);
RemoteCall::exportAs("GMLIB_API", "getPlayerHungry", [](Player* player) -> float {
return player->getMutableAttribute(Player::HUNGER)->getCurrentValue();
});
RemoteCall::exportAs("GMLIB_API", "getPlayerArmorCoverPercentage", [](Player* player) -> float {
return player->getArmorCoverPercentage();
});
RemoteCall::exportAs("GMLIB_API", "getPlayerArmorValue", [](Player* player) -> int {
return player->getArmorValue();
});
RemoteCall::exportAs("GMLIB_API", "getEntityOwnerUniqueId", [](Actor* entity) -> int64 {
return entity->getOwnerId().id;
});
RemoteCall::exportAs("GMLIB_API", "getItemCategoryName", [](ItemStack const* item) -> std::string {
return item->getCategoryName();
});
RemoteCall::exportAs("GMLIB_API", "getItemCustomName", [](ItemStack const* item) -> std::string {
return item->getCustomName();
});
RemoteCall::exportAs("GMLIB_API", "getItemEffecName", [](ItemStack const* item) -> std::string {
return item->getEffectName();
});
RemoteCall::exportAs("GMLIB_API", "itemIsFood", [](ItemStack const* item) -> bool {
if (auto itemDef = item->getItem()) {
return itemDef->isFood();
}
return false;
});
RemoteCall::exportAs("GMLIB_API", "setPlayerUIItem", [](Player* player, int slot, ItemStack const* item) -> void {
player->setPlayerUIItem((PlayerUISlot)slot, *item);
});
RemoteCall::exportAs("GMLIB_API", "getPlayerUIItem", [](Player* player, int slot) -> ItemStack* {
return const_cast<ItemStack*>(&player->getPlayerUIItem((PlayerUISlot)slot));
});
RemoteCall::exportAs(
"GMLIB_API",
"sendInventorySlotPacket",
[](Player* player, int containerId, int slot, ItemStack const* item) -> void {
InventorySlotPacket((ContainerID)containerId, slot, *item).sendTo(*player);
}
);
RemoteCall::exportAs("GMLIB_API", "getContainerType", [](Container* container) -> std::string {
return magic_enum::enum_name(container->getContainerType()).data();
});
RemoteCall::exportAs("GMLIB_API", "hasPlayerNbt", [](std::string const& uuid) -> bool {
auto uid = mce::UUID::fromString(uuid);
return GMLIB_Player::getPlayerNbt(uid) ? true : false;
});
RemoteCall::exportAs("GMLIB_API", "getItemMaxCount", [](ItemStack const* item) -> int {
return item->getMaxStackSize();
});
RemoteCall::exportAs("GMLIB_API", "entityHasFamily", [](Actor* entity, std::string const& family) -> bool {
return entity->hasFamily(HashedString(family));
});
RemoteCall::exportAs("GMLIB_API", "getPlayerDestroyBlockProgress", [](Player* player, Block const* block) -> float {
return player->getDestroyProgress(*block);
});
RemoteCall::exportAs("GMLIB_API", "getEntityEffectVisible", [](Actor* entity, int effectId) -> bool {
if (auto effect = entity->getEffect(effectId)) {
return effect->mEffectVisible;
}
return 0;
});
RemoteCall::exportAs("GMLIB_API", "getEntityEffectDuration", [](Actor* entity, int effectId) -> int {
if (auto effect = entity->getEffect(effectId)) {
return effect->mDuration;
}
return 0;
});
RemoteCall::exportAs("GMLIB_API", "getEntityEffectDurationEasy", [](Actor* entity, int effectId) -> int {
if (auto effect = entity->getEffect(effectId)) {
return effect->mDurationEasy;
}
return 0;
});
RemoteCall::exportAs("GMLIB_API", "getEntityEffectDurationHard", [](Actor* entity, int effectId) -> int {
if (auto effect = entity->getEffect(effectId)) {
return effect->mDurationHard;
}
return 0;
});
RemoteCall::exportAs("GMLIB_API", "getEntityEffectDurationNormal", [](Actor* entity, int effectId) -> int {
if (auto effect = entity->getEffect(effectId)) {
return effect->mDurationNormal;
}
return 0;
});
RemoteCall::exportAs("GMLIB_API", "getEntityEffectAmplifier", [](Actor* entity, int effectId) -> int {
if (auto effect = entity->getEffect(effectId)) {
return effect->mAmplifier;
}
return 0;
});
RemoteCall::exportAs("GMLIB_API", "getEntityEffectAmbient", [](Actor* entity, int effectId) -> bool {
if (auto effect = entity->getEffect(effectId)) {
return effect->mAmbient;
}
return 0;
});
RemoteCall::exportAs("GMLIB_API", "entityHasEffect", [](Actor* entity, int effectId) -> int {
return entity->hasEffect(*MobEffect::getById(effectId));
});
RemoteCall::exportAs("GMLIB_API", "getGameDifficulty", []() -> int {
if (auto level = ll::service::getLevel()) {
return (int)level->getDifficulty();
}
return -1;
});
RemoteCall::exportAs("GMLIB_API", "setGameDifficulty", [](int difficulty) -> void {
if (auto level = ll::service::getLevel()) {
level->setDifficulty((Difficulty)difficulty);
}
});
RemoteCall::exportAs("GMLIB_API", "getDefaultGameMode", []() -> int {
if (auto level = ll::service::getLevel()) {
return (int)level->getDefaultGameType();
}
return -1;
});
RemoteCall::exportAs("GMLIB_API", "setDefaultGameMode", [](int gameMode) -> void {
if (auto level = ll::service::getLevel()) {
level->setDefaultGameType((GameType)gameMode);
}
});
} }
+10 -10
View File
@@ -3,14 +3,14 @@
ll::Logger logger(PLUGIN_NAME); ll::Logger logger(PLUGIN_NAME);
namespace GMLIB_LegacyRemoteCallApi { namespace GMLIB {
std::unique_ptr<LRCA>& LRCA::getInstance() { std::unique_ptr<LegacyRemoteCallApi>& LegacyRemoteCallApi::getInstance() {
static std::unique_ptr<LRCA> instance; static std::unique_ptr<LegacyRemoteCallApi> instance;
return instance; return instance;
} }
bool LRCA::load() { bool LegacyRemoteCallApi::load() {
Export_Legacy_GMLib_ModAPI(); Export_Legacy_GMLib_ModAPI();
Export_Legacy_GMLib_ServerAPI(); Export_Legacy_GMLib_ServerAPI();
Export_Compatibility_API(); Export_Compatibility_API();
@@ -19,18 +19,18 @@ bool LRCA::load() {
logger.info("GMLIB-LegacyRemoteCallApi Loaded!"); logger.info("GMLIB-LegacyRemoteCallApi Loaded!");
logger.info( logger.info(
"Loaded Version: {} with {}", "Loaded Version: {} with {}",
fmt::format(fg(fmt::color::pink), "GMLIB-" + GMLIB::Version::getLibVersionString()), fmt::format(fg(fmt::color::pink), "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("Author: GroupMountain");
logger.info("Repository: https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi"); logger.info("Repository: https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi");
return true; 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(LegacyRemoteCallApi, LegacyRemoteCallApi::getInstance());
+9 -9
View File
@@ -1,17 +1,17 @@
#pragma once #pragma once
#include <ll/api/plugin/NativePlugin.h> #include <ll/api/mod/NativeMod.h>
#include <ll/api/plugin/RegisterHelper.h> #include <ll/api/mod/RegisterHelper.h>
namespace GMLIB_LegacyRemoteCallApi { namespace GMLIB {
class LRCA { class LegacyRemoteCallApi {
public: 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. /// @return True if the plugin is loaded successfully.
bool load(); bool load();
@@ -27,7 +27,7 @@ public:
// bool unload(); // bool unload();
private: private:
ll::plugin::NativePlugin& mSelf; ll::mod::NativeMod& mSelf;
}; };
} // namespace GMLIB_LegacyRemoteCallApi } // namespace GMLIB
+320 -188
View File
@@ -7,195 +7,327 @@ void Export_Event_API() {
"GMLIB_API", "GMLIB_API",
"callCustomEvent", "callCustomEvent",
[eventBus](std::string const& eventName, std::string const& eventId) -> bool { [eventBus](std::string const& eventName, std::string const& eventId) -> bool {
if (RemoteCall::hasFunc(eventName, eventId)) { if (!RemoteCall::hasFunc(eventName, eventId)) return false;
switch (doHash(eventName)) { switch (doHash(eventName)) {
case doHash("onClientLogin"): { case doHash("onClientLogin"): {
auto Call = RemoteCall::importAs<bool( auto Call = RemoteCall::importAs<bool(
std::string const& realName, std::string const& realName,
std::string const& uuid, std::string const& uuid,
std::string const& serverXuid, std::string const& serverXuid,
std::string const& clientXuid std::string const& clientXuid
)>(eventName, eventId); )>(eventName, eventId);
eventBus->emplaceListener<GMLIB::Event::PacketEvent::ClientLoginAfterEvent>( eventBus->emplaceListener<Event::PacketEvent::ClientLoginAfterEvent>(
[Call](GMLIB::Event::PacketEvent::ClientLoginAfterEvent& ev) { [Call](Event::PacketEvent::ClientLoginAfterEvent& ev) {
try { try {
Call( Call(
ev.getRealName(), ev.getRealName(),
ev.getUuid().asString(), ev.getUuid().asString(),
ev.getServerAuthXuid(), ev.getServerAuthXuid(),
ev.getClientAuthXuid() ev.getClientAuthXuid()
); );
} catch (...) {} } catch (...) {}
} }
); );
return true; return true;
} }
case doHash("onWeatherChange"): { case doHash("onWeatherChange"): {
auto Call = auto Call =
RemoteCall::importAs<bool(int lightningLevel, int rainLevel, int lightningLast, int rainLast)>( RemoteCall::importAs<bool(int lightningLevel, int rainLevel, int lightningLast, int rainLast)>(
eventName, eventName,
eventId eventId
); );
eventBus->emplaceListener<GMLIB::Event::LevelEvent::WeatherUpdateBeforeEvent>( eventBus->emplaceListener<Event::LevelEvent::WeatherUpdateBeforeEvent>(
[Call](GMLIB::Event::LevelEvent::WeatherUpdateBeforeEvent& ev) { [Call](Event::LevelEvent::WeatherUpdateBeforeEvent& ev) {
bool result = true; bool result = true;
try { try {
result = Call( result = Call(
ev.getLightningLevel(), ev.getLightningLevel(),
ev.getRainLevel(), ev.getRainLevel(),
ev.getLightningLastTick(), ev.getLightningLastTick(),
ev.getRainingLastTick() ev.getRainingLastTick()
); );
} catch (...) {} } catch (...) {}
if (!result) { if (!result) {
ev.cancel(); ev.cancel();
} }
} }
); );
return true; return true;
} }
case doHash("onMobPick"): { case doHash("onMobPick"): {
auto Call = RemoteCall::importAs<bool(Actor * mob, Actor * item)>(eventName, eventId); auto Call = RemoteCall::importAs<bool(Actor * mob, Actor * item)>(eventName, eventId);
eventBus->emplaceListener<GMLIB::Event::EntityEvent::MobPickupItemBeforeEvent>( eventBus->emplaceListener<Event::EntityEvent::MobPickupItemBeforeEvent>(
[Call](GMLIB::Event::EntityEvent::MobPickupItemBeforeEvent& ev) { [Call](Event::EntityEvent::MobPickupItemBeforeEvent& ev) {
bool result = true; bool result = true;
try { try {
result = Call(&ev.self(), (Actor*)&ev.getItemActor()); result = Call(&ev.self(), (Actor*)&ev.getItemActor());
} catch (...) {} } catch (...) {}
if (!result) { if (!result) {
ev.cancel(); ev.cancel();
} }
} }
); );
return true; return true;
} }
case doHash("onItemTrySpawn"): { case doHash("onItemTrySpawn"): {
auto Call = RemoteCall::importAs< auto Call =
bool(const ItemStack* item, std::pair<Vec3, int> position, Actor* spawner)>(eventName, eventId); RemoteCall::importAs<bool(const ItemStack* item, std::pair<Vec3, int> position, Actor* spawner)>(
eventBus->emplaceListener<GMLIB::Event::EntityEvent::ItemActorSpawnBeforeEvent>( eventName,
[Call](GMLIB::Event::EntityEvent::ItemActorSpawnBeforeEvent& ev) { eventId
auto pos = ev.getPosition(); );
auto dimid = ev.getBlockSource().getDimensionId().id; eventBus->emplaceListener<Event::EntityEvent::ItemActorSpawnBeforeEvent>(
std::pair<Vec3, int> lsePos = {pos, dimid}; [Call](Event::EntityEvent::ItemActorSpawnBeforeEvent& ev) {
bool result = true; auto pos = ev.getPosition();
try { auto dimid = ev.getBlockSource().getDimensionId().id;
result = Call(&ev.getItem(), lsePos, ev.getSpawner()); std::pair<Vec3, int> lsePos = {pos, dimid};
} catch (...) {} bool result = true;
if (!result) { try {
ev.cancel(); result = Call(&ev.getItem(), lsePos, ev.getSpawner());
} } catch (...) {}
} if (!result) {
); ev.cancel();
return true; }
} }
case doHash("onItemSpawned"): { );
auto Call = RemoteCall::importAs< return true;
bool(const ItemStack* item, Actor* itemActor, std::pair<Vec3, int> position, Actor* spawner)>( }
eventName, case doHash("onItemSpawned"): {
eventId auto Call = RemoteCall::importAs<
); bool(const ItemStack* item, Actor* itemActor, std::pair<Vec3, int> position, Actor* spawner)>(
eventBus->emplaceListener<GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent>( eventName,
[Call](GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent& ev) { eventId
auto pos = ev.getPosition(); );
auto dimid = ev.getBlockSource().getDimensionId().id; eventBus->emplaceListener<Event::EntityEvent::ItemActorSpawnAfterEvent>(
std::pair<Vec3, int> lsePos = {pos, dimid}; [Call](Event::EntityEvent::ItemActorSpawnAfterEvent& ev) {
try { auto pos = ev.getPosition();
Call(&ev.getItem(), (Actor*)&ev.getItemActor(), lsePos, ev.getSpawner()); auto dimid = ev.getBlockSource().getDimensionId().id;
} catch (...) {} std::pair<Vec3, int> lsePos = {pos, dimid};
} try {
); Call(&ev.getItem(), (Actor*)&ev.getItemActor(), lsePos, ev.getSpawner());
return true; } catch (...) {}
} }
case doHash("onEntityChangeDim"): { );
auto Call = RemoteCall::importAs<bool(Actor * entity, int toDimId)>(eventName, eventId); return true;
eventBus->emplaceListener<GMLIB::Event::EntityEvent::ActorChangeDimensionBeforeEvent>( }
[Call](GMLIB::Event::EntityEvent::ActorChangeDimensionBeforeEvent& ev) { case doHash("onEntityChangeDim"): {
bool result = true; auto Call = RemoteCall::importAs<bool(Actor * entity, int toDimId)>(eventName, eventId);
try { eventBus->emplaceListener<Event::EntityEvent::ActorChangeDimensionBeforeEvent>(
result = Call(&ev.self(), ev.getToDimensionId()); [Call](Event::EntityEvent::ActorChangeDimensionBeforeEvent& ev) {
} catch (...) {} bool result = true;
if (!result) { try {
ev.cancel(); 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); return true;
eventBus->emplaceListener<GMLIB::Event::PlayerEvent::PlayerStopSleepBeforeEvent>( }
[Call](GMLIB::Event::PlayerEvent::PlayerStopSleepBeforeEvent& ev) { case doHash("onLeaveBed"): {
bool result = true; auto Call = RemoteCall::importAs<bool(Player * pl)>(eventName, eventId);
try { eventBus->emplaceListener<Event::PlayerEvent::PlayerStopSleepBeforeEvent>(
result = Call(&ev.self()); [Call](Event::PlayerEvent::PlayerStopSleepBeforeEvent& ev) {
} catch (...) {} bool result = true;
if (!result) { try {
ev.cancel(); result = Call(&ev.self());
} } catch (...) {}
} if (!result) {
); ev.cancel();
return true; }
} }
case doHash("onDeathMessage"): { );
auto Call = return true;
RemoteCall::importAs<bool(std::string const& message, std::vector<std::string>, Actor* dead)>( }
eventName, case doHash("onDeathMessage"): {
eventId auto Call =
); RemoteCall::importAs<bool(std::string const& message, std::vector<std::string>, Actor* dead)>(
eventBus->emplaceListener<GMLIB::Event::EntityEvent::DeathMessageAfterEvent>( eventName,
[Call](GMLIB::Event::EntityEvent::DeathMessageAfterEvent& ev) { eventId
auto msg = ev.getDeathMessage(); );
auto source = ev.getDamageSource(); eventBus->emplaceListener<Event::EntityEvent::DeathMessageAfterEvent>(
try { [Call](Event::EntityEvent::DeathMessageAfterEvent& ev) {
Call(msg.first, msg.second, &ev.self()); auto msg = ev.getDeathMessage();
} catch (...) {} auto source = ev.getDamageSource();
} try {
); Call(msg.first, msg.second, &ev.self());
return true; } catch (...) {}
} }
case doHash("onMobHurted"): { );
auto Call = RemoteCall::importAs<bool(Actor * mob, Actor * source, float damage, int cause)>( return true;
eventName, }
eventId case doHash("onMobHurted"): {
); auto Call = RemoteCall::importAs<bool(Actor * mob, Actor * source, float damage, int cause)>(
eventBus->emplaceListener<GMLIB::Event::EntityEvent::MobHurtAfterEvent>( eventName,
[Call](GMLIB::Event::EntityEvent::MobHurtAfterEvent& ev) { eventId
auto& damageSource = ev.getSource(); );
Actor* source = nullptr; eventBus->emplaceListener<Event::EntityEvent::MobHurtAfterEvent>(
if (damageSource.isEntitySource()) { [Call](Event::EntityEvent::MobHurtAfterEvent& ev) {
auto uniqueId = damageSource.getDamagingEntityUniqueID(); auto& damageSource = ev.getSource();
source = ll::service::getLevel()->fetchEntity(uniqueId); Actor* source = nullptr;
if (source->getOwner()) { if (damageSource.isEntitySource()) {
source = source->getOwner(); auto uniqueId = damageSource.getDamagingEntityUniqueID();
} source = ll::service::getLevel()->fetchEntity(uniqueId);
} if (source->getOwner()) {
try { source = source->getOwner();
Call(&ev.self(), source, ev.getDamage(), (int)damageSource.getCause()); }
} catch (...) {} }
} try {
); Call(&ev.self(), source, ev.getDamage(), (int)damageSource.getCause());
return true; } catch (...) {}
} }
case doHash("onEndermanTake"): { );
auto Call = RemoteCall::importAs<bool(Actor * mob)>(eventName, eventId); return true;
eventBus->emplaceListener<GMLIB::Event::EntityEvent::EndermanTakeBlockBeforeEvent>( }
[Call](GMLIB::Event::EntityEvent::EndermanTakeBlockBeforeEvent& ev) { case doHash("onEndermanTake"): {
bool result = true; auto Call = RemoteCall::importAs<bool(Actor * mob)>(eventName, eventId);
try { eventBus->emplaceListener<Event::EntityEvent::EndermanTakeBlockBeforeEvent>(
result = Call(&ev.self()); [Call](Event::EntityEvent::EndermanTakeBlockBeforeEvent& ev) {
} catch (...) {} bool result = true;
if (!result) { try {
ev.cancel(); result = Call(&ev.self());
} } catch (...) {}
} if (!result) {
); ev.cancel();
return true; }
} }
default: );
return false; return true;
} }
case doHash("onEntityChangeDimAfter"): {
auto Call = RemoteCall::importAs<bool(Actor * mob, int fromDimId)>(eventName, eventId);
eventBus->emplaceListener<Event::EntityEvent::ActorChangeDimensionAfterEvent>(
[Call](Event::EntityEvent::ActorChangeDimensionAfterEvent& ev) {
bool result = true;
try {
result = Call(&ev.self(), ev.getFromDimensionId());
} catch (...) {}
}
);
return true;
}
case doHash("onDragonRespawn"): {
auto Call = RemoteCall::importAs<bool(int64 enderDragonUniqueID)>(eventName, eventId);
eventBus->emplaceListener<Event::EntityEvent::DragonRespawnBeforeEvent>(
[Call](Event::EntityEvent::DragonRespawnBeforeEvent& ev) {
bool result = true;
try {
result = Call(ev.getEnderDragon().id);
} catch (...) {}
if (!result) {
ev.cancel();
}
}
);
return true;
}
case doHash("onProjectileTryCreate"): {
auto Call = RemoteCall::importAs<bool(Actor * mob, int64 uniqueId)>(eventName, eventId);
eventBus->emplaceListener<Event::EntityEvent::ProjectileCreateBeforeEvent>(
[Call](Event::EntityEvent::ProjectileCreateBeforeEvent& ev) {
bool result = true;
try {
auto uid = ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1;
result = Call(&ev.self(), uid);
} catch (...) {}
if (!result) {
ev.cancel();
}
}
);
return true;
}
case doHash("onProjectileCreate"): {
auto Call = RemoteCall::importAs<bool(Actor * mob, int64 uniqueId)>(eventName, eventId);
eventBus->emplaceListener<Event::EntityEvent::ProjectileCreateAfterEvent>(
[Call](Event::EntityEvent::ProjectileCreateAfterEvent& ev) {
try {
auto uid = ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1;
Call(&ev.self(), uid);
} catch (...) {}
}
);
return true;
}
case doHash("onSpawnWanderingTrader"): {
auto Call = RemoteCall::importAs<bool(std::pair<BlockPos, int> pos)>(eventName, eventId);
eventBus->emplaceListener<Event::EntityEvent::SpawnWanderingTraderBeforeEvent>(
[Call](Event::EntityEvent::SpawnWanderingTraderBeforeEvent& ev) {
bool result = true;
try {
result = Call({ev.getPos(), ev.getRegion().getDimensionId()});
} catch (...) {}
if (!result) {
ev.cancel();
}
}
);
return true;
}
case doHash("onHandleRequestAction"): {
auto Call = RemoteCall::importAs<bool(
Player * player,
std::string const& actionType,
int count,
std::string const& sourceContainerNetId,
int sourceSlot,
std::string const& destinationContainerNetId,
int destinationSlot
)>(eventName, eventId);
eventBus->emplaceListener<Event::PlayerEvent::HandleRequestActionBeforeEvent>(
[Call](Event::PlayerEvent::HandleRequestActionBeforeEvent& ev) {
bool result = true;
try {
auto requestAction = (ItemStackRequestActionTransferBase*)&ev.getRequestAction();
auto source = requestAction->getSrc();
// TODO: The next version of LeviLamina changes to a member function
auto destination = ll::memory::dAccess<ItemStackRequestSlotInfo>(requestAction, 56);
result = Call(
&ev.self(),
magic_enum::enum_name(requestAction->mActionType).data(),
ll::memory::dAccess<uchar>(requestAction, 18),
magic_enum::enum_name(source.mOpenContainerNetId).data(),
source.mSlot,
magic_enum::enum_name(destination.mOpenContainerNetId).data(),
destination.mSlot
);
} catch (...) {}
if (!result) {
ev.cancel();
}
}
);
return true;
}
case doHash("onSendContainerClosePacket"): {
auto Call = RemoteCall::importAs<bool(Player * player, int ContainerNetId)>(eventName, eventId);
eventBus->emplaceListener<Event::PacketEvent::ContainerClosePacketSendAfterEvent>(
[Call](Event::PacketEvent::ContainerClosePacketSendAfterEvent& ev) {
try {
Call(
ev.getServerNetworkHandler()
.getServerPlayer(ev.getNetworkIdentifier(), ev.getPacket().mClientSubId),
(int)ev.getPacket().mContainerId
);
} catch (...) {}
}
);
return true;
}
case doHash("onServerStopping"): {
auto Call = RemoteCall::importAs<bool()>(eventName, eventId);
eventBus->emplaceListener<ll::event::server::ServerStoppingEvent>(
[Call](ll::event::server::ServerStoppingEvent& ev) {
try {
Call();
} catch (...) {}
}
);
return true;
}
default:
return false;
} }
return false;
} }
); );
} }
+9 -1
View File
@@ -3,9 +3,17 @@
#include <RemoteCallAPI.h> #include <RemoteCallAPI.h>
using namespace GMLIB;
using namespace Server;
using namespace Mod;
#define PLUGIN_NAME fmt::format(fg(fmt::color::light_green), "GMLIB-LRCA") #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 2
#define LIB_VERSION Version(LIB_VERSION_MAJOR, LIB_VERSION_MINOR, LIB_VERSION_PATCH)
extern ll::Logger logger; extern ll::Logger logger;
+10 -10
View File
@@ -33,7 +33,7 @@ void Export_Legacy_GMLib_ModAPI() {
} }
auto res = RecipeIngredient(result, 0, count); auto res = RecipeIngredient(result, 0, count);
auto unl = makeRecipeUnlockingKey(unlock); auto unl = makeRecipeUnlockingKey(unlock);
GMLIB::Mod::JsonRecipe::registerShapelessCraftingTableRecipe(recipe_id, types, res, unl); JsonRecipe::registerShapelessCraftingTableRecipe(recipe_id, types, res, unl);
} }
); );
RemoteCall::exportAs( RemoteCall::exportAs(
@@ -56,7 +56,7 @@ void Export_Legacy_GMLib_ModAPI() {
} }
auto res = RecipeIngredient(result, 0, count); auto res = RecipeIngredient(result, 0, count);
auto unl = makeRecipeUnlockingKey(unlock); auto unl = makeRecipeUnlockingKey(unlock);
GMLIB::Mod::JsonRecipe::registerShapedCraftingTableRecipe(recipe_id, shape, types, res, unl); JsonRecipe::registerShapedCraftingTableRecipe(recipe_id, shape, types, res, unl);
} }
); );
RemoteCall::exportAs( RemoteCall::exportAs(
@@ -72,7 +72,7 @@ void Export_Legacy_GMLib_ModAPI() {
} }
auto inp = RecipeIngredient(input, 0, 1); auto inp = RecipeIngredient(input, 0, 1);
auto outp = RecipeIngredient(output, 0, 1); auto outp = RecipeIngredient(output, 0, 1);
GMLIB::Mod::JsonRecipe::registerFurnaceRecipe(recipe_id, inp, outp, tags); JsonRecipe::registerFurnaceRecipe(recipe_id, inp, outp, tags);
} }
); );
RemoteCall::exportAs( RemoteCall::exportAs(
@@ -85,7 +85,7 @@ void Export_Legacy_GMLib_ModAPI() {
return; return;
} }
auto rea = RecipeIngredient(reagent, 0, 1); auto rea = RecipeIngredient(reagent, 0, 1);
GMLIB::Mod::JsonRecipe::registerBrewingMixRecipe(recipe_id, input, output, rea); JsonRecipe::registerBrewingMixRecipe(recipe_id, input, output, rea);
} }
); );
RemoteCall::exportAs( RemoteCall::exportAs(
@@ -100,7 +100,7 @@ void Export_Legacy_GMLib_ModAPI() {
auto inp = RecipeIngredient(input, 0, 1); auto inp = RecipeIngredient(input, 0, 1);
auto outp = RecipeIngredient(output, 0, 1); auto outp = RecipeIngredient(output, 0, 1);
auto rea = RecipeIngredient(reagent, 0, 1); auto rea = RecipeIngredient(reagent, 0, 1);
GMLIB::Mod::JsonRecipe::registerBrewingContainerRecipe(recipe_id, inp, outp, rea); JsonRecipe::registerBrewingContainerRecipe(recipe_id, inp, outp, rea);
} }
); );
RemoteCall::exportAs( RemoteCall::exportAs(
@@ -115,7 +115,7 @@ void Export_Legacy_GMLib_ModAPI() {
if (!level) { if (!level) {
return; return;
} }
GMLIB::Mod::JsonRecipe::registerSmithingTransformRecipe( JsonRecipe::registerSmithingTransformRecipe(
recipe_id, recipe_id,
smithing_template, smithing_template,
base, base,
@@ -135,7 +135,7 @@ void Export_Legacy_GMLib_ModAPI() {
if (!level) { if (!level) {
return; return;
} }
GMLIB::Mod::JsonRecipe::registerSmithingTrimRecipe(recipe_id, smithing_template, base, addition); JsonRecipe::registerSmithingTrimRecipe(recipe_id, smithing_template, base, addition);
} }
); );
RemoteCall::exportAs( RemoteCall::exportAs(
@@ -153,12 +153,12 @@ void Export_Legacy_GMLib_ModAPI() {
} }
auto inp = RecipeIngredient(input, 0, 1); auto inp = RecipeIngredient(input, 0, 1);
auto outp = RecipeIngredient(output, 0, 1); auto outp = RecipeIngredient(output, 0, 1);
GMLIB::Mod::JsonRecipe::registerStoneCutterRecipe(recipe_id, inp, outp); JsonRecipe::registerStoneCutterRecipe(recipe_id, inp, outp);
} }
); );
// 错误方块清理 // 错误方块清理
RemoteCall::exportAs("GMLib_ModAPI", "setUnknownBlockCleaner", []() -> void { RemoteCall::exportAs("GMLib_ModAPI", "setUnknownBlockCleaner", []() -> void {
GMLIB::Mod::VanillaFix::setAutoCleanUnknownBlockEnabled(); VanillaFix::setAutoCleanUnknownBlockEnabled();
}); });
// 实验性 // 实验性
RemoteCall::exportAs("GMLib_ModAPI", "registerExperimentsRequire", [](int experiment_id) -> void { RemoteCall::exportAs("GMLib_ModAPI", "registerExperimentsRequire", [](int experiment_id) -> void {
@@ -193,6 +193,6 @@ void Export_Legacy_GMLib_ModAPI() {
return false; return false;
}); });
RemoteCall::exportAs("GMLib_ModAPI", "setFixI18nEnabled", []() -> void { RemoteCall::exportAs("GMLib_ModAPI", "setFixI18nEnabled", []() -> void {
GMLIB::Mod::VanillaFix::setFixI18nEnabled(); VanillaFix::setFixI18nEnabled();
}); });
} }
+11 -7
View File
@@ -1,6 +1,4 @@
#include "GMLIB/Server/FakeListAPI.h"
#include "Global.h" #include "Global.h"
#include "mc/world/ActorUniqueID.h"
void Export_Legacy_GMLib_ServerAPI() { void Export_Legacy_GMLib_ServerAPI() {
RemoteCall::exportAs("GMLib_ServerAPI", "setEducationFeatureEnabled", []() -> void { RemoteCall::exportAs("GMLib_ServerAPI", "setEducationFeatureEnabled", []() -> void {
@@ -40,7 +38,7 @@ void Export_Legacy_GMLib_ServerAPI() {
"GMLib_ServerAPI", "GMLib_ServerAPI",
"spawnEntity", "spawnEntity",
[](std::pair<Vec3, int> pos, std::string const& name) -> Actor* { [](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( RemoteCall::exportAs(
@@ -48,7 +46,7 @@ void Export_Legacy_GMLib_ServerAPI() {
"shootProjectile", "shootProjectile",
[](Actor* owner, std::string const& name, float speed, float offset) -> Actor* { [](Actor* owner, std::string const& name, float speed, float offset) -> Actor* {
auto ac = (GMLIB_Actor*)owner; auto ac = (GMLIB_Actor*)owner;
return ac->shootProjectile(name, speed, offset); return ac->shootProjectile(name, speed, offset).as_ptr();
} }
); );
RemoteCall::exportAs( RemoteCall::exportAs(
@@ -64,13 +62,19 @@ void Export_Legacy_GMLib_ServerAPI() {
"GMLib_ServerAPI", "GMLib_ServerAPI",
"addFakeList", "addFakeList",
[](const std::string& name, const std::string& xuid) -> bool { [](const std::string& name, const std::string& xuid) -> bool {
return GMLIB::Server::FakeList::addFakeList(name, xuid, ActorUniqueID(-1)); return FakeList::addFakeList(name, xuid, ActorUniqueID(-1));
} }
); );
RemoteCall::exportAs("GMLib_ServerAPI", "removeFakeList", [](const std::string& nameOrXuid) -> bool { RemoteCall::exportAs("GMLib_ServerAPI", "removeFakeList", [](const std::string& nameOrXuid) -> bool {
return GMLIB::Server::FakeList::removeFakeList(nameOrXuid); return FakeList::removeFakeList(nameOrXuid);
}); });
RemoteCall::exportAs("GMLib_ServerAPI", "removeAllFakeList", []() -> void { RemoteCall::exportAs("GMLib_ServerAPI", "removeAllFakeList", []() -> void {
return GMLIB::Server::FakeList::removeAllFakeLists(); return FakeList::removeAllFakeLists();
});
RemoteCall::exportAs("GMLib_ServerAPI", "getMaxPlayers", []() -> int {
if (auto level = GMLIB_Level::getInstance()) {
return level->getMaxPlayerCount();
}
return {};
}); });
} }
+15 -12
View File
@@ -13,10 +13,10 @@ bool isParameters(std::string const& str) {
return std::regex_search(removeBrackets(str), reg); return std::regex_search(removeBrackets(str), reg);
} }
std::string GetValue(std::string const& from) { return GMLIB::Server::PlaceholderAPI::getValue(from); } std::string GetValue(std::string const& from) { return PlaceholderAPI::getValue(from); }
std::string GetValueWithPlayer(std::string const& a1, std::string const& a2) { std::string GetValueWithPlayer(std::string const& a1, std::string const& a2) {
return GMLIB::Server::PlaceholderAPI::getValue(a1, ll::service::bedrock::getLevel()->getPlayer(a2)); return PlaceholderAPI::getValue(a1, ll::service::bedrock::getLevel()->getPlayer(a2));
} }
bool registerPlayerPlaceholder( bool registerPlayerPlaceholder(
@@ -25,19 +25,20 @@ bool registerPlayerPlaceholder(
std::string const& PAPIName std::string const& PAPIName
) { ) {
if (RemoteCall::hasFunc(PluginName, FuncName)) { if (RemoteCall::hasFunc(PluginName, FuncName)) {
PlaceholderAPI::unregisterPlaceholder(PAPIName);
if (isParameters(PAPIName)) { if (isParameters(PAPIName)) {
auto Call = RemoteCall::importAs<std::string(Player * pl, std::unordered_map<std::string, std::string>)>( auto Call = RemoteCall::importAs<std::string(Player * pl, std::unordered_map<std::string, std::string>)>(
PluginName, PluginName,
FuncName FuncName
); );
GMLIB::Server::PlaceholderAPI::registerPlayerPlaceholder( PlaceholderAPI::registerPlayerPlaceholder(
PAPIName, PAPIName,
[Call](Player* sp, std::unordered_map<std::string, std::string> map) { return Call(sp, map); }, [Call](Player* sp, std::unordered_map<std::string, std::string> map) { return Call(sp, map); },
PluginName PluginName
); );
} else { } else {
auto Call = RemoteCall::importAs<std::string(Player * pl)>(PluginName, FuncName); auto Call = RemoteCall::importAs<std::string(Player * pl)>(PluginName, FuncName);
GMLIB::Server::PlaceholderAPI::registerPlayerPlaceholder( PlaceholderAPI::registerPlayerPlaceholder(
PAPIName, PAPIName,
[Call](Player* sp) { return Call(sp); }, [Call](Player* sp) { return Call(sp); },
PluginName PluginName
@@ -54,17 +55,18 @@ bool registerServerPlaceholder(
std::string const& PAPIName std::string const& PAPIName
) { ) {
if (RemoteCall::hasFunc(PluginName, FuncName)) { if (RemoteCall::hasFunc(PluginName, FuncName)) {
PlaceholderAPI::unregisterPlaceholder(PAPIName);
if (isParameters(PAPIName)) { if (isParameters(PAPIName)) {
auto Call = auto Call =
RemoteCall::importAs<std::string(std::unordered_map<std::string, std::string>)>(PluginName, FuncName); RemoteCall::importAs<std::string(std::unordered_map<std::string, std::string>)>(PluginName, FuncName);
GMLIB::Server::PlaceholderAPI::registerServerPlaceholder( PlaceholderAPI::registerServerPlaceholder(
PAPIName, PAPIName,
[Call](std::unordered_map<std::string, std::string> map) { return Call(map); }, [Call](std::unordered_map<std::string, std::string> map) { return Call(map); },
PluginName PluginName
); );
} else { } else {
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName); auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
GMLIB::Server::PlaceholderAPI::registerServerPlaceholder(PAPIName, [Call]() { return Call(); }, PluginName); PlaceholderAPI::registerServerPlaceholder(PAPIName, [Call]() { return Call(); }, PluginName);
} }
return true; return true;
} }
@@ -78,16 +80,17 @@ bool registerStaticPlaceholder(
int num int num
) { ) {
if (RemoteCall::hasFunc(PluginName, FuncName)) { if (RemoteCall::hasFunc(PluginName, FuncName)) {
PlaceholderAPI::unregisterPlaceholder(PAPIName);
if (isParameters(PAPIName)) { if (isParameters(PAPIName)) {
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName); auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
if (num == -1) { if (num == -1) {
GMLIB::Server::PlaceholderAPI::registerStaticPlaceholder( PlaceholderAPI::registerStaticPlaceholder(
PAPIName, PAPIName,
[Call] { return Call(); }, [Call] { return Call(); },
PluginName PluginName
); );
} else { } else {
GMLIB::Server::PlaceholderAPI::registerStaticPlaceholder( PlaceholderAPI::registerStaticPlaceholder(
PAPIName, PAPIName,
num, num,
[Call] { return Call(); }, [Call] { return Call(); },
@@ -101,14 +104,14 @@ bool registerStaticPlaceholder(
} }
std::string translateStringWithPlayer(std::string const& str, Player* pl) { std::string translateStringWithPlayer(std::string const& str, Player* pl) {
return GMLIB::Server::PlaceholderAPI::translateString(str, pl); return 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 PlaceholderAPI::translateString(str); }
bool unRegisterPlaceholder(std::string const& str) { return GMLIB::Server::PlaceholderAPI::unregisterPlaceholder(str); } bool unRegisterPlaceholder(std::string const& str) { return PlaceholderAPI::unregisterPlaceholder(str); }
std::vector<std::string> getAllPAPI() { return GMLIB::Server::PlaceholderAPI::getAllPAPI(); } std::vector<std::string> getAllPAPI() { return PlaceholderAPI::getAllPAPI(); }
} // namespace PAPIRemoteCall } // namespace PAPIRemoteCall
+3 -3
View File
@@ -1,7 +1,7 @@
{ {
"format_version": 2, "format_version": 2,
"tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi", "tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi",
"version": "0.12.6", "version": "0.13.2",
"info": { "info": {
"name": "GMLIB-LegacyRemoteCallApi", "name": "GMLIB-LegacyRemoteCallApi",
"description": "Legacy RemoteCall API for GMLIB", "description": "Legacy RemoteCall API for GMLIB",
@@ -14,9 +14,9 @@
"library" "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.2/GMLIB-LegacyRemoteCallApi-windows-x64.zip",
"dependencies": { "dependencies": {
"github.com/GroupMountain/GMLIB": ">=0.12.4" "github.com/GroupMountain/GMLIB": ">=0.13.0"
}, },
"files": { "files": {
"place": [ "place": [
+6 -7
View File
@@ -1,14 +1,16 @@
add_rules("mode.debug", "mode.release") add_rules("mode.debug", "mode.release")
add_repositories("liteldev-repo https://github.com/LiteLDev/xmake-repo.git") 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 if not has_config("vs_runtime") then
set_runtimes("MD") set_runtimes("MD")
end end
-- Option 1: Use the latest version of LeviLamina released on GitHub. -- Option 1: Use the latest version of LeviLamina released on GitHub.
add_requires("levilamina") add_requires("levilaminalibrary")
add_requires("legacyremotecall") add_requires("legacyremotecall")
add_requires("gmlib")
-- Option 2: Use a specific version of LeviLamina released on GitHub. -- Option 2: Use a specific version of LeviLamina released on GitHub.
-- add_requires("levilamina x.x.x") -- add_requires("levilamina x.x.x")
@@ -53,16 +55,13 @@ target("GMLIB-LegacyRemoteCallApi") -- Change this to your plugin name.
add_files( add_files(
"src/**.cpp" "src/**.cpp"
) )
add_links(
"SDK-GMLIB/Lib/GMLIB"
)
add_includedirs( add_includedirs(
"SDK-GMLIB",
"src" "src"
) )
add_packages( add_packages(
"levilamina", "levilaminalibrary",
"legacyremotecall" "legacyremotecall",
"gmlib"
) )
add_shflags( add_shflags(
"/DELAYLOAD:bedrock_server.dll" -- Magic to import symbols from BDS "/DELAYLOAD:bedrock_server.dll" -- Magic to import symbols from BDS