1新增 2修复
- 新增getEntityOwnerUniqueId接口 - 修复注册PAPI变量无法使用匿名函数 - 修复注册相同PAPI名字无法重载
This commit is contained in:
@@ -19,14 +19,25 @@ const PlaceholderAPI = {
|
|||||||
getAllPAPI: ll.import("BEPlaceholderAPI", "getAllPAPI")
|
getAllPAPI: ll.import("BEPlaceholderAPI", "getAllPAPI")
|
||||||
}
|
}
|
||||||
|
|
||||||
Function.prototype.getName =
|
Function.prototype.getName =
|
||||||
/**
|
/**
|
||||||
* 获取函数名字
|
* 获取函数名字
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function () {
|
function () {
|
||||||
return this.name || this.toString().match(/function\s*([^(]*)\(/)[1] || Math.ceil(Math.random() * 1000000).toString(16);
|
return this.name || this.toString().match(/function\s*([^(]*)\(/)?.[1] || this.toString().hashCode().toString(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String.prototype.hashCode = function () {
|
||||||
|
var hash = 0, i, chr;
|
||||||
|
if (this.length === 0) return hash;
|
||||||
|
for (i = 0; i < this.length; i++) {
|
||||||
|
chr = this.charCodeAt(i);
|
||||||
|
hash = ((hash << 5) - hash) + chr;
|
||||||
|
hash |= 0;
|
||||||
|
}
|
||||||
|
return hash;
|
||||||
|
};
|
||||||
|
|
||||||
/** PAPI变量类 */
|
/** PAPI变量类 */
|
||||||
class PAPI {
|
class PAPI {
|
||||||
@@ -79,7 +90,7 @@ class PAPI {
|
|||||||
static getValue(key) {
|
static getValue(key) {
|
||||||
return PlaceholderAPI.getValueAPI(key);
|
return PlaceholderAPI.getValueAPI(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取一个玩家变量的值
|
* 获取一个玩家变量的值
|
||||||
* @param {string} key PAPI变量名
|
* @param {string} key PAPI变量名
|
||||||
|
|||||||
Vendored
+3
@@ -1083,6 +1083,9 @@ interface Entity {
|
|||||||
|
|
||||||
/** (GMLIB)获取实体的命名 */
|
/** (GMLIB)获取实体的命名 */
|
||||||
getNameTag(): string;
|
getNameTag(): string;
|
||||||
|
|
||||||
|
/** 获取实体的主人 */
|
||||||
|
getEntityOwner(): Entity | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Block {
|
interface Block {
|
||||||
|
|||||||
+15
-3
@@ -318,6 +318,8 @@ const GMLIB_API = {
|
|||||||
getPlayerArmorCoverPercentage: ll.import("GMLIB_API", "getPlayerArmorCoverPercentage"),
|
getPlayerArmorCoverPercentage: ll.import("GMLIB_API", "getPlayerArmorCoverPercentage"),
|
||||||
/** 获取玩家盔甲值 @type {function(Player):number} */
|
/** 获取玩家盔甲值 @type {function(Player):number} */
|
||||||
getPlayerArmorValue: ll.import("GMLIB_API", "getPlayerArmorValue"),
|
getPlayerArmorValue: ll.import("GMLIB_API", "getPlayerArmorValue"),
|
||||||
|
/** 获取实体主人的UniqueID @type {function(Entity):Entity} */
|
||||||
|
getEntityOwnerUniqueId: ll.import("GMLIB_API", "getEntityOwnerUniqueId")
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 静态悬浮字类列表 @type {Map<number,StaticFloatingText>} */
|
/** 静态悬浮字类列表 @type {Map<number,StaticFloatingText>} */
|
||||||
@@ -2357,7 +2359,7 @@ LLSE_Player.prototype.getHungry =
|
|||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
function () {
|
function () {
|
||||||
return GMLIB_API.getPlayerHungry(this)
|
return GMLIB_API.getPlayerHungry(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
LLSE_Player.prototype.getArmorCoverPercentage =
|
LLSE_Player.prototype.getArmorCoverPercentage =
|
||||||
@@ -2366,7 +2368,7 @@ LLSE_Player.prototype.getArmorCoverPercentage =
|
|||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
function () {
|
function () {
|
||||||
return GMLIB_API.getPlayerArmorCoverPercentage(this)
|
return GMLIB_API.getPlayerArmorCoverPercentage(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
LLSE_Player.prototype.getArmorValue =
|
LLSE_Player.prototype.getArmorValue =
|
||||||
@@ -2375,7 +2377,17 @@ LLSE_Player.prototype.getArmorValue =
|
|||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
function () {
|
function () {
|
||||||
return GMLIB_API.getPlayerArmorValue(this)
|
return GMLIB_API.getPlayerArmorValue(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
LLSE_Player.prototype.getEntityOwner =
|
||||||
|
/**
|
||||||
|
* 获取实体的主人
|
||||||
|
* @returns {Entity|null}
|
||||||
|
*/
|
||||||
|
function () {
|
||||||
|
const uniqueId = GMLIB_API.getEntityOwnerUniqueId(this);
|
||||||
|
return uniqueId === -1 ? null : Minecraft.getEntityFromUniqueId(uniqueId);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
#include "magic_enum.hpp"
|
||||||
|
#include "mc/entity/systems/common/ServerCameraStateSystem.h"
|
||||||
#include "mc/enums/AbilitiesIndex.h"
|
#include "mc/enums/AbilitiesIndex.h"
|
||||||
|
#include "mc/scripting/modules/minecraft/ScriptCameraSetLocationOptions.h"
|
||||||
|
#include "mc/world/actor/common/CameraInstruction.h"
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -843,4 +847,5 @@ void Export_Compatibility_API() {
|
|||||||
RemoteCall::exportAs("GMLIB_API", "getPlayerArmorValue", [](Player* player) -> int {
|
RemoteCall::exportAs("GMLIB_API", "getPlayerArmorValue", [](Player* player) -> int {
|
||||||
return player->getArmorValue();
|
return player->getArmorValue();
|
||||||
});
|
});
|
||||||
|
RemoteCall::exportAs("GMLIB_API", "getEntityOwnerUniqueId", [](Actor* entity) -> int64 { return entity->getOwnerId().id; });
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include "GMLIB/Server/PlaceholderAPI.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
@@ -25,6 +26,7 @@ bool registerPlayerPlaceholder(
|
|||||||
std::string const& PAPIName
|
std::string const& PAPIName
|
||||||
) {
|
) {
|
||||||
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
||||||
|
PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
||||||
if (isParameters(PAPIName)) {
|
if (isParameters(PAPIName)) {
|
||||||
auto Call = RemoteCall::importAs<std::string(Player * pl, std::unordered_map<std::string, std::string>)>(
|
auto Call = RemoteCall::importAs<std::string(Player * pl, std::unordered_map<std::string, std::string>)>(
|
||||||
PluginName,
|
PluginName,
|
||||||
@@ -54,6 +56,7 @@ bool registerServerPlaceholder(
|
|||||||
std::string const& PAPIName
|
std::string const& PAPIName
|
||||||
) {
|
) {
|
||||||
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
||||||
|
PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
||||||
if (isParameters(PAPIName)) {
|
if (isParameters(PAPIName)) {
|
||||||
auto Call =
|
auto Call =
|
||||||
RemoteCall::importAs<std::string(std::unordered_map<std::string, std::string>)>(PluginName, FuncName);
|
RemoteCall::importAs<std::string(std::unordered_map<std::string, std::string>)>(PluginName, FuncName);
|
||||||
@@ -78,6 +81,7 @@ bool registerStaticPlaceholder(
|
|||||||
int num
|
int num
|
||||||
) {
|
) {
|
||||||
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
||||||
|
PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
||||||
if (isParameters(PAPIName)) {
|
if (isParameters(PAPIName)) {
|
||||||
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
|
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
|
||||||
if (num == -1) {
|
if (num == -1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user