feat: add PlaceholderAPI

This commit is contained in:
Tsubasa6848
2024-02-22 22:29:42 +08:00
Unverified
parent b2737599c8
commit 0001f80ff2
7 changed files with 203 additions and 8 deletions
+54
View File
@@ -0,0 +1,54 @@
const PAPIgetValueAPI = ll.import("BEPlaceholderAPI", "GetValue")
const PAPIgetValueByPlayerAPI = ll.import("BEPlaceholderAPI", "GetValueWithPlayer")
const PAPIregisterPlayerPlaceholderAPI = ll.import("BEPlaceholderAPI", "registerPlayerPlaceholder")
const PAPIregisterServerPlaceholderAPI = ll.import("BEPlaceholderAPI", "registerServerPlaceholder")
const PAPIregisterStaticPlaceholderAPI = ll.import("BEPlaceholderAPI", "registerStaticPlaceholder")
const PAPItranslateStringAPI = ll.import("BEPlaceholderAPI", "translateString")
const PAPIunRegisterPlaceholderAPI = ll.import("BEPlaceholderAPI", "unRegisterPlaceholder")
Function.prototype.getName = function () {
return this.name || this.toString().match(/function\s*([^(]*)\(/)[1]
}
class PAPI {
constructor() { }
static registerPlayerPlaceholder(func, PluginName, PAPIName) {
ll.export(func, PluginName, func.getName())
PAPIregisterPlayerPlaceholderAPI(PluginName, func.getName(), PAPIName)
}
static registerServerPlaceholder(func, PluginName, PAPIName) {
ll.export(func, PluginName, func.getName())
PAPIregisterServerPlaceholderAPI(PluginName, func.getName(), PAPIName)
}
static registerStaticPlaceholder(func, PluginName, PAPIName, UpdateInterval = 50) {
ll.export(func, PluginName, func.getName())
PAPIregisterStaticPlaceholderAPI(PluginName, func.getName(), PAPIName, UpdateInterval)
}
static getValue(key) {
return PAPIgetValueAPI(key)
}
static getValueByPlayer(key, xuid) {
return PAPIgetValueByPlayerAPI(key, xuid)
}
static translateString(str, xuid = "") {
return PAPItranslateStringAPI(str, xuid)
}
static unRegisterPlaceholder(str) {
return PAPIunRegisterPlaceholderAPI(str)
}
}
module.exports = {
PAPI
};