From 7fc855ffc9d8e8bf2d832a268ef3d72536a959dd Mon Sep 17 00:00:00 2001 From: zimuya4153 Date: Sun, 22 Jun 2025 21:03:37 +0800 Subject: [PATCH] fix: fix the papi batch export error --- lib/BEPlaceholderAPI-JS.js | 37 ++++++------------------------------- lib/PlaceholderAPI.js | 29 ++--------------------------- 2 files changed, 8 insertions(+), 58 deletions(-) diff --git a/lib/BEPlaceholderAPI-JS.js b/lib/BEPlaceholderAPI-JS.js index 2515128..73fbbc9 100644 --- a/lib/BEPlaceholderAPI-JS.js +++ b/lib/BEPlaceholderAPI-JS.js @@ -19,31 +19,6 @@ const PlaceholderAPI = { 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变量类 */ class PAPI { constructor() { @@ -58,8 +33,8 @@ class PAPI { * @returns {boolean} 是否注册成功 */ static registerPlayerPlaceholder(func, PluginName, PAPIName) { - ll.export(func, PluginName, func.getName()); - PlaceholderAPI.registerPlayerPlaceholderAPI(PluginName, func.getName(), PAPIName); + ll.export(func, PluginName, `Placeholder_${PAPIName}`); + PlaceholderAPI.registerPlayerPlaceholderAPI(PluginName, `Placeholder_${PAPIName}`, PAPIName); } /** @@ -70,8 +45,8 @@ class PAPI { * @returns {boolean} 是否注册成功 */ static registerServerPlaceholder(func, PluginName, PAPIName) { - ll.export(func, PluginName, func.getName()); - PlaceholderAPI.registerServerPlaceholderAPI(PluginName, func.getName(), PAPIName); + ll.export(func, PluginName, `Placeholder_${PAPIName}`); + PlaceholderAPI.registerServerPlaceholderAPI(PluginName, `Placeholder_${PAPIName}`, PAPIName); } /** @@ -83,8 +58,8 @@ class PAPI { * @returns {boolean} 是否注册成功 */ static registerStaticPlaceholder(func, PluginName, PAPIName, UpdateInterval = 50) { - ll.export(func, PluginName, func.getName()); - PlaceholderAPI.registerStaticPlaceholderAPI(PluginName, func.getName(), PAPIName, UpdateInterval); + ll.export(func, PluginName, `Placeholder_${PAPIName}`); + PlaceholderAPI.registerStaticPlaceholderAPI(PluginName, `Placeholder_${PAPIName}`, PAPIName, UpdateInterval); } /** diff --git a/lib/PlaceholderAPI.js b/lib/PlaceholderAPI.js index 93c2a53..0841d0e 100644 --- a/lib/PlaceholderAPI.js +++ b/lib/PlaceholderAPI.js @@ -47,31 +47,6 @@ const getPluginName = () => { 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 = { translate(value, actor = undefined, language = "") { return actor instanceof LLSE_Entity @@ -83,8 +58,8 @@ module.exports = { ll.exports((...args) => { if(!args[0].uniqueId) args[0] = undefined; return callback(...args) ?? ""; - }, pluginName, callback.getName()); - ll.importss("PlaceholderAPI", "registerPlaceholder")(placeholder, callback.getName(), pluginName); + }, pluginName, `Placeholder_${placeholder}`); + ll.importss("PlaceholderAPI", "registerPlaceholder")(placeholder, `Placeholder_${placeholder}`, pluginName); }, unregisterPlaceholder(placeholder) { return ll.importss("PlaceholderAPI", "unregisterPlaceholder")(placeholder);