Skip to content

Commit

Permalink
feat: add language config
Browse files Browse the repository at this point in the history
  • Loading branch information
KobeBryant114514 committed May 25, 2024
1 parent e653ffa commit 1773a04
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 57 deletions.
2 changes: 1 addition & 1 deletion SDK-GMLIB
Submodule SDK-GMLIB updated 51 files
+4 −4 GMLIB/Event/Entity/ActorChangeDImensionEvent.h
+3 −3 GMLIB/Event/Entity/DeathMessageEvent.h
+2 −2 GMLIB/Event/Entity/DragonRespawnEvent.h
+2 −2 GMLIB/Event/Entity/EconomyTradeEvent.h
+1 −1 GMLIB/Event/Entity/EndermanTakeBlockEvent.h
+1 −1 GMLIB/Event/Entity/ItemActorEvent.h
+21 −21 GMLIB/Event/Entity/ItemActorSpawnEvent.h
+2 −2 GMLIB/Event/Entity/MobHurtEvent.h
+2 −2 GMLIB/Event/Entity/MobPickupItemEvent.h
+2 −2 GMLIB/Event/Entity/ProjectileCreateEvent.h
+16 −16 GMLIB/Event/Level/ExplodeEvent.h
+8 −8 GMLIB/Event/Level/WeatherUpdateEvent.h
+12 −12 GMLIB/Event/Player/PlayerChangeDimensionEvent.h
+7 −7 GMLIB/Event/Player/PlayerSleepEvent.h
+2 −2 GMLIB/Event/RedStone/BlockMovedByPistonEvent.h
+8 −8 GMLIB/Event/RedStone/PistonPushEvent.h
+1 −1 GMLIB/Event/Registries/CreativeItemsInitEvent.h
+4 −4 GMLIB/Event/Registries/JsonItemInitEvent.h
+1 −1 GMLIB/Event/Registries/ResourcePackInitEvent.h
+0 −88 GMLIB/Files/Config/JsonConfig.h
+3 −3 GMLIB/Files/FileUtils.h
+15 −14 GMLIB/Files/JsonFile.h
+15 −15 GMLIB/Files/Language/I18n/JsonI18n.h
+15 −15 GMLIB/Files/Language/I18n/LangI18n.h
+13 −53 GMLIB/Files/Language/JsonLanguage.h
+9 −2 GMLIB/Files/Language/LangLanguage.h
+25 −14 GMLIB/Files/Language/McLang.h
+7 −7 GMLIB/Files/Language/ResourceLanguage.h
+20 −20 GMLIB/GMLIB.h
+6 −2 GMLIB/Macros.h
+1 −1 GMLIB/Mod/Addons/CustomDamageCause.h
+3 −2 GMLIB/Mod/Addons/CustomPacks.h
+1 −1 GMLIB/Mod/Addons/VanillaFix.h
+3 −3 GMLIB/Mod/CustomRecipe/CustomRecipe.h
+37 −32 GMLIB/Server/ActorAPI.h
+1 −37 GMLIB/Server/BinaryStreamAPI.h
+11 −11 GMLIB/Server/CompoundTagAPI.h
+1 −1 GMLIB/Server/FakeListAPI.h
+69 −53 GMLIB/Server/FloatingTextAPI.h
+2 −2 GMLIB/Server/FormAPI/NpcDialogueForm.h
+9 −9 GMLIB/Server/I18nAPI.h
+13 −13 GMLIB/Server/ItemStackAPI.h
+63 −31 GMLIB/Server/LevelAPI.h
+8 −8 GMLIB/Server/PlaceholderAPI.h
+59 −43 GMLIB/Server/PlayerAPI.h
+41 −41 GMLIB/Server/ScoreboardAPI.h
+23 −23 GMLIB/Server/SpawnerAPI.h
+35 −0 GMLIB/Server/StorageAPI.h
+30 −12 GMLIB/Server/UserCache.h
+1 −1 GMLIB/include_lib.h
+ Lib/GMLIB.lib
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "${pluginName}",
"entry": "${pluginFile}",
"type": "native",
"version": "0.12.2",
"version": "0.12.3",
"author": "GroupMountain",
"description": "Clean Entities",
"dependencies": [
Expand Down
4 changes: 3 additions & 1 deletion src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include <vector>

struct Config {
int version = 1;
int version = 2;

std::string language = "zh_CN";

struct basic {
std::string Command = "cleaner";
Expand Down
30 changes: 15 additions & 15 deletions src/Features/CleanTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DelayTask>(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<DelayTask>(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;
});
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Features/Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
40 changes: 20 additions & 20 deletions src/Features/VoteClean.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ 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) {
if (result.has_value()) {
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:
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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()) {
Expand All @@ -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;
Expand All @@ -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"));
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/Global.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
} // namespace Helper

extern std::string tr(std::string const& key, std::vector<std::string> const& params = {});
6 changes: 5 additions & 1 deletion src/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ ServerTimeScheduler& Entry::getScheduler() { return mScheduler.value(); }

} // namespace Cleaner

LL_REGISTER_PLUGIN(Cleaner::Entry, Cleaner::instance);
LL_REGISTER_PLUGIN(Cleaner::Entry, Cleaner::instance);

std::string tr(std::string const& key, std::vector<std::string> const& params) {
return I18nAPI::get(key, params, Cleaner::Entry::getInstance().getConfig().language);
}
26 changes: 13 additions & 13 deletions src/RegisterCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CleanerParam>()
Expand All @@ -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<CleanerParam>()
.required("action")
Expand All @@ -36,31 +36,31 @@ 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())}
));
}
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"));
}
}
}>();
Expand All @@ -70,22 +70,22 @@ 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) {
if (origin.getOriginType() == CommandOriginType::Player) {
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"));
}>();
}

Expand Down
4 changes: 2 additions & 2 deletions tooth.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
},
Expand Down

0 comments on commit 1773a04

Please sign in to comment.