Compare commits

..

81 Commits

19 changed files with 4289 additions and 406 deletions
+2
View File
@@ -11,6 +11,8 @@ jobs:
uses: actions/checkout@v2
- uses: xmake-io/github-action-setup-xmake@v1
with:
xmake-version: "2.9.3"
- run: |
xmake repo -u
+2
View File
@@ -11,6 +11,8 @@ jobs:
uses: actions/checkout@v2
- uses: xmake-io/github-action-setup-xmake@v1
with:
xmake-version: "2.9.3"
- run: |
xmake repo -u
+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 = {
/** 获取一个服务器变量的值 @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();
}
+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,
/** 创建掉落物的实体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
View File
@@ -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 };
+1395
View File
File diff suppressed because it is too large Load Diff
+1777 -91
View File
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -1,9 +1,10 @@
{
"name": "${pluginName}",
"entry": "${pluginFile}",
"version": "0.12.7",
"version": "0.13.3",
"author": "GroupMountain",
"type": "native",
"passive": true,
"dependencies": [
{
"name": "GMLIB"
+393 -26
View File
@@ -1,5 +1,6 @@
#include "Global.h"
#include <regex>
#include <vector>
bool isInteger(const std::string& str) {
std::regex pattern("^[+-]?\\d+$");
@@ -19,10 +20,10 @@ void Export_Compatibility_API() {
if (!level) {
return false;
}
return GMLIB::Mod::CustomRecipe::unregisterRecipe(id);
return CustomRecipe::unregisterRecipe(id);
});
RemoteCall::exportAs("GMLIB_API", "setCustomPackPath", [](std::string const& path) -> void {
GMLIB::Mod::CustomPacks::addCustomPackPath(path);
CustomPacks::addCustomPackPath(path);
});
RemoteCall::exportAs("GMLIB_API", "getServerMspt", []() -> float {
auto level = GMLIB_Level::getInstance();
@@ -96,70 +97,71 @@ void Export_Compatibility_API() {
"GMLIB_API",
"createFloatingText",
[](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);
GMLIB::Server::FloatingTextManager::getInstance().add(ft);
auto& manager = FloatingTextManager::getInstance();
auto ft = manager.createStatic(text, pos.first, pos.second, papi);
manager.add(ft);
return ft->getRuntimeID();
}
);
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);
return true;
}
return false;
});
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 {
if (auto ft = GMLIB::Server::FloatingTextManager::getInstance().getFloatingText(id)) {
if (auto ft = FloatingTextManager::getInstance().getFloatingText(id)) {
ft->sendTo(*pl);
return true;
}
return false;
});
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();
return true;
}
return false;
});
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);
return true;
}
return false;
});
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();
return true;
}
return false;
});
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);
return true;
}
return false;
});
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();
return true;
}
return false;
});
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;
});
RemoteCall::exportAs("GMLIB_API", "getVersion_LRCA", []() -> std::string { return LIB_VERSION.asString(); });
RemoteCall::exportAs("GMLIB_API", "getVersion_GMLIB", []() -> std::string {
return GMLIB::Version::getLibVersionString();
return Version::getLibVersionString();
});
RemoteCall::exportAs(
"GMLIB_API",
@@ -509,8 +511,7 @@ void Export_Compatibility_API() {
}
);
RemoteCall::exportAs("GMLIB_API", "getPlayerFromUuid", [](std::string const& uuid) -> Player* {
auto uid = mce::UUID::fromString(uuid);
return ll::service::getLevel()->getPlayer(uuid);
return ll::service::getLevel()->getPlayer(mce::UUID::fromString(uuid));
});
RemoteCall::exportAs("GMLIB_API", "getPlayerFromUniqueId", [](std::string const& uniqueId) -> Actor* {
auto auid = parseScriptUniqueID(uniqueId);
@@ -555,32 +556,32 @@ void Export_Compatibility_API() {
);
RemoteCall::exportAs("GMLIB_API", "getXuidByUuid", [](std::string const& uuid) -> std::string {
auto uid = mce::UUID::fromString(uuid);
auto result = GMLIB::UserCache::getXuidByUuid(uid);
auto result = UserCache::getXuidByUuid(uid);
return result ? result.value() : "";
});
RemoteCall::exportAs("GMLIB_API", "getNameByUuid", [](std::string const& uuid) -> std::string {
auto uid = mce::UUID::fromString(uuid);
auto result = GMLIB::UserCache::getNameByUuid(uid);
auto result = UserCache::getNameByUuid(uid);
return result ? result.value() : "";
});
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() : "";
});
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() : "";
});
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() : "";
});
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() : "";
});
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() : "";
});
RemoteCall::exportAs(
@@ -588,7 +589,7 @@ void Export_Compatibility_API() {
"getAllPlayerInfo",
[]() -> std::vector<std::unordered_map<std::string, std::string>> {
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;
info["Name"] = entry.mName;
info["Xuid"] = entry.mXuid;
@@ -598,8 +599,8 @@ void Export_Compatibility_API() {
return result;
}
);
RemoteCall::exportAs("GMLIB_API", "getBlockRuntimeId", [](std::string const& blockName) -> uint {
if (auto block = Block::tryGetFromRegistry(blockName)) {
RemoteCall::exportAs("GMLIB_API", "getBlockRuntimeId", [](std::string const& blockName, short legacyData) -> uint {
if (auto block = Block::tryGetFromRegistry(blockName, legacyData)) {
return block->getRuntimeId();
}
return 0;
@@ -630,4 +631,370 @@ void Export_Compatibility_API() {
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);
}
});
RemoteCall::exportAs(
"GMLIB_API",
"registerCustomShapelessRecipe",
[](std::string const& recipe_id, std::vector<std::string> ingredients, ItemStack* result) -> void {
auto level = GMLIB_Level::getInstance();
if (!level) {
return;
}
std::vector<Recipes::Type> types;
char rt = 'A';
for (auto& ing : ingredients) {
auto key = Recipes::Type(ing, rt, 1, 0);
types.push_back(key);
rt++;
}
CustomRecipe::registerShapelessCraftingTableRecipe(recipe_id, types, *result);
}
);
RemoteCall::exportAs(
"GMLIB_API",
"registerCustomShapedRecipe",
[](std::string const& recipe_id,
std::vector<std::string> shape,
std::vector<std::string> ingredients,
ItemStack* result) -> void {
auto level = GMLIB_Level::getInstance();
if (!level) {
return;
}
std::vector<Recipes::Type> types;
char rt = 'A';
for (auto& ing : ingredients) {
auto key = Recipes::Type(ing, rt, 1, 0);
types.push_back(key);
rt++;
}
CustomRecipe::registerShapedCraftingTableRecipe(recipe_id, shape, types, *result);
}
);
}
+2 -2
View File
@@ -19,7 +19,7 @@ bool LegacyRemoteCallApi::load() {
logger.info("GMLIB-LegacyRemoteCallApi Loaded!");
logger.info(
"Loaded Version: {} with {}",
fmt::format(fg(fmt::color::pink), "GMLIB-" + GMLIB::Version::getLibVersionString()),
fmt::format(fg(fmt::color::pink), "GMLIB-" + Version::getLibVersionString()),
fmt::format(fg(fmt::color::light_green), "GMLIB-LegacyRemoteCallApi-" + LIB_VERSION.asString())
);
logger.info("Author: GroupMountain");
@@ -33,4 +33,4 @@ bool LegacyRemoteCallApi::disable() { return true; }
} // namespace GMLIB
LL_REGISTER_PLUGIN(GMLIB::LegacyRemoteCallApi, GMLIB::LegacyRemoteCallApi::getInstance());
LL_REGISTER_MOD(LegacyRemoteCallApi, LegacyRemoteCallApi::getInstance());
+5 -5
View File
@@ -1,6 +1,6 @@
#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 {
@@ -9,9 +9,9 @@ class LegacyRemoteCallApi {
public:
static std::unique_ptr<LegacyRemoteCallApi>& getInstance();
LegacyRemoteCallApi(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
+192 -151
View File
@@ -1,201 +1,242 @@
#include "Global.h"
using namespace ll::hash_utils;
class LegacyScriptEventManager {
private:
int64 mNextEventId = 0;
std::unordered_map<int64, 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)] = 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 const& eventName, std::string const& eventId) -> bool {
if (RemoteCall::hasFunc(eventName, eventId)) {
[&eventBus, &eventManager](std::string const& eventName, std::string const& eventId) -> bool {
if (!RemoteCall::hasFunc(eventName, eventId)) return false;
switch (doHash(eventName)) {
case doHash("onClientLogin"): {
auto Call = RemoteCall::importAs<bool(
std::string const& realName,
REGISTER_EVENT_LISTEN(
Event::PacketEvent::ClientLoginAfterEvent,
(std::string const& realName,
std::string const& uuid,
std::string const& serverXuid,
std::string const& clientXuid
)>(eventName, eventId);
eventBus->emplaceListener<GMLIB::Event::PacketEvent::ClientLoginAfterEvent>(
[Call](GMLIB::Event::PacketEvent::ClientLoginAfterEvent& ev) {
try {
Call(
ev.getRealName(),
ev.getUuid().asString(),
ev.getServerAuthXuid(),
ev.getClientAuthXuid()
std::string const& clientXuid),
(ev.getRealName(), ev.getUuid().asString(), ev.getServerAuthXuid(), ev.getClientAuthXuid()),
logger.error("Event \"onClientLogin\" cannot be intercepted"),
);
} catch (...) {}
}
);
return true;
}
case doHash("onWeatherChange"): {
auto Call =
RemoteCall::importAs<bool(int lightningLevel, int rainLevel, int lightningLast, int rainLast)>(
eventName,
eventId
REGISTER_EVENT_LISTEN(
Event::LevelEvent::WeatherUpdateBeforeEvent,
(int lightningLevel, int rainLevel, int lightningLast, int rainLast),
(ev.getLightningLevel(), ev.getRainLevel(), ev.getLightningLastTick(), ev.getRainingLastTick()),
ev.cancel(),
);
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();
}
}
REGISTER_EVENT_LISTEN(
Event::EntityEvent::MobPickupItemBeforeEvent,
(Actor * mob, Actor * item),
(&ev.self(), (Actor*)&ev.getItemActor()),
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();
}
}
REGISTER_EVENT_LISTEN(
Event::EntityEvent::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(),
);
return true;
}
case doHash("onItemSpawned"): {
auto Call = RemoteCall::importAs<
bool(const ItemStack* item, Actor* itemActor, std::pair<Vec3, int> position, Actor* spawner)>(
eventName,
eventId
REGISTER_EVENT_LISTEN(
Event::EntityEvent::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"),
);
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 (...) {}
}
case doHash("onEntityTryChangeDim"): {
REGISTER_EVENT_LISTEN(
Event::EntityEvent::ActorChangeDimensionBeforeEvent,
(Actor * entity, int toDimId),
(&ev.self(), ev.getToDimensionId()),
ev.cancel(),
);
return true;
}
case doHash("onEntityChangeDim"): {
auto Call = RemoteCall::importAs<bool(Actor * entity, int toDimId)>(eventName, eventId);
eventBus->emplaceListener<GMLIB::Event::EntityEvent::ActorChangeDimensionBeforeEvent>(
[Call](GMLIB::Event::EntityEvent::ActorChangeDimensionBeforeEvent& ev) {
bool result = true;
try {
result = Call(&ev.self(), ev.getToDimensionId());
} catch (...) {}
if (!result) {
ev.cancel();
}
}
);
return true;
}
case doHash("onLeaveBed"): {
auto Call = RemoteCall::importAs<bool(Player * pl)>(eventName, eventId);
eventBus->emplaceListener<GMLIB::Event::PlayerEvent::PlayerStopSleepBeforeEvent>(
[Call](GMLIB::Event::PlayerEvent::PlayerStopSleepBeforeEvent& ev) {
bool result = true;
try {
result = Call(&ev.self());
} catch (...) {}
if (!result) {
ev.cancel();
}
}
REGISTER_EVENT_LISTEN(
Event::PlayerEvent::PlayerStopSleepBeforeEvent,
(Player * pl),
(&ev.self()),
ev.cancel(),
);
return true;
}
case doHash("onDeathMessage"): {
auto Call =
RemoteCall::importAs<bool(std::string const& message, std::vector<std::string>, Actor* dead)>(
eventName,
eventId
REGISTER_EVENT_LISTEN(
Event::EntityEvent::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"),
);
eventBus->emplaceListener<GMLIB::Event::EntityEvent::DeathMessageAfterEvent>(
[Call](GMLIB::Event::EntityEvent::DeathMessageAfterEvent& ev) {
auto msg = ev.getDeathMessage();
auto source = ev.getDamageSource();
try {
Call(msg.first, msg.second, &ev.self());
} catch (...) {}
}
);
return true;
}
case doHash("onMobHurted"): {
auto Call = RemoteCall::importAs<bool(Actor * mob, Actor * source, float damage, int cause)>(
eventName,
eventId
);
eventBus->emplaceListener<GMLIB::Event::EntityEvent::MobHurtAfterEvent>(
[Call](GMLIB::Event::EntityEvent::MobHurtAfterEvent& ev) {
REGISTER_EVENT_LISTEN(
Event::EntityEvent::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();
}
}
try {
Call(&ev.self(), source, ev.getDamage(), (int)damageSource.getCause());
} catch (...) {}
if (source->getOwner()) source = source->getOwner();
}
);
return true;
}
case doHash("onEndermanTake"): {
auto Call = RemoteCall::importAs<bool(Actor * mob)>(eventName, eventId);
eventBus->emplaceListener<GMLIB::Event::EntityEvent::EndermanTakeBlockBeforeEvent>(
[Call](GMLIB::Event::EntityEvent::EndermanTakeBlockBeforeEvent& ev) {
bool result = true;
try {
result = Call(&ev.self());
} catch (...) {}
if (!result) {
ev.cancel();
}
}
REGISTER_EVENT_LISTEN(
Event::EntityEvent::EndermanTakeBlockBeforeEvent,
(Actor * mob),
(&ev.self()),
ev.cancel(),
);
}
case doHash("onEntityChangeDim"): {
REGISTER_EVENT_LISTEN(
Event::EntityEvent::ActorChangeDimensionAfterEvent,
(Actor * mob, int fromDimId),
(&ev.self(), ev.getFromDimensionId()),
logger.error("Event \"onEntityChangeDim\" cannot be intercepted"),
);
}
case doHash("onDragonRespawn"): {
REGISTER_EVENT_LISTEN(
Event::EntityEvent::DragonRespawnBeforeEvent,
(int64 enderDragonUniqueID),
(ev.getEnderDragon().id),
ev.cancel(),
)
}
case doHash("onProjectileTryCreate"): {
REGISTER_EVENT_LISTEN(
Event::EntityEvent::ProjectileCreateBeforeEvent,
(Actor * mob, int64 uniqueId),
(&ev.self(), ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1),
ev.cancel(),
);
}
case doHash("onProjectileCreate"): {
REGISTER_EVENT_LISTEN(
Event::EntityEvent::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(
Event::EntityEvent::SpawnWanderingTraderBeforeEvent,
(std::pair<BlockPos, int> pos),
({ev.getPos(), ev.getRegion().getDimensionId()}),
ev.cancel(),
);
}
case doHash("onHandleRequestAction"): {
REGISTER_EVENT_LISTEN(Event::PlayerEvent::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();
);
}
case doHash("onSendContainerClosePacket"): {
REGISTER_EVENT_LISTEN(
Event::PacketEvent::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"),
);
return true;
}
default:
return false;
}
}
return false;
}
);
}
+7 -3
View File
@@ -3,13 +3,17 @@
#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 LIB_VERSION_MAJOR 0
#define LIB_VERSION_MINOR 12
#define LIB_VERSION_PATCH 7
#define LIB_VERSION_MINOR 13
#define LIB_VERSION_PATCH 3
#define LIB_VERSION GMLIB::Version(LIB_VERSION_MAJOR, LIB_VERSION_MINOR, LIB_VERSION_PATCH)
#define LIB_VERSION Version(LIB_VERSION_MAJOR, LIB_VERSION_MINOR, LIB_VERSION_PATCH)
extern ll::Logger logger;
+10 -18
View File
@@ -33,7 +33,7 @@ void Export_Legacy_GMLib_ModAPI() {
}
auto res = RecipeIngredient(result, 0, count);
auto unl = makeRecipeUnlockingKey(unlock);
GMLIB::Mod::JsonRecipe::registerShapelessCraftingTableRecipe(recipe_id, types, res, unl);
JsonRecipe::registerShapelessCraftingTableRecipe(recipe_id, types, res, unl);
}
);
RemoteCall::exportAs(
@@ -56,7 +56,7 @@ void Export_Legacy_GMLib_ModAPI() {
}
auto res = RecipeIngredient(result, 0, count);
auto unl = makeRecipeUnlockingKey(unlock);
GMLIB::Mod::JsonRecipe::registerShapedCraftingTableRecipe(recipe_id, shape, types, res, unl);
JsonRecipe::registerShapedCraftingTableRecipe(recipe_id, shape, types, res, unl);
}
);
RemoteCall::exportAs(
@@ -72,7 +72,7 @@ void Export_Legacy_GMLib_ModAPI() {
}
auto inp = RecipeIngredient(input, 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(
@@ -85,7 +85,7 @@ void Export_Legacy_GMLib_ModAPI() {
return;
}
auto rea = RecipeIngredient(reagent, 0, 1);
GMLIB::Mod::JsonRecipe::registerBrewingMixRecipe(recipe_id, input, output, rea);
JsonRecipe::registerBrewingMixRecipe(recipe_id, input, output, rea);
}
);
RemoteCall::exportAs(
@@ -100,7 +100,7 @@ void Export_Legacy_GMLib_ModAPI() {
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);
JsonRecipe::registerBrewingContainerRecipe(recipe_id, inp, outp, rea);
}
);
RemoteCall::exportAs(
@@ -115,13 +115,7 @@ void Export_Legacy_GMLib_ModAPI() {
if (!level) {
return;
}
GMLIB::Mod::JsonRecipe::registerSmithingTransformRecipe(
recipe_id,
smithing_template,
base,
addition,
result
);
JsonRecipe::registerSmithingTransformRecipe(recipe_id, smithing_template, base, addition, result);
}
);
RemoteCall::exportAs(
@@ -135,7 +129,7 @@ void Export_Legacy_GMLib_ModAPI() {
if (!level) {
return;
}
GMLIB::Mod::JsonRecipe::registerSmithingTrimRecipe(recipe_id, smithing_template, base, addition);
JsonRecipe::registerSmithingTrimRecipe(recipe_id, smithing_template, base, addition);
}
);
RemoteCall::exportAs(
@@ -153,12 +147,12 @@ void Export_Legacy_GMLib_ModAPI() {
}
auto inp = RecipeIngredient(input, 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 {
GMLIB::Mod::VanillaFix::setAutoCleanUnknownBlockEnabled();
VanillaFix::setAutoCleanUnknownBlockEnabled();
});
// 实验性
RemoteCall::exportAs("GMLib_ModAPI", "registerExperimentsRequire", [](int experiment_id) -> void {
@@ -192,7 +186,5 @@ void Export_Legacy_GMLib_ModAPI() {
}
return false;
});
RemoteCall::exportAs("GMLib_ModAPI", "setFixI18nEnabled", []() -> void {
GMLIB::Mod::VanillaFix::setFixI18nEnabled();
});
RemoteCall::exportAs("GMLib_ModAPI", "setFixI18nEnabled", []() -> void { VanillaFix::setFixI18nEnabled(); });
}
+11 -7
View File
@@ -1,6 +1,4 @@
#include "GMLIB/Server/FakeListAPI.h"
#include "Global.h"
#include "mc/world/ActorUniqueID.h"
void Export_Legacy_GMLib_ServerAPI() {
RemoteCall::exportAs("GMLib_ServerAPI", "setEducationFeatureEnabled", []() -> void {
@@ -40,7 +38,7 @@ void Export_Legacy_GMLib_ServerAPI() {
"GMLib_ServerAPI",
"spawnEntity",
[](std::pair<Vec3, int> pos, std::string const& name) -> Actor* {
return GMLIB_Spawner::spawnEntity(pos.first, pos.second, name);
return GMLIB_Spawner::spawnEntity(pos.first, pos.second, name).as_ptr();
}
);
RemoteCall::exportAs(
@@ -48,7 +46,7 @@ void Export_Legacy_GMLib_ServerAPI() {
"shootProjectile",
[](Actor* owner, std::string const& name, float speed, float offset) -> Actor* {
auto ac = (GMLIB_Actor*)owner;
return ac->shootProjectile(name, speed, offset);
return ac->shootProjectile(name, speed, offset).as_ptr();
}
);
RemoteCall::exportAs(
@@ -64,13 +62,19 @@ void Export_Legacy_GMLib_ServerAPI() {
"GMLib_ServerAPI",
"addFakeList",
[](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 {
return GMLIB::Server::FakeList::removeFakeList(nameOrXuid);
return FakeList::removeFakeList(nameOrXuid);
});
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 -27
View File
@@ -13,11 +13,9 @@ bool isParameters(std::string const& str) {
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) {
return GMLIB::Server::PlaceholderAPI::getValue(a1, ll::service::bedrock::getLevel()->getPlayer(a2));
}
std::string GetValueWithPlayer(std::string const& key, Player* player) { return PlaceholderAPI::getValue(key, player); }
bool registerPlayerPlaceholder(
std::string const& PluginName,
@@ -25,23 +23,20 @@ bool registerPlayerPlaceholder(
std::string const& PAPIName
) {
if (RemoteCall::hasFunc(PluginName, FuncName)) {
PlaceholderAPI::unregisterPlaceholder(PAPIName);
if (isParameters(PAPIName)) {
auto Call = RemoteCall::importAs<std::string(Player * pl, std::unordered_map<std::string, std::string>)>(
PluginName,
FuncName
);
GMLIB::Server::PlaceholderAPI::registerPlayerPlaceholder(
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::Server::PlaceholderAPI::registerPlayerPlaceholder(
PAPIName,
[Call](Player* sp) { return Call(sp); },
PluginName
);
PlaceholderAPI::registerPlayerPlaceholder(PAPIName, [Call](Player* sp) { return Call(sp); }, PluginName);
}
return true;
}
@@ -54,17 +49,18 @@ bool registerServerPlaceholder(
std::string const& PAPIName
) {
if (RemoteCall::hasFunc(PluginName, FuncName)) {
PlaceholderAPI::unregisterPlaceholder(PAPIName);
if (isParameters(PAPIName)) {
auto Call =
RemoteCall::importAs<std::string(std::unordered_map<std::string, std::string>)>(PluginName, FuncName);
GMLIB::Server::PlaceholderAPI::registerServerPlaceholder(
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::Server::PlaceholderAPI::registerServerPlaceholder(PAPIName, [Call]() { return Call(); }, PluginName);
PlaceholderAPI::registerServerPlaceholder(PAPIName, [Call]() { return Call(); }, PluginName);
}
return true;
}
@@ -78,21 +74,13 @@ bool registerStaticPlaceholder(
int num
) {
if (RemoteCall::hasFunc(PluginName, FuncName)) {
PlaceholderAPI::unregisterPlaceholder(PAPIName);
if (isParameters(PAPIName)) {
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
if (num == -1) {
GMLIB::Server::PlaceholderAPI::registerStaticPlaceholder(
PAPIName,
[Call] { return Call(); },
PluginName
);
PlaceholderAPI::registerStaticPlaceholder(PAPIName, [Call] { return Call(); }, PluginName);
} else {
GMLIB::Server::PlaceholderAPI::registerStaticPlaceholder(
PAPIName,
num,
[Call] { return Call(); },
PluginName
);
PlaceholderAPI::registerStaticPlaceholder(PAPIName, num, [Call] { return Call(); }, PluginName);
}
}
return true;
@@ -101,14 +89,14 @@ bool registerStaticPlaceholder(
}
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
+3 -3
View File
@@ -1,7 +1,7 @@
{
"format_version": 2,
"tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi",
"version": "0.12.7",
"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.12.7/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.12.7"
"github.com/GroupMountain/GMLIB": ">=0.13.0"
},
"files": {
"place": [
+2 -2
View File
@@ -8,7 +8,7 @@ if not has_config("vs_runtime") then
end
-- Option 1: Use the latest version of LeviLamina released on GitHub.
add_requires("levilamina")
add_requires("levilaminalibrary")
add_requires("legacyremotecall")
add_requires("gmlib")
@@ -59,7 +59,7 @@ target("GMLIB-LegacyRemoteCallApi") -- Change this to your plugin name.
"src"
)
add_packages(
"levilamina",
"levilaminalibrary",
"legacyremotecall",
"gmlib"
)