diff --git a/SDK-GMLIB b/SDK-GMLIB index fd84632..710cc6e 160000 --- a/SDK-GMLIB +++ b/SDK-GMLIB @@ -1 +1 @@ -Subproject commit fd8463224fca3a7a716b7dc29bac2cc4aeae4dfb +Subproject commit 710cc6e4c3b0e85fd793fba807d8fffd6c4b607f diff --git a/manifest.json b/manifest.json index 2592649..59fbc9b 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "name": "${pluginName}", "entry": "${pluginFile}", "type": "native", - "version": "0.12.2", + "version": "0.12.3", "author": "GroupMountain", "description": "Clean Entities", "dependencies": [ diff --git a/src/Config.h b/src/Config.h index ba58556..a76e511 100644 --- a/src/Config.h +++ b/src/Config.h @@ -3,7 +3,9 @@ #include struct Config { - int version = 1; + int version = 2; + + std::string language = "zh_CN"; struct basic { std::string Command = "cleaner"; diff --git a/src/Features/CleanTask.cpp b/src/Features/CleanTask.cpp index 225bd7a..1935a43 100644 --- a/src/Features/CleanTask.cpp +++ b/src/Features/CleanTask.cpp @@ -15,35 +15,35 @@ void CleanTask() { auto time_1 = std::chrono::seconds::duration(time); auto time_2 = std::chrono::seconds::duration(time - announce_time); if (config.Basic.ConsoleLog) { - logger.info(I18nAPI::get("cleaner.output.count1", {S(time_1.count())})); + logger.info(tr("cleaner.output.count1", {S(time_1.count())})); } if (config.Basic.SendBroadcast) { - Helper::broadcastMessage(I18nAPI::get("cleaner.output.count1", {S(time_1.count())})); + Helper::broadcastMessage(tr("cleaner.output.count1", {S(time_1.count())})); } if (config.Basic.SendToast) { - Helper::broadcastToast(I18nAPI::get("cleaner.output.count2", {S(announce_time)})); + Helper::broadcastToast(tr("cleaner.output.count2", {S(announce_time)})); } Cleaner::Entry::getInstance().getScheduler().add(time_2, [announce_time, &config] { if (config.Basic.ConsoleLog) { - logger.info(I18nAPI::get("cleaner.output.count2", {S(announce_time)})); + logger.info(tr("cleaner.output.count2", {S(announce_time)})); } if (config.Basic.SendBroadcast) { - Helper::broadcastMessage(I18nAPI::get("cleaner.output.count2", {S(announce_time)})); + Helper::broadcastMessage(tr("cleaner.output.count2", {S(announce_time)})); } if (config.Basic.SendToast) { - Helper::broadcastToast(I18nAPI::get("cleaner.output.count2", {S(announce_time)})); + Helper::broadcastToast(tr("cleaner.output.count2", {S(announce_time)})); } }); Cleaner::Entry::getInstance().getScheduler().add(time_1, [&config] { auto count = ExecuteClean(); if (config.Basic.ConsoleLog) { - logger.info(I18nAPI::get("cleaner.output.finish", {S(count)})); + logger.info(tr("cleaner.output.finish", {S(count)})); } if (config.Basic.SendBroadcast) { - Helper::broadcastMessage(I18nAPI::get("cleaner.output.finish", {S(count)})); + Helper::broadcastMessage(tr("cleaner.output.finish", {S(count)})); } if (config.Basic.SendToast) { - Helper::broadcastToast(I18nAPI::get("cleaner.output.finish", {S(count)})); + Helper::broadcastToast(tr("cleaner.output.finish", {S(count)})); } auto_clean_triggerred = false; }); @@ -62,13 +62,13 @@ void CleanTaskCount(int max_entities) { if (count >= max_entities) { auto_clean_triggerred = true; if (config.Basic.ConsoleLog) { - logger.warn(I18nAPI::get("cleaner.output.triggerAutoCleanCount", {S(count)})); + logger.warn(tr("cleaner.output.triggerAutoCleanCount", {S(count)})); } if (config.Basic.SendBroadcast) { - Helper::broadcastMessage(I18nAPI::get("cleaner.output.triggerAutoCleanCount", {S(count)})); + Helper::broadcastMessage(tr("cleaner.output.triggerAutoCleanCount", {S(count)})); } if (config.Basic.SendToast) { - Helper::broadcastToast(I18nAPI::get("cleaner.output.triggerAutoCleanCount", {S(count)})); + Helper::broadcastToast(tr("cleaner.output.triggerAutoCleanCount", {S(count)})); } CleanTask(); } @@ -84,13 +84,13 @@ void CleanTaskTPS(float min_tps) { auto_clean_triggerred = true; auto mspt = S(GMLIB_Level::getLevel()->getServerAverageTps()); if (config.Basic.ConsoleLog) { - logger.warn(I18nAPI::get("cleaner.output.triggerAutoCleanTps", {mspt})); + logger.warn(tr("cleaner.output.triggerAutoCleanTps", {mspt})); } if (config.Basic.SendBroadcast) { - Helper::broadcastMessage(I18nAPI::get("cleaner.output.triggerAutoCleanTps", {mspt})); + Helper::broadcastMessage(tr("cleaner.output.triggerAutoCleanTps", {mspt})); } if (config.Basic.SendToast) { - Helper::broadcastToast(I18nAPI::get("cleaner.output.triggerAutoCleanTps", {mspt})); + Helper::broadcastToast(tr("cleaner.output.triggerAutoCleanTps", {mspt})); } CleanTask(); } diff --git a/src/Features/Helper.cpp b/src/Features/Helper.cpp index daec340..8805e3a 100644 --- a/src/Features/Helper.cpp +++ b/src/Features/Helper.cpp @@ -3,11 +3,11 @@ namespace Helper { void broadcastMessage(std::string_view msg) { - GMLIB_Level::getInstance()->broadcast(I18nAPI::get("cleaner.info.prefix") + std::string(msg)); + GMLIB_Level::getInstance()->broadcast(tr("cleaner.info.prefix") + std::string(msg)); } void broadcastToast(std::string_view msg) { - GMLIB_Level::getInstance()->broadcastToast(I18nAPI::get("cleaner.info.prefix"), msg); + GMLIB_Level::getInstance()->broadcastToast(tr("cleaner.info.prefix"), msg); } } // namespace Helper \ No newline at end of file diff --git a/src/Features/VoteClean.cpp b/src/Features/VoteClean.cpp index 2ddcd82..1745f4d 100644 --- a/src/Features/VoteClean.cpp +++ b/src/Features/VoteClean.cpp @@ -24,10 +24,10 @@ int getPlayerCount() { void sendVoteForm(Player* pl) { auto fm = ll::form::ModalForm( - I18nAPI::get("cleaner.vote.title"), - I18nAPI::get("cleaner.vote.subtitle", {pl->getRealName()}), - I18nAPI::get("cleaner.vote.ok"), - I18nAPI::get("cleaner.vote.no") + tr("cleaner.vote.title"), + tr("cleaner.vote.subtitle", {pl->getRealName()}), + tr("cleaner.vote.ok"), + tr("cleaner.vote.no") ); ll::service::getLevel()->forEachPlayer([&](Player& pl) -> bool { fm.sendTo(pl, [](Player& player, ll::form::ModalFormResult result, ll::form::FormCancelReason reason) { @@ -35,12 +35,12 @@ void sendVoteForm(Player* pl) { switch (result.value()) { case ll::form::ModalFormSelectedButton::Upper: { voteList[player.getUuid()] = true; - player.sendMessage(I18nAPI::get("cleaner.vote.accept")); + player.sendMessage(tr("cleaner.vote.accept")); return; } case ll::form::ModalFormSelectedButton::Lower: { voteList[player.getUuid()] = false; - player.sendMessage(I18nAPI::get("cleaner.vote.deny")); + player.sendMessage(tr("cleaner.vote.deny")); return; } default: @@ -64,18 +64,18 @@ void checkVote() { float result = ((float)voteCount) / ((float)playerCount); if (result >= percentage) { if (config.Basic.SendBroadcast) { - Helper::broadcastMessage(I18nAPI::get("cleaner.vote.succeed")); + Helper::broadcastMessage(tr("cleaner.vote.succeed")); } if (config.Basic.SendToast) { - Helper::broadcastToast(I18nAPI::get("cleaner.vote.succeed")); + Helper::broadcastToast(tr("cleaner.vote.succeed")); } Cleaner::CleanTask(); } else { if (config.Basic.SendBroadcast) { - Helper::broadcastMessage(I18nAPI::get("cleaner.vote.failed")); + Helper::broadcastMessage(tr("cleaner.vote.failed")); } if (config.Basic.SendToast) { - Helper::broadcastToast(I18nAPI::get("cleaner.vote.failed")); + Helper::broadcastToast(tr("cleaner.vote.failed")); } } hasVote = false; @@ -89,10 +89,10 @@ void voteClean(Player* pl) { hasVote = true; playerCount = getPlayerCount(); if (config.Basic.SendBroadcast) { - Helper::broadcastMessage(I18nAPI::get("cleaner.vote.voteMessage", {pl->getRealName()})); + Helper::broadcastMessage(tr("cleaner.vote.voteMessage", {pl->getRealName()})); } if (config.Basic.SendToast) { - Helper::broadcastToast(I18nAPI::get("cleaner.vote.voteMessage", {pl->getRealName()})); + Helper::broadcastToast(tr("cleaner.vote.voteMessage", {pl->getRealName()})); } sendVoteForm(pl); auto cooldown = std::chrono::seconds::duration(config.VoteClean.Cooldown); @@ -103,10 +103,10 @@ void voteClean(Player* pl) { void confirmForm(Player* pl) { auto fm = ll::form::ModalForm( - I18nAPI::get("cleaner.vote.title"), - I18nAPI::get("cleaner.vote.confirmTubtitle"), - I18nAPI::get("cleaner.vote.confirmOk"), - I18nAPI::get("cleaner.vote.confirmNo") + tr("cleaner.vote.title"), + tr("cleaner.vote.confirmTubtitle"), + tr("cleaner.vote.confirmOk"), + tr("cleaner.vote.confirmNo") ); fm.sendTo(*pl, [](Player& player, ll::form::ModalFormResult result, ll::form::FormCancelReason reason) { if (result.has_value()) { @@ -115,7 +115,7 @@ void confirmForm(Player* pl) { return voteClean(&player); } case ll::form::ModalFormSelectedButton::Lower: { - return player.sendMessage(I18nAPI::get("cleaner.vote.cancel")); + return player.sendMessage(tr("cleaner.vote.cancel")); } default: return; @@ -129,14 +129,14 @@ void voteCommandExecute(Player* pl) { if (canVote) { confirmForm(pl); } else { - pl->sendMessage(I18nAPI::get("cleaner.vote.cooldown")); + pl->sendMessage(tr("cleaner.vote.cooldown")); } } else { if (voteList.count(pl->getUuid())) { - pl->sendMessage(I18nAPI::get("cleaner.vote.voted")); + pl->sendMessage(tr("cleaner.vote.voted")); } else { voteList[pl->getUuid()] = true; - pl->sendMessage(I18nAPI::get("cleaner.vote.accept")); + pl->sendMessage(tr("cleaner.vote.accept")); } } } diff --git a/src/Global.h b/src/Global.h index 9ad6640..3982287 100644 --- a/src/Global.h +++ b/src/Global.h @@ -12,4 +12,6 @@ extern void RegisterCommands(); namespace Helper { extern void broadcastMessage(std::string_view msg); extern void broadcastToast(std::string_view msg); -} // namespace Helper \ No newline at end of file +} // namespace Helper + +extern std::string tr(std::string const& key, std::vector const& params = {}); \ No newline at end of file diff --git a/src/Plugin.cpp b/src/Plugin.cpp index 351f49d..23a9e8b 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -44,4 +44,8 @@ ServerTimeScheduler& Entry::getScheduler() { return mScheduler.value(); } } // namespace Cleaner -LL_REGISTER_PLUGIN(Cleaner::Entry, Cleaner::instance); \ No newline at end of file +LL_REGISTER_PLUGIN(Cleaner::Entry, Cleaner::instance); + +std::string tr(std::string const& key, std::vector const& params) { + return I18nAPI::get(key, params, Cleaner::Entry::getInstance().getConfig().language); +} \ No newline at end of file diff --git a/src/RegisterCommand.cpp b/src/RegisterCommand.cpp index 9c3c4ef..a7a1468 100644 --- a/src/RegisterCommand.cpp +++ b/src/RegisterCommand.cpp @@ -13,7 +13,7 @@ void RegCleanerCommand() { auto& config = Cleaner::Entry::getInstance().getConfig(); auto& cmd = ll::command::CommandRegistrar::getInstance().getOrCreateCommand( config.Basic.Command, - I18nAPI::get("cleaner.command.cleaner"), + tr("cleaner.command.cleaner"), CommandPermissionLevel::GameDirectors ); cmd.overload() @@ -22,12 +22,12 @@ void RegCleanerCommand() { .execute<[&](CommandOrigin const& origin, CommandOutput& output, CleanerParam const& param) { auto ens = param.entity.results(origin); if (ens.empty()) { - return output.error(I18nAPI::get("cleaner.command.error.noTarget")); + return output.error(tr("cleaner.command.error.noTarget")); } for (auto en : ens) { en->despawn(); } - return output.success(I18nAPI::get("cleaner.command.despawnSuccess", {S(ens.size())})); + return output.success(tr("cleaner.command.despawnSuccess", {S(ens.size())})); }>(); cmd.overload() .required("action") @@ -36,18 +36,18 @@ void RegCleanerCommand() { case CleanerParam::Action::clean: { Cleaner::CleanTask(); if (Cleaner::Entry::getInstance().getConfig().Basic.ConsoleLog) { - logger.info(I18nAPI::get("cleaner.output.opClean")); + logger.info(tr("cleaner.output.opClean")); } if (Cleaner::Entry::getInstance().getConfig().Basic.SendBroadcast) { - Helper::broadcastMessage(I18nAPI::get("cleaner.output.opClean")); + Helper::broadcastMessage(tr("cleaner.output.opClean")); } if (Cleaner::Entry::getInstance().getConfig().Basic.SendToast) { - Helper::broadcastToast(I18nAPI::get("cleaner.output.opClean")); + Helper::broadcastToast(tr("cleaner.output.opClean")); } - return output.success(I18nAPI::get("cleaner.command.clean.output")); + return output.success(tr("cleaner.command.clean.output")); } case CleanerParam::Action::tps: { - return output.success(I18nAPI::get( + return output.success(tr( "cleaner.command.tps.output", {S(GMLIB_Level::getLevel()->getServerCurrentTps()), S(GMLIB_Level::getLevel()->getServerAverageTps())} @@ -55,12 +55,12 @@ void RegCleanerCommand() { } case CleanerParam::Action::mspt: { return output.success( - I18nAPI::get("cleaner.command.mspt.output", {S(GMLIB_Level::getLevel()->getServerMspt())}) + tr("cleaner.command.mspt.output", {S(GMLIB_Level::getLevel()->getServerMspt())}) ); } case CleanerParam::Action::reload: { Cleaner::reloadCleaner(); - return output.success(I18nAPI::get("cleaner.output.reload")); + return output.success(tr("cleaner.output.reload")); } } }>(); @@ -70,14 +70,14 @@ void RegCleanerCommand() { .execute<[&](CommandOrigin const& origin, CommandOutput& output, CleanerParam const& param) { Cleaner::Entry::getInstance().getConfig().ItemDespawn.DespawnTime = param.ticks; Cleaner::Entry::getInstance().saveConfig(); - return output.success(I18nAPI::get("cleaner.command.despawntime", {S(param.ticks)})); + return output.success(tr("cleaner.command.despawntime", {S(param.ticks)})); }>(); }; void RegVoteCommand() { auto& cmd = ll::command::CommandRegistrar::getInstance().getOrCreateCommand( Cleaner::Entry::getInstance().getConfig().VoteClean.VoteCleanCommand, - I18nAPI::get("cleaner.command.voteclean"), + tr("cleaner.command.voteclean"), CommandPermissionLevel::Any ); cmd.overload().execute<[&](CommandOrigin const& origin, CommandOutput& output) { @@ -85,7 +85,7 @@ void RegVoteCommand() { auto pl = (Player*)origin.getEntity(); return VoteClean::voteCommandExecute(pl); } - return output.error(I18nAPI::get("cleaner.command.error.playerOnly")); + return output.error(tr("cleaner.command.error.playerOnly")); }>(); } diff --git a/tooth.json b/tooth.json index 0b9443a..7ce5967 100644 --- a/tooth.json +++ b/tooth.json @@ -1,7 +1,7 @@ { "format_version": 2, "tooth": "github.com/GroupMountain/Cleaner", - "version": "0.12.2", + "version": "0.12.3", "info": { "name": "Cleaner", "description": "A Powerful Entities Cleaning up Plugin for BDS", @@ -13,7 +13,7 @@ "gmlib" ] }, - "asset_url": "https://github.com/GroupMountain/Cleaner/releases/download/v0.12.2/Cleaner-windows-x64.zip", + "asset_url": "https://github.com/GroupMountain/Cleaner/releases/download/v0.12.3/Cleaner-windows-x64.zip", "dependencies": { "github.com/GroupMountain/GMLIB": ">=0.12.4" },