Compare commits

...

10 Commits

14 changed files with 151 additions and 163 deletions
+37 -30
View File
@@ -1,3 +1,6 @@
// LiteLoader-AIDS automatic generated
/// <reference path="D:\LiteLoader\VSCode/dts/HelperLib-master/src/index.d.ts"/>
const GMLIB_API = {
createFloatingText: ll.import("GMLIB_API", "createFloatingText"),
deleteFloatingText: ll.import("GMLIB_API", "deleteFloatingText"),
@@ -102,10 +105,6 @@ class StaticFloatingText {
this.mPlaceholderAPI = papi;
this.mRuntimeId = GMLIB_API.createFloatingText(this.mPosition, this.mText, this.mPlaceholderAPI);
FloatingTextList.push(this);
this.sendToClients();
mc.listen("onJoin", (pl) => {
this.sendToClient(pl);
});
}
sendToClient(player) {
@@ -281,22 +280,15 @@ class Minecraft {
}
static getPlayerNbt(uuid) {
let snbt = GMLIB_API.getPlayerNbt(uuid);
if (snbt == "null") {
return null;
}
let nbt = NBT.parseSNBT(snbt);
return nbt;
return GMLIB_API.getPlayerNbt(uuid);
}
static setPlayerNbt(uuid, nbt, forceCreate = true) {
let snbt = nbt.toSNBT();
return GMLIB_API.setPlayerNbt(uuid, snbt, forceCreate);
return GMLIB_API.setPlayerNbt(uuid, nbt, forceCreate);
}
static setPlayerNbtTags(uuid, nbt, tags) {
let snbt = nbt.toSNBT();
return GMLIB_API.setPlayerNbtTags(uuid, snbt, tags);
return GMLIB_API.setPlayerNbtTags(uuid, nbt, tags);
}
static getPlayerPosition(uuid) {
@@ -319,18 +311,6 @@ class Minecraft {
return GMLIB_API.setWorldSpawn(pos);
}
static getPlayerSpawnPoint() {
return GMLIB_API.getPlayerSpawnPoint();
}
static setPlayerSpawnPoint(pos) {
GMLIB_API.setPlayerSpawnPoint(pos);
}
static clearPlayerSpawnPoint() {
GMLIB_API.clearPlayerSpawnPoint();
}
static setEducationFeatureEnabled() {
return GMLIB_API.setEducationFeatureEnabled();
}
@@ -367,10 +347,6 @@ class Minecraft {
return GMLIB_API.setUnknownBlockCleaner();
}
static playerToEntity(player) {
return GMLIB_API.PlayerToEntity(player);
}
static spawnEntity(pos, name) {
return GMLIB_API.spawnEntity(pos, name);
}
@@ -819,6 +795,31 @@ class JsonI18n {
}
};
LLSE_Player.prototype.toEntity = function () {
return GMLIB_API.PlayerToEntity(this);
}
LLSE_Player.prototype.getSpawnPoint = function () {
return GMLIB_API.getPlayerSpawnPoint(this);
}
LLSE_Player.prototype.setSpawnPoint = function (pos) {
return GMLIB_API.setPlayerSpawnPoint(this, pos);
}
LLSE_Player.prototype.clearSpawnPoint = function () {
return GMLIB_API.clearPlayerSpawnPoint(this);
}
LLSE_Entity.prototype.shootProjectile = function (proj, speed = 2, offset = 3) {
return GMLIB_API.shootProjectile(this, proj, speed, offset);
}
LLSE_Entity.prototype.throwEntity = function (proj, speed = 2, offset = 3) {
return GMLIB_API.throwEntity(this, proj, speed, offset);
}
module.exports = {
StaticFloatingText,
DynamicFloatingText,
@@ -832,3 +833,9 @@ module.exports = {
JsonI18n,
Version
};
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "${pluginName}",
"entry": "${pluginFile}",
"version": "0.10.0",
"version": "0.12.4",
"author": "GroupMountain",
"type": "native",
"dependencies": [
+19 -18
View File
@@ -53,25 +53,21 @@ void Export_Compatibility_API() {
}
return result;
});
RemoteCall::exportAs("GMLIB_API", "getPlayerNbt", [](std::string uuid) -> std::string {
RemoteCall::exportAs("GMLIB_API", "getPlayerNbt", [](std::string uuid) -> std::unique_ptr<CompoundTag> {
auto uid = mce::UUID::fromString(uuid);
auto nbt = GMLIB_Player::getPlayerNbt(uid);
if (nbt) {
return nbt->toSnbt();
}
return "null";
return std::move(GMLIB_Player::getPlayerNbt(uid));
});
RemoteCall::exportAs("GMLIB_API", "setPlayerNbt", [](std::string uuid, std::string snbt, bool forceCreate) -> bool {
RemoteCall::exportAs("GMLIB_API", "setPlayerNbt", [](std::string uuid, CompoundTag* nbt, bool forceCreate) -> bool {
auto uid = mce::UUID::fromString(uuid);
auto nbt = CompoundTag::fromSnbt(snbt);
logger.warn(nbt->toSnbt());
return GMLIB_Player::setPlayerNbt(uid, *nbt, forceCreate);
});
RemoteCall::exportAs(
"GMLIB_API",
"setPlayerNbtTags",
[](std::string uuid, std::string snbt, std::vector<std::string> tags) -> bool {
[](std::string uuid, CompoundTag* nbt, std::vector<std::string> tags) -> bool {
auto uid = mce::UUID::fromString(uuid);
auto nbt = CompoundTag::fromSnbt(snbt);
logger.warn(nbt->toSnbt());
return GMLIB_Player::setPlayerNbtTags(uid, *nbt, tags);
}
);
@@ -94,7 +90,7 @@ void Export_Compatibility_API() {
"GMLIB_API",
"createFloatingText",
[](std::pair<Vec3, int> pos, std::string text, bool papi) -> int {
auto ft = new GMLIB::Server::FloatingText(text, pos.first, pos.second, papi);
auto ft = new GMLIB::Server::StaticFloatingText(text, pos.first, pos.second, papi);
return ft->getRuntimeID();
}
);
@@ -112,7 +108,7 @@ void Export_Compatibility_API() {
RemoteCall::exportAs("GMLIB_API", "sendFloatingTextToPlayer", [](int id, Player* pl) -> bool {
auto ft = GMLIB::Server::FloatingText::getFloatingText(id);
if (ft) {
ft->sendToClient(pl);
ft->sendToClient(*pl);
return true;
}
return false;
@@ -128,7 +124,7 @@ void Export_Compatibility_API() {
RemoteCall::exportAs("GMLIB_API", "removeFloatingTextFromPlayer", [](int id, Player* pl) -> bool {
auto ft = GMLIB::Server::FloatingText::getFloatingText(id);
if (ft) {
ft->removeFromClient(pl);
ft->removeFromClient(*pl);
return true;
}
return false;
@@ -144,7 +140,7 @@ void Export_Compatibility_API() {
RemoteCall::exportAs("GMLIB_API", "updateClientFloatingTextData", [](int id, Player* pl) -> bool {
auto ft = GMLIB::Server::FloatingText::getFloatingText(id);
if (ft) {
ft->updateClient(pl);
ft->updateClient(*pl);
return true;
}
return false;
@@ -168,13 +164,18 @@ void Export_Compatibility_API() {
RemoteCall::exportAs(
"GMLIB_API",
"resourcePackTranslate",
[](std::string key, std::vector<std::string> params) -> std::string { return I18n::get(key, params); }
[](std::string key, std::vector<std::string> params) -> std::string { return I18nAPI::get(key, params); }
);
RemoteCall::exportAs("GMLIB_API", "chooseResourcePackI18nLanguage", [](std::string code) -> void {
I18n::chooseLanguage(code);
if (GMLIB_Level::getInstance()) {
I18nAPI::chooseLanguage(code);
}
});
RemoteCall::exportAs("GMLIB_API", "getResourcePackI18nLanguage", []() -> std::string {
return I18n::getCurrentLanguage()->getFullLanguageCode();
if (GMLIB_Level::getInstance()) {
return I18nAPI::getCurrentLanguageCode();
}
return "unknown";
});
RemoteCall::exportAs("GMLIB_API", "getPlayerPosition", [](std::string uuid) -> std::pair<BlockPos, int> {
auto uid = mce::UUID::fromString(uuid);
@@ -389,7 +390,7 @@ void Export_Compatibility_API() {
auto auids = GMLIB_Scoreboard::getInstance()->getInstance()->getAllEntities();
std::vector<std::string> result;
for (auto auid : auids) {
result.push_back(std::to_string(auid.get()));
result.push_back(std::to_string(auid.id));
}
return result;
});
+5 -1
View File
@@ -17,7 +17,11 @@ bool LRCA::load() {
ExportPAPI();
Export_Event_API();
logger.info("GMLIB-LegacyRemoteCallApi Loaded!");
logger.info("Version: {}", LIB_VERSION.asString());
logger.info(
"Loaded Version: {} with {}",
fmt::format(fg(fmt::color::pink), "GMLIB-" + GMLIB::Version::getLibVersionString()),
fmt::format(fg(fmt::color::light_green), "GMLIB-LegacyRemoteCallApi-"+LIB_VERSION.asString())
);
logger.info("Author: GroupMountain");
logger.info("Repository: https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi");
return true;
+15
View File
@@ -174,6 +174,21 @@ void Export_Event_API() {
);
return true;
}
case doHash("onEndermanTake"): {
auto Call = RemoteCall::importAs<bool(Actor * mob)>(eventName, eventId);
eventBus->emplaceListener<GMLIB::Event::EntityEvent::EndermanTakeBlockBeforeEvent>(
[Call](GMLIB::Event::EntityEvent::EndermanTakeBlockBeforeEvent& ev) {
bool result = true;
try {
result = Call(&ev.self());
} catch (...) {}
if (!result) {
ev.cancel();
}
}
);
return true;
}
default:
return false;
}
+3 -2
View File
@@ -3,8 +3,9 @@
#include <RemoteCallAPI.h>
#define PLUGIN_NAME "GMLIB-LRCA"
#define LIB_VERSION GMLIB::Version(0, 10, 0)
#define PLUGIN_NAME fmt::format(fg(fmt::color::light_green), "GMLIB-LRCA")
#define LIB_VERSION GMLIB::Version(0, 12, 2)
extern ll::Logger logger;
+6 -4
View File
@@ -2,16 +2,18 @@
void Export_Legacy_GMLib_ServerAPI() {
RemoteCall::exportAs("GMLib_ServerAPI", "setEducationFeatureEnabled", []() -> void {
GMLIB_Level::addEducationEditionRequired();
GMLIB_Level::tryEnableEducationEdition();
});
RemoteCall::exportAs("GMLib_ServerAPI", "registerAbilityCommand", []() -> void {
GMLIB_Level::forceEnableAbilityCommand();
GMLIB_Level::tryRegisterAbilityCommand();
});
RemoteCall::exportAs("GMLib_ServerAPI", "setEnableAchievement", []() -> void {
GMLIB_Level::setForceAchievementsEnabled();
});
RemoteCall::exportAs("GMLib_ServerAPI", "setForceTrustSkins", []() -> void { GMLIB_Level::setForceTrustSkin(); });
RemoteCall::exportAs("GMLib_ServerAPI", "enableCoResourcePack", []() -> void { GMLIB_Level::setCoResourcePack(); });
RemoteCall::exportAs("GMLib_ServerAPI", "setForceTrustSkins", []() -> void { GMLIB_Level::trustAllSkins(); });
RemoteCall::exportAs("GMLib_ServerAPI", "enableCoResourcePack", []() -> void {
GMLIB_Level::requireServerResourcePackAndAllowClientResourcePack();
});
RemoteCall::exportAs("GMLib_ServerAPI", "getLevelName", []() -> std::string {
auto level = GMLIB_Level::getInstance();
if (!level) {
+60 -26
View File
@@ -3,6 +3,16 @@
namespace PAPIRemoteCall {
std::string removeBrackets(std::string a1) {
a1.erase(a1.find_last_not_of("%") + 1);
return a1;
}
bool isParameters(std::string str) {
std::regex reg("[<]([^<>]+)[>]");
return std::regex_search(removeBrackets(str), reg);
}
std::string GetValue(std::string const& from) { return GMLIB::Server::PlaceholderAPI::getValue(from); }
std::string GetValueWithPlayer(std::string const& a1, std::string const& a2) {
@@ -15,12 +25,24 @@ bool registerPlayerPlaceholder(
std::string const& PAPIName
) {
if (RemoteCall::hasFunc(PluginName, FuncName)) {
auto Call = RemoteCall::importAs<std::string(Player * pl)>(PluginName, FuncName);
GMLIB::Server::PlaceholderAPI::registerPlayerPlaceholder(
PAPIName,
[Call](Player* sp) { return Call(sp); },
PluginName
);
if (isParameters(PAPIName)) {
auto Call = RemoteCall::importAs<std::string(Player * pl, std::unordered_map<std::string, std::string>)>(
PluginName,
FuncName
);
GMLIB::Server::PlaceholderAPI::registerPlayerPlaceholder(
PAPIName,
[Call](Player* sp, std::unordered_map<std::string, std::string> map) { return Call(sp, map); },
PluginName
);
} else {
auto Call = RemoteCall::importAs<std::string(Player * pl)>(PluginName, FuncName);
GMLIB::Server::PlaceholderAPI::registerPlayerPlaceholder(
PAPIName,
[Call](Player* sp) { return Call(sp); },
PluginName
);
}
return true;
}
return false;
@@ -32,12 +54,22 @@ bool registerServerPlaceholder(
std::string const& PAPIName
) {
if (RemoteCall::hasFunc(PluginName, FuncName)) {
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
GMLIB::Server::PlaceholderAPI::registerServerPlaceholder(
PAPIName,
[Call]() { return Call(); },
PluginName
);
if (isParameters(PAPIName)) {
auto Call =
RemoteCall::importAs<std::string(std::unordered_map<std::string, std::string>)>(PluginName, FuncName);
GMLIB::Server::PlaceholderAPI::registerServerPlaceholder(
PAPIName,
[Call](std::unordered_map<std::string, std::string> map) { return Call(map); },
PluginName
);
} else {
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
GMLIB::Server::PlaceholderAPI::registerServerPlaceholder(
PAPIName,
[Call]() { return Call(); },
PluginName
);
}
return true;
}
return false;
@@ -50,20 +82,22 @@ bool registerStaticPlaceholder(
int num
) {
if (RemoteCall::hasFunc(PluginName, FuncName)) {
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
if (num == -1) {
GMLIB::Server::PlaceholderAPI::registerStaticPlaceholder(
PAPIName,
[Call] { return Call(); },
PluginName
);
} else {
GMLIB::Server::PlaceholderAPI::registerStaticPlaceholder(
PAPIName,
num,
[Call] { return Call(); },
PluginName
);
if (isParameters(PAPIName)) {
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
if (num == -1) {
GMLIB::Server::PlaceholderAPI::registerStaticPlaceholder(
PAPIName,
[Call] { return Call(); },
PluginName
);
} else {
GMLIB::Server::PlaceholderAPI::registerStaticPlaceholder(
PAPIName,
num,
[Call] { return Call(); },
PluginName
);
}
}
return true;
}
@@ -1,53 +0,0 @@
/**
*
* @name GMLIB_LRCA-Plugin-Template
* @brief plugin template for GMLIB-LegacyRemoteCallApi
*
* @copyright Copyright (c) 2024 GroupMountain
* GMLIB-LegacyRemoteCallApi <https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi/>
*
*/
const PluginInfo = {
Name: "GMLIB_LRCA-Plugin-Template",
Author: "your name",
Version: "0.0.1"
}
// 导入 API
const { JsonConfig, JsonI18n } = require('./GMLIB-LegacyRemoteCallApi/lib/GMLIB_API-JS');
// 默认配置文件
const defaultConfig = {
"language": "zh_CN"
};
// 默认语言文件
const zh_CN = {
"consolelog.loaded": "加载成功!",
"consolelog.info": "插件作者: {1}, 当前版本: v{2}"
};
// 初始化配置文件
const config = new JsonConfig(`./plugins/${PluginInfo.Name}/config/config.json`, defaultConfig);
// 初始化 I18n
const I18n = new JsonI18n(`./plugins/${PluginInfo.Name}/language/`, config.get("language"));
I18n.loadLanguage("zh_CN", zh_CN); // 升级语言文件
I18n.setDefaultLanguage("zh_CN"); // 设置I18n无法翻译时采用的默认语言
// I18n快捷翻译函数
function tr(key, data = []) {
return I18n.translate(key, data);
}
// 监听服务器启动
// 在无特殊说明的情况下,一切 MCAPI 都应该在服务器启动后访问。
mc.listen("onServerStarted", () => {
// 你的代码
// 打印插件信息
logger.info(tr("consolelog.loaded"));
logger.info(tr("consolelog.info", [PluginInfo.Author, PluginInfo.Version]));
});
@@ -1,3 +0,0 @@
{
"language": "zh_CN"
}
@@ -1,4 +0,0 @@
{
"consolelog.loaded": "加载成功!",
"consolelog.info": "插件作者: {1}, 当前版本: v{2}"
}
@@ -1,16 +0,0 @@
{
"entry": "GMLIB_LRCA-Plugin-Template.js",
"name": "GMLIB_LRCA-Plugin-Template",
"type": "lse-quickjs",
"version": "0.0.1",
"author": "Your Name",
"description": "plugin description",
"dependencies": [
{
"name": "legacy-script-engine-quickjs"
},
{
"name": "GMLIB-LegacyRemoteCallApi"
}
]
}
+3 -3
View File
@@ -1,7 +1,7 @@
{
"format_version": 2,
"tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi",
"version": "0.10.0",
"version": "0.12.2",
"info": {
"name": "GMLIB-LegacyRemoteCallApi",
"description": "Legacy RemoteCall API for GMLIB",
@@ -14,9 +14,9 @@
"library"
]
},
"asset_url": "https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi/releases/download/v0.10.0/GMLIB-LegacyRemoteCallApi-windows-x64.zip",
"asset_url": "https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi/releases/download/v0.12.2/GMLIB-LegacyRemoteCallApi-windows-x64.zip",
"dependencies": {
"github.com/GroupMountain/GMLIB": ">=0.10.0"
"github.com/GroupMountain/GMLIB": ">=0.12.4"
},
"files": {
"place": [