fix: fix the papi batch export error

This commit is contained in:
zimuya4153
2025-06-22 21:03:37 +08:00
Unverified
parent bac05d765e
commit 7fc855ffc9
2 changed files with 8 additions and 58 deletions
+6 -31
View File
@@ -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);
}
/**