fix: fix translate
/ build (push) Failing after 2m16s

This commit is contained in:
2026-06-22 13:10:53 +08:00
Unverified
parent 51f48b8820
commit fddfdf4eeb
9 changed files with 54 additions and 26 deletions
+12 -3
View File
@@ -19,17 +19,26 @@ That allows players to freely switch languages on their own.
## Death Messages Translation
By default, this plugin uses resource packs for translation to ensure perfect compatibility with various addons. <br> `This requires ModAPI to be enabled.`
### Resource Pack Translation
By default, this plugin uses resource packs for translation to ensure perfect compatibility with various addons. <br>
<br>(The plugin automatically builds the resource pack and sends it to players upon joining. Using resource pack-based translation is recommended.)
>[!IMPORTANT]
>If you wnt to use Resource Pack Translation<br>
>This requires ModAPI to be enabled.<br>
>You can configure language for console in `server.properties` like `language=en_US`
### Server-Side Translation
If you prefer not to use resource packs, you can enable server-side translation in the configuration file.<br> This way, all translations are handled entirely on the server without requiring any client-side resource packs.
>[!IMPORTANT]
>You can configure language for Server-Side Translation in `./plugins/DeathMessages/config/config.json` like `Language=en_US`
#### For issues, please report them via GitHub Issues!!!
#### Pull Requests are also welcome!
You can also customize death messages by editing the language files.<br>
(The resource pack will be generated in the ./plugins/DeathMessages/log directory; feel free to modify it as needed.)
<br> `This requires ModAPI to be enabled.`
(The language files will be generated in the ./plugins/DeathMessages/lang directory; feel free to modify it as needed.)
>[!WARNING]
> DO NOT modify files in directory `./plugins/DeathMessages/resource`, unless you know what you are doing
High performance: Implemented using native functions with no additional data storage, resulting in minimal performance overhead.
Uses native death message broadcasting, preserving the vanilla showdeathmessages game rule behavior.
+1 -1
View File
@@ -2,7 +2,7 @@
"name": "${modName}",
"entry": "${modFile}",
"type": "native",
"version": "0.14.0",
"version": "0.14.1",
"author": "GroupMountain",
"description": "Better Death Messages",
"dependencies": [
+14 -1
View File
@@ -10,6 +10,8 @@
#include "mc/world/actor/Mob.h"
#include "mc/world/level/Level.h"
#include <gmlib/mc/locale/I18nAPI.h>
//===============GMLIB 0.13.5 ActorDamageCause.cc===============
phmap::flat_hash_map<int64, float> mFallHeightMap;
@@ -83,10 +85,21 @@ DeathMessageResult makeDeathMessage(
// 如果没有击杀者和试图逃离,那么不可能使用 .player 结尾
ll::utils::string_utils::replaceAll(res.first, ".player", "");
}
if (!DeathMessages::Entry::getInstance().isResourceI18nLoaded) {
res.first=tr(res.first, res.second);
auto translatedMessage=tr(res.first, res.second);
res.first = translatedMessage;
res.second = {};
}
auto& config = DeathMessages::Entry::getInstance().getConfig();
if (config.ConsoleLog.DeathMessage) {
auto translatedMessage=tr(res.first, res.second);
deathLogger->info(translatedMessage);
}
return res;
}
// 未定义返回vanilla值
+16 -3
View File
@@ -17,6 +17,7 @@
#include "gmlib/gm/i18n/LangI18n.h"
#include "gmlib/gm/i18n/ResourceI18n.h"
#include "gmlib/mc/locale/I18nAPI.h"
ll::io::LoggerRegistry& loggerRegistry = ll::io::LoggerRegistry::getInstance();
std::shared_ptr<ll::io::Logger> logger = loggerRegistry.getOrCreate(MOD_NAME);
@@ -53,9 +54,11 @@ bool Entry::load() {
ll::makePolymorphic<ll::io::PatternFormatter>("[{3:.3%F %T.} {2}][{1}] {0}", false);
deathLogger->addSink(std::make_shared<ll::io::FileSink>(path, polymorphicFormatter));
}
loadI18n();
if ((!getConfig().ServerSideTranslation.Enabled)&&ll::mod::ModManagerRegistry::getInstance().hasMod("ModAPI")) {
loadResourcePack();
}else {
loadI18n();
}
return true;
}
@@ -133,9 +136,19 @@ void Entry::loadResourcePack() {
LL_REGISTER_MOD(DeathMessages::Entry, DeathMessages::Entry::getInstance());
std::string tr(std::string const& key, std::vector<std::string> const& params) {
std::string tr(std::string const& key, std::vector<std::string> params) {
if (DeathMessages::Entry::getInstance().isResourceI18nLoaded) {
return gmlib::I18nAPI::get(key, params);
}
auto& i18n = DeathMessages::Entry::getInstance().getI18n();
return i18n.get(key, params);
logger->info(DeathMessages::Entry::getInstance().isResourceI18nLoaded ? "ResourceI18nLoaded" : "LangI18nLoaded");
if (params.size() > 1)
params.at(1) = gmlib::I18nAPI::get(
params.at(1),
{},
DeathMessages::Entry::getInstance().getConfig().ServerSideTranslation.Language
);
return i18n.get(key, params);
return key;
}
+1 -1
View File
@@ -17,4 +17,4 @@ extern bool isCrystal;
using DeathMessageResult = std::pair<std::string, std::vector<std::string>>;
extern DeathMessageResult translateDeathMessage(DeathMessageResult origin, std::string name, Actor* dead, ActorDamageSource* ads);
extern std::string tr(std::string const& key, std::vector<std::string> const& params = {});
extern std::string tr(std::string const& key, std::vector<std::string> params = {});
+5 -5
View File
@@ -87,8 +87,8 @@ LL_AUTO_TYPE_INSTANCE_HOOK(
auto res = translateDeathMessage(originl, a1, a2, this);
return res;
}
LL_AUTO_TYPE_INSTANCE_HOOK(
//
/*LL_AUTO_TYPE_INSTANCE_HOOK(
ActorDamageByActorHook,
HookPriority::Lowest,
ActorDamageByActorSource,
@@ -128,13 +128,13 @@ LL_AUTO_TYPE_INSTANCE_HOOK(
auto originl = origin(a1, a2);
auto res = translateDeathMessage(originl, a1, a2, this);
return res;
}
}*/
void uninstallHooks() {
MobDieHook::unhook();
CryatslHurtHook::unhook();
ActorDamageHook::unhook();
ActorDamageByActorHook::unhook();
/*ActorDamageByActorHook::unhook();
ActorDamageByBlockHook::unhook();
ActorDamageByChildHook::unhook();
ActorDamageByChildHook::unhook();*/
}
+3 -11
View File
@@ -8,7 +8,6 @@
#include "ll/api/event/EventBus.h"
ll::event::ListenerPtr playerConnectEventListener;
ll::event::ListenerPtr playerDieEventListener;
ll::event::ListenerPtr playerDisconnectEventListener;
void ListenEvents() {
auto& config = DeathMessages::Entry::getInstance().getConfig();
@@ -30,20 +29,13 @@ void ListenEvents() {
}
);
}
if (config.ConsoleLog.DeathMessage) {
playerDieEventListener=eventBus.emplaceListener<ll::event::player::PlayerDieEvent>(
[](ll::event::player::PlayerDieEvent& ev) {
auto [key, params] = ev.source().getDeathMessage(ev.self().getRealName(), &ev.self());
auto info = tr(key, params);
deathLogger->info(info);
}
);
}
//Die Message move to DeathMessage.cpp 93L
}
void uninstallEventListeners() {
auto& eventBus = ll::event::EventBus::getInstance();
eventBus.removeListener(playerDieEventListener);
eventBus.removeListener(playerConnectEventListener);
eventBus.removeListener(playerDisconnectEventListener);
}
+1
View File
@@ -4,3 +4,4 @@
#define LL_MEMORY_OPERATORS
#include "ll/api/memory/MemoryOperators.h" // IWYU pragma: keep
+1 -1
View File
@@ -2,7 +2,7 @@
"format_version": 3,
"format_uuid": "289f771f-2c9a-4d73-9f3f-8492495a924d",
"tooth": "github.com/GroupMountain/DeathMessages",
"version": "0.14.0",
"version": "0.14.1",
"info": {
"name": "DeathMessages",
"description": "Better Death Messages on MCBE",