Compare commits
39 Commits
@@ -12,7 +12,7 @@ jobs:
|
|||||||
|
|
||||||
- uses: xmake-io/github-action-setup-xmake@v1
|
- uses: xmake-io/github-action-setup-xmake@v1
|
||||||
with:
|
with:
|
||||||
xmake-version: "2.9.3"
|
xmake-version: 2.9.9
|
||||||
|
|
||||||
- run: |
|
- run: |
|
||||||
xmake repo -u
|
xmake repo -u
|
||||||
@@ -23,14 +23,8 @@ jobs:
|
|||||||
- run: |
|
- run: |
|
||||||
xmake -w -y
|
xmake -w -y
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v3
|
- uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }}
|
name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }}
|
||||||
path: |
|
path: |
|
||||||
bin/DLL/
|
bin/
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: PDB
|
|
||||||
path: |
|
|
||||||
bin/PDB/
|
|
||||||
@@ -12,7 +12,7 @@ jobs:
|
|||||||
|
|
||||||
- uses: xmake-io/github-action-setup-xmake@v1
|
- uses: xmake-io/github-action-setup-xmake@v1
|
||||||
with:
|
with:
|
||||||
xmake-version: "2.9.3"
|
xmake-version: 2.9.9
|
||||||
|
|
||||||
- run: |
|
- run: |
|
||||||
xmake repo -u
|
xmake repo -u
|
||||||
@@ -23,17 +23,11 @@ jobs:
|
|||||||
- run: |
|
- run: |
|
||||||
xmake -w -y
|
xmake -w -y
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v3
|
- uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }}
|
name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }}
|
||||||
path: |
|
path: |
|
||||||
bin/DLL/
|
bin/
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: PDB
|
|
||||||
path: |
|
|
||||||
bin/PDB/
|
|
||||||
|
|
||||||
upload-to-release:
|
upload-to-release:
|
||||||
needs:
|
needs:
|
||||||
@@ -45,32 +39,23 @@ jobs:
|
|||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Download Plugin
|
- name: Download Mod
|
||||||
uses: actions/download-artifact@v3
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }}
|
name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }}
|
||||||
path: release/Plugin/
|
path: artifact
|
||||||
|
|
||||||
- name: Download PDB
|
|
||||||
uses: actions/download-artifact@v3
|
|
||||||
with:
|
|
||||||
name: PDB
|
|
||||||
path: release/PDB/
|
|
||||||
|
|
||||||
- name: Copy additional files
|
- name: Copy additional files
|
||||||
run: |
|
run: |
|
||||||
cp LICENSE README.md release/Plugin/
|
cp -v LICENSE README.md artifact/
|
||||||
|
|
||||||
- name: Archive release
|
- name: Archive release
|
||||||
run: |
|
run: |
|
||||||
cd release/Plugin
|
|
||||||
zip -r ../${{ github.event.repository.name }}-windows-x64.zip *
|
zip -r ../${{ github.event.repository.name }}-windows-x64.zip *
|
||||||
cd ..
|
working-directory: artifact
|
||||||
|
|
||||||
- name: Create GitHub Release
|
- name: Create GitHub Release
|
||||||
id: create_release
|
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
with:
|
with:
|
||||||
files: |
|
files: |
|
||||||
release/${{ github.event.repository.name }}-windows-x64.zip
|
${{ github.event.repository.name }}-windows-x64.zip
|
||||||
release/PDB/${{ github.event.repository.name }}.pdb
|
|
||||||
Vendored
+4
-4
@@ -1,4 +1,4 @@
|
|||||||
declare class PAPI {
|
export class PAPI {
|
||||||
/** 注册一个玩家PAPI变量 */
|
/** 注册一个玩家PAPI变量 */
|
||||||
static registerPlayerPlaceholder(
|
static registerPlayerPlaceholder(
|
||||||
/** PAPI调用函数 */
|
/** PAPI调用函数 */
|
||||||
@@ -12,7 +12,7 @@ declare class PAPI {
|
|||||||
pluginsName: string,
|
pluginsName: string,
|
||||||
/** PAPI变量 */
|
/** PAPI变量 */
|
||||||
PAPIName: string
|
PAPIName: string
|
||||||
): boolean;
|
): void;
|
||||||
|
|
||||||
/** 注册一个服务器PAPI变量 */
|
/** 注册一个服务器PAPI变量 */
|
||||||
static registerServerPlaceholder(
|
static registerServerPlaceholder(
|
||||||
@@ -25,7 +25,7 @@ declare class PAPI {
|
|||||||
pluginsName: string,
|
pluginsName: string,
|
||||||
/** PAPI变量 */
|
/** PAPI变量 */
|
||||||
PAPIName: string
|
PAPIName: string
|
||||||
): boolean;
|
): void;
|
||||||
|
|
||||||
/** 注册一个静态PAPI变量 */
|
/** 注册一个静态PAPI变量 */
|
||||||
static registerStaticPlaceholder(
|
static registerStaticPlaceholder(
|
||||||
@@ -37,7 +37,7 @@ declare class PAPI {
|
|||||||
PAPIName: string,
|
PAPIName: string,
|
||||||
/** 更新时间 */
|
/** 更新时间 */
|
||||||
UpdateInterval: number
|
UpdateInterval: number
|
||||||
): boolean;
|
): void;
|
||||||
|
|
||||||
/** 获取一个服务器变量的值 */
|
/** 获取一个服务器变量的值 */
|
||||||
static getValue(
|
static getValue(
|
||||||
|
|||||||
+12
-12
@@ -1,22 +1,22 @@
|
|||||||
const PlaceholderAPI = {
|
const PlaceholderAPI = {
|
||||||
/** 获取一个服务器变量的值 @type {function(string):string} */
|
/** 获取一个服务器变量的值 @type {function(string):string} */
|
||||||
getValueAPI: ll.import("BEPlaceholderAPI", "GetValue"),
|
getValueAPI: ll.imports("BEPlaceholderAPI", "GetValue"),
|
||||||
/** 获取一个玩家变量的值 @type {function(string,Player):string} */
|
/** 获取一个玩家变量的值 @type {function(string,Player):string} */
|
||||||
getValueByPlayerAPI: ll.import("BEPlaceholderAPI", "GetValueWithPlayer"),
|
getValueByPlayerAPI: ll.imports("BEPlaceholderAPI", "GetValueWithPlayer"),
|
||||||
/** 注册一个玩家变量 @type {function(string,string,string):boolean} */
|
/** 注册一个玩家变量 @type {function(string,string,string):boolean} */
|
||||||
registerPlayerPlaceholderAPI: ll.import("BEPlaceholderAPI", "registerPlayerPlaceholder"),
|
registerPlayerPlaceholderAPI: ll.imports("BEPlaceholderAPI", "registerPlayerPlaceholder"),
|
||||||
/** 注册一个服务器变量 @type {function(string,string,string):boolean} */
|
/** 注册一个服务器变量 @type {function(string,string,string):boolean} */
|
||||||
registerServerPlaceholderAPI: ll.import("BEPlaceholderAPI", "registerServerPlaceholder"),
|
registerServerPlaceholderAPI: ll.imports("BEPlaceholderAPI", "registerServerPlaceholder"),
|
||||||
/** 注册一个静态变量 @type {function(string,string,string,number):boolean} */
|
/** 注册一个静态变量 @type {function(string,string,string,number):boolean} */
|
||||||
registerStaticPlaceholderAPI: ll.import("BEPlaceholderAPI", "registerStaticPlaceholder"),
|
registerStaticPlaceholderAPI: ll.imports("BEPlaceholderAPI", "registerStaticPlaceholder"),
|
||||||
/** 翻译包含PAPI服务器变量的字符串 @type {function(string):string} */
|
/** 翻译包含PAPI服务器变量的字符串 @type {function(string):string} */
|
||||||
translateStringAPI: ll.import("BEPlaceholderAPI", "translateString"),
|
translateStringAPI: ll.imports("BEPlaceholderAPI", "translateString"),
|
||||||
/** 翻译包含PAPI玩家变量的字符串 @type {function(string,Player):string} */
|
/** 翻译包含PAPI玩家变量的字符串 @type {function(string,Player):string} */
|
||||||
translateStringWithPlayerAPI: ll.import("BEPlaceholderAPI", "translateStringWithPlayer"),
|
translateStringWithPlayerAPI: ll.imports("BEPlaceholderAPI", "translateStringWithPlayer"),
|
||||||
/** 注销PAPI变量 @type {function(string):boolean} */
|
/** 注销PAPI变量 @type {function(string):boolean} */
|
||||||
unRegisterPlaceholderAPI: ll.import("BEPlaceholderAPI", "unRegisterPlaceholder"),
|
unRegisterPlaceholderAPI: ll.imports("BEPlaceholderAPI", "unRegisterPlaceholder"),
|
||||||
/** 获取所有已注册的PAPI变量 @type {function():Array.<string>} */
|
/** 获取所有已注册的PAPI变量 @type {function():Array.<string>} */
|
||||||
getAllPAPI: ll.import("BEPlaceholderAPI", "getAllPAPI")
|
getAllPAPI: ll.imports("BEPlaceholderAPI", "getAllPAPI")
|
||||||
}
|
}
|
||||||
|
|
||||||
Function.prototype.getName =
|
Function.prototype.getName =
|
||||||
@@ -59,7 +59,7 @@ class PAPI {
|
|||||||
*/
|
*/
|
||||||
static registerPlayerPlaceholder(func, PluginName, PAPIName) {
|
static registerPlayerPlaceholder(func, PluginName, PAPIName) {
|
||||||
ll.export(func, PluginName, func.getName());
|
ll.export(func, PluginName, func.getName());
|
||||||
return PlaceholderAPI.registerPlayerPlaceholderAPI(PluginName, func.getName(), PAPIName);
|
PlaceholderAPI.registerPlayerPlaceholderAPI(PluginName, func.getName(), PAPIName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,7 +71,7 @@ class PAPI {
|
|||||||
*/
|
*/
|
||||||
static registerServerPlaceholder(func, PluginName, PAPIName) {
|
static registerServerPlaceholder(func, PluginName, PAPIName) {
|
||||||
ll.export(func, PluginName, func.getName());
|
ll.export(func, PluginName, func.getName());
|
||||||
return PlaceholderAPI.registerServerPlaceholderAPI(PluginName, func.getName(), PAPIName);
|
PlaceholderAPI.registerServerPlaceholderAPI(PluginName, func.getName(), PAPIName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,7 +84,7 @@ class PAPI {
|
|||||||
*/
|
*/
|
||||||
static registerStaticPlaceholder(func, PluginName, PAPIName, UpdateInterval = 50) {
|
static registerStaticPlaceholder(func, PluginName, PAPIName, UpdateInterval = 50) {
|
||||||
ll.export(func, PluginName, func.getName());
|
ll.export(func, PluginName, func.getName());
|
||||||
return PlaceholderAPI.registerStaticPlaceholderAPI(PluginName, func.getName(), PAPIName, UpdateInterval);
|
PlaceholderAPI.registerStaticPlaceholderAPI(PluginName, func.getName(), PAPIName, UpdateInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Vendored
+852
-209
File diff suppressed because it is too large
Load Diff
+202
-21
@@ -1,28 +1,209 @@
|
|||||||
/** 事件创建函数 @type {function(string,string):boolean} */
|
/**
|
||||||
const CallEvent = ll.import("GMLIB_Event_API", "callCustomEvent");
|
* @returns {string}
|
||||||
/** 获取事件ID函数 @type {function():string} */
|
*/
|
||||||
const getNextEventId = ll.import("GMLIB_Event_API", "getNextScriptEventId");
|
const getPluginName = () => {
|
||||||
|
// quickjs
|
||||||
|
try {
|
||||||
|
throw new Error("getPluginName");
|
||||||
|
} catch (error) {
|
||||||
|
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
|
||||||
class Event {
|
try {
|
||||||
constructor() { throw new Error("Static class cannot be instantiated"); }
|
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 = {
|
||||||
|
Event: {
|
||||||
|
/**
|
||||||
|
* 事件订阅记录
|
||||||
|
* 例如: {事件名: [事件ID, ...], ...}
|
||||||
|
* @type {Object.<string, number[]>}
|
||||||
|
*/
|
||||||
|
mEventData: {},
|
||||||
|
/**
|
||||||
|
* 事件异常处理回调
|
||||||
|
* @param {Error} error
|
||||||
|
* @param {string} eventName
|
||||||
|
* @param {number} eventID
|
||||||
|
* @param {string} pluginName
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
mErrorHanlerCallback: (error, eventName, eventID, pluginName) => {
|
||||||
|
logger.error(`Info: ${pluginName}-${eventName}-${eventID} Exception: ${error.message}\n${error.stack}`);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 监听事件
|
* 监听事件(兼容旧版)
|
||||||
* @param {string} event 事件名称
|
* @param {string} eventName
|
||||||
* @param {function} callback 回调
|
* @param {function} callback
|
||||||
* @returns {boolean} 是否创建成功
|
* @param {boolean}
|
||||||
*/
|
*/
|
||||||
static listen(event, callback) {
|
listen: function (eventName, callback) {
|
||||||
let eventId = getNextEventId();
|
try {
|
||||||
ll.export(callback, event, eventId);
|
if (typeof callback !== "function") return false;
|
||||||
let result = CallEvent(event, eventId);
|
const eventReflection = {
|
||||||
if (!result) {
|
onServerStopping: "ll::ServerStoppingEvent",
|
||||||
logger.error(`Cannot listen event "${event}" !`);
|
onClientLogin: "gmlib::ClientLoginAfterEvent",
|
||||||
logger.error(`GMLIB Script Event "${event}" does not exist !`);
|
onWeatherChange: "gmlib::WeatherUpdateBeforeEvent",
|
||||||
|
onMobPick: "gmlib::MobPickupItemBeforeEvent",
|
||||||
|
onItemTrySpawn: "gmlib::ItemActorSpawnBeforeEvent",
|
||||||
|
onItemSpawned: "gmlib::ItemActorSpawnAfterEvent",
|
||||||
|
onEntityTryChangeDim: "gmlib::ActorChangeDimensionBeforeEvent",
|
||||||
|
onLeaveBed: "gmlib::PlayerStopSleepBeforeEvent",
|
||||||
|
onDeathMessage: "gmlib::DeathMessageAfterEvent",
|
||||||
|
onMobHurted: "gmlib::MobHurtAfterEvent",
|
||||||
|
onEndermanTake: "gmlib::EndermanTakeBlockBeforeEvent",
|
||||||
|
onEntityChangeDim: "gmlib::ActorChangeDimensionAfterEvent",
|
||||||
|
onDragonRespawn: "gmlib::DragonRespawnBeforeEvent",
|
||||||
|
onProjectileTryCreate: "gmlib::ProjectileCreateBeforeEvent",
|
||||||
|
onProjectileCreate: "gmlib::ProjectileCreateAfterEvent",
|
||||||
|
onSpawnWanderingTrader: "gmlib::SpawnWanderingTraderBeforeEvent",
|
||||||
|
onHandleRequestAction: "gmlib::HandleRequestActionBeforeEvent",
|
||||||
|
onSendContainerClosePacket: "gmlib::ContainerClosePacketSendAfterEvent"
|
||||||
|
};
|
||||||
|
this.emplaceListener(eventReflection[eventName] ?? eventName, event => {
|
||||||
|
const result = callback(...event.params);
|
||||||
|
if (typeof (result) === "boolean" && !result) event.cancel();
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
} catch { }
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订阅事件
|
||||||
|
* @param {string} eventName
|
||||||
|
* @param {function} callback
|
||||||
|
* @param {number?} priority
|
||||||
|
* @param {string?} pluginName
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
emplaceListener: function (eventName, callback, priority = this.EventPriority.Normal, pluginName = getPluginName()) {
|
||||||
|
if (typeof callback !== "function") throw new Error("callback must be a function!");
|
||||||
|
const /** @type {number} */ eventId = ll.importss("GMLIB_Event_API", "emplaceListener")(pluginName, eventName, priority);
|
||||||
|
if (eventId === -1) throw new Error(`Event ${eventName} creation failed!`);
|
||||||
|
ll.exports((...data) => {
|
||||||
|
let /** @type {boolean} */ result = typeof (data.slice(-1)[0]) === "boolean" ? data.pop() : false;
|
||||||
|
try {
|
||||||
|
callback({
|
||||||
|
params: data,
|
||||||
|
cancel: () => result = true,
|
||||||
|
setCancelled: (/** @type {boolean} */value) => { result = value; },
|
||||||
|
isCancelled: () => result,
|
||||||
|
getId: () => eventId,
|
||||||
|
getEventType: () => eventName
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
try {
|
||||||
|
this.mErrorHanlerCallback(error, eventName, eventId, pluginName);
|
||||||
|
} catch { }
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}, pluginName, eventName + "_" + eventId);
|
||||||
}
|
(this.mEventData[eventName] ??= []).push(eventId);
|
||||||
|
return eventId;
|
||||||
|
},
|
||||||
|
|
||||||
module.exports = { Event };
|
/**
|
||||||
|
* 取消事件订阅
|
||||||
|
* @param {number} eventId
|
||||||
|
* @param {boolean}
|
||||||
|
*/
|
||||||
|
removeListener: function (eventId) {
|
||||||
|
const result = ll.importss("GMLIB_Event_API", "removeListener")(eventId);
|
||||||
|
if (result) {
|
||||||
|
for (let [eventName, eventIds] of Object.entries(this.mEventData)) {
|
||||||
|
this.mEventData[eventName] = eventIds.filter(id => id !== eventId);
|
||||||
|
if (this.mEventData[eventName].length === 0) delete this.mEventData[eventName];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断事件订阅是否存在
|
||||||
|
* @param {number} eventId
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
hasListener: function (eventId) {
|
||||||
|
return ll.importss("GMLIB_Event_API", "hasListener")(eventId);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取订阅事件优先级
|
||||||
|
* @param {number} eventId
|
||||||
|
* @returns {number?}
|
||||||
|
*/
|
||||||
|
getListenerPriority: function (eventId) {
|
||||||
|
const priority = ll.importss("GMLIB_Event_API", "getListenerPriority")(eventId);
|
||||||
|
return priority === -1 ? undefined : priority;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取订阅事件列表
|
||||||
|
* @param {string | undefined} eventName
|
||||||
|
* @returns {number[] | Object.<string, number[]>}
|
||||||
|
*/
|
||||||
|
getListener: function (eventName) {
|
||||||
|
return eventName === undefined ? this.mEventData : this.mEventData[eventName] ?? [];
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置异常处理回调
|
||||||
|
* @param {function(Error, string, number, string): void} callback
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
setErrorHanlerCallback: function (callback) {
|
||||||
|
if (callback === undefined || typeof callback !== "function") return false;
|
||||||
|
this.mErrorHanlerCallback = callback;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 事件优先级
|
||||||
|
*/
|
||||||
|
EventPriority: {
|
||||||
|
Highest: 0,
|
||||||
|
High: 100,
|
||||||
|
Normal: 200,
|
||||||
|
Low: 300,
|
||||||
|
Lowest: 400
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
+156
-156
@@ -1,182 +1,182 @@
|
|||||||
// const getNextCallbackId = ll.import("GMLIB_FormAPI", "getNextFormCallbackId");
|
// // const getNextCallbackId = ll.imports("GMLIB_FormAPI", "getNextFormCallbackId");
|
||||||
|
|
||||||
class ServerSettingForm {
|
// class ServerSettingForm {
|
||||||
constructor() {
|
// constructor() {
|
||||||
throw new Error("Static class cannot be instantiated");
|
// throw new Error("Static class cannot be instantiated");
|
||||||
}
|
// }
|
||||||
|
|
||||||
static getDefaultPriority() {
|
// static getDefaultPriority() {
|
||||||
return ll.import("GMLIB_ServerSettingForm", "getDefaultPriority")();
|
// return ll.imports("GMLIB_ServerSettingForm", "getDefaultPriority")();
|
||||||
}
|
// }
|
||||||
|
|
||||||
static hasTitle() {
|
// static hasTitle() {
|
||||||
return ll.import("GMLIB_ServerSettingForm", "hasTitle")();
|
// return ll.imports("GMLIB_ServerSettingForm", "hasTitle")();
|
||||||
}
|
// }
|
||||||
|
|
||||||
static getTitle() {
|
// static getTitle() {
|
||||||
return ll.import("GMLIB_ServerSettingForm", "getTitle")();
|
// return ll.imports("GMLIB_ServerSettingForm", "getTitle")();
|
||||||
}
|
// }
|
||||||
|
|
||||||
static setTitle(title, forceModify = false) {
|
// static setTitle(title, forceModify = false) {
|
||||||
return ll.import("GMLIB_ServerSettingForm", "setTitle")(title, forceModify);
|
// return ll.imports("GMLIB_ServerSettingForm", "setTitle")(title, forceModify);
|
||||||
}
|
// }
|
||||||
|
|
||||||
static hasIcon() {
|
// static hasIcon() {
|
||||||
return ll.import("GMLIB_ServerSettingForm", "hasIcon")();
|
// return ll.imports("GMLIB_ServerSettingForm", "hasIcon")();
|
||||||
}
|
// }
|
||||||
|
|
||||||
static getIconData() {
|
// static getIconData() {
|
||||||
return hasIcon() ? ll.import("GMLIB_ServerSettingForm", "getIconData")() : null;
|
// return hasIcon() ? ll.imports("GMLIB_ServerSettingForm", "getIconData")() : null;
|
||||||
}
|
// }
|
||||||
|
|
||||||
static getIconType() {
|
// static getIconType() {
|
||||||
return ll.import("GMLIB_ServerSettingForm", "getIconType")();
|
// return ll.imports("GMLIB_ServerSettingForm", "getIconType")();
|
||||||
}
|
// }
|
||||||
|
|
||||||
static setIcon(data, type = 0, forceModify = false) {
|
// static setIcon(data, type = 0, forceModify = false) {
|
||||||
return ll.import("GMLIB_ServerSettingForm", "setIcon")(data, type, forceModify);
|
// return ll.imports("GMLIB_ServerSettingForm", "setIcon")(data, type, forceModify);
|
||||||
}
|
// }
|
||||||
|
|
||||||
static addLabel(
|
// static addLabel(
|
||||||
text,
|
// text,
|
||||||
playerDetector = (pl) => { return true; },
|
// playerDetector = (pl) => { return true; },
|
||||||
priority = this.getDefaultPriority()
|
// priority = this.getDefaultPriority()
|
||||||
) {
|
// ) {
|
||||||
let detectorId = getNextCallbackId();
|
// let detectorId = getNextCallbackId();
|
||||||
ll.export(playerDetector, "GMLIB_FORM_CALLBACK", detectorId);
|
// ll.export(playerDetector, "GMLIB_FORM_CALLBACK", detectorId);
|
||||||
return ll.import("GMLIB_ServerSettingForm", "addLabel")(text, detectorId, priority);
|
// return ll.imports("GMLIB_ServerSettingForm", "addLabel")(text, detectorId, priority);
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
static addInput(
|
// static addInput(
|
||||||
text,
|
// text,
|
||||||
placeholder,
|
// placeholder,
|
||||||
defaultVal,
|
// defaultVal,
|
||||||
callback = (pl, input) => { },
|
// callback = (pl, input) => { },
|
||||||
playerDetector = (pl) => { return true; },
|
// playerDetector = (pl) => { return true; },
|
||||||
priority = this.getDefaultPriority()
|
// priority = this.getDefaultPriority()
|
||||||
) {
|
// ) {
|
||||||
let callbackId = getNextCallbackId();
|
// let callbackId = getNextCallbackId();
|
||||||
ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
// ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
||||||
let detectorId = getNextCallbackId();
|
// let detectorId = getNextCallbackId();
|
||||||
ll.export(playerDetector, "GMLIB_FORM_CALLBACK", detectorId);
|
// ll.export(playerDetector, "GMLIB_FORM_CALLBACK", detectorId);
|
||||||
return ll.import("GMLIB_ServerSettingForm", "addInput")(text, placeholder, defaultVal, callbackId, detectorId, priority);
|
// return ll.imports("GMLIB_ServerSettingForm", "addInput")(text, placeholder, defaultVal, callbackId, detectorId, priority);
|
||||||
}
|
// }
|
||||||
|
|
||||||
static addToggle(
|
// static addToggle(
|
||||||
text,
|
// text,
|
||||||
defaultVal = false,
|
// defaultVal = false,
|
||||||
callback = (pl, input) => { },
|
// callback = (pl, input) => { },
|
||||||
playerDetector = (pl) => { return true; },
|
// playerDetector = (pl) => { return true; },
|
||||||
priority = this.getDefaultPriority()
|
// priority = this.getDefaultPriority()
|
||||||
) {
|
// ) {
|
||||||
let callbackId = getNextCallbackId();
|
// let callbackId = getNextCallbackId();
|
||||||
ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
// ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
||||||
let detectorId = getNextCallbackId();
|
// let detectorId = getNextCallbackId();
|
||||||
ll.export(playerDetector, "GMLIB_FORM_CALLBACK", detectorId);
|
// ll.export(playerDetector, "GMLIB_FORM_CALLBACK", detectorId);
|
||||||
return ll.import("GMLIB_ServerSettingForm", "addToggle")(text, defaultVal, callbackId, detectorId, priority);
|
// return ll.imports("GMLIB_ServerSettingForm", "addToggle")(text, defaultVal, callbackId, detectorId, priority);
|
||||||
}
|
// }
|
||||||
|
|
||||||
static addDropdown(
|
// static addDropdown(
|
||||||
text,
|
// text,
|
||||||
options,
|
// options,
|
||||||
defaultVal = 0,
|
// defaultVal = 0,
|
||||||
callback = (pl, input) => { },
|
// callback = (pl, input) => { },
|
||||||
playerDetector = (pl) => { return true; },
|
// playerDetector = (pl) => { return true; },
|
||||||
priority = this.getDefaultPriority()
|
// priority = this.getDefaultPriority()
|
||||||
) {
|
// ) {
|
||||||
let callbackId = getNextCallbackId();
|
// let callbackId = getNextCallbackId();
|
||||||
ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
// ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
||||||
let detectorId = getNextCallbackId();
|
// let detectorId = getNextCallbackId();
|
||||||
ll.export(playerDetector, "GMLIB_FORM_CALLBACK", detectorId);
|
// ll.export(playerDetector, "GMLIB_FORM_CALLBACK", detectorId);
|
||||||
return ll.import("GMLIB_ServerSettingForm", "addDropdown")(text, options, defaultVal, callbackId, detectorId, priority);
|
// return ll.imports("GMLIB_ServerSettingForm", "addDropdown")(text, options, defaultVal, callbackId, detectorId, priority);
|
||||||
}
|
// }
|
||||||
|
|
||||||
static addSlider(
|
// static addSlider(
|
||||||
text,
|
// text,
|
||||||
min,
|
// min,
|
||||||
max,
|
// max,
|
||||||
step = 0.0,
|
// step = 0.0,
|
||||||
defaultVal = 0.0,
|
// defaultVal = 0.0,
|
||||||
callback = (pl, input) => { },
|
// callback = (pl, input) => { },
|
||||||
playerDetector = (pl) => { return true; },
|
// playerDetector = (pl) => { return true; },
|
||||||
priority = this.getDefaultPriority()
|
// priority = this.getDefaultPriority()
|
||||||
) {
|
// ) {
|
||||||
let callbackId = getNextCallbackId();
|
// let callbackId = getNextCallbackId();
|
||||||
ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
// ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
||||||
let detectorId = getNextCallbackId();
|
// let detectorId = getNextCallbackId();
|
||||||
ll.export(playerDetector, "GMLIB_FORM_CALLBACK", detectorId);
|
// ll.export(playerDetector, "GMLIB_FORM_CALLBACK", detectorId);
|
||||||
return ll.import("GMLIB_ServerSettingForm", "addSlider")(text, min, max, step, defaultVal, callbackId, detectorId, priority);
|
// return ll.imports("GMLIB_ServerSettingForm", "addSlider")(text, min, max, step, defaultVal, callbackId, detectorId, priority);
|
||||||
}
|
// }
|
||||||
|
|
||||||
static addStepSlider(
|
// static addStepSlider(
|
||||||
text,
|
// text,
|
||||||
steps,
|
// steps,
|
||||||
defaultVal = 0,
|
// defaultVal = 0,
|
||||||
callback = (pl, input) => { },
|
// callback = (pl, input) => { },
|
||||||
playerDetector = (pl) => { return true; },
|
// playerDetector = (pl) => { return true; },
|
||||||
priority = this.getDefaultPriority()
|
// priority = this.getDefaultPriority()
|
||||||
) {
|
// ) {
|
||||||
let callbackId = getNextCallbackId();
|
// let callbackId = getNextCallbackId();
|
||||||
ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
// ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
||||||
let detectorId = getNextCallbackId();
|
// let detectorId = getNextCallbackId();
|
||||||
ll.export(playerDetector, "GMLIB_FORM_CALLBACK", detectorId);
|
// ll.export(playerDetector, "GMLIB_FORM_CALLBACK", detectorId);
|
||||||
return ll.import("GMLIB_ServerSettingForm", "addStepSlider")(text, steps, defaultVal, callbackId, detectorId, priority);
|
// return ll.imports("GMLIB_ServerSettingForm", "addStepSlider")(text, steps, defaultVal, callbackId, detectorId, priority);
|
||||||
}
|
// }
|
||||||
|
|
||||||
static removeElement(id) {
|
// static removeElement(id) {
|
||||||
return ll.import("GMLIB_ServerSettingForm", "removeElement")(id);
|
// return ll.imports("GMLIB_ServerSettingForm", "removeElement")(id);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
class NpcDialogueForm {
|
// class NpcDialogueForm {
|
||||||
constructor(npcName, sceneName, dialogue) {
|
// constructor(npcName, sceneName, dialogue) {
|
||||||
this.mFormId = ll.import("GMLIB_NpcDialogueForm", "createForm")(npcName, sceneName, dialogue);
|
// this.mFormId = ll.imports("GMLIB_NpcDialogueForm", "createForm")(npcName, sceneName, dialogue);
|
||||||
}
|
// }
|
||||||
|
|
||||||
addButton(button) {
|
// addButton(button) {
|
||||||
return ll.import("GMLIB_NpcDialogueForm", "addButton")(this.mFormId, button);
|
// return ll.imports("GMLIB_NpcDialogueForm", "addButton")(this.mFormId, button);
|
||||||
}
|
// }
|
||||||
|
|
||||||
sendTo(pl, callback = (pl, index, type) => { }, free = true) {
|
// sendTo(pl, callback = (pl, index, type) => { }, free = true) {
|
||||||
let callbackId = getNextCallbackId();
|
// let callbackId = getNextCallbackId();
|
||||||
ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
// ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
||||||
ll.import("GMLIB_NpcDialogueForm", "sendTo")(this.mFormId, pl, callbackId);
|
// ll.imports("GMLIB_NpcDialogueForm", "sendTo")(this.mFormId, pl, callbackId);
|
||||||
if (free) {
|
// if (free) {
|
||||||
this.destroy();
|
// this.destroy();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
destroy() {
|
// destroy() {
|
||||||
ll.import("GMLIB_NpcDialogueForm", "destroyForm")(this.mFormId);
|
// ll.imports("GMLIB_NpcDialogueForm", "destroyForm")(this.mFormId);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
class ChestForm {
|
// class ChestForm {
|
||||||
constructor(npcName, sceneName, dialogue) {
|
// constructor(npcName, sceneName, dialogue) {
|
||||||
this.mFormId = ll.import("GMLIB_NpcDialogueForm", "createForm")(npcName, sceneName, dialogue);
|
// this.mFormId = ll.imports("GMLIB_NpcDialogueForm", "createForm")(npcName, sceneName, dialogue);
|
||||||
}
|
// }
|
||||||
|
|
||||||
addButton(button) {
|
// addButton(button) {
|
||||||
return ll.import("GMLIB_NpcDialogueForm", "addButton")(this.mFormId, button);
|
// return ll.imports("GMLIB_NpcDialogueForm", "addButton")(this.mFormId, button);
|
||||||
}
|
// }
|
||||||
|
|
||||||
sendTo(pl, free = true) {
|
// sendTo(pl, free = true) {
|
||||||
//let callbackId = getNextCallbackId();
|
// //let callbackId = getNextCallbackId();
|
||||||
//ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
// //ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
||||||
//ll.import("GMLIB_NpcDialogueForm", "sendTo")(this.mFormId, pl, callbackId);
|
// //ll.imports("GMLIB_NpcDialogueForm", "sendTo")(this.mFormId, pl, callbackId);
|
||||||
//if (free) {
|
// //if (free) {
|
||||||
// this.destroy();
|
// // this.destroy();
|
||||||
//}
|
// //}
|
||||||
}
|
// }
|
||||||
|
|
||||||
destroy() {
|
// destroy() {
|
||||||
//ll.import("GMLIB_NpcDialogueForm", "destroyForm")(this.mFormId);
|
// //ll.imports("GMLIB_NpcDialogueForm", "destroyForm")(this.mFormId);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
module.exports = {
|
// module.exports = {
|
||||||
ServerSettingForm,
|
// ServerSettingForm,
|
||||||
NpcDialogueForm,
|
// NpcDialogueForm,
|
||||||
ChestForm
|
// ChestForm
|
||||||
};
|
// };
|
||||||
Vendored
+202
-21
@@ -1,5 +1,5 @@
|
|||||||
/** 静态悬浮字类 */
|
/** 静态悬浮字类 */
|
||||||
declare class StaticFloatingText {
|
export class StaticFloatingText {
|
||||||
constructor(
|
constructor(
|
||||||
/** 生成的坐标 */
|
/** 生成的坐标 */
|
||||||
pos: FloatPos,
|
pos: FloatPos,
|
||||||
@@ -73,7 +73,7 @@ declare class StaticFloatingText {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 动态悬浮字类 */
|
/** 动态悬浮字类 */
|
||||||
declare class DynamicFloatingText extends StaticFloatingText {
|
export class DynamicFloatingText extends StaticFloatingText {
|
||||||
constructor(
|
constructor(
|
||||||
/** 生成的坐标 */
|
/** 生成的坐标 */
|
||||||
pos: FloatPos,
|
pos: FloatPos,
|
||||||
@@ -113,7 +113,7 @@ declare class DynamicFloatingText extends StaticFloatingText {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 基础游戏API类 */
|
/** 基础游戏API类 */
|
||||||
declare class Minecraft {
|
export class Minecraft {
|
||||||
private constructor();
|
private constructor();
|
||||||
|
|
||||||
/** 获取服务器平均tps */
|
/** 获取服务器平均tps */
|
||||||
@@ -393,7 +393,7 @@ declare class Minecraft {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 合成表类 */
|
/** 合成表类 */
|
||||||
declare class Recipes {
|
export class Recipes {
|
||||||
private constructor();
|
private constructor();
|
||||||
|
|
||||||
/** 注销合成表 */
|
/** 注销合成表 */
|
||||||
@@ -534,7 +534,7 @@ declare class Recipes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 实验性功能类 */
|
/** 实验性功能类 */
|
||||||
declare class Experiments {
|
export class Experiments {
|
||||||
private constructor();
|
private constructor();
|
||||||
|
|
||||||
/** 获取所有实验的id */
|
/** 获取所有实验的id */
|
||||||
@@ -568,7 +568,7 @@ declare class Experiments {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 计分板类 */
|
/** 计分板类 */
|
||||||
declare class Scoreboard {
|
export class Scoreboard {
|
||||||
private constructor();
|
private constructor();
|
||||||
|
|
||||||
/** 获取所有跟踪实体 */
|
/** 获取所有跟踪实体 */
|
||||||
@@ -788,7 +788,7 @@ declare class Scoreboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 仿LSE的JsonConfigFile类 */
|
/** 仿LSE的JsonConfigFile类 */
|
||||||
declare class JsonConfig {
|
export class JsonConfig {
|
||||||
constructor(
|
constructor(
|
||||||
/** 文件路径 */
|
/** 文件路径 */
|
||||||
path: string,
|
path: string,
|
||||||
@@ -832,7 +832,7 @@ declare class JsonConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** JSON语言文件 */
|
/** JSON语言文件 */
|
||||||
declare class JsonLanguage extends JsonConfig {
|
export class JsonLanguage extends JsonConfig {
|
||||||
/** 创建或打开一个 Json 语言文件 */
|
/** 创建或打开一个 Json 语言文件 */
|
||||||
constructor(
|
constructor(
|
||||||
/** 文件路径 */
|
/** 文件路径 */
|
||||||
@@ -851,7 +851,7 @@ declare class JsonLanguage extends JsonConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** JSON版翻译类 */
|
/** JSON版翻译类 */
|
||||||
declare class JsonI18n {
|
export class JsonI18n {
|
||||||
/** 加载翻译数据目录 */
|
/** 加载翻译数据目录 */
|
||||||
constructor(
|
constructor(
|
||||||
/** 目录 */
|
/** 目录 */
|
||||||
@@ -895,7 +895,7 @@ declare class JsonI18n {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 版本类 */
|
/** 版本类 */
|
||||||
declare class Version {
|
export class Version {
|
||||||
/** 创建版本对象 */
|
/** 创建版本对象 */
|
||||||
constructor(
|
constructor(
|
||||||
/** 主版本号 */
|
/** 主版本号 */
|
||||||
@@ -944,7 +944,7 @@ declare class Version {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 翻译API类 */
|
/** 翻译API类 */
|
||||||
declare class I18nAPI {
|
export class I18nAPI {
|
||||||
private constructor();
|
private constructor();
|
||||||
|
|
||||||
/** 获取键翻译 */
|
/** 获取键翻译 */
|
||||||
@@ -1005,7 +1005,7 @@ declare class I18nAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 玩家信息存储类 */
|
/** 玩家信息存储类 */
|
||||||
declare class UserCache {
|
export class UserCache {
|
||||||
private constructor();
|
private constructor();
|
||||||
|
|
||||||
/** 根据uuid查xuid */
|
/** 根据uuid查xuid */
|
||||||
@@ -1122,21 +1122,31 @@ type PacketData = (
|
|||||||
);
|
);
|
||||||
|
|
||||||
/** 二进制流数据包类 */
|
/** 二进制流数据包类 */
|
||||||
declare class GMLIB_BinaryStream {
|
export class GMLIB_BinaryStream {
|
||||||
/** 数据包ID */
|
/** 数据包ID */
|
||||||
#id: number;
|
#id: number;
|
||||||
/** 数据包是否被销毁 */
|
/** 数据包是否被销毁 */
|
||||||
#destroy: boolean;
|
#destroy: boolean;
|
||||||
|
|
||||||
|
/** 构造二进流数据包 */
|
||||||
constructor(
|
constructor(
|
||||||
/** 数据包数据 */
|
/** 数据包数据 */
|
||||||
data: PacketData[]?
|
data: PacketData[]?
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/** 拷贝二进制流数据包 */
|
||||||
|
constructor(
|
||||||
|
/** 要拷贝的二进制流数据包 */
|
||||||
|
stream: GMLIB_BinaryStream
|
||||||
|
);
|
||||||
|
|
||||||
|
/** 获取数据包的ID */
|
||||||
|
getId(): number;
|
||||||
|
|
||||||
/** 发送数据包 */
|
/** 发送数据包 */
|
||||||
sendTo(
|
sendTo(
|
||||||
/** 要发送数据包的玩家对象 */
|
/** 要发送数据包的玩家对象 */
|
||||||
player: Player,
|
player: Player | Entity,
|
||||||
/** 数据包发送后是否销毁 */
|
/** 数据包发送后是否销毁 */
|
||||||
free: boolean = true
|
free: boolean = true
|
||||||
): GMLIB_BinaryStream;
|
): GMLIB_BinaryStream;
|
||||||
@@ -1144,7 +1154,7 @@ declare class GMLIB_BinaryStream {
|
|||||||
/** 发送数据包到玩家数组 */
|
/** 发送数据包到玩家数组 */
|
||||||
sendToPlayers(
|
sendToPlayers(
|
||||||
/** 要发送数据包的玩家对象数组 */
|
/** 要发送数据包的玩家对象数组 */
|
||||||
players: Player[],
|
players: Player[] | Entity[],
|
||||||
/** 数据包发送后是否销毁 */
|
/** 数据包发送后是否销毁 */
|
||||||
free: boolean = true
|
free: boolean = true
|
||||||
): GMLIB_BinaryStream;
|
): GMLIB_BinaryStream;
|
||||||
@@ -1337,6 +1347,165 @@ declare class GMLIB_BinaryStream {
|
|||||||
): GMLIB_BinaryStream;
|
): GMLIB_BinaryStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum ActorType {
|
||||||
|
Undefined = 1,
|
||||||
|
TypeMask = 0b11111111,
|
||||||
|
None = 0,
|
||||||
|
Mob = 1 << 8,
|
||||||
|
PathfinderMob = 1 << 9 | Mob,
|
||||||
|
UnknownType = 1 << 10,
|
||||||
|
Monster = 1 << 11 | PathfinderMob,
|
||||||
|
Animal = 1 << 12 | PathfinderMob,
|
||||||
|
WaterAnimal = 1 << 13 | PathfinderMob,
|
||||||
|
TamableAnimal = 1 << 14 | Animal,
|
||||||
|
Ambient = 1 << 15 | Mob,
|
||||||
|
UndeadMob = 1 << 16 | Monster,
|
||||||
|
ZombieMonster = 1 << 17 | UndeadMob,
|
||||||
|
Arthropod = 1 << 18 | Monster,
|
||||||
|
Minecart = 1 << 19,
|
||||||
|
SkeletonMonster = 1 << 20 | UndeadMob,
|
||||||
|
EquineAnimal = 1 << 21 | TamableAnimal,
|
||||||
|
Projectile = 1 << 22,
|
||||||
|
AbstractArrow = 1 << 23,
|
||||||
|
VillagerBase = 1 << 24 | PathfinderMob,
|
||||||
|
|
||||||
|
Chicken = 10 | Animal,
|
||||||
|
Cow = 11 | Animal,
|
||||||
|
Pig = 12 | Animal,
|
||||||
|
Sheep = 13 | Animal,
|
||||||
|
Wolf = 14 | TamableAnimal,
|
||||||
|
Villager = 15 | VillagerBase,
|
||||||
|
MushroomCow = 16 | Animal,
|
||||||
|
Squid = 17 | WaterAnimal,
|
||||||
|
Rabbit = 18 | Animal,
|
||||||
|
Bat = 19 | Ambient,
|
||||||
|
IronGolem = 20 | PathfinderMob,
|
||||||
|
SnowGolem = 21 | PathfinderMob,
|
||||||
|
Ocelot = 22 | TamableAnimal,
|
||||||
|
Horse = 23 | EquineAnimal,
|
||||||
|
Donkey = 24 | EquineAnimal,
|
||||||
|
Mule = 25 | EquineAnimal,
|
||||||
|
SkeletonHorse = 26 | EquineAnimal | UndeadMob,
|
||||||
|
ZombieHorse = 27 | EquineAnimal | UndeadMob,
|
||||||
|
PolarBear = 28 | Animal,
|
||||||
|
Llama = 29 | Animal,
|
||||||
|
Parrot = 30 | TamableAnimal,
|
||||||
|
Dolphin = 31 | WaterAnimal,
|
||||||
|
Zombie = 32 | ZombieMonster,
|
||||||
|
Creeper = 33 | Monster,
|
||||||
|
Skeleton = 34 | SkeletonMonster,
|
||||||
|
Spider = 35 | Arthropod,
|
||||||
|
PigZombie = 36 | UndeadMob,
|
||||||
|
Slime = 37 | Monster,
|
||||||
|
EnderMan = 38 | Monster,
|
||||||
|
Silverfish = 39 | Arthropod,
|
||||||
|
CaveSpider = 40 | Arthropod,
|
||||||
|
Ghast = 41 | Monster,
|
||||||
|
LavaSlime = 42 | Monster,
|
||||||
|
Blaze = 43 | Monster,
|
||||||
|
ZombieVillager = 44 | ZombieMonster,
|
||||||
|
Witch = 45 | Monster,
|
||||||
|
Stray = 46 | SkeletonMonster,
|
||||||
|
Husk = 47 | ZombieMonster,
|
||||||
|
WitherSkeleton = 48 | SkeletonMonster,
|
||||||
|
Guardian = 49 | Monster,
|
||||||
|
ElderGuardian = 50 | Monster,
|
||||||
|
Npc = 51 | Mob,
|
||||||
|
WitherBoss = 52 | UndeadMob,
|
||||||
|
Dragon = 53 | Monster,
|
||||||
|
Shulker = 54 | Monster,
|
||||||
|
Endermite = 55 | Arthropod,
|
||||||
|
Agent = 56 | Mob,
|
||||||
|
Vindicator = 57 | Monster,
|
||||||
|
Phantom = 58 | UndeadMob,
|
||||||
|
IllagerBeast = 59 | Monster,
|
||||||
|
UNUSED60 = 60,
|
||||||
|
ArmorStand = 61 | Mob,
|
||||||
|
TripodCamera = 62 | Mob,
|
||||||
|
Player = 63 | Mob,
|
||||||
|
ItemEntity = 64 | None,
|
||||||
|
PrimedTnt = 65 | None,
|
||||||
|
FallingBlock = 66 | None,
|
||||||
|
MovingBlock = 67 | None,
|
||||||
|
ExperiencePotion = 68 | Projectile,
|
||||||
|
Experience = 69 | None,
|
||||||
|
EyeOfEnder = 70 | None,
|
||||||
|
EnderCrystal = 71 | None,
|
||||||
|
FireworksRocket = 72 | None,
|
||||||
|
Trident = 73 | Projectile | AbstractArrow,
|
||||||
|
Turtle = 74 | Animal,
|
||||||
|
Cat = 75 | TamableAnimal,
|
||||||
|
ShulkerBullet = 76 | Projectile,
|
||||||
|
FishingHook = 77 | None,
|
||||||
|
Chalkboard = 78 | None,
|
||||||
|
DragonFireball = 79 | Projectile,
|
||||||
|
Arrow = 80 | Projectile | AbstractArrow,
|
||||||
|
Snowball = 81 | Projectile,
|
||||||
|
ThrownEgg = 82 | Projectile,
|
||||||
|
Painting = 83 | None,
|
||||||
|
MinecartRideable = 84 | Minecart,
|
||||||
|
LargeFireball = 85 | Projectile,
|
||||||
|
ThrownPotion = 86 | Projectile,
|
||||||
|
Enderpearl = 87 | Projectile,
|
||||||
|
LeashKnot = 88 | None,
|
||||||
|
WitherSkull = 89 | Projectile,
|
||||||
|
BoatRideable = 90 | None,
|
||||||
|
WitherSkullDangerous = 91 | Projectile,
|
||||||
|
UNUSED92 = 92,
|
||||||
|
LightningBolt = 93 | None,
|
||||||
|
SmallFireball = 94 | Projectile,
|
||||||
|
AreaEffectCloud = 95 | None,
|
||||||
|
MinecartHopper = 96 | Minecart,
|
||||||
|
MinecartTNT = 97 | Minecart,
|
||||||
|
MinecartChest = 98 | Minecart,
|
||||||
|
MinecartFurnace = 99 | Minecart,
|
||||||
|
MinecartCommandBlock = 100 | Minecart,
|
||||||
|
LingeringPotion = 101 | Projectile,
|
||||||
|
LlamaSpit = 102 | Projectile,
|
||||||
|
EvocationFang = 103 | Projectile,
|
||||||
|
EvocationIllager = 104 | Monster,
|
||||||
|
Vex = 105 | Monster,
|
||||||
|
IceBomb = 106 | Projectile,
|
||||||
|
Balloon = 107 | None,
|
||||||
|
Pufferfish = 108 | WaterAnimal,
|
||||||
|
Salmon = 109 | WaterAnimal,
|
||||||
|
Drowned = 110 | ZombieMonster,
|
||||||
|
Tropicalfish = 111 | WaterAnimal,
|
||||||
|
Fish = 112 | WaterAnimal,
|
||||||
|
Panda = 113 | Animal,
|
||||||
|
Pillager = 114 | Monster,
|
||||||
|
VillagerV2 = 115 | VillagerBase,
|
||||||
|
ZombieVillagerV2 = 116 | ZombieMonster,
|
||||||
|
Shield = 117 | None,
|
||||||
|
WanderingTrader = 118 | PathfinderMob,
|
||||||
|
Lectern = 119 | None,
|
||||||
|
ElderGuardianGhost = 120 | Monster,
|
||||||
|
Fox = 121 | Animal,
|
||||||
|
Bee = 122 | Mob,
|
||||||
|
Piglin = 123 | Mob,
|
||||||
|
Hoglin = 124 | Animal,
|
||||||
|
Strider = 125 | Animal,
|
||||||
|
Zoglin = 126 | UndeadMob,
|
||||||
|
PiglinBrute = 127 | Mob,
|
||||||
|
Goat = 128 | Animal,
|
||||||
|
GlowSquid = 129 | WaterAnimal,
|
||||||
|
Axolotl = 130 | Animal,
|
||||||
|
Warden = 131 | Monster,
|
||||||
|
Frog = 132 | Animal,
|
||||||
|
Tadpole = 133 | WaterAnimal,
|
||||||
|
Allay = 134 | Mob,
|
||||||
|
ChestBoatRideable = 136 | BoatRideable,
|
||||||
|
TraderLlama = 137 | Llama,
|
||||||
|
Camel = 138 | Animal,
|
||||||
|
Sniffer = 139 | Animal,
|
||||||
|
Breeze = 140 | Monster,
|
||||||
|
BreezeWindChargeProjectile = 141 | Projectile,
|
||||||
|
Armadillo = 142 | Animal,
|
||||||
|
WindChargeProjectile = 143 | Projectile,
|
||||||
|
Bogged = 144 | SkeletonMonster,
|
||||||
|
OminousItemSpawner = 145
|
||||||
|
}
|
||||||
|
|
||||||
interface Player {
|
interface Player {
|
||||||
/** (GMLIB)转换成实体对象 */
|
/** (GMLIB)转换成实体对象 */
|
||||||
toEntity(): Entity;
|
toEntity(): Entity;
|
||||||
@@ -1387,6 +1556,9 @@ interface Player {
|
|||||||
slot: number
|
slot: number
|
||||||
): Item;
|
): Item;
|
||||||
|
|
||||||
|
/** (GMLIB & Glacie)获取客户端版本协议*/
|
||||||
|
getNetworkProtocolVersion(): number
|
||||||
|
|
||||||
/** (GMLIB)发送更新更新物品数据包 */
|
/** (GMLIB)发送更新更新物品数据包 */
|
||||||
sendInventorySlotPacket(
|
sendInventorySlotPacket(
|
||||||
/** 容器ID */
|
/** 容器ID */
|
||||||
@@ -1509,6 +1681,21 @@ interface Entity {
|
|||||||
/** 是否显示粒子效果 */
|
/** 是否显示粒子效果 */
|
||||||
ShowParticles: boolean
|
ShowParticles: boolean
|
||||||
}[];
|
}[];
|
||||||
|
|
||||||
|
/** 实体是否为某类型 */
|
||||||
|
isType(
|
||||||
|
/** 实体类型 */
|
||||||
|
type: ActorType
|
||||||
|
): boolean;
|
||||||
|
|
||||||
|
/** 实体是否包含某类型 */
|
||||||
|
hasType(
|
||||||
|
/** 实体类型 */
|
||||||
|
type: ActorType
|
||||||
|
): boolean;
|
||||||
|
|
||||||
|
/** 获取实体类型ID */
|
||||||
|
getEntityTypeId(): ActorType;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Block {
|
interface Block {
|
||||||
@@ -1533,9 +1720,6 @@ interface Block {
|
|||||||
/** (GMLIB) */
|
/** (GMLIB) */
|
||||||
canDropWithAnyTool(): boolean;
|
canDropWithAnyTool(): boolean;
|
||||||
|
|
||||||
/** (GMLIB)方块是否不需要工具采集 */
|
|
||||||
isAlwaysDestroyable(): boolean;
|
|
||||||
|
|
||||||
/** (GMLIB)检测方块是否能被玩家挖掘(比如插件拦截) */
|
/** (GMLIB)检测方块是否能被玩家挖掘(比如插件拦截) */
|
||||||
playerWillDestroy(
|
playerWillDestroy(
|
||||||
/** 挖掘的玩家对象 */
|
/** 挖掘的玩家对象 */
|
||||||
@@ -1574,9 +1758,6 @@ interface Item {
|
|||||||
block: Block
|
block: Block
|
||||||
): boolean;
|
): boolean;
|
||||||
|
|
||||||
/** (GMLIB)获取物品可以拥有的附魔 */
|
|
||||||
getLegalEnchants(): string[]
|
|
||||||
|
|
||||||
/** (GMLIB)添加附魔 */
|
/** (GMLIB)添加附魔 */
|
||||||
applyEnchant(
|
applyEnchant(
|
||||||
/** 附魔的命名空间ID */
|
/** 附魔的命名空间ID */
|
||||||
|
|||||||
+506
-312
File diff suppressed because it is too large
Load Diff
Vendored
+42
@@ -0,0 +1,42 @@
|
|||||||
|
/** 翻译带PAPI变量文本 */
|
||||||
|
export function translate(
|
||||||
|
/** 要翻译的文本 */
|
||||||
|
value: String,
|
||||||
|
/** 实体对象 */
|
||||||
|
actor?: Entity,
|
||||||
|
/** 目标翻译语言 */
|
||||||
|
language?: String
|
||||||
|
): String;
|
||||||
|
|
||||||
|
/** 注册PAPI变量 */
|
||||||
|
export function registerPlaceholder(
|
||||||
|
/** papi变量 */
|
||||||
|
placeholder: String,
|
||||||
|
/** 回调 */
|
||||||
|
callback: (
|
||||||
|
/** 实体对象 */ actor: Entity,
|
||||||
|
/** 参数 */ params: String[],
|
||||||
|
/** 目标翻译语言 */language: String
|
||||||
|
) => String | undefined
|
||||||
|
): void;
|
||||||
|
|
||||||
|
/** 注销PAPI变量 */
|
||||||
|
export function unregisterPlaceholder(
|
||||||
|
/** papi变量 */
|
||||||
|
placeholder: String
|
||||||
|
): Boolean;
|
||||||
|
|
||||||
|
/** 根据模组名注销PAPI变量 */
|
||||||
|
export function unregisterPlaceholderFromModName(
|
||||||
|
/** 模组名 */
|
||||||
|
modName: String
|
||||||
|
): Boolean;
|
||||||
|
|
||||||
|
/** 获取一个papi变量的值 */
|
||||||
|
export function getValue(
|
||||||
|
/** papi变量名 */
|
||||||
|
placeholder: String,
|
||||||
|
actor?: Entity,
|
||||||
|
params?: Record<String, String>,
|
||||||
|
language?: string
|
||||||
|
): Boolean;
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
/// <reference path='d:/dts/dts/helperlib/src/index.d.ts'/>
|
||||||
|
|
||||||
|
const getPluginName = () => {
|
||||||
|
// quickjs
|
||||||
|
try {
|
||||||
|
throw new Error("getPluginName");
|
||||||
|
} catch (error) {
|
||||||
|
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 =
|
||||||
|
/**
|
||||||
|
* 获取函数名字
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
function () {
|
||||||
|
return this.name || this.toString().match(/function\s*([^(]*)\(/)?.[1] || getStringHashCode(this.toString()).toString(16);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取字符串哈希值
|
||||||
|
* @param {string} str 字符串
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
function getStringHashCode(str) {
|
||||||
|
let hash = 0, chr;
|
||||||
|
if (str.length === 0) return hash;
|
||||||
|
for (let i = 0; i < str.length; i++) {
|
||||||
|
chr = str.charCodeAt(i);
|
||||||
|
hash = ((hash << 5) - hash) + chr;
|
||||||
|
hash |= 0;
|
||||||
|
}
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
translate(value, actor = undefined, language = "") {
|
||||||
|
return actor instanceof LLSE_Entity
|
||||||
|
? ll.importss("PlaceholderAPI", "translateFromActor")(value, actor, language)
|
||||||
|
: ll.importss("PlaceholderAPI", "translate")(value, language);
|
||||||
|
},
|
||||||
|
registerPlaceholder(placeholder, callback) {
|
||||||
|
const pluginName = getPluginName();
|
||||||
|
ll.exports((...args) => {
|
||||||
|
if(!args[0].uniqueId) args[0] = undefined;
|
||||||
|
return callback(...args) ?? "<std::nullopt>";
|
||||||
|
}, pluginName, callback.getName());
|
||||||
|
ll.importss("PlaceholderAPI", "registerPlaceholder")(placeholder, callback.getName(), pluginName);
|
||||||
|
},
|
||||||
|
unregisterPlaceholder(placeholder) {
|
||||||
|
return ll.importss("PlaceholderAPI", "unregisterPlaceholder")(placeholder);
|
||||||
|
},
|
||||||
|
unregisterPlaceholderFromModName(placeholder) {
|
||||||
|
return ll.importss("PlaceholderAPI", "unregisterPlaceholderFromModName")(placeholder);
|
||||||
|
},
|
||||||
|
getValue(placeholder, actor = undefined, params = {}, language = "") {
|
||||||
|
if (actor instanceof LLSE_Player) actor = ll.imports("GMLib_ServerAPI", "PlayerToEntity")(actor);
|
||||||
|
const result = actor instanceof LLSE_Entity
|
||||||
|
? ll.importss("PlaceholderAPI", "getValueFromActor")(placeholder, actor, params, language)
|
||||||
|
: ll.importss("PlaceholderAPI", "getValue")(placeholder, params, language);
|
||||||
|
return result !== "<std::nullopt>" ? result : undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
+6
-3
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "${pluginName}",
|
"name": "${modName}",
|
||||||
"entry": "${pluginFile}",
|
"entry": "${modFile}",
|
||||||
"version": "0.13.3",
|
"version": "${modVersion}",
|
||||||
"author": "GroupMountain",
|
"author": "GroupMountain",
|
||||||
"type": "native",
|
"type": "native",
|
||||||
"passive": true,
|
"passive": true,
|
||||||
@@ -11,6 +11,9 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "LegacyRemoteCall"
|
"name": "LegacyRemoteCall"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "iListenAttentively"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
function beautify_json(value, indent)
|
|
||||||
import("core.base.json")
|
|
||||||
local json_text = ""
|
|
||||||
local stack = {}
|
|
||||||
|
|
||||||
local function escape_str(s)
|
|
||||||
return string.gsub(s, '[%c\\"]', function(c)
|
|
||||||
local replacements = {['\b'] = '\\b', ['\f'] = '\\f', ['\n'] = '\\n', ['\r'] = '\\r', ['\t'] = '\\t', ['"'] = '\\"', ['\\'] = '\\\\'}
|
|
||||||
return replacements[c] or string.format('\\u%04x', c:byte())
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function is_null(v)
|
|
||||||
return v == json.null
|
|
||||||
end
|
|
||||||
|
|
||||||
local function is_empty_table(t)
|
|
||||||
if type(t) ~= 'table' then return false end
|
|
||||||
for _ in pairs(t) do
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
local function is_array(t)
|
|
||||||
return type(t) == 'table' and json.is_marked_as_array(t) or #t > 0
|
|
||||||
end
|
|
||||||
|
|
||||||
local function serialize(val, level)
|
|
||||||
local spaces = string.rep(" ", level * indent)
|
|
||||||
|
|
||||||
if type(val) == "table" and not stack[val] then
|
|
||||||
if is_empty_table(val) then
|
|
||||||
json_text = json_text .. (is_array(val) and "[]" or "{}")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
stack[val] = true
|
|
||||||
local isArray = is_array(val)
|
|
||||||
json_text = json_text .. (isArray and "[\n" or "{\n")
|
|
||||||
|
|
||||||
local keys = isArray and {} or {}
|
|
||||||
for k in pairs(val) do
|
|
||||||
table.insert(keys, k)
|
|
||||||
end
|
|
||||||
if not isArray then
|
|
||||||
table.sort(keys)
|
|
||||||
end
|
|
||||||
|
|
||||||
for _, k in ipairs(keys) do
|
|
||||||
local v = val[k]
|
|
||||||
json_text = json_text .. spaces .. (isArray and "" or '"' .. escape_str(tostring(k)) .. '": ')
|
|
||||||
serialize(v, level + 1)
|
|
||||||
json_text = json_text .. ",\n"
|
|
||||||
end
|
|
||||||
|
|
||||||
json_text = string.sub(json_text, 1, -3) .. "\n" .. string.rep(" ", (level - 1) * indent) .. (isArray and "]" or "}")
|
|
||||||
stack[val] = nil
|
|
||||||
elseif type(val) == "string" then
|
|
||||||
json_text = json_text .. '"' .. escape_str(val) .. '"'
|
|
||||||
elseif type(val) == "number" then
|
|
||||||
if val % 1 == 0 then
|
|
||||||
json_text = json_text .. tostring(math.floor(val))
|
|
||||||
else
|
|
||||||
json_text = json_text .. tostring(val)
|
|
||||||
end
|
|
||||||
elseif type(val) == "boolean" then
|
|
||||||
json_text = json_text .. tostring(val)
|
|
||||||
elseif is_null(val) then
|
|
||||||
json_text = json_text .. "null"
|
|
||||||
else
|
|
||||||
error("Invalid value type: " .. type(val))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
serialize(value, 1)
|
|
||||||
return json_text
|
|
||||||
end
|
|
||||||
|
|
||||||
function string_formatter(str, variables)
|
|
||||||
return str:gsub("%${(.-)}", function(var)
|
|
||||||
return variables[var] or "${" .. var .. "}"
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function pack_plugin(target,plugin_define)
|
|
||||||
import("lib.detect.find_file")
|
|
||||||
|
|
||||||
local manifest_path = find_file("manifest.json", os.projectdir())
|
|
||||||
if manifest_path then
|
|
||||||
local manifest = io.readfile(manifest_path)
|
|
||||||
local bindir = path.join(os.projectdir(), "bin/DLL")
|
|
||||||
local pdbdir = path.join(os.projectdir(), "bin/PDB")
|
|
||||||
local outputdir = path.join(bindir, plugin_define.pluginName)
|
|
||||||
local targetfile = path.join(outputdir, plugin_define.pluginFile)
|
|
||||||
local pdbfile = path.join(pdbdir, path.basename(plugin_define.pluginFile) .. ".pdb")
|
|
||||||
local libfile = path.join(os.projectdir(), "lib")
|
|
||||||
local manifestfile = path.join(outputdir, "manifest.json")
|
|
||||||
local oritargetfile = target:targetfile()
|
|
||||||
local oripdbfile = path.join(path.directory(oritargetfile), path.basename(oritargetfile) .. ".pdb")
|
|
||||||
|
|
||||||
os.mkdir(outputdir)
|
|
||||||
os.cp(oritargetfile, targetfile)
|
|
||||||
if os.isfile(oripdbfile) then
|
|
||||||
os.cp(oripdbfile, pdbfile)
|
|
||||||
end
|
|
||||||
os.cp(libfile, outputdir)
|
|
||||||
|
|
||||||
formattedmanifest = string_formatter(manifest, plugin_define)
|
|
||||||
io.writefile(manifestfile,formattedmanifest)
|
|
||||||
cprint("${bright green}[Plugin Packer]: ${reset}plugin already generated to " .. outputdir)
|
|
||||||
else
|
|
||||||
cprint("${bright yellow}warn: ${reset}not found manifest.json in root dir!")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
return {
|
|
||||||
pack_plugin = pack_plugin,
|
|
||||||
beautify_json = beautify_json,
|
|
||||||
string_formatter = string_formatter
|
|
||||||
}
|
|
||||||
+26
-9
@@ -1,19 +1,27 @@
|
|||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
using namespace ll::hash_utils;
|
|
||||||
|
|
||||||
class LegacyScriptBinaryStreamManager {
|
class LegacyScriptBinaryStreamManager {
|
||||||
private:
|
private:
|
||||||
int64 mNextBinaryStreamId = 0;
|
int64 mNextBinaryStreamId = 0;
|
||||||
std::unordered_map<uint64, std::shared_ptr<gmlib::network::BinaryStream>> mBinaryStream;
|
std::unordered_map<uint64, std::shared_ptr<GMBinaryStream>> mBinaryStream;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
uint getNextId() { return mNextBinaryStreamId++; }
|
uint getNextId() { return mNextBinaryStreamId++; }
|
||||||
|
|
||||||
void cretateBinaryStream(uint id) { mBinaryStream[id] = std::make_shared<gmlib::network::BinaryStream>(); }
|
void cretateBinaryStream(uint id) { mBinaryStream[id] = std::make_shared<GMBinaryStream>(); }
|
||||||
|
|
||||||
|
uint64 copyBinaryStream(uint id) {
|
||||||
|
auto nextId = getNextId();
|
||||||
|
cretateBinaryStream(nextId);
|
||||||
|
if (auto bs = getBinaryStream(nextId); bs != nullptr) {
|
||||||
|
getBinaryStream(nextId)->mBuffer = getBinaryStream(id)->mBuffer;
|
||||||
|
}
|
||||||
|
return nextId;
|
||||||
|
}
|
||||||
|
|
||||||
void removeBinaryStream(uint64 id) { mBinaryStream.erase(id); }
|
void removeBinaryStream(uint64 id) { mBinaryStream.erase(id); }
|
||||||
|
|
||||||
std::shared_ptr<gmlib::network::BinaryStream> getBinaryStream(uint64 id) {
|
std::shared_ptr<GMBinaryStream> getBinaryStream(uint64 id) {
|
||||||
return mBinaryStream.contains(id) ? mBinaryStream.at(id) : nullptr;
|
return mBinaryStream.contains(id) ? mBinaryStream.at(id) : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +46,7 @@ template <typename T, typename R, typename A, typename... AS>
|
|||||||
struct Info<R (T::*)(A, AS...)> {
|
struct Info<R (T::*)(A, AS...)> {
|
||||||
using ArgT = A;
|
using ArgT = A;
|
||||||
};
|
};
|
||||||
#define EXPORTAPI2(T) EXPORTAPI(#T, Info<decltype(&gmlib::network::BinaryStream::T)>::ArgT, bs->T(value))
|
#define EXPORTAPI2(T) EXPORTAPI(#T, Info<decltype(&BinaryStream::T)>::ArgT, bs->T(value))
|
||||||
|
|
||||||
void Export_BinaryStream_API() {
|
void Export_BinaryStream_API() {
|
||||||
RemoteCall::exportAs("GMLIB_BinaryStream_API", "create", []() -> uint64 {
|
RemoteCall::exportAs("GMLIB_BinaryStream_API", "create", []() -> uint64 {
|
||||||
@@ -46,21 +54,31 @@ void Export_BinaryStream_API() {
|
|||||||
BinaryStreamManager.cretateBinaryStream(id);
|
BinaryStreamManager.cretateBinaryStream(id);
|
||||||
return id;
|
return id;
|
||||||
});
|
});
|
||||||
|
RemoteCall::exportAs("GMLIB_BinaryStream_API", "copy", [](uint64 id) -> uint64 {
|
||||||
|
return BinaryStreamManager.copyBinaryStream(id);
|
||||||
|
});
|
||||||
RemoteCall::exportAs("GMLIB_BinaryStream_API", "reset", [](uint64 id) -> void {
|
RemoteCall::exportAs("GMLIB_BinaryStream_API", "reset", [](uint64 id) -> void {
|
||||||
if (BinaryStreamManager.getBinaryStream(id) == nullptr) BinaryStreamManager.cretateBinaryStream(id);
|
if (BinaryStreamManager.getBinaryStream(id) == nullptr) BinaryStreamManager.cretateBinaryStream(id);
|
||||||
else BinaryStreamManager.getBinaryStream(id)->reset();
|
else {
|
||||||
|
auto bs = BinaryStreamManager.getBinaryStream(id);
|
||||||
|
bs->mBuffer.clear();
|
||||||
|
bs->mReadPointer = 0;
|
||||||
|
bs->mHasOverflowed = false;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_BinaryStream_API", "sendTo", [](uint64 id, Player* player) -> void {
|
RemoteCall::exportAs("GMLIB_BinaryStream_API", "sendTo", [](uint64 id, Player* player) -> void {
|
||||||
if (auto bs = BinaryStreamManager.getBinaryStream(id); bs != nullptr) bs->sendTo(*player);
|
if (auto bs = BinaryStreamManager.getBinaryStream(id); bs != nullptr)
|
||||||
|
bs->sendTo(static_cast<GMPlayer&>(*player));
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_BinaryStream_API", "destroy", [](uint64 id) -> void {
|
RemoteCall::exportAs("GMLIB_BinaryStream_API", "destroy", [](uint64 id) -> void {
|
||||||
BinaryStreamManager.removeBinaryStream(id);
|
BinaryStreamManager.removeBinaryStream(id);
|
||||||
});
|
});
|
||||||
EXPORTAPI("writePacketHeader", int, bs->writePacketHeader((MinecraftPacketIds)value));
|
EXPORTAPI("writePacketHeader", int, bs->writePacketHeader((MinecraftPacketIds)value));
|
||||||
EXPORTAPI("writeUuid", std::string const&, bs->writeUuid(mce::UUID::fromString(value)));
|
EXPORTAPI("writeUuid", std::string const&, bs->writeUuid(mce::UUID::fromString(value)));
|
||||||
EXPORTAPI("writeItem", ItemStack*, bs->writeType(NetworkItemStackDescriptor(*value)));
|
EXPORTAPI("writeItem", ItemStack*, bs->writeNetworkItemStackDescriptor(NetworkItemStackDescriptor(*value)));
|
||||||
EXPORTAPI("writeString", std::string const&, bs->writeString(value));
|
EXPORTAPI("writeString", std::string const&, bs->writeString(value));
|
||||||
EXPORTAPI("writeCompoundTag", CompoundTag*, bs->writeCompoundTag(*value));
|
EXPORTAPI("writeCompoundTag", CompoundTag*, bs->writeCompoundTag(*value));
|
||||||
|
EXPORTAPI("writeUnsignedChar", uchar, bs->writeUnsignedChar(value));
|
||||||
EXPORTAPI2(writeBool);
|
EXPORTAPI2(writeBool);
|
||||||
EXPORTAPI2(writeByte);
|
EXPORTAPI2(writeByte);
|
||||||
EXPORTAPI2(writeDouble);
|
EXPORTAPI2(writeDouble);
|
||||||
@@ -69,7 +87,6 @@ void Export_BinaryStream_API() {
|
|||||||
EXPORTAPI2(writeSignedInt);
|
EXPORTAPI2(writeSignedInt);
|
||||||
EXPORTAPI2(writeSignedInt64);
|
EXPORTAPI2(writeSignedInt64);
|
||||||
EXPORTAPI2(writeSignedShort);
|
EXPORTAPI2(writeSignedShort);
|
||||||
EXPORTAPI2(writeUnsignedChar);
|
|
||||||
EXPORTAPI2(writeUnsignedInt);
|
EXPORTAPI2(writeUnsignedInt);
|
||||||
EXPORTAPI2(writeUnsignedInt64);
|
EXPORTAPI2(writeUnsignedInt64);
|
||||||
EXPORTAPI2(writeUnsignedShort);
|
EXPORTAPI2(writeUnsignedShort);
|
||||||
|
|||||||
+357
-272
File diff suppressed because it is too large
Load Diff
+18
-11
@@ -1,31 +1,31 @@
|
|||||||
#include "Entry.h"
|
#include "Entry.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
|
||||||
ll::Logger logger(PLUGIN_NAME);
|
|
||||||
|
|
||||||
namespace gmlib {
|
namespace gmlib {
|
||||||
|
|
||||||
std::unique_ptr<LegacyRemoteCallApi>& LegacyRemoteCallApi::getInstance() {
|
LegacyRemoteCallApi& LegacyRemoteCallApi::getInstance() {
|
||||||
static std::unique_ptr<LegacyRemoteCallApi> instance;
|
static LegacyRemoteCallApi instance;
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LegacyRemoteCallApi::load() {
|
bool LegacyRemoteCallApi::load() {
|
||||||
|
(void)CustomRecipeRegistry::getInstance();
|
||||||
Export_Legacy_GMLib_ModAPI();
|
Export_Legacy_GMLib_ModAPI();
|
||||||
Export_Legacy_GMLib_ServerAPI();
|
Export_Legacy_GMLib_ServerAPI();
|
||||||
Export_Compatibility_API();
|
Export_Compatibility_API();
|
||||||
ExportPAPI();
|
ExportPAPI();
|
||||||
Export_Event_API();
|
Export_Event_API();
|
||||||
Export_BinaryStream_API();
|
Export_BinaryStream_API();
|
||||||
Export_Form_API();
|
// Export_Form_API();
|
||||||
logger.info("GMLIB-LegacyRemoteCallApi Loaded!");
|
auto logger = ll::io::LoggerRegistry::getInstance().getOrCreate(PLUGIN_NAME);
|
||||||
logger.info(
|
logger->info("GMLIB-LegacyRemoteCallApi Loaded!");
|
||||||
|
logger->info(
|
||||||
"Loaded Version: {} with {}",
|
"Loaded Version: {} with {}",
|
||||||
fmt::format(fg(fmt::color::pink), "GMLIB-" + gmlib::Version::getLibVersionString()),
|
fmt::format(fg(fmt::color::pink), "GMLIB-" GMLIB_FILE_VERSION_STRING),
|
||||||
fmt::format(fg(fmt::color::light_green), "GMLIB-LegacyRemoteCallApi-" + LIB_VERSION.asString())
|
fmt::format(fg(fmt::color::light_green), "GMLIB-LegacyRemoteCallApi-{}", LIB_VERSION.to_string())
|
||||||
);
|
);
|
||||||
logger.info("Author: GroupMountain");
|
logger->info("Author: GroupMountain");
|
||||||
logger.info("Repository: https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi");
|
logger->info("Repository: https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,3 +36,10 @@ bool LegacyRemoteCallApi::disable() { return true; }
|
|||||||
} // namespace gmlib
|
} // namespace gmlib
|
||||||
|
|
||||||
LL_REGISTER_MOD(gmlib::LegacyRemoteCallApi, gmlib::LegacyRemoteCallApi::getInstance());
|
LL_REGISTER_MOD(gmlib::LegacyRemoteCallApi, gmlib::LegacyRemoteCallApi::getInstance());
|
||||||
|
|
||||||
|
|
||||||
|
ll::thread::ThreadPoolExecutor const& getThreadPoolExecutor() {
|
||||||
|
return gmlib::LegacyRemoteCallApi::getInstance().getThreadPoolExecutor();
|
||||||
|
}
|
||||||
|
|
||||||
|
ll::io::Logger& getLogger() { return gmlib::LegacyRemoteCallApi::getInstance().getSelf().getLogger(); }
|
||||||
+6
-2
@@ -1,15 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <ll/api/mod/NativeMod.h>
|
#include <ll/api/mod/NativeMod.h>
|
||||||
#include <ll/api/mod/RegisterHelper.h>
|
#include <ll/api/mod/RegisterHelper.h>
|
||||||
|
#include <ll/api/thread/ThreadPoolExecutor.h>
|
||||||
|
|
||||||
namespace gmlib {
|
namespace gmlib {
|
||||||
|
|
||||||
class LegacyRemoteCallApi {
|
class LegacyRemoteCallApi {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static std::unique_ptr<LegacyRemoteCallApi>& getInstance();
|
static LegacyRemoteCallApi& getInstance();
|
||||||
|
|
||||||
LegacyRemoteCallApi(ll::mod::NativeMod& self) : mSelf(self) {}
|
LegacyRemoteCallApi() : mSelf(*ll::mod::NativeMod::current()), mThreadPoolExecutor(getSelf().getName()) {}
|
||||||
|
|
||||||
[[nodiscard]] ll::mod::NativeMod& getSelf() const { return mSelf; }
|
[[nodiscard]] ll::mod::NativeMod& getSelf() const { return mSelf; }
|
||||||
|
|
||||||
@@ -26,8 +27,11 @@ public:
|
|||||||
// /// @return True if the plugin is unloaded successfully.
|
// /// @return True if the plugin is unloaded successfully.
|
||||||
// bool unload();
|
// bool unload();
|
||||||
|
|
||||||
|
ll::thread::ThreadPoolExecutor& getThreadPoolExecutor() { return mThreadPoolExecutor; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ll::mod::NativeMod& mSelf;
|
ll::mod::NativeMod& mSelf;
|
||||||
|
ll::thread::ThreadPoolExecutor mThreadPoolExecutor;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gmlib
|
} // namespace gmlib
|
||||||
|
|||||||
+242
-173
@@ -1,205 +1,286 @@
|
|||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
using namespace ll::hash_utils;
|
using namespace ll::hash_utils;
|
||||||
|
|
||||||
class LegacyScriptEventManager {
|
class EventManager {
|
||||||
private:
|
private:
|
||||||
int64 mNextEventId = 0;
|
std::unordered_map<ullong, ll::event::ListenerPtr> mEventIds;
|
||||||
std::unordered_map<uint64, ll::event::ListenerPtr> mEventListeners;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::string getNextEventId() {
|
static EventManager& getInstance() {
|
||||||
mNextEventId++;
|
static std::unique_ptr<EventManager> instance;
|
||||||
return "GMLIB_EVENT_" + std::to_string(mNextEventId);
|
if (!instance) instance = std::make_unique<EventManager>();
|
||||||
}
|
|
||||||
|
|
||||||
void emplaceListener(std::string const& scriptEventId, ll::event::ListenerPtr listenerPtr) {
|
|
||||||
mEventListeners[doHash(scriptEventId)] = std::move(listenerPtr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeListener(std::string const& scriptEventId) {
|
|
||||||
ll::event::EventBus::getInstance().removeListener(mEventListeners[doHash(scriptEventId)]);
|
|
||||||
mEventListeners.erase(doHash(scriptEventId));
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
static LegacyScriptEventManager& getInstance() {
|
|
||||||
static std::unique_ptr<LegacyScriptEventManager> instance;
|
|
||||||
if (!instance) {
|
|
||||||
instance = std::make_unique<LegacyScriptEventManager>();
|
|
||||||
}
|
|
||||||
return *instance;
|
return *instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ullong getNextId() {
|
||||||
|
auto id = mEventIds.size();
|
||||||
|
mEventIds.emplace(id, nullptr);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool addListener(ullong id, ll::event::ListenerPtr const& listener) {
|
||||||
|
if (mEventIds.contains(id) && mEventIds[id]) return false;
|
||||||
|
mEventIds[id] = listener;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool removeListener(ullong id) {
|
||||||
|
if (ll::event::EventBus::getInstance().removeListener(mEventIds[id])) {
|
||||||
|
mEventIds[id] = nullptr;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hasListener(ullong id) { return mEventIds.contains(id) && mEventIds[id]; }
|
||||||
|
|
||||||
|
ll::event::ListenerPtr getListener(ullong id) { return mEventIds.contains(id) ? mEventIds[id] : nullptr; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#define REGISTER_EVENT_LISTEN(eventType, callFunction, eventParams, cancelFunction, otherFunction) \
|
#define REGISTER_EVENT_LISTEN(eventType, paramType, params, cancelFun, ...) \
|
||||||
eventManager.emplaceListener( \
|
auto eventPtr = ll::event::EventBus::getInstance().emplaceListener<eventType>( \
|
||||||
eventId, \
|
[pluginName, eventName, eventId](eventType& event) -> void { \
|
||||||
eventBus.emplaceListener<eventType>([eventName, eventId, &eventBus, &eventManager](eventType& ev) -> void { \
|
if (!RemoteCall::hasFunc(pluginName, eventName + "_" + std::to_string(eventId))) { \
|
||||||
if (!RemoteCall::hasFunc(eventName, eventId)) { \
|
EventManager::getInstance().removeListener(eventId); \
|
||||||
eventManager.removeListener(eventId); \
|
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
bool result = true; \
|
|
||||||
try { \
|
try { \
|
||||||
otherFunction; \
|
__VA_ARGS__ \
|
||||||
result = RemoteCall::importAs<bool callFunction>(eventName, eventId) eventParams; \
|
auto result = \
|
||||||
|
RemoteCall::importAs<bool paramType>(pluginName, eventName + "_" + std::to_string(eventId)) \
|
||||||
|
params; \
|
||||||
|
cancelFun \
|
||||||
} catch (...) {} \
|
} catch (...) {} \
|
||||||
if (!result) cancelFunction; \
|
}, \
|
||||||
}) \
|
ll::event::EventPriority(priority) \
|
||||||
); \
|
); \
|
||||||
return true;
|
return eventId
|
||||||
|
|
||||||
void Export_Event_API() {
|
void Export_Event_API() {
|
||||||
RemoteCall::exportAs("GMLIB_Event_API", "getNextScriptEventId", []() -> std::string {
|
RemoteCall::exportAs("GMLIB_Event_API", "removeListener", [](ll::event::ListenerId eventId) -> bool {
|
||||||
return LegacyScriptEventManager::getInstance().getNextEventId();
|
return EventManager::getInstance().removeListener(eventId);
|
||||||
});
|
});
|
||||||
auto& eventBus = ll::event::EventBus::getInstance();
|
|
||||||
auto& eventManager = LegacyScriptEventManager::getInstance();
|
RemoteCall::exportAs("GMLIB_Event_API", "hasListener", [](ll::event::ListenerId eventId) -> bool {
|
||||||
|
return EventManager::getInstance().hasListener(eventId);
|
||||||
|
});
|
||||||
|
|
||||||
|
RemoteCall::exportAs("GMLIB_Event_API", "getListenerPriority", [](ll::event::ListenerId eventId) -> int {
|
||||||
|
if (auto event = EventManager::getInstance().getListener(eventId); event != nullptr) {
|
||||||
|
return (int)event->getPriority();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
});
|
||||||
|
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
"GMLIB_Event_API",
|
"GMLIB_Event_API",
|
||||||
"callCustomEvent",
|
"emplaceListener",
|
||||||
[&eventBus, &eventManager](std::string const& eventName, std::string const& eventId) -> bool {
|
[](std::string const& pluginName, std::string const& eventName, int priority) -> llong {
|
||||||
if (!RemoteCall::hasFunc(eventName, eventId)) return false;
|
auto eventId = EventManager::getInstance().getNextId();
|
||||||
switch (doHash(eventName)) {
|
switch (doHash(eventName)) {
|
||||||
case doHash("onClientLogin"): {
|
case doHash("ll::ServerStoppingEvent"): {
|
||||||
|
REGISTER_EVENT_LISTEN(ll::event::ServerStoppingEvent, (), (), , );
|
||||||
|
}
|
||||||
|
case doHash("gmlib::ClientLoginAfterEvent"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
gmlib::event::packet::ClientLoginAfterEvent,
|
ila::mc::ClientLoginAfterEvent,
|
||||||
(std::string const& realName,
|
(std::string const& realName,
|
||||||
std::string const& uuid,
|
std::string const& uuid,
|
||||||
std::string const& serverXuid,
|
std::string const& serverXuid,
|
||||||
std::string const& clientXuid),
|
std::string const& clientXuid),
|
||||||
(ev.getRealName(), ev.getUuid().asString(), ev.getServerAuthXuid(), ev.getClientAuthXuid()),
|
(event.realName(), event.uuid().asString(), event.serverAuthXuid(), event.clientAuthXuid()),
|
||||||
logger.error("Event \"onClientLogin\" cannot be intercepted"),
|
if (result) event.disConnectClient();
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
case doHash("onWeatherChange"): {
|
case doHash("gmlib::WeatherUpdateBeforeEvent"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
gmlib::event::level::WeatherUpdateBeforeEvent,
|
ila::mc::WeatherUpdateBeforeEvent,
|
||||||
(int lightningLevel, int rainLevel, int lightningLast, int rainLast),
|
(float rainLevel, int rainTime, float lightningLevel, int lightningTime, bool isCancelled),
|
||||||
(ev.getLightningLevel(), ev.getRainLevel(), ev.getLightningLastTick(), ev.getRainingLastTick()),
|
(event.rainLevel(),
|
||||||
ev.cancel(),
|
event.rainTime(),
|
||||||
)
|
event.lightningLevel(),
|
||||||
|
event.lightningTime(),
|
||||||
|
event.isCancelled()),
|
||||||
|
event.setCancelled(result);
|
||||||
|
);
|
||||||
}
|
}
|
||||||
case doHash("onMobPick"): {
|
case doHash("gmlib::WeatherUpdateAfterEvent"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
gmlib::event::entity::MobPickupItemBeforeEvent,
|
ila::mc::WeatherUpdateAfterEvent,
|
||||||
|
(float rainLevel, int rainTime, float lightningLevel, int lightningTime),
|
||||||
|
(event.rainLevel(), event.rainTime(), event.lightningLevel(), event.lightningTime()),
|
||||||
|
,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case doHash("gmlib::MobPickupItemBeforeEvent"): {
|
||||||
|
REGISTER_EVENT_LISTEN(ila::mc::ActorPickupItemBeforeEvent,
|
||||||
|
(Actor * mob, Actor * item, bool isCancelled),
|
||||||
|
(&event.self(), (Actor*)&event.itemActor(), event.isCancelled()),
|
||||||
|
event.setCancelled(result););
|
||||||
|
}
|
||||||
|
case doHash("gmlib::MobPickupItemAfterEvent"): {
|
||||||
|
REGISTER_EVENT_LISTEN(
|
||||||
|
ila::mc::ActorPickupItemAfterEvent,
|
||||||
(Actor * mob, Actor * item),
|
(Actor * mob, Actor * item),
|
||||||
(&ev.self(), (Actor*)&ev.getItemActor()),
|
(&event.self(), (Actor*)&event.itemActor()),
|
||||||
ev.cancel(),
|
,
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
case doHash("onItemTrySpawn"): {
|
case doHash("gmlib::ItemActorSpawnBeforeEvent"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
gmlib::event::entity::ItemActorSpawnBeforeEvent,
|
ila::mc::SpawnItemActorBeforeEvent,
|
||||||
(const ItemStack* item, std::pair<Vec3, int> position, int64 spawnerUniqueId),
|
(ItemStack * item, std::pair<Vec3, int> position, int64 spawnerUniqueId, bool isCancelled),
|
||||||
(&ev.getItem(),
|
(&event.item(),
|
||||||
{ev.getPosition(), ev.getBlockSource().getDimensionId().id},
|
{event.pos(), event.blockSource().getDimensionId().id},
|
||||||
ev.getSpawner().has_value() ? ev.getSpawner()->getOrCreateUniqueID().id : -1),
|
event.spawner() ? event.spawner()->getOrCreateUniqueID().rawID : -1,
|
||||||
ev.cancel(),
|
event.isCancelled()),
|
||||||
)
|
event.setCancelled(result);
|
||||||
|
);
|
||||||
}
|
}
|
||||||
case doHash("onItemSpawned"): {
|
case doHash("gmlib::ItemActorSpawnAfterEvent"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
gmlib::event::entity::ItemActorSpawnAfterEvent,
|
ila::mc::SpawnItemActorAfterEvent,
|
||||||
(const ItemStack* item, Actor* itemActor, std::pair<Vec3, int> position, int64 spawnerUniqueId),
|
(Actor * item, std::pair<Vec3, int> position, int64 spawnerUniqueId),
|
||||||
(&ev.getItem(),
|
(&event.itemActor(),
|
||||||
(Actor*)&ev.getItemActor(),
|
{event.pos(), event.blockSource().getDimensionId().id},
|
||||||
{ev.getPosition(), ev.getBlockSource().getDimensionId().id},
|
event.spawner() ? event.spawner()->getOrCreateUniqueID().rawID : -1),
|
||||||
ev.getSpawner().has_value() ? ev.getSpawner()->getOrCreateUniqueID().id : -1),
|
,
|
||||||
logger.error("Event \"onItemSpawned\" cannot be intercepted"),
|
);
|
||||||
)
|
|
||||||
}
|
}
|
||||||
case doHash("onEntityTryChangeDim"): {
|
case doHash("gmlib::ActorChangeDimensionBeforeEvent"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(ila::mc::ActorChangeDimensionBeforeEvent,
|
||||||
gmlib::event::entity::ActorChangeDimensionBeforeEvent,
|
(Actor * entity, int toDimId, bool isCancelled),
|
||||||
(Actor * entity, int toDimId),
|
(&event.self(), event.toDimensionId(), event.isCancelled()),
|
||||||
(&ev.self(), ev.getToDimensionId()),
|
event.setCancelled(result););
|
||||||
ev.cancel(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
case doHash("onLeaveBed"): {
|
case doHash("gmlib::ActorChangeDimensionAfterEvent"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
gmlib::event::player::PlayerStopSleepBeforeEvent,
|
ila::mc::ActorChangeDimensionAfterEvent,
|
||||||
(Player * pl),
|
(Actor * entity, int fromDimId, int toDimId),
|
||||||
(&ev.self()),
|
(&event.self(), event.fromDimensionId(), event.toDimensionId()),
|
||||||
ev.cancel(),
|
,
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
case doHash("onDeathMessage"): {
|
case doHash("gmlib::PlayerStartSleepBeforeEvent"): {
|
||||||
|
REGISTER_EVENT_LISTEN(ila::mc::PlayerStartSleepBeforeEvent,
|
||||||
|
(Player * entity, BlockPos pos, bool isCancelled),
|
||||||
|
(&event.self(), event.pos(), event.isCancelled()),
|
||||||
|
event.setCancelled(result););
|
||||||
|
}
|
||||||
|
case doHash("gmlib::PlayerStartSleepAfterEvent"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
gmlib::event::entity::DeathMessageAfterEvent,
|
ila::mc::PlayerStartSleepAfterEvent,
|
||||||
|
(Player * entity, BlockPos pos, int result),
|
||||||
|
(&event.self(), event.pos(), (int)event.result()),
|
||||||
|
,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case doHash("gmlib::PlayerStopSleepBeforeEvent"): {
|
||||||
|
REGISTER_EVENT_LISTEN(
|
||||||
|
ila::mc::PlayerStopSleepBeforeEvent,
|
||||||
|
(Player * entity, bool forcefulWakeUp, bool updateLevelList, bool isCancelled),
|
||||||
|
(&event.self(), event.forcefulWakeUp(), event.updateLevelList(), false),
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case doHash("gmlib::PlayerStopSleepAfterEvent"): {
|
||||||
|
REGISTER_EVENT_LISTEN(
|
||||||
|
ila::mc::PlayerStopSleepAfterEvent,
|
||||||
|
(Player * entity, bool forcefulWakeUp, bool updateLevelList, bool),
|
||||||
|
(&event.self(), event.forcefulWakeUp(), event.updateLevelList(), false),
|
||||||
|
,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case doHash("gmlib::DeathMessageAfterEvent"): {
|
||||||
|
REGISTER_EVENT_LISTEN(
|
||||||
|
ila::mc::DeathMessageAfterEvent,
|
||||||
(std::string const& message, std::vector<std::string>, Actor* dead),
|
(std::string const& message, std::vector<std::string>, Actor* dead),
|
||||||
(ev.getDeathMessage().first, ev.getDeathMessage().second, &ev.self()),
|
(event.result().first, event.result().second, &event.self()),
|
||||||
logger.error("Event \"onDeathMessage\" cannot be intercepted"),
|
,
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
case doHash("onMobHurted"): {
|
case doHash("gmlib::MobHurtAfterEvent"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
gmlib::event::entity::MobHurtAfterEvent,
|
ila::mc::MobHealthChangeAfterEvent,
|
||||||
(Actor * mob, Actor * source, float damage, int cause),
|
(Actor * mob, Actor * source, float damage, int cause),
|
||||||
(&ev.self(), source, ev.getDamage(), (int)damageSource.getCause()),
|
(&event.self(), source, event.oldValue() - event.newValue(), (int)damageSource->mCause),
|
||||||
logger.error("Event \"onMobHurted\" cannot be intercepted"),
|
,
|
||||||
auto& damageSource = ev.getSource();
|
if (event.newValue() > event.oldValue()) return;
|
||||||
|
auto& damageSource = event.buff().mSource;
|
||||||
Actor* source = nullptr;
|
Actor* source = nullptr;
|
||||||
if (damageSource.isEntitySource()) {
|
if (damageSource->isEntitySource()) {
|
||||||
auto uniqueId = damageSource.getDamagingEntityUniqueID();
|
auto uniqueId = damageSource->getDamagingEntityUniqueID();
|
||||||
source = ll::service::getLevel()->fetchEntity(uniqueId);
|
source = ll::service::getLevel()->fetchEntity(uniqueId, false);
|
||||||
if (source->getOwner()) source = source->getOwner();
|
if (source->getOwner()) source = source->getOwner();
|
||||||
}
|
}
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
case doHash("onEndermanTake"): {
|
case doHash("gmlib::EndermanTakeBlockBeforeEvent"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(ila::mc::EndermanTakeBlockBeforeEvent,
|
||||||
gmlib::event::entity::EndermanTakeBlockBeforeEvent,
|
(Actor * mob, bool isCancelled),
|
||||||
(Actor * mob),
|
(&event.self(), event.isCancelled()),
|
||||||
(&ev.self()),
|
event.setCancelled(result););
|
||||||
ev.cancel(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
case doHash("onEntityChangeDim"): {
|
case doHash("gmlib::DragonRespawnBeforeEvent"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(ila::mc::DragonRespawnBeforeEvent,
|
||||||
gmlib::event::entity::ActorChangeDimensionAfterEvent,
|
(bool isCancelled),
|
||||||
(Actor * mob, int fromDimId),
|
(event.isCancelled()),
|
||||||
(&ev.self(), ev.getFromDimensionId()),
|
event.setCancelled(result););
|
||||||
logger.error("Event \"onEntityChangeDim\" cannot be intercepted"),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
case doHash("onDragonRespawn"): {
|
case doHash("gmlib::DragonRespawnAfterEvent"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(ila::mc::DragonRespawnAfterEvent, (Actor * mob), (&event.self()), );
|
||||||
gmlib::event::entity::DragonRespawnBeforeEvent,
|
|
||||||
(int64 enderDragonUniqueID),
|
|
||||||
(ev.getEnderDragon().id),
|
|
||||||
ev.cancel(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
case doHash("onProjectileTryCreate"): {
|
case doHash("gmlib::ProjectileCreateBeforeEvent"): {
|
||||||
|
REGISTER_EVENT_LISTEN(ila::mc::ProjectileCreateBeforeEvent,
|
||||||
|
(Actor * mob, int64 uniqueId, bool isCancelled),
|
||||||
|
(&event.self(), event.self().getOwnerId().rawID, event.isCancelled()),
|
||||||
|
event.setCancelled(result););
|
||||||
|
}
|
||||||
|
case doHash("gmlib::ProjectileCreateAfterEvent"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
gmlib::event::entity::ProjectileCreateBeforeEvent,
|
ila::mc::ProjectileCreateAfterEvent,
|
||||||
(Actor * mob, int64 uniqueId),
|
(Actor * mob, int64 uniqueId),
|
||||||
(&ev.self(), ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1),
|
(&event.self(), event.self().getOwnerId().rawID),
|
||||||
ev.cancel(),
|
);
|
||||||
)
|
|
||||||
}
|
}
|
||||||
case doHash("onProjectileCreate"): {
|
case doHash("gmlib::SpawnWanderingTraderBeforeEvent"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(ila::mc::SpawnWanderingTraderBeforeEvent,
|
||||||
gmlib::event::entity::ProjectileCreateAfterEvent,
|
(std::pair<BlockPos, int> pos, bool isCancelled),
|
||||||
(Actor * mob, int64 uniqueId),
|
({event.pos(), event.blockSource().getDimensionId()}, event.isCancelled()),
|
||||||
(&ev.self(), ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1),
|
event.setCancelled(result););
|
||||||
logger.error("Event \"onProjectileCreate\" cannot be intercepted"),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
case doHash("onSpawnWanderingTrader"): {
|
case doHash("gmlib::HandleRequestActionBeforeEvent"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
|
||||||
gmlib::event::entity::SpawnWanderingTraderBeforeEvent,
|
|
||||||
(std::pair<BlockPos, int> pos),
|
|
||||||
({ev.getPos(), ev.getRegion().getDimensionId()}),
|
|
||||||
ev.cancel(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
case doHash("onHandleRequestAction"): {
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
gmlib::event::player::HandleRequestActionBeforeEvent,
|
ila::mc::PlayerRequestItemActionBeforeEvent,
|
||||||
|
(
|
||||||
|
Player * player,
|
||||||
|
std::string const& actionType,
|
||||||
|
int count,
|
||||||
|
std::string const& sourceContainerNetId,
|
||||||
|
int sourceSlot,
|
||||||
|
std::string const& destinationContainerNetId,
|
||||||
|
int destinationSlot,
|
||||||
|
bool isCancelled
|
||||||
|
),
|
||||||
|
(
|
||||||
|
(Player*)&event.self(),
|
||||||
|
magic_enum::enum_name(event.actionType()).data(),
|
||||||
|
event.amount(),
|
||||||
|
magic_enum::enum_name(event.src().mFullContainerName.mName).data(),
|
||||||
|
(int)event.src().mSlot,
|
||||||
|
magic_enum::enum_name(event.dst().mFullContainerName.mName).data(),
|
||||||
|
(int)event.dst().mSlot,
|
||||||
|
event.isCancelled()
|
||||||
|
),
|
||||||
|
event.setCancelled(result);,
|
||||||
|
);
|
||||||
|
// clang-format on
|
||||||
|
}
|
||||||
|
case doHash("gmlib::HandleRequestActionAfterEvent"): {
|
||||||
|
// clang-format off
|
||||||
|
REGISTER_EVENT_LISTEN(
|
||||||
|
ila::mc::PlayerRequestItemActionAfterEvent,
|
||||||
(
|
(
|
||||||
Player * player,
|
Player * player,
|
||||||
std::string const& actionType,
|
std::string const& actionType,
|
||||||
@@ -210,40 +291,28 @@ void Export_Event_API() {
|
|||||||
int destinationSlot
|
int destinationSlot
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
(Player*)&ev.self(),
|
(Player*)&event.self(),
|
||||||
magic_enum::enum_name(requestAction.mActionType).data(),
|
magic_enum::enum_name(event.actionType()).data(),
|
||||||
(int)requestAction.mAmount,
|
event.amount(),
|
||||||
magic_enum::enum_name(requestAction.mSrc.mOpenContainerNetId).data(),
|
magic_enum::enum_name(event.src().mFullContainerName.mName).data(),
|
||||||
(int)requestAction.mSrc.mSlot,
|
(int)event.src().mSlot,
|
||||||
magic_enum::enum_name(requestAction.mDst.mOpenContainerNetId).data(),
|
magic_enum::enum_name(event.dst().mFullContainerName.mName).data(),
|
||||||
(int)requestAction.mDst.mSlot
|
(int)event.dst().mSlot
|
||||||
),
|
),
|
||||||
ev.cancel(),
|
,
|
||||||
auto& requestAction = (ItemStackRequestActionTransferBase&)ev.getRequestAction();
|
);
|
||||||
)
|
|
||||||
// clang-format on
|
// clang-format on
|
||||||
}
|
}
|
||||||
case doHash("onSendContainerClosePacket"): {
|
case doHash("gmlib::ContainerClosePacketSendAfterEvent"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
gmlib::event::packet::ContainerClosePacketSendAfterEvent,
|
ila::mc::PlayerCloseContainerAfterEvent,
|
||||||
(Player * player, int ContainerNetId),
|
(Player * player, int containerId, bool serverInitiatedClose, bool),
|
||||||
(ev.getServerNetworkHandler()
|
(&event.self(), (int)event.containerId(), event.serverInitiatedClose(), false),
|
||||||
.getServerPlayer(ev.getNetworkIdentifier(), ev.getPacket().mClientSubId),
|
,
|
||||||
(int)ev.getPacket().mContainerId),
|
);
|
||||||
logger.error("Event \"onSendContainerClosePacket\" cannot be intercepted"),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
case doHash("onServerStopping"): {
|
|
||||||
REGISTER_EVENT_LISTEN(
|
|
||||||
ll::event::server::ServerStoppingEvent,
|
|
||||||
(),
|
|
||||||
(),
|
|
||||||
logger.error("Event \"onServerStopping\" cannot be intercepted"),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
+272
-272
@@ -1,288 +1,288 @@
|
|||||||
#include "Global.h"
|
// #include "Global.h"
|
||||||
|
|
||||||
using namespace ll::hash_utils;
|
// using namespace ll::hash_utils;
|
||||||
|
|
||||||
class LegacyScriptFormManager {
|
// class LegacyScriptFormManager {
|
||||||
private:
|
// private:
|
||||||
int64 mNextFormCallbackId = 0;
|
// int64 mNextFormCallbackId = 0;
|
||||||
int64 mNextFormId = 0;
|
// int64 mNextFormId = 0;
|
||||||
std::unordered_map<int64, std::unique_ptr<gmlib::form::NpcDialogueForm>> mNpcDialogueForms;
|
// std::unordered_map<int64, std::unique_ptr<gmlib::form::NpcDialogueForm>> mNpcDialogueForms;
|
||||||
// std::unordered_map<int64, std::unique_ptr<ChestForm>> mChestForms;
|
// // std::unordered_map<int64, std::unique_ptr<ChestForm>> mChestForms;
|
||||||
|
|
||||||
public:
|
// public:
|
||||||
// std::string getNextFormCallbackId() {
|
// // std::string getNextFormCallbackId() {
|
||||||
// return "GMLIB_FormApi_" + std::to_string(mNextFormCallbackId++);
|
// // return "GMLIB_FormApi_" + std::to_string(mNextFormCallbackId++);
|
||||||
// }
|
// // }
|
||||||
|
|
||||||
int64 getNextFormId() {
|
// int64 getNextFormId() {
|
||||||
mNextFormId++;
|
// mNextFormId++;
|
||||||
return mNextFormId;
|
// return mNextFormId;
|
||||||
}
|
// }
|
||||||
|
|
||||||
int64 createNpcDialogueForm(std::string const& npcName, std::string const& sceneName, std::string const& dialogue) {
|
// int64 createNpcDialogueForm(std::string const& npcName, std::string const& sceneName, std::string const& dialogue) {
|
||||||
auto formId = LegacyScriptFormManager::getInstance().getNextFormId();
|
// auto formId = LegacyScriptFormManager::getInstance().getNextFormId();
|
||||||
auto formPtr = std::make_unique<gmlib::form::NpcDialogueForm>(npcName, sceneName, dialogue);
|
// auto formPtr = std::make_unique<gmlib::form::NpcDialogueForm>(npcName, sceneName, dialogue);
|
||||||
mNpcDialogueForms[formId] = std::move(formPtr);
|
// mNpcDialogueForms[formId] = std::move(formPtr);
|
||||||
return formId;
|
// return formId;
|
||||||
}
|
// }
|
||||||
|
|
||||||
bool destroyNpcDialogueForm(int64 formId) {
|
// bool destroyNpcDialogueForm(int64 formId) {
|
||||||
if (mNpcDialogueForms.contains(formId)) {
|
// if (mNpcDialogueForms.contains(formId)) {
|
||||||
mNpcDialogueForms.erase(formId);
|
// mNpcDialogueForms.erase(formId);
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
|
||||||
optional_ref<gmlib::form::NpcDialogueForm> getNpcDialogueForm(int64 formId) {
|
// optional_ref<gmlib::form::NpcDialogueForm> getNpcDialogueForm(int64 formId) {
|
||||||
if (mNpcDialogueForms.contains(formId)) {
|
// if (mNpcDialogueForms.contains(formId)) {
|
||||||
return mNpcDialogueForms[formId].get();
|
// return mNpcDialogueForms[formId].get();
|
||||||
}
|
// }
|
||||||
return {};
|
// return {};
|
||||||
}
|
// }
|
||||||
|
|
||||||
/*
|
// /*
|
||||||
int64 createChestForm(std::string const& npcName, std::string const& sceneName, std::string const& dialogue) {
|
// int64 createChestForm(std::string const& npcName, std::string const& sceneName, std::string const& dialogue) {
|
||||||
auto formId = LegacyScriptFormManager::getInstance().getNextFormId();
|
// auto formId = LegacyScriptFormManager::getInstance().getNextFormId();
|
||||||
auto formPtr = std::make_unique<ChestForm>(npcName, sceneName, dialogue);
|
// auto formPtr = std::make_unique<ChestForm>(npcName, sceneName, dialogue);
|
||||||
mChestForms[formId] = std::move(formPtr);
|
// mChestForms[formId] = std::move(formPtr);
|
||||||
return formId;
|
// return formId;
|
||||||
}
|
// }
|
||||||
|
|
||||||
bool destroyChestForm(int64 formId) {
|
// bool destroyChestForm(int64 formId) {
|
||||||
if (mChestForms.contains(formId)) {
|
// if (mChestForms.contains(formId)) {
|
||||||
mChestForms.erase(formId);
|
// mChestForms.erase(formId);
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
|
||||||
optional_ref<ChestForm> getChestForm(int64 formId) {
|
// optional_ref<ChestForm> getChestForm(int64 formId) {
|
||||||
if (mChestForms.contains(formId)) {
|
// if (mChestForms.contains(formId)) {
|
||||||
return mChestForms[formId].get();
|
// return mChestForms[formId].get();
|
||||||
}
|
// }
|
||||||
return {};
|
// return {};
|
||||||
}
|
// }
|
||||||
|
|
||||||
*/
|
// */
|
||||||
public:
|
// public:
|
||||||
static LegacyScriptFormManager& getInstance() {
|
// static LegacyScriptFormManager& getInstance() {
|
||||||
static std::unique_ptr<LegacyScriptFormManager> instance;
|
// static std::unique_ptr<LegacyScriptFormManager> instance;
|
||||||
if (!instance) {
|
// if (!instance) {
|
||||||
instance = std::make_unique<LegacyScriptFormManager>();
|
// instance = std::make_unique<LegacyScriptFormManager>();
|
||||||
}
|
// }
|
||||||
return *instance;
|
// return *instance;
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
|
||||||
#define PLAYER_DETECROR \
|
// #define PLAYER_DETECROR \
|
||||||
[detectorId, result](::Player& pl) -> bool { \
|
// [detectorId, result](::Player& pl) -> bool { \
|
||||||
try { \
|
// try { \
|
||||||
if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", detectorId)) { \
|
// if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", detectorId)) { \
|
||||||
auto const& detector = RemoteCall::importAs<bool(::Player*)>("GMLIB_FORM_CALLBACK", detectorId); \
|
// auto const& detector = RemoteCall::importAs<bool(::Player*)>("GMLIB_FORM_CALLBACK", detectorId); \
|
||||||
return detector(&pl); \
|
// return detector(&pl); \
|
||||||
} else { \
|
// } else { \
|
||||||
gmlib::form::ServerSettingForm::removeElement(result); \
|
// gmlib::form::ServerSettingForm::removeElement(result); \
|
||||||
} \
|
// } \
|
||||||
} catch (...) {} \
|
// } catch (...) {} \
|
||||||
return false; \
|
// return false; \
|
||||||
}
|
// }
|
||||||
|
|
||||||
#define CALLBACK_TYPE(type) \
|
// #define CALLBACK_TYPE(type) \
|
||||||
[callbackId, result](Player& pl, type data) { \
|
// [callbackId, result](Player& pl, type data) { \
|
||||||
try { \
|
// try { \
|
||||||
if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", callbackId)) { \
|
// if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", callbackId)) { \
|
||||||
auto const& callback = RemoteCall::importAs<void(Player*, type)>("GMLIB_FORM_CALLBACK", callbackId); \
|
// auto const& callback = RemoteCall::importAs<void(Player*, type)>("GMLIB_FORM_CALLBACK", callbackId); \
|
||||||
callback(&pl, data); \
|
// callback(&pl, data); \
|
||||||
} else { \
|
// } else { \
|
||||||
gmlib::form::ServerSettingForm::removeElement(result); \
|
// gmlib::form::ServerSettingForm::removeElement(result); \
|
||||||
} \
|
// } \
|
||||||
} catch (...) {} \
|
// } catch (...) {} \
|
||||||
}
|
// }
|
||||||
|
|
||||||
#define CALLBACK_TYPE_NORMAL \
|
// #define CALLBACK_TYPE_NORMAL \
|
||||||
[callbackId](::Player& pl) { \
|
// [callbackId](::Player& pl) { \
|
||||||
try { \
|
// try { \
|
||||||
if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", callbackId)) { \
|
// if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", callbackId)) { \
|
||||||
auto const& callback = RemoteCall::importAs<void(::Player*)>("GMLIB_FORM_CALLBACK", callbackId); \
|
// auto const& callback = RemoteCall::importAs<void(::Player*)>("GMLIB_FORM_CALLBACK", callbackId); \
|
||||||
callback(&pl); \
|
// callback(&pl); \
|
||||||
} \
|
// } \
|
||||||
} catch (...) {} \
|
// } catch (...) {} \
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
void Export_Form_API() {
|
// void Export_Form_API() {
|
||||||
//////////////////////////////// Form Manager /////////////////////////////////
|
// //////////////////////////////// Form Manager /////////////////////////////////
|
||||||
// RemoteCall::exportAs("GMLIB_FormAPI", "getNextFormCallbackId", []() -> std::string {
|
// // RemoteCall::exportAs("GMLIB_FormAPI", "getNextFormCallbackId", []() -> std::string {
|
||||||
// return LegacyScriptFormManager::getInstance().getNextFormCallbackId();
|
// // return LegacyScriptFormManager::getInstance().getNextFormCallbackId();
|
||||||
// });
|
// // });
|
||||||
////////////////////////////// ServerSettingForm //////////////////////////////
|
// ////////////////////////////// ServerSettingForm //////////////////////////////
|
||||||
RemoteCall::exportAs("GMLIB_ServerSettingForm", "getDefaultPriority", []() -> int {
|
// RemoteCall::exportAs("GMLIB_ServerSettingForm", "getDefaultPriority", []() -> int {
|
||||||
return gmlib::form::ServerSettingForm::getDefaultPriority();
|
// return gmlib::form::ServerSettingForm::getDefaultPriority();
|
||||||
});
|
// });
|
||||||
RemoteCall::exportAs("GMLIB_ServerSettingForm", "hasTitle", []() -> bool { return gmlib::form::ServerSettingForm::hasTitle(); });
|
// RemoteCall::exportAs("GMLIB_ServerSettingForm", "hasTitle", []() -> bool { return gmlib::form::ServerSettingForm::hasTitle(); });
|
||||||
RemoteCall::exportAs("GMLIB_ServerSettingForm", "getTitle", []() -> std::string {
|
// RemoteCall::exportAs("GMLIB_ServerSettingForm", "getTitle", []() -> std::string {
|
||||||
return gmlib::form::ServerSettingForm::getTitle();
|
// return gmlib::form::ServerSettingForm::getTitle();
|
||||||
});
|
// });
|
||||||
RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "setTitle", [](std::string const& title, bool forceModify) -> bool {
|
// RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "setTitle", [](std::string const& title, bool forceModify) -> bool {
|
||||||
return gmlib::form::ServerSettingForm::setTitle(title, forceModify);
|
// return gmlib::form::ServerSettingForm::setTitle(title, forceModify);
|
||||||
});
|
// });
|
||||||
RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "hasIcon", []() -> bool { return gmlib::form::ServerSettingForm::hasIcon(); });
|
// RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "hasIcon", []() -> bool { return gmlib::form::ServerSettingForm::hasIcon(); });
|
||||||
RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "getIconData", []() -> std::string {
|
// RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "getIconData", []() -> std::string {
|
||||||
return gmlib::form::ServerSettingForm::getIconData().value_or("");
|
// return gmlib::form::ServerSettingForm::getIconData().value_or("");
|
||||||
});
|
// });
|
||||||
RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "getIconType", []() -> int {
|
// RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "getIconType", []() -> int {
|
||||||
return gmlib::form::ServerSettingForm::getIconType()
|
// return gmlib::form::ServerSettingForm::getIconType()
|
||||||
.transform([](gmlib::form::IconType&& type) -> int { return (int)type; })
|
// .transform([](gmlib::form::IconType&& type) -> int { return (int)type; })
|
||||||
.value_or(-1);
|
// .value_or(-1);
|
||||||
});
|
// });
|
||||||
RemoteCall::exportAs(
|
// RemoteCall::exportAs(
|
||||||
"GMLIB_gmlib::form::ServerSettingForm",
|
// "GMLIB_gmlib::form::ServerSettingForm",
|
||||||
"setIcon",
|
// "setIcon",
|
||||||
[](std::string const& title, uchar type, bool forceModify) -> bool {
|
// [](std::string const& title, uchar type, bool forceModify) -> bool {
|
||||||
return gmlib::form::ServerSettingForm::setIcon(title, gmlib::form::IconType(type), forceModify);
|
// return gmlib::form::ServerSettingForm::setIcon(title, gmlib::form::IconType(type), forceModify);
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
RemoteCall::exportAs(
|
// RemoteCall::exportAs(
|
||||||
"GMLIB_gmlib::form::ServerSettingForm",
|
// "GMLIB_gmlib::form::ServerSettingForm",
|
||||||
"addLabel",
|
// "addLabel",
|
||||||
[](std::string const& text, std::string const& detectorId, int priority) -> uint {
|
// [](std::string const& text, std::string const& detectorId, int priority) -> uint {
|
||||||
uint result = gmlib::form::ServerSettingForm::addLabel(text, PLAYER_DETECROR, priority);
|
// uint result = gmlib::form::ServerSettingForm::addLabel(text, PLAYER_DETECROR, priority);
|
||||||
return result;
|
// return result;
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
RemoteCall::exportAs(
|
// RemoteCall::exportAs(
|
||||||
"GMLIB_gmlib::form::ServerSettingForm",
|
// "GMLIB_gmlib::form::ServerSettingForm",
|
||||||
"addInput",
|
// "addInput",
|
||||||
[](std::string const& text,
|
// [](std::string const& text,
|
||||||
std::string const& placeholder,
|
// std::string const& placeholder,
|
||||||
std::string const& defaultVal,
|
// std::string const& defaultVal,
|
||||||
std::string const& callbackId,
|
// std::string const& callbackId,
|
||||||
std::string const& detectorId,
|
// std::string const& detectorId,
|
||||||
int priority) -> uint {
|
// int priority) -> uint {
|
||||||
uint result = gmlib::form::ServerSettingForm::addInput(
|
// uint result = gmlib::form::ServerSettingForm::addInput(
|
||||||
text,
|
// text,
|
||||||
placeholder,
|
// placeholder,
|
||||||
defaultVal,
|
// defaultVal,
|
||||||
CALLBACK_TYPE(std::string const&),
|
// CALLBACK_TYPE(std::string const&),
|
||||||
PLAYER_DETECROR,
|
// PLAYER_DETECROR,
|
||||||
priority
|
// priority
|
||||||
);
|
// );
|
||||||
return result;
|
// return result;
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
RemoteCall::exportAs(
|
// RemoteCall::exportAs(
|
||||||
"GMLIB_gmlib::form::ServerSettingForm",
|
// "GMLIB_gmlib::form::ServerSettingForm",
|
||||||
"addToggle",
|
// "addToggle",
|
||||||
[](std::string const& text,
|
// [](std::string const& text,
|
||||||
bool defaultVal,
|
// bool defaultVal,
|
||||||
std::string const& callbackId,
|
// std::string const& callbackId,
|
||||||
std::string const& detectorId,
|
// std::string const& detectorId,
|
||||||
int priority) -> uint {
|
// int priority) -> uint {
|
||||||
uint result = gmlib::form::ServerSettingForm::addToggle(text, defaultVal, CALLBACK_TYPE(bool), PLAYER_DETECROR, priority);
|
// uint result = gmlib::form::ServerSettingForm::addToggle(text, defaultVal, CALLBACK_TYPE(bool), PLAYER_DETECROR, priority);
|
||||||
return result;
|
// return result;
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
RemoteCall::exportAs(
|
// RemoteCall::exportAs(
|
||||||
"GMLIB_gmlib::form::ServerSettingForm",
|
// "GMLIB_gmlib::form::ServerSettingForm",
|
||||||
"addDropdown",
|
// "addDropdown",
|
||||||
[](std::string const& text,
|
// [](std::string const& text,
|
||||||
std::vector<std::string> options,
|
// std::vector<std::string> options,
|
||||||
int64 defaultVal,
|
// int64 defaultVal,
|
||||||
std::string const& callbackId,
|
// std::string const& callbackId,
|
||||||
std::string const& detectorId,
|
// std::string const& detectorId,
|
||||||
int priority) -> uint {
|
// int priority) -> uint {
|
||||||
uint result = gmlib::form::ServerSettingForm::addDropdown(
|
// uint result = gmlib::form::ServerSettingForm::addDropdown(
|
||||||
text,
|
// text,
|
||||||
options,
|
// options,
|
||||||
defaultVal,
|
// defaultVal,
|
||||||
CALLBACK_TYPE(int64),
|
// CALLBACK_TYPE(int64),
|
||||||
PLAYER_DETECROR,
|
// PLAYER_DETECROR,
|
||||||
priority
|
// priority
|
||||||
);
|
// );
|
||||||
return result;
|
// return result;
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
RemoteCall::exportAs(
|
// RemoteCall::exportAs(
|
||||||
"GMLIB_gmlib::form::ServerSettingForm",
|
// "GMLIB_gmlib::form::ServerSettingForm",
|
||||||
"addSlider",
|
// "addSlider",
|
||||||
[](std::string const& text,
|
// [](std::string const& text,
|
||||||
double min,
|
// double min,
|
||||||
double max,
|
// double max,
|
||||||
double step,
|
// double step,
|
||||||
double defaultVal,
|
// double defaultVal,
|
||||||
std::string const& callbackId,
|
// std::string const& callbackId,
|
||||||
std::string const& detectorId,
|
// std::string const& detectorId,
|
||||||
int priority) -> uint {
|
// int priority) -> uint {
|
||||||
uint result = gmlib::form::ServerSettingForm::addSlider(
|
// uint result = gmlib::form::ServerSettingForm::addSlider(
|
||||||
text,
|
// text,
|
||||||
min,
|
// min,
|
||||||
max,
|
// max,
|
||||||
step,
|
// step,
|
||||||
defaultVal,
|
// defaultVal,
|
||||||
CALLBACK_TYPE(double),
|
// CALLBACK_TYPE(double),
|
||||||
PLAYER_DETECROR,
|
// PLAYER_DETECROR,
|
||||||
priority
|
// priority
|
||||||
);
|
// );
|
||||||
return result;
|
// return result;
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
RemoteCall::exportAs(
|
// RemoteCall::exportAs(
|
||||||
"GMLIB_gmlib::form::ServerSettingForm",
|
// "GMLIB_gmlib::form::ServerSettingForm",
|
||||||
"addStepSlider",
|
// "addStepSlider",
|
||||||
[](std::string const& text,
|
// [](std::string const& text,
|
||||||
std::vector<std::string> steps,
|
// std::vector<std::string> steps,
|
||||||
int64 defaultVal,
|
// int64 defaultVal,
|
||||||
std::string const& callbackId,
|
// std::string const& callbackId,
|
||||||
std::string const& detectorId,
|
// std::string const& detectorId,
|
||||||
int priority) -> uint {
|
// int priority) -> uint {
|
||||||
uint result = gmlib::form::ServerSettingForm::addStepSlider(
|
// uint result = gmlib::form::ServerSettingForm::addStepSlider(
|
||||||
text,
|
// text,
|
||||||
steps,
|
// steps,
|
||||||
defaultVal,
|
// defaultVal,
|
||||||
CALLBACK_TYPE(int64),
|
// CALLBACK_TYPE(int64),
|
||||||
PLAYER_DETECROR,
|
// PLAYER_DETECROR,
|
||||||
priority
|
// priority
|
||||||
);
|
// );
|
||||||
return result;
|
// return result;
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "removeElement", [](uint id) -> bool {
|
// RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "removeElement", [](uint id) -> bool {
|
||||||
return gmlib::form::ServerSettingForm::removeElement(id);
|
// return gmlib::form::ServerSettingForm::removeElement(id);
|
||||||
});
|
// });
|
||||||
////////////////////////////// NpcDialogueForm //////////////////////////////
|
// ////////////////////////////// NpcDialogueForm //////////////////////////////
|
||||||
RemoteCall::exportAs(
|
// RemoteCall::exportAs(
|
||||||
"GMLIB_NpcDialogueForm",
|
// "GMLIB_NpcDialogueForm",
|
||||||
"createForm",
|
// "createForm",
|
||||||
[](std::string const& npcName, std::string const& sceneName, std::string const& dialogue) -> int64 {
|
// [](std::string const& npcName, std::string const& sceneName, std::string const& dialogue) -> int64 {
|
||||||
return LegacyScriptFormManager::getInstance().createNpcDialogueForm(npcName, sceneName, dialogue);
|
// return LegacyScriptFormManager::getInstance().createNpcDialogueForm(npcName, sceneName, dialogue);
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
RemoteCall::exportAs("GMLIB_NpcDialogueForm", "destroyForm", [](int64 formId) -> bool {
|
// RemoteCall::exportAs("GMLIB_NpcDialogueForm", "destroyForm", [](int64 formId) -> bool {
|
||||||
return LegacyScriptFormManager::getInstance().destroyNpcDialogueForm(formId);
|
// return LegacyScriptFormManager::getInstance().destroyNpcDialogueForm(formId);
|
||||||
});
|
// });
|
||||||
RemoteCall::exportAs(
|
// RemoteCall::exportAs(
|
||||||
"GMLIB_NpcDialogueForm",
|
// "GMLIB_NpcDialogueForm",
|
||||||
"addButton",
|
// "addButton",
|
||||||
[](int64 formId, std::string const& button, std::string const& callbackId) -> void {
|
// [](int64 formId, std::string const& button, std::string const& callbackId) -> void {
|
||||||
if (auto formPtr = LegacyScriptFormManager::getInstance().getNpcDialogueForm(formId)) {
|
// if (auto formPtr = LegacyScriptFormManager::getInstance().getNpcDialogueForm(formId)) {
|
||||||
formPtr->addButton(button, CALLBACK_TYPE_NORMAL);
|
// formPtr->addButton(button, CALLBACK_TYPE_NORMAL);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
RemoteCall::exportAs(
|
// RemoteCall::exportAs(
|
||||||
"GMLIB_NpcDialogueForm",
|
// "GMLIB_NpcDialogueForm",
|
||||||
"onPlayerClose",
|
// "onPlayerClose",
|
||||||
[](int64 formId, std::string const& callbackId) -> void {
|
// [](int64 formId, std::string const& callbackId) -> void {
|
||||||
if (auto formPtr = LegacyScriptFormManager::getInstance().getNpcDialogueForm(formId)) {
|
// if (auto formPtr = LegacyScriptFormManager::getInstance().getNpcDialogueForm(formId)) {
|
||||||
formPtr->onPlayerClose(CALLBACK_TYPE_NORMAL);
|
// formPtr->onPlayerClose(CALLBACK_TYPE_NORMAL);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
RemoteCall::exportAs("GMLIB_NpcDialogueForm", "sendTo", [](int64 formId, ::Player* pl) -> void {
|
// RemoteCall::exportAs("GMLIB_NpcDialogueForm", "sendTo", [](int64 formId, ::Player* pl) -> void {
|
||||||
if (auto formPtr = LegacyScriptFormManager::getInstance().getNpcDialogueForm(formId)) {
|
// if (auto formPtr = LegacyScriptFormManager::getInstance().getNpcDialogueForm(formId)) {
|
||||||
formPtr->sendTo(*pl);
|
// formPtr->sendTo(*pl);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
////////////////////////////// ChestForm //////////////////////////////
|
// ////////////////////////////// ChestForm //////////////////////////////
|
||||||
}
|
// }
|
||||||
+19
-9
@@ -1,17 +1,25 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <headers/include_all.h>
|
// clang-format off
|
||||||
|
#define GMLIB_GLOBAL_USING
|
||||||
|
#include <gmlib/GlobalUsing.h>
|
||||||
|
#include <gmlib/include_all.h>
|
||||||
|
#include <ila/include_all.h>
|
||||||
#include <RemoteCallAPI.h>
|
#include <RemoteCallAPI.h>
|
||||||
|
using namespace gmlib::mod;
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
#define PLUGIN_NAME fmt::format(fg(fmt::color::light_green), "GMLIB-LRCA")
|
#define PLUGIN_NAME fmt::format(fg(fmt::color::light_green), "GMLIB-LRCA")
|
||||||
|
|
||||||
#define LIB_VERSION_MAJOR 0
|
#define LIB_VERSION_MAJOR 1
|
||||||
#define LIB_VERSION_MINOR 13
|
#define LIB_VERSION_MINOR 0
|
||||||
#define LIB_VERSION_PATCH 3
|
#define LIB_VERSION_PATCH 0
|
||||||
|
#define LIB_VERSION_PRERELEASE std::nullopt
|
||||||
|
|
||||||
#define LIB_VERSION gmlib::Version(LIB_VERSION_MAJOR, LIB_VERSION_MINOR, LIB_VERSION_PATCH)
|
#ifdef LIB_VERSION_PRERELEASE
|
||||||
|
#define LIB_VERSION ll::data::Version(LIB_VERSION_MAJOR, LIB_VERSION_MINOR, LIB_VERSION_PATCH, LIB_VERSION_PRERELEASE)
|
||||||
extern ll::Logger logger;
|
#else
|
||||||
|
#define LIB_VERSION ll::data::Version(LIB_VERSION_MAJOR, LIB_VERSION_MINOR, LIB_VERSION_PATCH)
|
||||||
|
#endif
|
||||||
|
|
||||||
extern void Export_Legacy_GMLib_ModAPI();
|
extern void Export_Legacy_GMLib_ModAPI();
|
||||||
extern void Export_Legacy_GMLib_ServerAPI();
|
extern void Export_Legacy_GMLib_ServerAPI();
|
||||||
@@ -19,4 +27,6 @@ extern void Export_Compatibility_API();
|
|||||||
extern void ExportPAPI();
|
extern void ExportPAPI();
|
||||||
extern void Export_Event_API();
|
extern void Export_Event_API();
|
||||||
extern void Export_BinaryStream_API();
|
extern void Export_BinaryStream_API();
|
||||||
extern void Export_Form_API();
|
extern ll::thread::ThreadPoolExecutor const& getThreadPoolExecutor();
|
||||||
|
extern ll::io::Logger& getLogger();
|
||||||
|
// extern void Export_Form_API();
|
||||||
+59
-82
@@ -1,10 +1,10 @@
|
|||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
|
||||||
std::unordered_set<std::string> HardCodedKeys = {"AlwaysUnlocked", "PlayerHasManyItems", "PlayerInWater", "None"};
|
ICustomRecipe::UnlockingRequirement makeRecipeUnlockingKey(std::string const& key) {
|
||||||
|
if (auto context = magic_enum::enum_cast<RecipeUnlockingContext>(key)) {
|
||||||
std::variant<std::string, std::vector<RecipeIngredient>> makeRecipeUnlockingKey(std::string const& key) {
|
return ICustomRecipe::UnlockingRequirement(*context);
|
||||||
if (HardCodedKeys.count(key)) return key;
|
}
|
||||||
return std::vector<RecipeIngredient>({RecipeIngredient(key, 0, 1)});
|
return ICustomRecipe::UnlockingRequirement({ICustomRecipe::Ingredient(key)});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Export_Legacy_GMLib_ModAPI() {
|
void Export_Legacy_GMLib_ModAPI() {
|
||||||
@@ -17,17 +17,13 @@ void Export_Legacy_GMLib_ModAPI() {
|
|||||||
std::string const& result,
|
std::string const& result,
|
||||||
int count,
|
int count,
|
||||||
std::string const& unlock) -> void {
|
std::string const& unlock) -> void {
|
||||||
if (!gmlib::world::Level::getInstance().has_value()) return;
|
if (!GMLevel::getInstance().has_value()) return;
|
||||||
std::vector<RecipeIngredient> types;
|
std::vector<ICustomRecipe::Ingredient> types;
|
||||||
for (auto ing : ingredients) {
|
for (auto& ing : ingredients) {
|
||||||
types.emplace_back(ing, 0, 1);
|
types.emplace_back(ICustomRecipe::Ingredient{ing, 1});
|
||||||
}
|
}
|
||||||
gmlib::mod::recipe::JsonRecipeRegistry::registerShapelessCraftingTableRecipe(
|
CustomRecipeRegistry::getInstance()
|
||||||
recipe_id,
|
.registerShapelessRecipe(recipe_id, types, ItemInstance(result, count), makeRecipeUnlockingKey(unlock));
|
||||||
types,
|
|
||||||
RecipeIngredient(result, 0, count),
|
|
||||||
makeRecipeUnlockingKey(unlock)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
@@ -39,16 +35,17 @@ void Export_Legacy_GMLib_ModAPI() {
|
|||||||
std::string const& result,
|
std::string const& result,
|
||||||
int count,
|
int count,
|
||||||
std::string const& unlock) -> void {
|
std::string const& unlock) -> void {
|
||||||
if (!gmlib::world::Level::getInstance().has_value()) return;
|
if (!GMLevel::getInstance().has_value()) return;
|
||||||
std::vector<RecipeIngredient> types;
|
ICustomShapedRecipe::ShapedIngredients types;
|
||||||
for (auto ing : ingredients) {
|
char index = 'A';
|
||||||
types.push_back(RecipeIngredient(ing, 0, 1));
|
for (auto& ing : ingredients) {
|
||||||
|
types.add(std::string(1, index++), ICustomRecipe::Ingredient{ing});
|
||||||
}
|
}
|
||||||
gmlib::mod::recipe::JsonRecipeRegistry::registerShapedCraftingTableRecipe(
|
CustomRecipeRegistry::getInstance().registerShapedRecipe(
|
||||||
recipe_id,
|
recipe_id,
|
||||||
shape,
|
shape,
|
||||||
types,
|
types,
|
||||||
RecipeIngredient(result, 0, count),
|
ItemInstance(result, count),
|
||||||
makeRecipeUnlockingKey(unlock)
|
makeRecipeUnlockingKey(unlock)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -60,13 +57,9 @@ void Export_Legacy_GMLib_ModAPI() {
|
|||||||
std::string const& input,
|
std::string const& input,
|
||||||
std::string const& output,
|
std::string const& output,
|
||||||
std::vector<std::string> tags) -> void {
|
std::vector<std::string> tags) -> void {
|
||||||
if (!gmlib::world::Level::getInstance().has_value()) return;
|
if (!GMLevel::getInstance().has_value()) return;
|
||||||
gmlib::mod::recipe::JsonRecipeRegistry::registerFurnaceRecipe(
|
CustomRecipeRegistry::getInstance()
|
||||||
recipe_id,
|
.registerFurnaceRecipe(ICustomRecipe::Ingredient{input}, ItemInstance{output}, tags);
|
||||||
RecipeIngredient(input, 0, 1),
|
|
||||||
RecipeIngredient(output, 0, 1),
|
|
||||||
tags
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
@@ -74,12 +67,11 @@ void Export_Legacy_GMLib_ModAPI() {
|
|||||||
"registerBrewingMixRecipe",
|
"registerBrewingMixRecipe",
|
||||||
[](std::string const& recipe_id, std::string const& input, std::string const& output, std::string const& reagent
|
[](std::string const& recipe_id, std::string const& input, std::string const& output, std::string const& reagent
|
||||||
) -> void {
|
) -> void {
|
||||||
if (!gmlib::world::Level::getInstance().has_value()) return;
|
if (!GMLevel::getInstance().has_value()) return;
|
||||||
gmlib::mod::recipe::JsonRecipeRegistry::registerBrewingMixRecipe(
|
CustomRecipeRegistry::getInstance().registerBrewingRecipe(
|
||||||
recipe_id,
|
ICustomRecipe::Ingredient{input},
|
||||||
input,
|
ICustomRecipe::Ingredient{reagent},
|
||||||
output,
|
ICustomRecipe::Ingredient{output}
|
||||||
RecipeIngredient(reagent, 0, 1)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -88,12 +80,11 @@ void Export_Legacy_GMLib_ModAPI() {
|
|||||||
"registerBrewingContainerRecipe",
|
"registerBrewingContainerRecipe",
|
||||||
[](std::string const& recipe_id, std::string const& input, std::string const& output, std::string const& reagent
|
[](std::string const& recipe_id, std::string const& input, std::string const& output, std::string const& reagent
|
||||||
) -> void {
|
) -> void {
|
||||||
if (!gmlib::world::Level::getInstance().has_value()) return;
|
if (!GMLevel::getInstance().has_value()) return;
|
||||||
gmlib::mod::recipe::JsonRecipeRegistry::registerBrewingContainerRecipe(
|
CustomRecipeRegistry::getInstance().registerBrewingRecipe(
|
||||||
recipe_id,
|
ICustomRecipe::Ingredient{input},
|
||||||
RecipeIngredient(input, 0, 1),
|
ICustomRecipe::Ingredient{reagent},
|
||||||
RecipeIngredient(output, 0, 1),
|
ICustomRecipe::Ingredient{output}
|
||||||
RecipeIngredient(reagent, 0, 1)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -105,13 +96,13 @@ void Export_Legacy_GMLib_ModAPI() {
|
|||||||
std::string const& base,
|
std::string const& base,
|
||||||
std::string const& addition,
|
std::string const& addition,
|
||||||
std::string const& result) -> void {
|
std::string const& result) -> void {
|
||||||
if (!gmlib::world::Level::getInstance().has_value()) return;
|
if (!GMLevel::getInstance().has_value()) return;
|
||||||
gmlib::mod::recipe::JsonRecipeRegistry::registerSmithingTransformRecipe(
|
CustomRecipeRegistry::getInstance().registerSmithingTransformRecipe(
|
||||||
recipe_id,
|
recipe_id,
|
||||||
smithing_template,
|
ICustomRecipe::Ingredient{smithing_template},
|
||||||
base,
|
ICustomRecipe::Ingredient{base},
|
||||||
addition,
|
ICustomRecipe::Ingredient{addition},
|
||||||
result
|
ItemInstance{result}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -122,12 +113,12 @@ void Export_Legacy_GMLib_ModAPI() {
|
|||||||
std::string const& smithing_template,
|
std::string const& smithing_template,
|
||||||
std::string const& base,
|
std::string const& base,
|
||||||
std::string const& addition) -> void {
|
std::string const& addition) -> void {
|
||||||
if (!gmlib::world::Level::getInstance().has_value()) return;
|
if (!GMLevel::getInstance().has_value()) return;
|
||||||
gmlib::mod::recipe::JsonRecipeRegistry::registerSmithingTrimRecipe(
|
CustomRecipeRegistry::getInstance().registerSmithingTrimRecipe(
|
||||||
recipe_id,
|
recipe_id,
|
||||||
smithing_template,
|
ICustomRecipe::Ingredient{smithing_template},
|
||||||
base,
|
ICustomRecipe::Ingredient{base},
|
||||||
addition
|
ICustomRecipe::Ingredient{addition}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -140,49 +131,35 @@ void Export_Legacy_GMLib_ModAPI() {
|
|||||||
std::string const& output,
|
std::string const& output,
|
||||||
int output_data,
|
int output_data,
|
||||||
int output_count) -> void {
|
int output_count) -> void {
|
||||||
if (!gmlib::world::Level::getInstance().has_value()) return;
|
if (!GMLevel::getInstance().has_value()) return;
|
||||||
gmlib::mod::recipe::JsonRecipeRegistry::registerStoneCutterRecipe(
|
CustomRecipeRegistry::getInstance().registerStoneCutterRecipe(
|
||||||
recipe_id,
|
recipe_id,
|
||||||
RecipeIngredient(input, 0, 1),
|
ICustomRecipe::Ingredient{input, 1, input_data},
|
||||||
RecipeIngredient(output, 0, 1)
|
{output, output_count, output_data}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
// 错误方块清理
|
// 错误方块清理
|
||||||
RemoteCall::exportAs("GMLib_ModAPI", "setUnknownBlockCleaner", []() -> void {
|
RemoteCall::exportAs("GMLib_ModAPI", "setUnknownBlockCleaner", []() -> void {
|
||||||
gmlib::tools::VanillaFix::setAutoCleanUnknownBlockEnabled();
|
getLogger().error("setUnknownBlockCleaner is not implemented");
|
||||||
});
|
});
|
||||||
// 实验性
|
// 实验性
|
||||||
RemoteCall::exportAs("GMLib_ModAPI", "registerExperimentsRequire", [](int experiment_id) -> void {
|
RemoteCall::exportAs("GMLib_ModAPI", "registerExperimentsRequire", [](int experiment_id) -> void {
|
||||||
auto list = gmlib::world::Level::getAllExperiments();
|
GMLevel::getInstance().and_then([&](GMLevel& level) {
|
||||||
std::unordered_set<AllExperiments> set(list.begin(), list.end());
|
level.setExperimentEnabled((AllExperiments)experiment_id);
|
||||||
if (set.contains((AllExperiments)experiment_id)) {
|
return true;
|
||||||
gmlib::world::Level::addExperimentsRequire((AllExperiments)experiment_id);
|
});
|
||||||
} else {
|
|
||||||
ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLib_ModAPI", "setExperimentEnabled", [](int experiment_id, bool value) -> void {
|
RemoteCall::exportAs("GMLib_ModAPI", "setExperimentEnabled", [](int experiment_id, bool value) -> void {
|
||||||
if (gmlib::world::Level::getInstance()) {
|
GMLevel::getInstance().and_then([&](GMLevel& level) {
|
||||||
auto list = gmlib::world::Level::getAllExperiments();
|
level.setExperimentEnabled((AllExperiments)experiment_id, value);
|
||||||
std::unordered_set<AllExperiments> set(list.begin(), list.end());
|
return true;
|
||||||
if (set.contains((AllExperiments)experiment_id)) {
|
});
|
||||||
gmlib::world::Level::getInstance()->setExperimentEnabled(((AllExperiments)experiment_id), value);
|
|
||||||
} else ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLib_ModAPI", "getExperimentEnabled", [](int experiment_id) -> bool {
|
RemoteCall::exportAs("GMLib_ModAPI", "getExperimentEnabled", [](int experiment_id) -> bool {
|
||||||
if (gmlib::world::Level::getInstance()) {
|
return GMLevel::getInstance()
|
||||||
auto list = gmlib::world::Level::getAllExperiments();
|
.transform([&](GMLevel& level) { return level.getExperimentEnabled((AllExperiments)experiment_id); })
|
||||||
std::unordered_set<AllExperiments> set(list.begin(), list.end());
|
.value_or(false);
|
||||||
if (set.contains((AllExperiments)experiment_id)) {
|
|
||||||
return gmlib::world::Level::getInstance()->getExperimentEnabled(((AllExperiments)experiment_id));
|
|
||||||
}
|
|
||||||
ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
RemoteCall::exportAs("GMLib_ModAPI", "setFixI18nEnabled", []() -> void {
|
|
||||||
gmlib::tools::VanillaFix::setFixI18nEnabled();
|
|
||||||
});
|
});
|
||||||
|
RemoteCall::exportAs("GMLib_ModAPI", "setFixI18nEnabled", []() -> void {});
|
||||||
}
|
}
|
||||||
+28
-25
@@ -2,59 +2,62 @@
|
|||||||
|
|
||||||
void Export_Legacy_GMLib_ServerAPI() {
|
void Export_Legacy_GMLib_ServerAPI() {
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "setEducationFeatureEnabled", []() -> void {
|
RemoteCall::exportAs("GMLib_ServerAPI", "setEducationFeatureEnabled", []() -> void {
|
||||||
gmlib::world::Level::tryEnableEducationEdition();
|
getLogger().error("GMLib_ServerAPI::setEducationFeatureEnabled is not implemented");
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "registerAbilityCommand", []() -> void {
|
RemoteCall::exportAs("GMLib_ServerAPI", "registerAbilityCommand", []() -> void {
|
||||||
gmlib::world::Level::tryRegisterAbilityCommand();
|
getLogger().error("GMLib_ServerAPI::registerAbilityCommand is not implemented");
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "setEnableAchievement", []() -> void {
|
RemoteCall::exportAs("GMLib_ServerAPI", "setEnableAchievement", []() -> void {
|
||||||
gmlib::world::Level::setForceAchievementsEnabled();
|
getLogger().error("GMLib_ServerAPI::setEnableAchievement is not implemented");
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "setForceTrustSkins", []() -> void {
|
RemoteCall::exportAs("GMLib_ServerAPI", "setForceTrustSkins", []() -> void {
|
||||||
gmlib::world::Level::trustAllSkins();
|
getLogger().error("GMLib_ServerAPI::setForceTrustSkins is not implemented");
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "enableCoResourcePack", []() -> void {
|
RemoteCall::exportAs("GMLib_ServerAPI", "enableCoResourcePack", []() -> void {
|
||||||
gmlib::world::Level::requireServerResourcePackAndAllowClientResourcePack();
|
getLogger().error("GMLib_ServerAPI::enableCoResourcePack is not implemented");
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "getLevelName", []() -> std::string {
|
RemoteCall::exportAs("GMLib_ServerAPI", "getLevelName", []() -> std::string {
|
||||||
return gmlib::world::Level::getInstance()
|
return GMLevel::getInstance().transform(
|
||||||
.transform([](gmlib::world::Level& level) -> std::string { return level.getLevelName(); })
|
[](GMLevel& level) -> std::string { return level.getLevelName(); }
|
||||||
.value_or("");
|
).value_or("");
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "setLevelName", [](std::string const& name) -> void {
|
RemoteCall::exportAs("GMLib_ServerAPI", "setLevelName", [](std::string const& name) -> void {
|
||||||
if (auto level = gmlib::world::Level::getInstance()) {
|
if (auto level = GMLevel::getInstance()) {
|
||||||
level->setLevelName(name);
|
level->setLevelName(name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "getLevelSeed", []() -> std::string {
|
RemoteCall::exportAs("GMLib_ServerAPI", "getLevelSeed", []() -> std::string {
|
||||||
return gmlib::world::Level::getInstance()
|
return GMLevel::getInstance()
|
||||||
.transform([](gmlib::world::Level& level) -> std::string { return std::to_string(level.getSeed()); })
|
.transform([](GMLevel& level) -> std::string { return std::to_string(level.getSeed()); })
|
||||||
.value_or("");
|
.value_or("");
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "setFakeSeed", [](int64_t seed) -> void {
|
RemoteCall::exportAs("GMLib_ServerAPI", "setFakeSeed", [](int64_t seed) -> void {
|
||||||
return gmlib::world::Level::setFakeSeed(seed);
|
getLogger().error("GMLib_ServerAPI::setFakeSeed is not implemented");
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
"GMLib_ServerAPI",
|
"GMLib_ServerAPI",
|
||||||
"spawnEntity",
|
"spawnEntity",
|
||||||
[](std::pair<Vec3, int> pos, std::string const& name) -> Actor* {
|
[](std::pair<Vec3, int> pos, std::string const& name) -> Actor* {
|
||||||
return gmlib::world::Spawner::spawnEntity(pos.first, pos.second, name).as_ptr();
|
return GMSpawner::spawnEntity(pos.first, pos.second, name).as_ptr();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
"GMLib_ServerAPI",
|
"GMLib_ServerAPI",
|
||||||
"shootProjectile",
|
"shootProjectile",
|
||||||
[](Actor* owner, std::string const& name, float speed, float offset) -> Actor* {
|
[](Actor* owner, std::string const& name, float speed, float offset) -> Actor* {
|
||||||
auto ac = (gmlib::world::Actor*)owner;
|
auto actor = GMSpawner::spawnEntity(owner->getPosition(), owner->getDimensionId(), name);
|
||||||
return ac->shootProjectile(name, speed, offset).as_ptr();
|
if (!actor) return nullptr;
|
||||||
|
((GMActor*)owner)->setProjectile((GMActor&)*actor, speed, offset);
|
||||||
|
return actor.as_ptr();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
"GMLib_ServerAPI",
|
"GMLib_ServerAPI",
|
||||||
"throwEntity",
|
"throwEntity",
|
||||||
[](Actor* owner, Actor* actor, float speed, float offset) -> bool {
|
[](Actor* owner, Actor* actor, float speed, float offset) -> bool {
|
||||||
auto ac = (gmlib::world::Actor*)owner;
|
auto ac = (GMActor*)owner;
|
||||||
return ac->throwEntity(*actor, speed, offset);
|
ac->setProjectile((GMActor&)*actor, speed, offset);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "PlayerToEntity", [](Player* player) -> Actor* { return (Actor*)player; });
|
RemoteCall::exportAs("GMLib_ServerAPI", "PlayerToEntity", [](Player* player) -> Actor* { return (Actor*)player; });
|
||||||
@@ -62,18 +65,18 @@ void Export_Legacy_GMLib_ServerAPI() {
|
|||||||
"GMLib_ServerAPI",
|
"GMLib_ServerAPI",
|
||||||
"addFakeList",
|
"addFakeList",
|
||||||
[](const std::string& name, const std::string& xuid) -> bool {
|
[](const std::string& name, const std::string& xuid) -> bool {
|
||||||
return gmlib::tools::FakeList::addFakeList(name, xuid, ActorUniqueID(-1));
|
PlayerListAPI::push_back(name, xuid);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "removeFakeList", [](const std::string& nameOrXuid) -> bool {
|
RemoteCall::exportAs("GMLib_ServerAPI", "removeFakeList", [](const std::string& nameOrXuid) -> bool {
|
||||||
return gmlib::tools::FakeList::removeFakeList(nameOrXuid);
|
PlayerListAPI::erase(nameOrXuid);
|
||||||
});
|
return true;
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "removeAllFakeList", []() -> void {
|
|
||||||
return gmlib::tools::FakeList::removeAllFakeLists();
|
|
||||||
});
|
});
|
||||||
|
RemoteCall::exportAs("GMLib_ServerAPI", "removeAllFakeList", []() -> void { PlayerListAPI::clear(); });
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "getMaxPlayers", []() -> int {
|
RemoteCall::exportAs("GMLib_ServerAPI", "getMaxPlayers", []() -> int {
|
||||||
return gmlib::world::Level::getInstance()
|
return GMLevel::getInstance().transform(
|
||||||
.transform([](gmlib::world::Level& level) -> int { return level.getMaxPlayerCount(); })
|
[](GMLevel& level) -> int { return level.getMaxPlayerCount(); }
|
||||||
.value_or(0);
|
).value_or(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+153
-69
@@ -2,122 +2,198 @@
|
|||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
namespace PAPIRemoteCall {
|
namespace PAPIRemoteCall {
|
||||||
|
std::string GetValue(std::string const& from) { return PlaceholderAPI::getValue(from, std::nullopt).value_or(""); }
|
||||||
std::string removeBrackets(std::string a1) {
|
|
||||||
a1.erase(a1.find_last_not_of("%") + 1);
|
|
||||||
return a1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isParameters(std::string const& str) {
|
|
||||||
std::regex reg("[<]([^<>]+)[>]");
|
|
||||||
return std::regex_search(removeBrackets(str), reg);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string GetValue(std::string const& from) { return gmlib::tools::PlaceholderAPI::getValue(from); }
|
|
||||||
|
|
||||||
std::string GetValueWithPlayer(std::string const& key, Player* player) {
|
std::string GetValueWithPlayer(std::string const& key, Player* player) {
|
||||||
return gmlib::tools::PlaceholderAPI::getValue(key, player);
|
return PlaceholderAPI::getValue(key, (GMActor*)player).value_or("");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool registerPlayerPlaceholder(
|
void registerPlayerPlaceholder(
|
||||||
std::string const& PluginName,
|
std::string const& PluginName,
|
||||||
std::string const& FuncName,
|
std::string const& FuncName,
|
||||||
std::string const& PAPIName
|
std::string const& PAPIName
|
||||||
) {
|
) {
|
||||||
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
if (!RemoteCall::hasFunc(PluginName, FuncName)) return;
|
||||||
gmlib::tools::PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
auto func = [=]() -> void {
|
||||||
if (isParameters(PAPIName)) {
|
PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
||||||
auto Call = RemoteCall::importAs<std::string(Player * pl, std::unordered_map<std::string, std::string>)>(
|
std::weak_ptr mod = ll::mod::ModManagerRegistry::getInstance().getMod(PluginName);
|
||||||
|
if (mod.expired()) return;
|
||||||
|
PlaceholderAPI::registerPlaceholder(
|
||||||
|
PAPIName,
|
||||||
|
[Call = RemoteCall::importAs<std::string(Player * pl, std::unordered_map<std::string, std::string>)>(
|
||||||
PluginName,
|
PluginName,
|
||||||
FuncName
|
FuncName
|
||||||
|
)](optional_ref<Actor> actor, ll::StringMap<std::string> const& params, auto&&...
|
||||||
|
) -> std::optional<std::string> {
|
||||||
|
if (actor.has_value() && ((Actor*)actor.as_ptr())->isPlayer()) {
|
||||||
|
std::unordered_map<std::string, std::string> paramMap;
|
||||||
|
for (auto& [key, val] : params) {
|
||||||
|
paramMap[key] = val;
|
||||||
|
}
|
||||||
|
return Call((Player*)actor.as_ptr(), paramMap);
|
||||||
|
}
|
||||||
|
return std::nullopt;
|
||||||
|
},
|
||||||
|
mod
|
||||||
);
|
);
|
||||||
gmlib::tools::PlaceholderAPI::registerPlayerPlaceholder(
|
};
|
||||||
PAPIName,
|
if (ll::mod::ModManagerRegistry::getInstance().hasMod(PluginName)) {
|
||||||
[Call](Player* sp, std::unordered_map<std::string, std::string> map) { return Call(sp, map); },
|
func();
|
||||||
PluginName
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
auto Call = RemoteCall::importAs<std::string(Player * pl)>(PluginName, FuncName);
|
getThreadPoolExecutor().execute(func);
|
||||||
gmlib::tools::PlaceholderAPI::registerPlayerPlaceholder(
|
|
||||||
PAPIName,
|
|
||||||
[Call](Player* sp) { return Call(sp); },
|
|
||||||
PluginName
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool registerServerPlaceholder(
|
void registerServerPlaceholder(
|
||||||
std::string const& PluginName,
|
std::string const& PluginName,
|
||||||
std::string const& FuncName,
|
std::string const& FuncName,
|
||||||
std::string const& PAPIName
|
std::string const& PAPIName
|
||||||
) {
|
) {
|
||||||
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
if (!RemoteCall::hasFunc(PluginName, FuncName)) return;
|
||||||
gmlib::tools::PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
auto func = [=]() -> void {
|
||||||
if (isParameters(PAPIName)) {
|
PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
||||||
auto Call =
|
std::weak_ptr mod = ll::mod::ModManagerRegistry::getInstance().getMod(PluginName);
|
||||||
RemoteCall::importAs<std::string(std::unordered_map<std::string, std::string>)>(PluginName, FuncName);
|
if (mod.expired()) return;
|
||||||
gmlib::tools::PlaceholderAPI::registerServerPlaceholder(
|
PlaceholderAPI::registerPlaceholder(
|
||||||
PAPIName,
|
PAPIName,
|
||||||
[Call](std::unordered_map<std::string, std::string> map) { return Call(map); },
|
[Call = RemoteCall::importAs<std::string(std::unordered_map<std::string, std::string>)>(
|
||||||
PluginName
|
PluginName,
|
||||||
|
FuncName
|
||||||
|
)](auto, ll::StringMap<std::string> const& params, auto&&...) -> std::optional<std::string> {
|
||||||
|
std::unordered_map<std::string, std::string> paramMap;
|
||||||
|
for (auto& [key, val] : params) {
|
||||||
|
paramMap[key] = val;
|
||||||
|
}
|
||||||
|
return Call(paramMap);
|
||||||
|
},
|
||||||
|
mod
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
if (ll::mod::ModManagerRegistry::getInstance().hasMod(PluginName)) {
|
||||||
|
func();
|
||||||
} else {
|
} else {
|
||||||
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
|
getThreadPoolExecutor().execute(func);
|
||||||
gmlib::tools::PlaceholderAPI::registerServerPlaceholder(PAPIName, [Call]() { return Call(); }, PluginName);
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool registerStaticPlaceholder(
|
void registerStaticPlaceholder(
|
||||||
std::string const& PluginName,
|
std::string const& PluginName,
|
||||||
std::string const& FuncName,
|
std::string const& FuncName,
|
||||||
std::string const& PAPIName,
|
std::string const& PAPIName,
|
||||||
int num
|
int num
|
||||||
) {
|
) {
|
||||||
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
if (!RemoteCall::hasFunc(PluginName, FuncName)) return;
|
||||||
gmlib::tools::PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
auto func = [=]() -> void {
|
||||||
if (isParameters(PAPIName)) {
|
PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
||||||
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
|
std::weak_ptr mod = ll::mod::ModManagerRegistry::getInstance().getMod(PluginName);
|
||||||
if (num == -1) {
|
if (mod.expired()) return;
|
||||||
gmlib::tools::PlaceholderAPI::registerStaticPlaceholder(
|
PlaceholderAPI::registerPlaceholder(
|
||||||
PAPIName,
|
PAPIName,
|
||||||
[Call] { return Call(); },
|
[Call = RemoteCall::importAs<std::string()>(PluginName, FuncName)](auto&&...)
|
||||||
PluginName
|
-> std::optional<std::string> { return Call(); },
|
||||||
|
mod
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
if (ll::mod::ModManagerRegistry::getInstance().hasMod(PluginName)) {
|
||||||
|
func();
|
||||||
} else {
|
} else {
|
||||||
gmlib::tools::PlaceholderAPI::registerStaticPlaceholder(
|
getThreadPoolExecutor().execute(func);
|
||||||
PAPIName,
|
|
||||||
num,
|
|
||||||
[Call] { return Call(); },
|
|
||||||
PluginName
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string translateStringWithPlayer(std::string const& str, Player* pl) {
|
std::string translateStringWithPlayer(std::string const& str, Player* pl) {
|
||||||
return gmlib::tools::PlaceholderAPI::translateString(str, pl);
|
return PlaceholderAPI::translate(str, (GMActor*)pl);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string translateString(std::string const& str) { return gmlib::tools::PlaceholderAPI::translateString(str); }
|
std::string translateString(std::string const& str) { return PlaceholderAPI::translate(str, std::nullopt); }
|
||||||
|
|
||||||
bool unRegisterPlaceholder(std::string const& str) { return gmlib::tools::PlaceholderAPI::unregisterPlaceholder(str); }
|
bool unRegisterPlaceholder(std::string const& str) { return PlaceholderAPI::unregisterPlaceholder(str); }
|
||||||
|
|
||||||
std::vector<std::string> getAllPAPI() { return gmlib::tools::PlaceholderAPI::getAllPAPI(); }
|
std::vector<std::string> getAllPAPI() {
|
||||||
|
std::vector<std::string> result;
|
||||||
|
for (auto& papi : PlaceholderAPI::getAllPlaceholderData()) {
|
||||||
|
result.push_back(papi.first);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace PAPIRemoteCall
|
} // namespace PAPIRemoteCall
|
||||||
|
|
||||||
|
namespace NewPapiRemoteCall {
|
||||||
|
std::string translate(std::string const& value, std::string const& language) {
|
||||||
|
return PlaceholderAPI::translate(value, std::nullopt, language);
|
||||||
|
}
|
||||||
|
std::string translateFromActor(std::string const& value, Actor* actor, std::string const& language) {
|
||||||
|
return PlaceholderAPI::translate(value, (GMActor*)actor, language);
|
||||||
|
}
|
||||||
|
void registerPlaceholder(std::string const& placeholder, std::string const& funcName, std::string const& pluginName) {
|
||||||
|
if (!RemoteCall::hasFunc(pluginName, funcName)) return;
|
||||||
|
auto func = [=]() -> void {
|
||||||
|
if (std::weak_ptr mod = ll::mod::ModManagerRegistry::getInstance().getMod(pluginName); !mod.expired()) {
|
||||||
|
PlaceholderAPI::unregisterPlaceholder(placeholder);
|
||||||
|
PlaceholderAPI::registerPlaceholder(
|
||||||
|
placeholder,
|
||||||
|
[Call = RemoteCall::importAs<
|
||||||
|
std::string(Actor*, std::unordered_map<std::string, std::string>, std::string)>(
|
||||||
|
pluginName,
|
||||||
|
funcName
|
||||||
|
)](optional_ref<Actor> actor, ll::StringMap<std::string> const& params, std::string const& language
|
||||||
|
) -> std::optional<std::string> {
|
||||||
|
std::unordered_map<std::string, std::string> paramMap;
|
||||||
|
for (auto& [key, val] : params) {
|
||||||
|
paramMap[key] = val;
|
||||||
|
}
|
||||||
|
auto result = Call((Actor*)actor.as_ptr(), paramMap, language);
|
||||||
|
return result == "<std::nullopt>" ? std::nullopt : std::optional(result);
|
||||||
|
},
|
||||||
|
mod
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (ll::mod::ModManagerRegistry::getInstance().hasMod(pluginName)) {
|
||||||
|
func();
|
||||||
|
} else {
|
||||||
|
getThreadPoolExecutor().execute(func);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool unregisterPlaceholder(std::string const& placeholder) {
|
||||||
|
return PlaceholderAPI::unregisterPlaceholder(placeholder);
|
||||||
|
}
|
||||||
|
bool unregisterPlaceholderFromModName(std::string const& pluginName) {
|
||||||
|
std::weak_ptr plugin = ll::mod::ModManagerRegistry::getInstance().getMod(pluginName);
|
||||||
|
if (plugin.expired()) return false;
|
||||||
|
return PlaceholderAPI::unregisterPlaceholder(plugin);
|
||||||
|
}
|
||||||
|
std::string getValue(
|
||||||
|
std::string const& placeholder,
|
||||||
|
std::unordered_map<std::string, std::string> params,
|
||||||
|
std::string const& language
|
||||||
|
) {
|
||||||
|
ll::StringMap<std::string> paramMap;
|
||||||
|
for (auto& [key, val] : params) {
|
||||||
|
paramMap[key] = val;
|
||||||
|
}
|
||||||
|
return PlaceholderAPI::getValue(placeholder, std::nullopt, paramMap, language).value_or("<std::nullopt>");
|
||||||
|
}
|
||||||
|
std::string getValueFromActor(
|
||||||
|
std::string const& placeholder,
|
||||||
|
Actor* actor,
|
||||||
|
std::unordered_map<std::string, std::string> params,
|
||||||
|
std::string const& language
|
||||||
|
) {
|
||||||
|
ll::StringMap<std::string> paramMap;
|
||||||
|
for (auto& [key, val] : params) {
|
||||||
|
paramMap[key] = val;
|
||||||
|
}
|
||||||
|
return PlaceholderAPI::getValue(placeholder, (GMActor*)actor, paramMap, language).value_or("<std::nullopt>");
|
||||||
|
}
|
||||||
|
} // namespace NewPapiRemoteCall
|
||||||
|
|
||||||
#define EXPORTAPI(T) \
|
#define EXPORTAPI(T) \
|
||||||
RemoteCall::exportAs("BEPlaceholderAPI", ll::utils::string_utils::replaceAll(#T, "PAPIRemoteCall::", ""), T);
|
RemoteCall::exportAs("BEPlaceholderAPI", ll::utils::string_utils::replaceAll(#T, "PAPIRemoteCall::", ""), T);
|
||||||
|
|
||||||
|
#define EXPORTAPI2(T) RemoteCall::exportAs("PlaceholderAPI", #T, NewPapiRemoteCall::T);
|
||||||
|
|
||||||
void ExportPAPI() {
|
void ExportPAPI() {
|
||||||
EXPORTAPI(PAPIRemoteCall::registerPlayerPlaceholder);
|
EXPORTAPI(PAPIRemoteCall::registerPlayerPlaceholder);
|
||||||
EXPORTAPI(PAPIRemoteCall::registerServerPlaceholder);
|
EXPORTAPI(PAPIRemoteCall::registerServerPlaceholder);
|
||||||
@@ -128,4 +204,12 @@ void ExportPAPI() {
|
|||||||
EXPORTAPI(PAPIRemoteCall::translateStringWithPlayer);
|
EXPORTAPI(PAPIRemoteCall::translateStringWithPlayer);
|
||||||
EXPORTAPI(PAPIRemoteCall::unRegisterPlaceholder);
|
EXPORTAPI(PAPIRemoteCall::unRegisterPlaceholder);
|
||||||
EXPORTAPI(PAPIRemoteCall::getAllPAPI);
|
EXPORTAPI(PAPIRemoteCall::getAllPAPI);
|
||||||
|
|
||||||
|
EXPORTAPI2(translate);
|
||||||
|
EXPORTAPI2(translateFromActor);
|
||||||
|
EXPORTAPI2(registerPlaceholder);
|
||||||
|
EXPORTAPI2(unregisterPlaceholder);
|
||||||
|
EXPORTAPI2(unregisterPlaceholderFromModName);
|
||||||
|
EXPORTAPI2(getValue);
|
||||||
|
EXPORTAPI2(getValueFromActor);
|
||||||
}
|
}
|
||||||
+31
-14
@@ -1,29 +1,46 @@
|
|||||||
{
|
{
|
||||||
"format_version": 2,
|
"format_version": 3,
|
||||||
|
"format_uuid": "289f771f-2c9a-4d73-9f3f-8492495a924d",
|
||||||
"tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi",
|
"tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi",
|
||||||
"version": "0.13.3",
|
"version": "1.2.0",
|
||||||
"info": {
|
"info": {
|
||||||
"name": "GMLIB-LegacyRemoteCallApi",
|
"name": "GMLIB-LegacyRemoteCallApi",
|
||||||
"description": "Legacy RemoteCall API for GMLIB",
|
"description": "Legacy RemoteCall API for GMLIB",
|
||||||
"source": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi",
|
|
||||||
"author": "GroupMountain",
|
|
||||||
"tags": [
|
"tags": [
|
||||||
"levilamina",
|
"platform:levilamina",
|
||||||
|
"type:mod",
|
||||||
"gmlib",
|
"gmlib",
|
||||||
"lse",
|
"lse",
|
||||||
"library"
|
"library"
|
||||||
]
|
],
|
||||||
|
"avatar_url": "https://raw.githubusercontent.com/GroupMountain/GMLIB-LegacyRemoteCallApi/refs/heads/main/icon.jpg"
|
||||||
},
|
},
|
||||||
"asset_url": "https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi/releases/download/v0.13.3/GMLIB-LegacyRemoteCallApi-windows-x64.zip",
|
"variants": [
|
||||||
"dependencies": {
|
|
||||||
"github.com/GroupMountain/GMLIB": ">=0.13.0"
|
|
||||||
},
|
|
||||||
"files": {
|
|
||||||
"place": [
|
|
||||||
{
|
{
|
||||||
"src": "GMLIB-LegacyRemoteCallApi/*",
|
"platform": "win-x64",
|
||||||
"dest": "plugins/GMLIB-LegacyRemoteCallApi"
|
"dependencies": {
|
||||||
|
"github.com/LiteLDev/LeviLamina": ">=1.3.0",
|
||||||
|
"github.com/GroupMountain/GMLIB-Release": ">=1.3.0-rc.1",
|
||||||
|
"github.com/MiracleForest/iListenAttentively-Release": ">=0.6.0"
|
||||||
|
},
|
||||||
|
"assets": [
|
||||||
|
{
|
||||||
|
"type": "zip",
|
||||||
|
"urls": [
|
||||||
|
"https://{{tooth}}/releases/download/v{{version}}/GMLIB-LegacyRemoteCallApi-windows-x64.zip"
|
||||||
|
],
|
||||||
|
"placements": [
|
||||||
|
{
|
||||||
|
"type": "dir",
|
||||||
|
"src": "GMLIB-LegacyRemoteCallApi",
|
||||||
|
"dest": "plugins/GMLIB-LegacyRemoteCallApi/"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"remove_files": [
|
||||||
|
"plugins/GMLIB-LegacyRemoteCallApi"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
@@ -2,55 +2,28 @@ add_rules("mode.debug", "mode.release")
|
|||||||
|
|
||||||
add_repositories("liteldev-repo https://github.com/LiteLDev/xmake-repo.git")
|
add_repositories("liteldev-repo https://github.com/LiteLDev/xmake-repo.git")
|
||||||
add_repositories("groupmountain-repo https://github.com/GroupMountain/xmake-repo.git")
|
add_repositories("groupmountain-repo https://github.com/GroupMountain/xmake-repo.git")
|
||||||
|
add_repositories("miracleforest-repo https://github.com/MiracleForest/xmake-repo.git")
|
||||||
|
|
||||||
if not has_config("vs_runtime") then
|
if not has_config("vs_runtime") then
|
||||||
set_runtimes("MD")
|
set_runtimes("MD")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Option 1: Use the latest version of LeviLamina released on GitHub.
|
add_requires("levilamina 1.3.0", {configs = {target_type = "server"}})
|
||||||
add_requires("levilaminalibrary")
|
|
||||||
add_requires("legacyremotecall")
|
add_requires("legacyremotecall")
|
||||||
add_requires("gmlib")
|
add_requires("levibuildscript")
|
||||||
|
add_requires("ilistenattentively 0.6.0")
|
||||||
|
add_requires("gmlib 1.3.0-rc.1")
|
||||||
|
|
||||||
-- Option 2: Use a specific version of LeviLamina released on GitHub.
|
target("GMLIB-LegacyRemoteCallApi")
|
||||||
-- add_requires("levilamina x.x.x")
|
|
||||||
|
|
||||||
-- Option 3: Use the latest commit of LeviLamina on GitHub.
|
|
||||||
-- -- Here, "develop" is the branch name. You can change it to any branch name you want.
|
|
||||||
-- add_requires("levilamina develop")
|
|
||||||
-- -- You can also use debug build of LeviLamina.
|
|
||||||
-- -- add_requires("levilamina develop", {debug = true})
|
|
||||||
-- package("levilamina")
|
|
||||||
-- add_urls("https://github.com/LiteLDev/LeviLamina.git")
|
|
||||||
|
|
||||||
-- add_deps("ctre 3.8.1")
|
|
||||||
-- add_deps("entt 3.12.2")
|
|
||||||
-- add_deps("fmt 10.1.1")
|
|
||||||
-- add_deps("gsl 4.0.0")
|
|
||||||
-- add_deps("leveldb 1.23")
|
|
||||||
-- add_deps("magic_enum 0.9.0")
|
|
||||||
-- add_deps("nlohmann_json 3.11.2")
|
|
||||||
-- add_deps("rapidjson 1.1.0")
|
|
||||||
-- add_deps("pcg_cpp 1.0.0")
|
|
||||||
-- add_deps("pfr 2.1.1")
|
|
||||||
-- add_deps("preloader 1.4.0")
|
|
||||||
-- add_deps("symbolprovider 1.1.0")
|
|
||||||
|
|
||||||
-- -- You may need to change this to the target BDS version of your choice.
|
|
||||||
-- add_deps("bdslibrary 1.20.50.03")
|
|
||||||
|
|
||||||
-- on_install(function (package)
|
|
||||||
-- import("package.tools.xmake").install(package)
|
|
||||||
-- end)
|
|
||||||
|
|
||||||
target("GMLIB-LegacyRemoteCallApi") -- Change this to your plugin name.
|
|
||||||
add_cxflags(
|
add_cxflags(
|
||||||
"/EHa",
|
"/EHa",
|
||||||
"/utf-8"
|
"/utf-8",
|
||||||
|
"/bigobj"
|
||||||
)
|
)
|
||||||
add_defines(
|
add_defines(
|
||||||
"NOMINMAX",
|
"NOMINMAX",
|
||||||
"UNICODE"
|
"UNICODE",
|
||||||
|
"_HAS_CXX23=1"
|
||||||
)
|
)
|
||||||
add_files(
|
add_files(
|
||||||
"src/**.cpp"
|
"src/**.cpp"
|
||||||
@@ -59,25 +32,21 @@ target("GMLIB-LegacyRemoteCallApi") -- Change this to your plugin name.
|
|||||||
"src"
|
"src"
|
||||||
)
|
)
|
||||||
add_packages(
|
add_packages(
|
||||||
"levilaminalibrary",
|
"levilamina",
|
||||||
"legacyremotecall",
|
"legacyremotecall",
|
||||||
|
"ilistenattentively",
|
||||||
"gmlib"
|
"gmlib"
|
||||||
)
|
)
|
||||||
add_shflags(
|
add_rules("@levibuildscript/linkrule")
|
||||||
"/DELAYLOAD:bedrock_server.dll" -- Magic to import symbols from BDS
|
add_rules("@levibuildscript/modpacker")
|
||||||
)
|
set_exceptions("none")
|
||||||
set_exceptions("none") -- To avoid conflicts with /EHa
|
|
||||||
set_kind("shared")
|
set_kind("shared")
|
||||||
set_languages("c++23")
|
set_languages("cxx20")
|
||||||
set_symbols("debug")
|
set_symbols("debug")
|
||||||
|
|
||||||
after_build(function (target)
|
after_build(function (target)
|
||||||
local plugin_packer = import("scripts.after_build")
|
local target_path = path.join("bin", target:name(), "lib")
|
||||||
|
if os.exists(target_path) then
|
||||||
local plugin_define = {
|
os.rm(target_path)
|
||||||
pluginName = target:name(),
|
end
|
||||||
pluginFile = path.filename(target:targetfile()),
|
os.cp("lib", target_path)
|
||||||
}
|
|
||||||
|
|
||||||
plugin_packer.pack_plugin(target,plugin_define)
|
|
||||||
end)
|
end)
|
||||||
Reference in New Issue
Block a user