Compare commits
13 Commits
@@ -7,23 +7,30 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- uses: actions/checkout@v6
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- uses: xmake-io/github-action-setup-xmake@v1
|
- uses: xmake-io/github-action-setup-xmake@v1
|
||||||
|
# with:
|
||||||
|
# xmake-version: branch@master
|
||||||
|
|
||||||
|
- uses: actions/cache@v5
|
||||||
with:
|
with:
|
||||||
xmake-version: 3.0.0
|
path: |
|
||||||
|
~/AppData/Local/.xmake
|
||||||
|
key: xmake-${{ hashFiles('xmake.lua') }}
|
||||||
|
restore-keys: |
|
||||||
|
xmake-
|
||||||
|
|
||||||
- run: |
|
- run: |
|
||||||
xmake repo -u
|
xmake repo -u
|
||||||
|
|
||||||
- run: |
|
- run: |
|
||||||
xmake f -a x64 -m release -p windows -v -y
|
xmake f -a x64 -m release -p windows -y
|
||||||
|
|
||||||
- run: |
|
- run: |
|
||||||
xmake -w -y
|
xmake -w -y
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v4
|
- uses: actions/upload-artifact@v7
|
||||||
with:
|
with:
|
||||||
name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }}
|
name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }}
|
||||||
path: |
|
path: |
|
||||||
|
|||||||
@@ -7,23 +7,31 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- uses: actions/checkout@v6
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- uses: xmake-io/github-action-setup-xmake@v1
|
- uses: xmake-io/github-action-setup-xmake@v1
|
||||||
|
# with:
|
||||||
|
# xmake-version: branch@master
|
||||||
|
|
||||||
|
- uses: actions/cache@v5
|
||||||
with:
|
with:
|
||||||
xmake-version: 3.0.0
|
path: |
|
||||||
|
~/AppData/Local/.xmake
|
||||||
|
key: xmake-${{ hashFiles('xmake.lua') }}
|
||||||
|
restore-keys: |
|
||||||
|
xmake-
|
||||||
|
|
||||||
|
|
||||||
- run: |
|
- run: |
|
||||||
xmake repo -u
|
xmake repo -u
|
||||||
|
|
||||||
- run: |
|
- run: |
|
||||||
xmake f -a x64 -m release -p windows -v -y
|
xmake f -a x64 -m release -p windows -y
|
||||||
|
|
||||||
- run: |
|
- run: |
|
||||||
xmake -w -y
|
xmake -w -y
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v4
|
- uses: actions/upload-artifact@v7
|
||||||
with:
|
with:
|
||||||
name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }}
|
name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }}
|
||||||
path: |
|
path: |
|
||||||
@@ -37,10 +45,10 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Download Mod
|
- name: Download Mod
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v7
|
||||||
with:
|
with:
|
||||||
name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }}
|
name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }}
|
||||||
path: artifact
|
path: artifact
|
||||||
@@ -55,7 +63,7 @@ jobs:
|
|||||||
working-directory: artifact
|
working-directory: artifact
|
||||||
|
|
||||||
- name: Create GitHub Release
|
- name: Create GitHub Release
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v3
|
||||||
with:
|
with:
|
||||||
files: |
|
files: |
|
||||||
${{ github.event.repository.name }}-windows-x64.zip
|
${{ github.event.repository.name }}-windows-x64.zip
|
||||||
+19
-16
@@ -1,11 +1,13 @@
|
|||||||
/**
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
const getPluginName = () => {
|
const getPluginName = () => {
|
||||||
// quickjs
|
if (getPluginName.PluginNameCache) return getPluginName.PluginNameCache;
|
||||||
try {
|
|
||||||
throw new Error("getPluginName");
|
return getPluginName.PluginNameCache = (() => {
|
||||||
} catch (error) {
|
if (ll.getCurrentPluginInfo) return ll.getCurrentPluginInfo().name;
|
||||||
|
|
||||||
|
const error = new Error("getPluginName");
|
||||||
|
switch (ll.scriptEngineVersion) {
|
||||||
|
case "QuickJS": {
|
||||||
|
if (!error.stack) break;
|
||||||
const /** @type {string} */ line = error.stack.trim().split("\n").pop().trim();
|
const /** @type {string} */ line = error.stack.trim().split("\n").pop().trim();
|
||||||
if (line.includes("<anonymous>")) {
|
if (line.includes("<anonymous>")) {
|
||||||
return line.slice(
|
return line.slice(
|
||||||
@@ -19,33 +21,34 @@ const getPluginName = () => {
|
|||||||
line.indexOf("\\")
|
line.indexOf("\\")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
case "V8 12.4.254.21-node.21": {
|
||||||
// nodejs
|
|
||||||
try {
|
try {
|
||||||
const path = require('path');
|
const selfFileName = require('path').basename(__filename);
|
||||||
const selfFileName = path.basename(__filename);
|
|
||||||
const pluginDirectory = Object.entries(
|
const pluginDirectory = Object.entries(
|
||||||
require('module')._pathCache
|
require('module')._pathCache
|
||||||
).find(
|
).find(
|
||||||
([key, _]) =>
|
([key, _]) => key.includes(selfFileName)
|
||||||
key.includes(selfFileName)
|
|
||||||
)[0].split("\u0000")[1];
|
)[0].split("\u0000")[1];
|
||||||
const directories = pluginDirectory.split("\\");
|
const directories = pluginDirectory.split("\\");
|
||||||
const pluginName = directories[directories.findIndex(value => value === "plugins") + 1].trim();
|
const pluginName = directories[directories.findIndex(value => value === "plugins") + 1].trim();
|
||||||
if (pluginName) return pluginName;
|
if (pluginName) return pluginName;
|
||||||
} catch { }
|
} catch { }
|
||||||
try {
|
|
||||||
throw new Error("getPluginName");
|
if (!error.stack) break;
|
||||||
} catch (error) {
|
|
||||||
const /** @type {string} */ line = error.stack.trim().split("\n").pop().trim();
|
const /** @type {string} */ line = error.stack.trim().split("\n").pop().trim();
|
||||||
if (line.includes(".js") && /:\d+:\d+$/.test(line)) {
|
if (line.includes(".js") && /:\d+:\d+$/.test(line)) {
|
||||||
const directories = line.split("\\");
|
const directories = line.split("\\");
|
||||||
const pluginName = directories[directories.findIndex(value => value === "plugins") + 1].trim();
|
const pluginName = directories[directories.findIndex(value => value === "plugins") + 1].trim();
|
||||||
if (pluginName) return pluginName;
|
if (pluginName) return pluginName;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: break;
|
||||||
}
|
}
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
|
})();
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
Vendored
+3
-3
@@ -1078,12 +1078,12 @@ export class UserCache {
|
|||||||
|
|
||||||
/** 获取玩家信息 */
|
/** 获取玩家信息 */
|
||||||
static getPlayerInfo(
|
static getPlayerInfo(
|
||||||
/** 玩家名 或 xuid 或 uuid */
|
/** 玩家名 或 xuid 或 uuid 或 serverId 或 uniqueId */
|
||||||
playerIdentifier: string
|
playerIdentifier: string
|
||||||
): { Xuid: String, Uuid: string, Name: string } | null;
|
): { Xuid: string, Uuid: string, Name: string, ServerId: string, ActorUniqueID: string } | null;
|
||||||
|
|
||||||
/** 获取所有玩家信息 */
|
/** 获取所有玩家信息 */
|
||||||
static getAllPlayerInfo(): { Xuid: String; Uuid: string; Name: string; }[]
|
static getAllPlayerInfo(): { Xuid: string, Uuid: string, Name: string, ServerId: string, ActorUniqueID: string }[]
|
||||||
}
|
}
|
||||||
|
|
||||||
type PacketDataItem = (
|
type PacketDataItem = (
|
||||||
|
|||||||
+12
-8
@@ -216,7 +216,9 @@ const GMLIB_API = {
|
|||||||
getXuidByName: ll.imports("GMLIB_API", "getXuidByName"),
|
getXuidByName: ll.imports("GMLIB_API", "getXuidByName"),
|
||||||
/** 根据名字获取uuid @type {function(string):string} */
|
/** 根据名字获取uuid @type {function(string):string} */
|
||||||
getUuidByName: ll.imports("GMLIB_API", "getUuidByName"),
|
getUuidByName: ll.imports("GMLIB_API", "getUuidByName"),
|
||||||
/** 获取所有已记录的玩家信息 @type {function():Array.<{"Uuid":string,"Xuid":string,"Name":string}>} */
|
/** 根据信息获取玩家信息 @type {function():{"Uuid":string,"Xuid":string,"Name":string,"ServerId":string,"ActorUniqueID":string}} */
|
||||||
|
getPlayerInfo: ll.imports("GMLIB_API", "getPlayerInfo"),
|
||||||
|
/** 获取所有已记录的玩家信息 @type {function():Array.<{"Uuid":string,"Xuid":string,"Name":string,"ServerId":string,"ActorUniqueID":string}>} */
|
||||||
getAllPlayerInfo: ll.imports("GMLIB_API", "getAllPlayerInfo"),
|
getAllPlayerInfo: ll.imports("GMLIB_API", "getAllPlayerInfo"),
|
||||||
/** 获取方块RuntimeId @type {function(string,number):number} */
|
/** 获取方块RuntimeId @type {function(string,number):number} */
|
||||||
getBlockRuntimeId: ll.imports("GMLIB_API", "getBlockRuntimeId"),
|
getBlockRuntimeId: ll.imports("GMLIB_API", "getBlockRuntimeId"),
|
||||||
@@ -326,7 +328,7 @@ const GMLIB_API = {
|
|||||||
getItemCategoryName: ll.imports("GMLIB_API", "getItemCategoryName"),
|
getItemCategoryName: ll.imports("GMLIB_API", "getItemCategoryName"),
|
||||||
/** 获取物品的命名 @type {function(Item):string} */
|
/** 获取物品的命名 @type {function(Item):string} */
|
||||||
getItemCustomName: ll.imports("GMLIB_API", "getItemCustomName"),
|
getItemCustomName: ll.imports("GMLIB_API", "getItemCustomName"),
|
||||||
/** 获取物品BUFF效果名称 @type {function(Item):string} */
|
/** 获取物品BUFF效果名称 @type {function(Item,boolean):string} */
|
||||||
getItemEffecName: ll.imports("GMLIB_API", "getItemEffecName"),
|
getItemEffecName: ll.imports("GMLIB_API", "getItemEffecName"),
|
||||||
/** 物品是否为食物 @type {function(Item):boolean} */
|
/** 物品是否为食物 @type {function(Item):boolean} */
|
||||||
itemIsFood: ll.imports("GMLIB_API", "itemIsFood"),
|
itemIsFood: ll.imports("GMLIB_API", "itemIsFood"),
|
||||||
@@ -2107,16 +2109,17 @@ class UserCache {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取玩家信息
|
* 获取玩家信息
|
||||||
* @param {string} playerIdentifier 玩家的 xuid 或 uuid 或 名称
|
* @param {string} playerIdentifier 玩家的 xuid 或 uuid 或 realName 或 serverId 或 uniqueId
|
||||||
* @returns {{Xuid: String, Uuid: string, Name: string}?} 玩家信息
|
* @returns {{Xuid: string, Uuid: string, Name: string, ServerId: string, ActorUniqueID: string}?} 玩家信息
|
||||||
*/
|
*/
|
||||||
static getPlayerInfo(playerIdentifier) {
|
static getPlayerInfo(playerIdentifier) {
|
||||||
return GMLIB_API.getAllPlayerInfo().find(Info => Object.keys(Info).some(InfoKey => Info[InfoKey] === playerIdentifier));
|
const result = GMLIB_API.getPlayerInfo(playerIdentifier)
|
||||||
|
return Object.keys(result).length === 0 ? null : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有玩家信息
|
* 获取所有玩家信息
|
||||||
* @returns {Array.<{Xuid: String, Uuid: string, Name: string}>} 包含所有玩家信息的数组
|
* @returns {Array.<{Xuid: string, Uuid: string, Name: string, ServerId: string, ActorUniqueID: string}>} 包含所有玩家信息的数组
|
||||||
*/
|
*/
|
||||||
static getAllPlayerInfo() {
|
static getAllPlayerInfo() {
|
||||||
return GMLIB_API.getAllPlayerInfo();
|
return GMLIB_API.getAllPlayerInfo();
|
||||||
@@ -3001,10 +3004,11 @@ LLSE_Item.prototype.getCustomName =
|
|||||||
LLSE_Item.prototype.getEffecName =
|
LLSE_Item.prototype.getEffecName =
|
||||||
/**
|
/**
|
||||||
* 获取物品的BUFF效果名称
|
* 获取物品的BUFF效果名称
|
||||||
|
* @param {boolean} playerIsCreative 玩家是否为创造模式
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function () {
|
function (playerIsCreative = false) {
|
||||||
return GMLIB_API.getItemEffecName(this);
|
return GMLIB_API.getItemEffecName(this, playerIsCreative);
|
||||||
};
|
};
|
||||||
|
|
||||||
LLSE_Item.prototype.isFood =
|
LLSE_Item.prototype.isFood =
|
||||||
|
|||||||
+19
-13
@@ -1,10 +1,15 @@
|
|||||||
/// <reference path='d:/dts/dts/helperlib/src/index.d.ts'/>
|
/// <reference path='d:/dts/dts/helperlib/src/index.d.ts'/>
|
||||||
|
|
||||||
const getPluginName = () => {
|
const getPluginName = () => {
|
||||||
// quickjs
|
if (getPluginName.PluginNameCache) return getPluginName.PluginNameCache;
|
||||||
try {
|
|
||||||
throw new Error("getPluginName");
|
return getPluginName.PluginNameCache = (() => {
|
||||||
} catch (error) {
|
if (ll.getCurrentPluginInfo) return ll.getCurrentPluginInfo().name;
|
||||||
|
|
||||||
|
const error = new Error("getPluginName");
|
||||||
|
switch (ll.scriptEngineVersion) {
|
||||||
|
case "QuickJS": {
|
||||||
|
if (!error.stack) break;
|
||||||
const /** @type {string} */ line = error.stack.trim().split("\n").pop().trim();
|
const /** @type {string} */ line = error.stack.trim().split("\n").pop().trim();
|
||||||
if (line.includes("<anonymous>")) {
|
if (line.includes("<anonymous>")) {
|
||||||
return line.slice(
|
return line.slice(
|
||||||
@@ -18,33 +23,34 @@ const getPluginName = () => {
|
|||||||
line.indexOf("\\")
|
line.indexOf("\\")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
case "V8 12.4.254.21-node.21": {
|
||||||
// nodejs
|
|
||||||
try {
|
try {
|
||||||
const path = require('path');
|
const selfFileName = require('path').basename(__filename);
|
||||||
const selfFileName = path.basename(__filename);
|
|
||||||
const pluginDirectory = Object.entries(
|
const pluginDirectory = Object.entries(
|
||||||
require('module')._pathCache
|
require('module')._pathCache
|
||||||
).find(
|
).find(
|
||||||
([key, _]) =>
|
([key, _]) => key.includes(selfFileName)
|
||||||
key.includes(selfFileName)
|
|
||||||
)[0].split("\u0000")[1];
|
)[0].split("\u0000")[1];
|
||||||
const directories = pluginDirectory.split("\\");
|
const directories = pluginDirectory.split("\\");
|
||||||
const pluginName = directories[directories.findIndex(value => value === "plugins") + 1].trim();
|
const pluginName = directories[directories.findIndex(value => value === "plugins") + 1].trim();
|
||||||
if (pluginName) return pluginName;
|
if (pluginName) return pluginName;
|
||||||
} catch { }
|
} catch { }
|
||||||
try {
|
|
||||||
throw new Error("getPluginName");
|
if (!error.stack) break;
|
||||||
} catch (error) {
|
|
||||||
const /** @type {string} */ line = error.stack.trim().split("\n").pop().trim();
|
const /** @type {string} */ line = error.stack.trim().split("\n").pop().trim();
|
||||||
if (line.includes(".js") && /:\d+:\d+$/.test(line)) {
|
if (line.includes(".js") && /:\d+:\d+$/.test(line)) {
|
||||||
const directories = line.split("\\");
|
const directories = line.split("\\");
|
||||||
const pluginName = directories[directories.findIndex(value => value === "plugins") + 1].trim();
|
const pluginName = directories[directories.findIndex(value => value === "plugins") + 1].trim();
|
||||||
if (pluginName) return pluginName;
|
if (pluginName) return pluginName;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: break;
|
||||||
}
|
}
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
|
})();
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
@@ -14,6 +14,9 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "iListenAttentively"
|
"name": "iListenAttentively"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ModAPI"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
+79
-35
@@ -1,4 +1,5 @@
|
|||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
#include "gmlib/mc/world/actor/Player.h"
|
||||||
#include "mc/platform/UUID.h"
|
#include "mc/platform/UUID.h"
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
@@ -11,7 +12,7 @@ void Export_Compatibility_API() {
|
|||||||
return CustomRecipeRegistry::getInstance().unregisterRecipe(id, true);
|
return CustomRecipeRegistry::getInstance().unregisterRecipe(id, true);
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_API", "setCustomPackPath", [](std::string const& path) -> void {
|
RemoteCall::exportAs("GMLIB_API", "setCustomPackPath", [](std::string const& path) -> void {
|
||||||
AddonsLoader::addCustomPackPath(path);
|
AddonsLoader::getInstance().addCustomPackPath(path);
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_API", "getServerMspt", []() -> double {
|
RemoteCall::exportAs("GMLIB_API", "getServerMspt", []() -> double {
|
||||||
return GMLevel::getInstance().transform(
|
return GMLevel::getInstance().transform(
|
||||||
@@ -19,14 +20,10 @@ void Export_Compatibility_API() {
|
|||||||
).value_or(0.0);
|
).value_or(0.0);
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_API", "getServerCurrentTps", []() -> float {
|
RemoteCall::exportAs("GMLIB_API", "getServerCurrentTps", []() -> float {
|
||||||
return GMLevel::getInstance().transform(
|
return TpsStatus::getInstance().getLevelCurrentTps();
|
||||||
[](GMLevel& level) -> float { return level.getServerCurrentTps(); }
|
|
||||||
).value_or(0.0);
|
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_API", "getServerAverageTps", []() -> double {
|
RemoteCall::exportAs("GMLIB_API", "getServerAverageTps", []() -> double {
|
||||||
return GMLevel::getInstance().transform(
|
return TpsStatus::getInstance().getLevelAverageTps();
|
||||||
[](GMLevel& level) -> double { return level.getServerAverageTps(); }
|
|
||||||
).value_or(0.0);
|
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_API", "getAllPlayerUuids", []() -> std::vector<std::string> {
|
RemoteCall::exportAs("GMLIB_API", "getAllPlayerUuids", []() -> std::vector<std::string> {
|
||||||
std::vector<std::string> result;
|
std::vector<std::string> result;
|
||||||
@@ -445,13 +442,28 @@ void Export_Compatibility_API() {
|
|||||||
return ll::service::getLevel()->fetchEntity(parseScriptUniqueID(uniqueId), false);
|
return ll::service::getLevel()->fetchEntity(parseScriptUniqueID(uniqueId), false);
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_API", "getWorldSpawn", []() -> std::pair<BlockPos, int> {
|
RemoteCall::exportAs("GMLIB_API", "getWorldSpawn", []() -> std::pair<BlockPos, int> {
|
||||||
return {GMLevel::getInstance()->getLevelData().getSpawnPos(), 0};
|
constexpr static HashedString SPAWN_POS{"spawnPos"};
|
||||||
|
|
||||||
|
auto& levelData = GMLevel::getInstance()->getLevelData();
|
||||||
|
if (auto it = levelData.mValues->find(SPAWN_POS); it != levelData.mValues->end()) {
|
||||||
|
|
||||||
|
if (auto value = std::get_if<BlockPos>(&it->second.mValue.get()); value) {
|
||||||
|
return {*value, 0};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (auto it = levelData.mOverrides->find(SPAWN_POS); it != levelData.mOverrides->end()) {
|
||||||
|
if (auto value = std::get_if<BlockPos>(&it->second.mValue.get()); value) {
|
||||||
|
return {*value, 0};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {BlockPos::ZERO(), 1};
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_API", "setWorldSpawn", [](std::pair<BlockPos, int> pos) -> bool {
|
RemoteCall::exportAs("GMLIB_API", "setWorldSpawn", [](std::pair<BlockPos, int> pos) -> bool {
|
||||||
if (pos.second != 0) return false;
|
if (pos.second != 0) return false;
|
||||||
GMLevel::getInstance()->getLevelData().setSpawnPos(pos.first);
|
GMLevel::getInstance()->getLevelData().setSpawnPos(pos.first);
|
||||||
auto pkt = SetSpawnPositionPacket();
|
auto pkt = SetSpawnPositionPacket();
|
||||||
pkt.mSpawnBlockPos = NetworkBlockPosition(pos.first);
|
pkt.mSpawnBlockPos = pos.first;
|
||||||
|
|
||||||
pkt.mDimensionType = 0;
|
pkt.mDimensionType = 0;
|
||||||
pkt.mSpawnPosType = SpawnPositionType::WorldSpawn;
|
pkt.mSpawnPosType = SpawnPositionType::WorldSpawn;
|
||||||
pkt.sendToClients();
|
pkt.sendToClients();
|
||||||
@@ -484,7 +496,7 @@ void Export_Compatibility_API() {
|
|||||||
return "";
|
return "";
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_API", "getXuidByName", [](std::string const& name) -> std::string {
|
RemoteCall::exportAs("GMLIB_API", "getXuidByName", [](std::string const& name) -> std::string {
|
||||||
if (auto uce = UserCache::getInstance()->from(name, UserCache::QueryType::Name)) {
|
if (auto uce = UserCache::getInstance()->from(name, UserCache::Name)) {
|
||||||
return uce->mXuid;
|
return uce->mXuid;
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
@@ -496,34 +508,63 @@ void Export_Compatibility_API() {
|
|||||||
return "";
|
return "";
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_API", "getNameByXuid", [](std::string const& xuid) -> std::string {
|
RemoteCall::exportAs("GMLIB_API", "getNameByXuid", [](std::string const& xuid) -> std::string {
|
||||||
if (auto uce = UserCache::getInstance()->from(xuid, UserCache::QueryType::Xuid)) {
|
if (auto uce = UserCache::getInstance()->from(xuid, UserCache::Xuid)) {
|
||||||
return uce->mName;
|
return uce->mName;
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_API", "getUuidByXuid", [](std::string const& xuid) -> std::string {
|
RemoteCall::exportAs("GMLIB_API", "getUuidByXuid", [](std::string const& xuid) -> std::string {
|
||||||
if (auto uce = UserCache::getInstance()->from(xuid, UserCache::QueryType::Xuid)) {
|
if (auto uce = UserCache::getInstance()->from(xuid, UserCache::Xuid)) {
|
||||||
return uce->mUuid.asString();
|
return uce->mUuid.asString();
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_API", "getUuidByName", [](std::string const& name) -> std::string {
|
RemoteCall::exportAs("GMLIB_API", "getUuidByName", [](std::string const& name) -> std::string {
|
||||||
if (auto uce = UserCache::getInstance()->from(name, UserCache::QueryType::Name)) {
|
if (auto uce = UserCache::getInstance()->from(name, UserCache::Name)) {
|
||||||
return uce->mUuid.asString();
|
return uce->mUuid.asString();
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
});
|
});
|
||||||
|
RemoteCall::exportAs(
|
||||||
|
"GMLIB_API",
|
||||||
|
"getPlayerInfo",
|
||||||
|
[](std::string const& info) -> std::unordered_map<std::string, std::string> {
|
||||||
|
// TODO: 下个GMLIB更新直接改成from(info, UserCache::QueryType::All)
|
||||||
|
std::unordered_map<std::string, std::string> result;
|
||||||
|
if (auto uce = UserCache::getInstance()->from(mce::UUID::fromString(info))) {
|
||||||
|
ll::reflection::forEachMember(*uce, [&](std::string_view name, auto&& member) {
|
||||||
|
result[std::string{name.substr(1)}] = fmt::to_string(member);
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if (auto uniqeuId = ll::string_utils::svtoll(info); uniqeuId) {
|
||||||
|
if (auto uce = UserCache::getInstance()->from(ActorUniqueID{*uniqeuId})) {
|
||||||
|
ll::reflection::forEachMember(*uce, [&](std::string_view name, auto&& member) {
|
||||||
|
result[std::string{name.substr(1)}] = fmt::to_string(member);
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (auto uce = UserCache::getInstance()->from(info, UserCache::Default)) {
|
||||||
|
ll::reflection::forEachMember(*uce, [&](std::string_view name, auto&& member) {
|
||||||
|
result[std::string{name.substr(1)}] = fmt::to_string(member);
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
);
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
"GMLIB_API",
|
"GMLIB_API",
|
||||||
"getAllPlayerInfo",
|
"getAllPlayerInfo",
|
||||||
[]() -> std::vector<std::unordered_map<std::string, std::string>> {
|
[]() -> std::vector<std::unordered_map<std::string, std::string>> {
|
||||||
std::vector<std::unordered_map<std::string, std::string>> result;
|
std::vector<std::unordered_map<std::string, std::string>> result;
|
||||||
for (auto entry : UserCache::getInstance()->entries()) {
|
for (auto& entry : UserCache::getInstance()->entries()) {
|
||||||
result.push_back({
|
std::unordered_map<std::string, std::string> item;
|
||||||
{"Name", entry.mName },
|
ll::reflection::forEachMember(entry, [&](std::string_view name, auto&& member) {
|
||||||
{"Xuid", entry.mXuid },
|
item[std::string{name.substr(1)}] = fmt::to_string(member);
|
||||||
{"Uuid", entry.mUuid.asString()}
|
|
||||||
});
|
});
|
||||||
|
result.emplace_back(std::move(item));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -534,7 +575,7 @@ void Export_Compatibility_API() {
|
|||||||
.value_or(0);
|
.value_or(0);
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_API", "getBlockTranslateKey", [](Block const* block) -> std::string {
|
RemoteCall::exportAs("GMLIB_API", "getBlockTranslateKey", [](Block const* block) -> std::string {
|
||||||
return block->getLegacyBlock().mDescriptionId.get() + ".name";
|
return block->mBlockType->mDescriptionId.get() + ".name";
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_API", "getItemTranslateKey", [](ItemStack* item) -> std::string {
|
RemoteCall::exportAs("GMLIB_API", "getItemTranslateKey", [](ItemStack* item) -> std::string {
|
||||||
return item->getDescriptionId();
|
return item->getDescriptionId();
|
||||||
@@ -573,7 +614,7 @@ void Export_Compatibility_API() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs("GMLIB_API", "itemCanDestroyBlock", [](ItemStack const* item, Block const* block) -> bool {
|
RemoteCall::exportAs("GMLIB_API", "itemCanDestroyBlock", [](ItemStack const* item, Block const* block) -> bool {
|
||||||
return std::ranges::any_of(item->mCanDestroy, [block](BlockLegacy const* blockLegacy) {
|
return std::ranges::any_of(item->mCanDestroy, [block](BlockType const* blockLegacy) {
|
||||||
return blockLegacy && block->getTypeName() == blockLegacy->getTypeName();
|
return blockLegacy && block->getTypeName() == blockLegacy->getTypeName();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -590,13 +631,13 @@ void Export_Compatibility_API() {
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_API", "blockCanDropWithAnyTool", [](Block const* block) -> bool {
|
RemoteCall::exportAs("GMLIB_API", "blockCanDropWithAnyTool", [](Block const* block) -> bool {
|
||||||
return !block->getLegacyBlock().mRequiresCorrectToolForDrops;
|
return !block->mBlockType->mRequiresCorrectToolForDrops;
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
"GMLIB_API",
|
"GMLIB_API",
|
||||||
"blockPlayerWillDestroy",
|
"blockPlayerWillDestroy",
|
||||||
[](Block const* block, Player* player, std::pair<BlockPos, int> pos) -> bool {
|
[](Block const* block, Player* player, std::pair<BlockPos, int> pos) -> bool {
|
||||||
return block->getLegacyBlock().playerWillDestroy(*player, pos.first, *block);
|
return block->mBlockType->playerWillDestroy(*player, pos.first, *block);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs("GMLIB_API", "playerAttack", [](Player* player, Actor* entity) -> bool {
|
RemoteCall::exportAs("GMLIB_API", "playerAttack", [](Player* player, Actor* entity) -> bool {
|
||||||
@@ -632,21 +673,21 @@ void Export_Compatibility_API() {
|
|||||||
result.push_back({
|
result.push_back({
|
||||||
{"Name", gameRule.mName },
|
{"Name", gameRule.mName },
|
||||||
{"Type", "Bool" },
|
{"Type", "Bool" },
|
||||||
{"Value", std::to_string(gameRule.mValue->boolVal)}
|
{"Value", std::to_string(std::get<bool>(*gameRule.mValue))}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case GameRule::Type::Float:
|
case GameRule::Type::Float:
|
||||||
result.push_back({
|
result.push_back({
|
||||||
{"Name", gameRule.mName },
|
{"Name", gameRule.mName },
|
||||||
{"Type", "Float" },
|
{"Type", "Float" },
|
||||||
{"Value", std::to_string(gameRule.mValue->floatVal)}
|
{"Value", std::to_string(std::get<float>(*gameRule.mValue))}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case GameRule::Type::Int:
|
case GameRule::Type::Int:
|
||||||
result.push_back({
|
result.push_back({
|
||||||
{"Name", gameRule.mName },
|
{"Name", gameRule.mName },
|
||||||
{"Type", "Int" },
|
{"Type", "Int" },
|
||||||
{"Value", std::to_string(gameRule.mValue->intVal)}
|
{"Value", std::to_string(std::get<int>(*gameRule.mValue))}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case GameRule::Type::Invalid:
|
case GameRule::Type::Invalid:
|
||||||
@@ -674,7 +715,7 @@ void Export_Compatibility_API() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs("GMLIB_API", "removeEnchants", [](ItemStack* item) -> void { item->removeEnchants(); });
|
RemoteCall::exportAs("GMLIB_API", "removeEnchants", [](ItemStack* item) -> void { (void)item->removeEnchants(); });
|
||||||
RemoteCall::exportAs("GMLIB_API", "hasEnchant", [](ItemStack* item, std::string const& typeName) -> bool {
|
RemoteCall::exportAs("GMLIB_API", "hasEnchant", [](ItemStack* item, std::string const& typeName) -> bool {
|
||||||
return EnchantUtils::hasEnchant(Enchant::mEnchantNameToType()[HashedString(typeName)], *item);
|
return EnchantUtils::hasEnchant(Enchant::mEnchantNameToType()[HashedString(typeName)], *item);
|
||||||
});
|
});
|
||||||
@@ -703,7 +744,7 @@ void Export_Compatibility_API() {
|
|||||||
return entity->getNameTag();
|
return entity->getNameTag();
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_API", "ItemisUnbreakable", [](ItemStack const* item) -> bool {
|
RemoteCall::exportAs("GMLIB_API", "ItemisUnbreakable", [](ItemStack const* item) -> bool {
|
||||||
return ((GMItemStack*)item)->isUnbreakable();
|
return ((GMItemStack*)item)->getUnbreakable();
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_API", "setItemUnbreakable", [](ItemStack const* item, bool value) -> void {
|
RemoteCall::exportAs("GMLIB_API", "setItemUnbreakable", [](ItemStack const* item, bool value) -> void {
|
||||||
((GMItemStack*)item)->setUnbreakable(value);
|
((GMItemStack*)item)->setUnbreakable(value);
|
||||||
@@ -745,9 +786,9 @@ void Export_Compatibility_API() {
|
|||||||
"GMLIB_API",
|
"GMLIB_API",
|
||||||
"setItemCanDestroy",
|
"setItemCanDestroy",
|
||||||
[](ItemStack const* item, std::vector<std::string> blocks) -> void {
|
[](ItemStack const* item, std::vector<std::string> blocks) -> void {
|
||||||
std::vector<const BlockLegacy*> data;
|
std::vector<const BlockType*> data;
|
||||||
for (auto& name : blocks) {
|
for (auto& name : blocks) {
|
||||||
if (auto block = BlockLegacy::tryGetFromRegistry(name)) {
|
if (auto block = BlockType::tryGetFromRegistry(name)) {
|
||||||
data.push_back(block.as_ptr());
|
data.push_back(block.as_ptr());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -765,9 +806,9 @@ void Export_Compatibility_API() {
|
|||||||
"GMLIB_API",
|
"GMLIB_API",
|
||||||
"setItemCanPlaceOn",
|
"setItemCanPlaceOn",
|
||||||
[](ItemStack const* item, std::vector<std::string> blocks) -> void {
|
[](ItemStack const* item, std::vector<std::string> blocks) -> void {
|
||||||
std::vector<const BlockLegacy*> data;
|
std::vector<const BlockType*> data;
|
||||||
for (auto& name : blocks) {
|
for (auto& name : blocks) {
|
||||||
if (auto block = BlockLegacy::tryGetFromRegistry(name)) {
|
if (auto block = BlockType::tryGetFromRegistry(name)) {
|
||||||
data.push_back(block.as_ptr());
|
data.push_back(block.as_ptr());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -775,7 +816,7 @@ void Export_Compatibility_API() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs("GMLIB_API", "getPlayerHungry", [](Player* player) -> float {
|
RemoteCall::exportAs("GMLIB_API", "getPlayerHungry", [](Player* player) -> float {
|
||||||
return player->getMutableAttribute(Player::HUNGER()).mInstance->mCurrentValue;
|
return player->getAttribute(Player::HUNGER()).mPtr->mCurrentValue;
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_API", "getPlayerArmorCoverPercentage", [](Player* player) -> float {
|
RemoteCall::exportAs("GMLIB_API", "getPlayerArmorCoverPercentage", [](Player* player) -> float {
|
||||||
return player->getArmorCoverPercentage();
|
return player->getArmorCoverPercentage();
|
||||||
@@ -795,9 +836,9 @@ void Export_Compatibility_API() {
|
|||||||
RemoteCall::exportAs("GMLIB_API", "getItemCustomName", [](ItemStack const* item) -> std::string {
|
RemoteCall::exportAs("GMLIB_API", "getItemCustomName", [](ItemStack const* item) -> std::string {
|
||||||
return item->getCustomName();
|
return item->getCustomName();
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_API", "getItemEffecName", [](ItemStack const* item) -> std::string {
|
RemoteCall::exportAs("GMLIB_API", "getItemEffecName", [](ItemStack const* item, bool playerIsCreative) -> std::string {
|
||||||
if (auto item2 = item->mItem) {
|
if (auto item2 = item->mItem) {
|
||||||
return item2->buildEffectDescriptionName(*item);
|
return item2->buildEffectDescriptionName(*item, playerIsCreative);
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
});
|
});
|
||||||
@@ -972,7 +1013,10 @@ void Export_Compatibility_API() {
|
|||||||
return entity->isType((ActorType)type);
|
return entity->isType((ActorType)type);
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_API", "entityHasType", [](Actor* entity, int type) -> bool {
|
RemoteCall::exportAs("GMLIB_API", "entityHasType", [](Actor* entity, int type) -> bool {
|
||||||
return entity->hasType((ActorType)type);
|
if (auto component = entity->mEntityContext->tryGetComponent<ActorTypeComponent>(); component) {
|
||||||
|
return (type & std::to_underlying(component->mType)) == type;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_API", "getEntityTypeId", [](Actor* entity) -> int {
|
RemoteCall::exportAs("GMLIB_API", "getEntityTypeId", [](Actor* entity) -> int {
|
||||||
return (int)entity->getEntityTypeId();
|
return (int)entity->getEntityTypeId();
|
||||||
|
|||||||
+3
-2
@@ -216,10 +216,11 @@ void Export_Event_API() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
case doHash("gmlib::EndermanTakeBlockBeforeEvent"): {
|
case doHash("gmlib::EndermanTakeBlockBeforeEvent"): {
|
||||||
REGISTER_EVENT_LISTEN(ila::mc::EndermanTakeBlockBeforeEvent,
|
REGISTER_EVENT_LISTEN(ila::mc::MobTakeBlockBeforeEvent,
|
||||||
(Actor * mob, bool isCancelled),
|
(Actor * mob, bool isCancelled),
|
||||||
(&event.self(), event.isCancelled()),
|
(&event.self(), event.isCancelled()),
|
||||||
event.setCancelled(result););
|
event.setCancelled(result);
|
||||||
|
, if (!event.self().isType(ActorType::EnderMan)) return;);
|
||||||
}
|
}
|
||||||
case doHash("gmlib::DragonRespawnBeforeEvent"): {
|
case doHash("gmlib::DragonRespawnBeforeEvent"): {
|
||||||
REGISTER_EVENT_LISTEN(ila::mc::DragonRespawnBeforeEvent,
|
REGISTER_EVENT_LISTEN(ila::mc::DragonRespawnBeforeEvent,
|
||||||
|
|||||||
+29
-5
@@ -2,19 +2,27 @@
|
|||||||
// clang-format off
|
// clang-format off
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable : 4996)
|
#pragma warning(disable : 4996)
|
||||||
#define GMLIB_GLOBAL_USING
|
#pragma include_alias("mc/world/item/HumanoidArmorItem.h", "modapi/item/types/mc/HumanoidArmorItem.h")
|
||||||
#include <gmlib/GlobalUsing.h>
|
#include <gmlib/include_ll.h>
|
||||||
#include <gmlib/include_all.h>
|
#include <gmlib/include_lib.h>
|
||||||
|
#include <gmlib/include_mc.h>
|
||||||
#include <ila/include_all.h>
|
#include <ila/include_all.h>
|
||||||
|
#include <modapi/addons/AddonsLoader.h>
|
||||||
|
#include <modapi/recipe/CustomRecipeRegistry.h>
|
||||||
|
#include <modapi/item/CustomItemRegistry.h>
|
||||||
#include <RemoteCallAPI.h>
|
#include <RemoteCallAPI.h>
|
||||||
using namespace gmlib::mod;
|
using namespace gmlib;
|
||||||
|
using namespace gmlib::ui;
|
||||||
|
using namespace gmlib::i18n;
|
||||||
|
using namespace gmlib::memory;
|
||||||
|
using namespace modapi;
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
// clang-format on
|
// 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 1
|
#define LIB_VERSION_MAJOR 1
|
||||||
#define LIB_VERSION_MINOR 0
|
#define LIB_VERSION_MINOR 8
|
||||||
#define LIB_VERSION_PATCH 0
|
#define LIB_VERSION_PATCH 0
|
||||||
#define LIB_VERSION_PRERELEASE std::nullopt
|
#define LIB_VERSION_PRERELEASE std::nullopt
|
||||||
|
|
||||||
@@ -33,3 +41,19 @@ extern void Export_BinaryStream_API();
|
|||||||
extern ll::thread::ThreadPoolExecutor const& getThreadPoolExecutor();
|
extern ll::thread::ThreadPoolExecutor const& getThreadPoolExecutor();
|
||||||
extern ll::io::Logger& getLogger();
|
extern ll::io::Logger& getLogger();
|
||||||
// extern void Export_Form_API();
|
// extern void Export_Form_API();
|
||||||
|
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct fmt::formatter<ActorUniqueID> : fmt::formatter<int64> {
|
||||||
|
template <class FormatContext>
|
||||||
|
auto format(ActorUniqueID const& t, FormatContext& ctx) const {
|
||||||
|
return formatter<int64>::format(t.rawID, ctx);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template <>
|
||||||
|
struct fmt::formatter<mce::UUID> : fmt::formatter<std::string> {
|
||||||
|
template <class FormatContext>
|
||||||
|
auto format(mce::UUID const& t, FormatContext& ctx) const {
|
||||||
|
return formatter<std::string>::format(t.asString(), ctx);
|
||||||
|
}
|
||||||
|
};
|
||||||
+39
-27
@@ -2,10 +2,12 @@
|
|||||||
#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 GetValue(std::string const& from) {
|
||||||
|
return PlaceholderAPI::getInstance().getValue(from, std::nullopt).value_or("");
|
||||||
|
}
|
||||||
|
|
||||||
std::string GetValueWithPlayer(std::string const& key, Player* player) {
|
std::string GetValueWithPlayer(std::string const& key, Player* player) {
|
||||||
return PlaceholderAPI::getValue(key, (GMActor*)player).value_or("");
|
return PlaceholderAPI::getInstance().getValue(key, (GMActor*)player).value_or("");
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerPlayerPlaceholder(
|
void registerPlayerPlaceholder(
|
||||||
@@ -15,15 +17,15 @@ void registerPlayerPlaceholder(
|
|||||||
) {
|
) {
|
||||||
if (!RemoteCall::hasFunc(PluginName, FuncName)) return;
|
if (!RemoteCall::hasFunc(PluginName, FuncName)) return;
|
||||||
auto func = [=]() -> void {
|
auto func = [=]() -> void {
|
||||||
PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
PlaceholderAPI::getInstance().unregisterPlaceholder(PAPIName);
|
||||||
std::weak_ptr mod = ll::mod::ModManagerRegistry::getInstance().getMod(PluginName);
|
std::weak_ptr mod = ll::mod::ModManagerRegistry::getInstance().getMod(PluginName);
|
||||||
if (mod.expired()) return;
|
if (mod.expired()) return;
|
||||||
PlaceholderAPI::registerPlaceholder(
|
PlaceholderAPI::getInstance().registerPlaceholder(
|
||||||
PAPIName,
|
PAPIName,
|
||||||
[Call = RemoteCall::importAs<std::string(Player * pl, std::unordered_map<std::string, std::string>)>(
|
[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&&...
|
)](optional_ref<Actor> actor, ll::SmallStringMap<std::string> const& params, auto&&...
|
||||||
) -> std::optional<std::string> {
|
) -> std::optional<std::string> {
|
||||||
if (actor.has_value() && ((Actor*)actor.as_ptr())->isPlayer()) {
|
if (actor.has_value() && ((Actor*)actor.as_ptr())->isPlayer()) {
|
||||||
std::unordered_map<std::string, std::string> paramMap;
|
std::unordered_map<std::string, std::string> paramMap;
|
||||||
@@ -34,6 +36,7 @@ void registerPlayerPlaceholder(
|
|||||||
}
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
},
|
},
|
||||||
|
false,
|
||||||
mod
|
mod
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -51,21 +54,22 @@ void registerServerPlaceholder(
|
|||||||
) {
|
) {
|
||||||
if (!RemoteCall::hasFunc(PluginName, FuncName)) return;
|
if (!RemoteCall::hasFunc(PluginName, FuncName)) return;
|
||||||
auto func = [=]() -> void {
|
auto func = [=]() -> void {
|
||||||
PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
PlaceholderAPI::getInstance().unregisterPlaceholder(PAPIName);
|
||||||
std::weak_ptr mod = ll::mod::ModManagerRegistry::getInstance().getMod(PluginName);
|
std::weak_ptr mod = ll::mod::ModManagerRegistry::getInstance().getMod(PluginName);
|
||||||
if (mod.expired()) return;
|
if (mod.expired()) return;
|
||||||
PlaceholderAPI::registerPlaceholder(
|
PlaceholderAPI::getInstance().registerPlaceholder(
|
||||||
PAPIName,
|
PAPIName,
|
||||||
[Call = RemoteCall::importAs<std::string(std::unordered_map<std::string, std::string>)>(
|
[Call = RemoteCall::importAs<std::string(std::unordered_map<std::string, std::string>)>(
|
||||||
PluginName,
|
PluginName,
|
||||||
FuncName
|
FuncName
|
||||||
)](auto, ll::StringMap<std::string> const& params, auto&&...) -> std::optional<std::string> {
|
)](auto, ll::SmallStringMap<std::string> const& params, auto&&...) -> std::optional<std::string> {
|
||||||
std::unordered_map<std::string, std::string> paramMap;
|
std::unordered_map<std::string, std::string> paramMap;
|
||||||
for (auto& [key, val] : params) {
|
for (auto& [key, val] : params) {
|
||||||
paramMap[key] = val;
|
paramMap[key] = val;
|
||||||
}
|
}
|
||||||
return Call(paramMap);
|
return Call(paramMap);
|
||||||
},
|
},
|
||||||
|
false,
|
||||||
mod
|
mod
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -84,13 +88,14 @@ void registerStaticPlaceholder(
|
|||||||
) {
|
) {
|
||||||
if (!RemoteCall::hasFunc(PluginName, FuncName)) return;
|
if (!RemoteCall::hasFunc(PluginName, FuncName)) return;
|
||||||
auto func = [=]() -> void {
|
auto func = [=]() -> void {
|
||||||
PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
PlaceholderAPI::getInstance().unregisterPlaceholder(PAPIName);
|
||||||
std::weak_ptr mod = ll::mod::ModManagerRegistry::getInstance().getMod(PluginName);
|
std::weak_ptr mod = ll::mod::ModManagerRegistry::getInstance().getMod(PluginName);
|
||||||
if (mod.expired()) return;
|
if (mod.expired()) return;
|
||||||
PlaceholderAPI::registerPlaceholder(
|
PlaceholderAPI::getInstance().registerPlaceholder(
|
||||||
PAPIName,
|
PAPIName,
|
||||||
[Call = RemoteCall::importAs<std::string()>(PluginName, FuncName)](auto&&...)
|
[Call = RemoteCall::importAs<std::string()>(PluginName, FuncName)](auto&&...
|
||||||
-> std::optional<std::string> { return Call(); },
|
) -> std::optional<std::string> { return Call(); },
|
||||||
|
false,
|
||||||
mod
|
mod
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -102,16 +107,18 @@ void registerStaticPlaceholder(
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string translateStringWithPlayer(std::string const& str, Player* pl) {
|
std::string translateStringWithPlayer(std::string const& str, Player* pl) {
|
||||||
return PlaceholderAPI::translate(str, (GMActor*)pl);
|
return PlaceholderAPI::getInstance().translate(str, (GMActor*)pl);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string translateString(std::string const& str) { return PlaceholderAPI::translate(str, std::nullopt); }
|
std::string translateString(std::string const& str) {
|
||||||
|
return PlaceholderAPI::getInstance().translate(str, std::nullopt);
|
||||||
|
}
|
||||||
|
|
||||||
bool unRegisterPlaceholder(std::string const& str) { return PlaceholderAPI::unregisterPlaceholder(str); }
|
bool unRegisterPlaceholder(std::string const& str) { return PlaceholderAPI::getInstance().unregisterPlaceholder(str); }
|
||||||
|
|
||||||
std::vector<std::string> getAllPAPI() {
|
std::vector<std::string> getAllPAPI() {
|
||||||
std::vector<std::string> result;
|
std::vector<std::string> result;
|
||||||
for (auto& papi : PlaceholderAPI::getAllPlaceholderData()) {
|
for (auto& papi : PlaceholderAPI::getInstance().getAllPlaceholderData()) {
|
||||||
result.push_back(papi.first);
|
result.push_back(papi.first);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -121,23 +128,23 @@ std::vector<std::string> getAllPAPI() {
|
|||||||
|
|
||||||
namespace NewPapiRemoteCall {
|
namespace NewPapiRemoteCall {
|
||||||
std::string translate(std::string const& value, std::string const& language) {
|
std::string translate(std::string const& value, std::string const& language) {
|
||||||
return PlaceholderAPI::translate(value, std::nullopt, language);
|
return PlaceholderAPI::getInstance().translate(value, std::nullopt, language);
|
||||||
}
|
}
|
||||||
std::string translateFromActor(std::string const& value, Actor* actor, std::string const& language) {
|
std::string translateFromActor(std::string const& value, Actor* actor, std::string const& language) {
|
||||||
return PlaceholderAPI::translate(value, (GMActor*)actor, language);
|
return PlaceholderAPI::getInstance().translate(value, (GMActor*)actor, language);
|
||||||
}
|
}
|
||||||
void registerPlaceholder(std::string const& placeholder, std::string const& funcName, std::string const& pluginName) {
|
void registerPlaceholder(std::string const& placeholder, std::string const& funcName, std::string const& pluginName) {
|
||||||
if (!RemoteCall::hasFunc(pluginName, funcName)) return;
|
if (!RemoteCall::hasFunc(pluginName, funcName)) return;
|
||||||
auto func = [=]() -> void {
|
auto func = [=]() -> void {
|
||||||
if (std::weak_ptr mod = ll::mod::ModManagerRegistry::getInstance().getMod(pluginName); !mod.expired()) {
|
if (std::weak_ptr mod = ll::mod::ModManagerRegistry::getInstance().getMod(pluginName); !mod.expired()) {
|
||||||
PlaceholderAPI::unregisterPlaceholder(placeholder);
|
PlaceholderAPI::getInstance().unregisterPlaceholder(placeholder);
|
||||||
PlaceholderAPI::registerPlaceholder(
|
PlaceholderAPI::getInstance().registerPlaceholder(
|
||||||
placeholder,
|
placeholder,
|
||||||
[Call = RemoteCall::importAs<
|
[Call = RemoteCall::importAs<
|
||||||
std::string(Actor*, std::unordered_map<std::string, std::string>, std::string)>(
|
std::string(Actor*, std::unordered_map<std::string, std::string>, std::string)>(
|
||||||
pluginName,
|
pluginName,
|
||||||
funcName
|
funcName
|
||||||
)](optional_ref<Actor> actor, ll::StringMap<std::string> const& params, std::string const& language
|
)](optional_ref<Actor> actor, ll::SmallStringMap<std::string> const& params, std::string const& language
|
||||||
) -> std::optional<std::string> {
|
) -> std::optional<std::string> {
|
||||||
std::unordered_map<std::string, std::string> paramMap;
|
std::unordered_map<std::string, std::string> paramMap;
|
||||||
for (auto& [key, val] : params) {
|
for (auto& [key, val] : params) {
|
||||||
@@ -146,6 +153,7 @@ void registerPlaceholder(std::string const& placeholder, std::string const& func
|
|||||||
auto result = Call((Actor*)actor.as_ptr(), paramMap, language);
|
auto result = Call((Actor*)actor.as_ptr(), paramMap, language);
|
||||||
return result == "<std::nullopt>" ? std::nullopt : std::optional(result);
|
return result == "<std::nullopt>" ? std::nullopt : std::optional(result);
|
||||||
},
|
},
|
||||||
|
false,
|
||||||
mod
|
mod
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -157,23 +165,25 @@ void registerPlaceholder(std::string const& placeholder, std::string const& func
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool unregisterPlaceholder(std::string const& placeholder) {
|
bool unregisterPlaceholder(std::string const& placeholder) {
|
||||||
return PlaceholderAPI::unregisterPlaceholder(placeholder);
|
return PlaceholderAPI::getInstance().unregisterPlaceholder(placeholder);
|
||||||
}
|
}
|
||||||
bool unregisterPlaceholderFromModName(std::string const& pluginName) {
|
bool unregisterPlaceholderFromModName(std::string const& pluginName) {
|
||||||
std::weak_ptr plugin = ll::mod::ModManagerRegistry::getInstance().getMod(pluginName);
|
std::weak_ptr plugin = ll::mod::ModManagerRegistry::getInstance().getMod(pluginName);
|
||||||
if (plugin.expired()) return false;
|
if (plugin.expired()) return false;
|
||||||
return PlaceholderAPI::unregisterPlaceholder(plugin);
|
return PlaceholderAPI::getInstance().unregisterPlaceholder(plugin);
|
||||||
}
|
}
|
||||||
std::string getValue(
|
std::string getValue(
|
||||||
std::string const& placeholder,
|
std::string const& placeholder,
|
||||||
std::unordered_map<std::string, std::string> params,
|
std::unordered_map<std::string, std::string> params,
|
||||||
std::string const& language
|
std::string const& language
|
||||||
) {
|
) {
|
||||||
ll::StringMap<std::string> paramMap;
|
ll::SmallStringMap<std::string> paramMap;
|
||||||
for (auto& [key, val] : params) {
|
for (auto& [key, val] : params) {
|
||||||
paramMap[key] = val;
|
paramMap[key] = val;
|
||||||
}
|
}
|
||||||
return PlaceholderAPI::getValue(placeholder, std::nullopt, paramMap, language).value_or("<std::nullopt>");
|
return PlaceholderAPI::getInstance()
|
||||||
|
.getValue(placeholder, std::nullopt, paramMap, language)
|
||||||
|
.value_or("<std::nullopt>");
|
||||||
}
|
}
|
||||||
std::string getValueFromActor(
|
std::string getValueFromActor(
|
||||||
std::string const& placeholder,
|
std::string const& placeholder,
|
||||||
@@ -181,11 +191,13 @@ std::string getValueFromActor(
|
|||||||
std::unordered_map<std::string, std::string> params,
|
std::unordered_map<std::string, std::string> params,
|
||||||
std::string const& language
|
std::string const& language
|
||||||
) {
|
) {
|
||||||
ll::StringMap<std::string> paramMap;
|
ll::SmallStringMap<std::string> paramMap;
|
||||||
for (auto& [key, val] : params) {
|
for (auto& [key, val] : params) {
|
||||||
paramMap[key] = val;
|
paramMap[key] = val;
|
||||||
}
|
}
|
||||||
return PlaceholderAPI::getValue(placeholder, (GMActor*)actor, paramMap, language).value_or("<std::nullopt>");
|
return PlaceholderAPI::getInstance()
|
||||||
|
.getValue(placeholder, (GMActor*)actor, paramMap, language)
|
||||||
|
.value_or("<std::nullopt>");
|
||||||
}
|
}
|
||||||
} // namespace NewPapiRemoteCall
|
} // namespace NewPapiRemoteCall
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -2,7 +2,7 @@
|
|||||||
"format_version": 3,
|
"format_version": 3,
|
||||||
"format_uuid": "289f771f-2c9a-4d73-9f3f-8492495a924d",
|
"format_uuid": "289f771f-2c9a-4d73-9f3f-8492495a924d",
|
||||||
"tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi",
|
"tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi",
|
||||||
"version": "1.4.1",
|
"version": "1.10.0",
|
||||||
"info": {
|
"info": {
|
||||||
"name": "GMLIB-LegacyRemoteCallApi",
|
"name": "GMLIB-LegacyRemoteCallApi",
|
||||||
"description": "Legacy RemoteCall API for GMLIB",
|
"description": "Legacy RemoteCall API for GMLIB",
|
||||||
@@ -19,9 +19,10 @@
|
|||||||
{
|
{
|
||||||
"platform": "win-x64",
|
"platform": "win-x64",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"github.com/LiteLDev/LeviLamina": ">=1.3.0",
|
"github.com/LiteLDev/LeviLamina": ">=26.10.0",
|
||||||
"github.com/GroupMountain/GMLIB-Release": ">=1.3.0-rc.1",
|
"github.com/GroupMountain/GMLIB-Release": ">=26.10.0",
|
||||||
"github.com/MiracleForest/iListenAttentively-Release": ">=0.6.0"
|
"github.com/GroupMountain/ModAPI-Release": ">=26.10.0",
|
||||||
|
"github.com/MiracleForest/iListenAttentively-Release": ">=0.12.0"
|
||||||
},
|
},
|
||||||
"assets": [
|
"assets": [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,11 +8,18 @@ if not has_config("vs_runtime") then
|
|||||||
set_runtimes("MD")
|
set_runtimes("MD")
|
||||||
end
|
end
|
||||||
|
|
||||||
add_requires("levilamina 1.4.1", {configs = {target_type = "server"}})
|
add_requires("levilamina 26.10.5", {configs = {target_type = "server"}})
|
||||||
add_requires("legacyremotecall")
|
add_requires("legacyremotecall")
|
||||||
add_requires("levibuildscript")
|
add_requires("levibuildscript 0.6.0")
|
||||||
add_requires("ilistenattentively 0.7.0")
|
add_requires("ilistenattentively 0.12.0")
|
||||||
add_requires("gmlib 1.4.3")
|
add_requires("gmlib 26.10.0")
|
||||||
|
add_requires("modapi 26.10.0")
|
||||||
|
|
||||||
|
rule("package_envs")
|
||||||
|
before_link(function (target)
|
||||||
|
os.addenvs(target:pkgenvs())
|
||||||
|
end)
|
||||||
|
rule_end()
|
||||||
|
|
||||||
target("GMLIB-LegacyRemoteCallApi")
|
target("GMLIB-LegacyRemoteCallApi")
|
||||||
add_cxflags(
|
add_cxflags(
|
||||||
@@ -25,6 +32,7 @@ target("GMLIB-LegacyRemoteCallApi")
|
|||||||
"UNICODE",
|
"UNICODE",
|
||||||
"_HAS_CXX23=1"
|
"_HAS_CXX23=1"
|
||||||
)
|
)
|
||||||
|
add_defines("LL_PLAT_S") --TODO: check client compatibility
|
||||||
add_files(
|
add_files(
|
||||||
"src/**.cpp"
|
"src/**.cpp"
|
||||||
)
|
)
|
||||||
@@ -34,9 +42,12 @@ target("GMLIB-LegacyRemoteCallApi")
|
|||||||
add_packages(
|
add_packages(
|
||||||
"levilamina",
|
"levilamina",
|
||||||
"legacyremotecall",
|
"legacyremotecall",
|
||||||
|
"levibuildscript",
|
||||||
"ilistenattentively",
|
"ilistenattentively",
|
||||||
"gmlib"
|
"gmlib",
|
||||||
|
"modapi"
|
||||||
)
|
)
|
||||||
|
add_rules("package_envs")
|
||||||
add_rules("@levibuildscript/linkrule")
|
add_rules("@levibuildscript/linkrule")
|
||||||
add_rules("@levibuildscript/modpacker")
|
add_rules("@levibuildscript/modpacker")
|
||||||
set_exceptions("none")
|
set_exceptions("none")
|
||||||
|
|||||||
Reference in New Issue
Block a user