1新增 2修复

- 新增getEntityOwnerUniqueId接口
- 修复注册PAPI变量无法使用匿名函数
- 修复注册相同PAPI名字无法重载
This commit is contained in:
子沐呀
2024-07-18 21:39:49 +08:00
Unverified
parent a47f8c729d
commit 52897a25a7
5 changed files with 47 additions and 12 deletions
+18 -7
View File
@@ -20,13 +20,24 @@ const PlaceholderAPI = {
}
Function.prototype.getName =
/**
* 获取函数名字
* @returns {string}
*/
function () {
return this.name || this.toString().match(/function\s*([^(]*)\(/)[1] || Math.ceil(Math.random() * 1000000).toString(16);
}
/**
* 获取函数名字
* @returns {string}
*/
function () {
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变量类 */
class PAPI {
+3
View File
@@ -1083,6 +1083,9 @@ interface Entity {
/** (GMLIB)获取实体的命名 */
getNameTag(): string;
/** 获取实体的主人 */
getEntityOwner(): Entity | null;
}
interface Block {
+15 -3
View File
@@ -318,6 +318,8 @@ const GMLIB_API = {
getPlayerArmorCoverPercentage: ll.import("GMLIB_API", "getPlayerArmorCoverPercentage"),
/** 获取玩家盔甲值 @type {function(Player):number} */
getPlayerArmorValue: ll.import("GMLIB_API", "getPlayerArmorValue"),
/** 获取实体主人的UniqueID @type {function(Entity):Entity} */
getEntityOwnerUniqueId: ll.import("GMLIB_API", "getEntityOwnerUniqueId")
}
/** 静态悬浮字类列表 @type {Map<number,StaticFloatingText>} */
@@ -2357,7 +2359,7 @@ LLSE_Player.prototype.getHungry =
* @returns {number}
*/
function () {
return GMLIB_API.getPlayerHungry(this)
return GMLIB_API.getPlayerHungry(this);
}
LLSE_Player.prototype.getArmorCoverPercentage =
@@ -2366,7 +2368,7 @@ LLSE_Player.prototype.getArmorCoverPercentage =
* @returns {number}
*/
function () {
return GMLIB_API.getPlayerArmorCoverPercentage(this)
return GMLIB_API.getPlayerArmorCoverPercentage(this);
}
LLSE_Player.prototype.getArmorValue =
@@ -2375,7 +2377,17 @@ LLSE_Player.prototype.getArmorValue =
* @returns {number}
*/
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 = {
+5
View File
@@ -1,5 +1,9 @@
#include "Global.h"
#include "magic_enum.hpp"
#include "mc/entity/systems/common/ServerCameraStateSystem.h"
#include "mc/enums/AbilitiesIndex.h"
#include "mc/scripting/modules/minecraft/ScriptCameraSetLocationOptions.h"
#include "mc/world/actor/common/CameraInstruction.h"
#include <regex>
#include <vector>
@@ -843,4 +847,5 @@ void Export_Compatibility_API() {
RemoteCall::exportAs("GMLIB_API", "getPlayerArmorValue", [](Player* player) -> int {
return player->getArmorValue();
});
RemoteCall::exportAs("GMLIB_API", "getEntityOwnerUniqueId", [](Actor* entity) -> int64 { return entity->getOwnerId().id; });
}
+4
View File
@@ -1,3 +1,4 @@
#include "GMLIB/Server/PlaceholderAPI.h"
#include "Global.h"
#include <regex>
@@ -25,6 +26,7 @@ bool registerPlayerPlaceholder(
std::string const& PAPIName
) {
if (RemoteCall::hasFunc(PluginName, FuncName)) {
PlaceholderAPI::unregisterPlaceholder(PAPIName);
if (isParameters(PAPIName)) {
auto Call = RemoteCall::importAs<std::string(Player * pl, std::unordered_map<std::string, std::string>)>(
PluginName,
@@ -54,6 +56,7 @@ bool registerServerPlaceholder(
std::string const& PAPIName
) {
if (RemoteCall::hasFunc(PluginName, FuncName)) {
PlaceholderAPI::unregisterPlaceholder(PAPIName);
if (isParameters(PAPIName)) {
auto Call =
RemoteCall::importAs<std::string(std::unordered_map<std::string, std::string>)>(PluginName, FuncName);
@@ -78,6 +81,7 @@ bool registerStaticPlaceholder(
int num
) {
if (RemoteCall::hasFunc(PluginName, FuncName)) {
PlaceholderAPI::unregisterPlaceholder(PAPIName);
if (isParameters(PAPIName)) {
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
if (num == -1) {