feat: add PlaceholderAPI
This commit is contained in:
@@ -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
|
||||
};
|
||||
@@ -41,10 +41,11 @@ const GMLIB_API = {
|
||||
const FloatingTextList = [];
|
||||
|
||||
class StaticFloatingText {
|
||||
constructor(pos, text) {
|
||||
constructor(pos, text, papi = true) {
|
||||
this.mPosition = pos;
|
||||
this.mText = text;
|
||||
this.mRuntimeId = GMLIB_API.createFloatingText(this.mPosition, this.mText);
|
||||
this.mPlaceholderAPI = papi;
|
||||
this.mRuntimeId = GMLIB_API.createFloatingText(this.mPosition, this.mText, this.mPlaceholderAPI);
|
||||
FloatingTextList.push(this);
|
||||
this.sendToClients();
|
||||
mc.listen("onJoin", (pl) => {
|
||||
@@ -127,8 +128,8 @@ class StaticFloatingText {
|
||||
}
|
||||
|
||||
class DynamicFloatingText extends StaticFloatingText {
|
||||
constructor(pos, text, updateRate = 1) {
|
||||
super(pos, text);
|
||||
constructor(pos, text, updateRate = 1, papi = true) {
|
||||
super(pos, text, papi);
|
||||
this.mUpdateRate = updateRate;
|
||||
this.mTaskId = null;
|
||||
this.startUpdate();
|
||||
@@ -345,4 +346,4 @@ class Experiments {
|
||||
}
|
||||
}
|
||||
|
||||
export { StaticFloatingText, DynamicFloatingText, Minecraft, Recipes, Experiments };
|
||||
module.exports = { StaticFloatingText, DynamicFloatingText, Minecraft, Recipes, Experiments };
|
||||
Reference in New Issue
Block a user