Compare commits

..

4 Commits

8 changed files with 26 additions and 76 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ jobs:
- uses: xmake-io/github-action-setup-xmake@v1 - uses: xmake-io/github-action-setup-xmake@v1
with: with:
xmake-version: 2.9.9 xmake-version: 3.0.0
- run: | - run: |
xmake repo -u xmake repo -u
+1 -1
View File
@@ -12,7 +12,7 @@ jobs:
- uses: xmake-io/github-action-setup-xmake@v1 - uses: xmake-io/github-action-setup-xmake@v1
with: with:
xmake-version: 2.9.9 xmake-version: 3.0.0
- run: | - run: |
xmake repo -u xmake repo -u
+6 -31
View File
@@ -19,31 +19,6 @@ const PlaceholderAPI = {
getAllPAPI: ll.imports("BEPlaceholderAPI", "getAllPAPI") getAllPAPI: ll.imports("BEPlaceholderAPI", "getAllPAPI")
} }
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变量类 */ /** PAPI变量类 */
class PAPI { class PAPI {
constructor() { constructor() {
@@ -58,8 +33,8 @@ class PAPI {
* @returns {boolean} 是否注册成功 * @returns {boolean} 是否注册成功
*/ */
static registerPlayerPlaceholder(func, PluginName, PAPIName) { static registerPlayerPlaceholder(func, PluginName, PAPIName) {
ll.export(func, PluginName, func.getName()); ll.export(func, PluginName, `Placeholder_${PAPIName}`);
PlaceholderAPI.registerPlayerPlaceholderAPI(PluginName, func.getName(), PAPIName); PlaceholderAPI.registerPlayerPlaceholderAPI(PluginName, `Placeholder_${PAPIName}`, PAPIName);
} }
/** /**
@@ -70,8 +45,8 @@ class PAPI {
* @returns {boolean} 是否注册成功 * @returns {boolean} 是否注册成功
*/ */
static registerServerPlaceholder(func, PluginName, PAPIName) { static registerServerPlaceholder(func, PluginName, PAPIName) {
ll.export(func, PluginName, func.getName()); ll.export(func, PluginName, `Placeholder_${PAPIName}`);
PlaceholderAPI.registerServerPlaceholderAPI(PluginName, func.getName(), PAPIName); PlaceholderAPI.registerServerPlaceholderAPI(PluginName, `Placeholder_${PAPIName}`, PAPIName);
} }
/** /**
@@ -83,8 +58,8 @@ class PAPI {
* @returns {boolean} 是否注册成功 * @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, `Placeholder_${PAPIName}`);
PlaceholderAPI.registerStaticPlaceholderAPI(PluginName, func.getName(), PAPIName, UpdateInterval); PlaceholderAPI.registerStaticPlaceholderAPI(PluginName, `Placeholder_${PAPIName}`, PAPIName, UpdateInterval);
} }
/** /**
+4 -4
View File
@@ -116,7 +116,7 @@ module.exports = {
*/ */
emplaceListener: function (eventName, callback, priority = this.EventPriority.Normal, pluginName = getPluginName()) { emplaceListener: function (eventName, callback, priority = this.EventPriority.Normal, pluginName = getPluginName()) {
if (typeof callback !== "function") throw new Error("callback must be a function!"); if (typeof callback !== "function") throw new Error("callback must be a function!");
const /** @type {number} */ eventId = ll.importss("GMLIB_Event_API", "emplaceListener")(pluginName, eventName, priority); const /** @type {number} */ eventId = ll.imports("GMLIB_Event_API", "emplaceListener")(pluginName, eventName, priority);
if (eventId === -1) throw new Error(`Event ${eventName} creation failed!`); if (eventId === -1) throw new Error(`Event ${eventName} creation failed!`);
ll.exports((...data) => { ll.exports((...data) => {
let /** @type {boolean} */ result = typeof (data.slice(-1)[0]) === "boolean" ? data.pop() : false; let /** @type {boolean} */ result = typeof (data.slice(-1)[0]) === "boolean" ? data.pop() : false;
@@ -146,7 +146,7 @@ module.exports = {
* @param {boolean} * @param {boolean}
*/ */
removeListener: function (eventId) { removeListener: function (eventId) {
const result = ll.importss("GMLIB_Event_API", "removeListener")(eventId); const result = ll.imports("GMLIB_Event_API", "removeListener")(eventId);
if (result) { if (result) {
for (let [eventName, eventIds] of Object.entries(this.mEventData)) { for (let [eventName, eventIds] of Object.entries(this.mEventData)) {
this.mEventData[eventName] = eventIds.filter(id => id !== eventId); this.mEventData[eventName] = eventIds.filter(id => id !== eventId);
@@ -162,7 +162,7 @@ module.exports = {
* @returns {boolean} * @returns {boolean}
*/ */
hasListener: function (eventId) { hasListener: function (eventId) {
return ll.importss("GMLIB_Event_API", "hasListener")(eventId); return ll.imports("GMLIB_Event_API", "hasListener")(eventId);
}, },
/** /**
@@ -171,7 +171,7 @@ module.exports = {
* @returns {number?} * @returns {number?}
*/ */
getListenerPriority: function (eventId) { getListenerPriority: function (eventId) {
const priority = ll.importss("GMLIB_Event_API", "getListenerPriority")(eventId); const priority = ll.imports("GMLIB_Event_API", "getListenerPriority")(eventId);
return priority === -1 ? undefined : priority; return priority === -1 ? undefined : priority;
}, },
+8 -33
View File
@@ -47,56 +47,31 @@ const getPluginName = () => {
return "Unknown"; return "Unknown";
}; };
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;
}
module.exports = { module.exports = {
translate(value, actor = undefined, language = "") { translate(value, actor = undefined, language = "") {
return actor instanceof LLSE_Entity return actor instanceof LLSE_Entity
? ll.importss("PlaceholderAPI", "translateFromActor")(value, actor, language) ? ll.imports("PlaceholderAPI", "translateFromActor")(value, actor, language)
: ll.importss("PlaceholderAPI", "translate")(value, language); : ll.imports("PlaceholderAPI", "translate")(value, language);
}, },
registerPlaceholder(placeholder, callback) { registerPlaceholder(placeholder, callback) {
const pluginName = getPluginName(); const pluginName = getPluginName();
ll.exports((...args) => { ll.exports((...args) => {
if(!args[0].uniqueId) args[0] = undefined; if(!args[0].uniqueId) args[0] = undefined;
return callback(...args) ?? "<std::nullopt>"; return callback(...args) ?? "<std::nullopt>";
}, pluginName, callback.getName()); }, pluginName, `Placeholder_${placeholder}`);
ll.importss("PlaceholderAPI", "registerPlaceholder")(placeholder, callback.getName(), pluginName); ll.imports("PlaceholderAPI", "registerPlaceholder")(placeholder, `Placeholder_${placeholder}`, pluginName);
}, },
unregisterPlaceholder(placeholder) { unregisterPlaceholder(placeholder) {
return ll.importss("PlaceholderAPI", "unregisterPlaceholder")(placeholder); return ll.imports("PlaceholderAPI", "unregisterPlaceholder")(placeholder);
}, },
unregisterPlaceholderFromModName(placeholder) { unregisterPlaceholderFromModName(placeholder) {
return ll.importss("PlaceholderAPI", "unregisterPlaceholderFromModName")(placeholder); return ll.imports("PlaceholderAPI", "unregisterPlaceholderFromModName")(placeholder);
}, },
getValue(placeholder, actor = undefined, params = {}, language = "") { getValue(placeholder, actor = undefined, params = {}, language = "") {
if (actor instanceof LLSE_Player) actor = ll.imports("GMLib_ServerAPI", "PlayerToEntity")(actor); if (actor instanceof LLSE_Player) actor = ll.imports("GMLib_ServerAPI", "PlayerToEntity")(actor);
const result = actor instanceof LLSE_Entity const result = actor instanceof LLSE_Entity
? ll.importss("PlaceholderAPI", "getValueFromActor")(placeholder, actor, params, language) ? ll.imports("PlaceholderAPI", "getValueFromActor")(placeholder, actor, params, language)
: ll.importss("PlaceholderAPI", "getValue")(placeholder, params, language); : ll.imports("PlaceholderAPI", "getValue")(placeholder, params, language);
return result !== "<std::nullopt>" ? result : undefined; return result !== "<std::nullopt>" ? result : undefined;
} }
}; };
+2 -2
View File
@@ -559,7 +559,7 @@ void Export_Compatibility_API() {
} }
); );
RemoteCall::exportAs("GMLIB_API", "getBlockDestroySpeed", [](Block const* block) -> float { RemoteCall::exportAs("GMLIB_API", "getBlockDestroySpeed", [](Block const* block) -> float {
return block->mDirectData->mUnkc08fbd.as<float>(); return block->mDirectData->mDestroySpeed;
}); });
RemoteCall::exportAs("GMLIB_API", "getDestroyBlockSpeed", [](ItemStack const* item, Block const* block) -> float { RemoteCall::exportAs("GMLIB_API", "getDestroyBlockSpeed", [](ItemStack const* item, Block const* block) -> float {
return item->getItem()->getDestroySpeed(*item, *block); return item->getItem()->getDestroySpeed(*item, *block);
@@ -613,7 +613,7 @@ void Export_Compatibility_API() {
"getBlockLightEmission", "getBlockLightEmission",
[](std::string const& blockName, short legacyData) -> char { [](std::string const& blockName, short legacyData) -> char {
return Block::tryGetFromRegistry(blockName) return Block::tryGetFromRegistry(blockName)
.transform([](const Block& block) -> char { return block.mDirectData->mUnkda4e0e.as<char>(); }) .transform([](const Block& block) -> char { return block.mDirectData->mLightEmission->mValue; })
.value_or(-1); .value_or(-1);
} }
); );
+1 -1
View File
@@ -2,7 +2,7 @@
"format_version": 3, "format_version": 3,
"format_uuid": "289f771f-2c9a-4d73-9f3f-8492495a924d", "format_uuid": "289f771f-2c9a-4d73-9f3f-8492495a924d",
"tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi", "tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi",
"version": "1.2.0", "version": "1.4.0",
"info": { "info": {
"name": "GMLIB-LegacyRemoteCallApi", "name": "GMLIB-LegacyRemoteCallApi",
"description": "Legacy RemoteCall API for GMLIB", "description": "Legacy RemoteCall API for GMLIB",
+3 -3
View File
@@ -8,11 +8,11 @@ if not has_config("vs_runtime") then
set_runtimes("MD") set_runtimes("MD")
end end
add_requires("levilamina 1.3.0", {configs = {target_type = "server"}}) add_requires("levilamina 1.4.1", {configs = {target_type = "server"}})
add_requires("legacyremotecall") add_requires("legacyremotecall")
add_requires("levibuildscript") add_requires("levibuildscript")
add_requires("ilistenattentively 0.6.0") add_requires("ilistenattentively 0.7.0")
add_requires("gmlib 1.3.0-rc.1") add_requires("gmlib 1.4.0")
target("GMLIB-LegacyRemoteCallApi") target("GMLIB-LegacyRemoteCallApi")
add_cxflags( add_cxflags(