feat: adapt gmlib 1.0.0
This commit is contained in:
+40
-3
@@ -2,13 +2,50 @@
|
||||
* @returns {string}
|
||||
*/
|
||||
const getPluginName = () => {
|
||||
// quickjs
|
||||
try {
|
||||
throw new Error("getPluginName");
|
||||
} catch (error) {
|
||||
return error.stack.trim().match(/plugins\\(.*)\\.*\.js:[0-9]+\)$/i)?.[1]
|
||||
|| error.stack.trim().match(/at <anonymous> \(([^\\|/]+)(.*?):\d+:\d+\)$/i)?.[1]
|
||||
|| "Unknown";
|
||||
const /** @type {string} */ line = error.stack.trim().split("\n").pop().trim();
|
||||
if (line.includes("<anonymous>")) {
|
||||
return line.slice(
|
||||
line.indexOf("(") + 1,
|
||||
line.indexOf("\\")
|
||||
);
|
||||
}
|
||||
if (line.includes("<eval>")) {
|
||||
return line.slice(
|
||||
line.indexOf("/", line.indexOf("/") + 1) + 1,
|
||||
line.indexOf("\\")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// nodejs
|
||||
try {
|
||||
const path = require('path');
|
||||
const selfFileName = path.basename(__filename);
|
||||
const pluginDirectory = Object.entries(
|
||||
require('module')._pathCache
|
||||
).find(
|
||||
([key, _]) =>
|
||||
key.includes(selfFileName)
|
||||
)[0].split("\u0000")[1];
|
||||
const directories = pluginDirectory.split("\\");
|
||||
const pluginName = directories[directories.findIndex(value => value === "plugins") + 1].trim();
|
||||
if (pluginName) return pluginName;
|
||||
} catch { }
|
||||
try {
|
||||
throw new Error("getPluginName");
|
||||
} catch (error) {
|
||||
const /** @type {string} */ line = error.stack.trim().split("\n").pop().trim();
|
||||
if (line.includes(".js") && /:\d+:\d+$/.test(line)) {
|
||||
const directories = line.split("\\");
|
||||
const pluginName = directories[directories.findIndex(value => value === "plugins") + 1].trim();
|
||||
if (pluginName) return pluginName;
|
||||
}
|
||||
}
|
||||
return "Unknown";
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
||||
+2
-3
@@ -256,7 +256,7 @@ const GMLIB_API = {
|
||||
blockPlayerWillDestroy: ll.import("GMLIB_API", "blockPlayerWillDestroy"),
|
||||
/** 使玩家攻击实体 @type {function(Entity,Player):boolean} */
|
||||
playerAttack: ll.import("GMLIB_API", "playerAttack"),
|
||||
/** @type {function(Player,Entity):boolean} */
|
||||
/** @type {function(Player,Entity):void} */
|
||||
playerPullInEntity: ll.import("GMLIB_API", "playerPullInEntity"),
|
||||
/** 根据命令空间获取翻译键名 @type {function(string):string} */
|
||||
getBlockTranslateKeyFromName: ll.import("GMLIB_API", "getBlockTranslateKeyFromName"),
|
||||
@@ -2739,10 +2739,9 @@ LLSE_Player.prototype.pullInEntity =
|
||||
/**
|
||||
*
|
||||
* @param {Entity} entity 实体对象
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function (entity) {
|
||||
return GMLIB_API.playerPullInEntity(this, entity);
|
||||
GMLIB_API.playerPullInEntity(this, entity);
|
||||
};
|
||||
|
||||
LLSE_Item.prototype.applyEnchant =
|
||||
|
||||
+40
-3
@@ -1,13 +1,50 @@
|
||||
/// <reference path='d:/dts/dts/helperlib/src/index.d.ts'/>
|
||||
|
||||
const getPluginName = () => {
|
||||
// quickjs
|
||||
try {
|
||||
throw new Error("getPluginName");
|
||||
} catch (error) {
|
||||
return error.stack.trim().match(/plugins\\(.*)\\.*\.js:[0-9]+\)$/i)?.[1]
|
||||
|| error.stack.trim().match(/at <anonymous> \(([^\\|/]+)(.*?):\d+:\d+\)$/i)?.[1]
|
||||
|| "Unknown";
|
||||
const /** @type {string} */ line = error.stack.trim().split("\n").pop().trim();
|
||||
if (line.includes("<anonymous>")) {
|
||||
return line.slice(
|
||||
line.indexOf("(") + 1,
|
||||
line.indexOf("\\")
|
||||
);
|
||||
}
|
||||
if (line.includes("<eval>")) {
|
||||
return line.slice(
|
||||
line.indexOf("/", line.indexOf("/") + 1) + 1,
|
||||
line.indexOf("\\")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// nodejs
|
||||
try {
|
||||
const path = require('path');
|
||||
const selfFileName = path.basename(__filename);
|
||||
const pluginDirectory = Object.entries(
|
||||
require('module')._pathCache
|
||||
).find(
|
||||
([key, _]) =>
|
||||
key.includes(selfFileName)
|
||||
)[0].split("\u0000")[1];
|
||||
const directories = pluginDirectory.split("\\");
|
||||
const pluginName = directories[directories.findIndex(value => value === "plugins") + 1].trim();
|
||||
if (pluginName) return pluginName;
|
||||
} catch { }
|
||||
try {
|
||||
throw new Error("getPluginName");
|
||||
} catch (error) {
|
||||
const /** @type {string} */ line = error.stack.trim().split("\n").pop().trim();
|
||||
if (line.includes(".js") && /:\d+:\d+$/.test(line)) {
|
||||
const directories = line.split("\\");
|
||||
const pluginName = directories[directories.findIndex(value => value === "plugins") + 1].trim();
|
||||
if (pluginName) return pluginName;
|
||||
}
|
||||
}
|
||||
return "Unknown";
|
||||
};
|
||||
|
||||
Function.prototype.getName =
|
||||
|
||||
Reference in New Issue
Block a user