refactor: refactor config

This commit is contained in:
Tsubasa6848
2024-02-15 21:37:27 +08:00
Unverified
parent af2cbd45aa
commit 6d7b07a355
3 changed files with 22 additions and 14 deletions
+19 -11
View File
@@ -10,9 +10,12 @@ using namespace ll::chrono_literals;
int item_despawn_time = 3000;
ServerTimeAsyncScheduler scheduler;
ServerTimeScheduler scheduler;
bool auto_clean_triggerred = false;
bool ConsoleLog = true;
bool Announce = true;
namespace Cleaner {
bool isMatch(std::string& A, std::string& B) {
@@ -130,30 +133,33 @@ int CountEntities() {
void CleanTask() {
auto time = Config->getValue<int>({"Basic", "Notice1"}, 20);
auto announce_time = Config->getValue<int>({"Basic", "Notice2"}, 15);
auto announce_time = Config->getValue<int>({"Basic", "Notice2"}, 5);
auto time_1 = std::chrono::seconds::duration(time);
auto time_2 = std::chrono::seconds::duration(time - announce_time);
if (Config->getValue<bool>({"Basic", "ConsoleLog"}, true)) {
if (ConsoleLog) {
logger.info(tr("cleaner.output.count1", {S(time_1.count())}));
}
if (Config->getValue<bool>({"Basic", "SendBroadcast"}, true)) {
TextPacket::createRawMessage(tr("cleaner.output.count1", {S(time_1.count())})).sendToClients();
if (Announce) {
TextPacket::createRawMessage(tr("cleaner.info.prefix") + tr("cleaner.output.count1", {S(time_1.count())}))
.sendToClients();
}
scheduler.add<DelayTask>(time_2, [announce_time] {
if (Config->getValue<bool>({"Basic", "ConsoleLog"}, true)) {
if (ConsoleLog) {
logger.info(tr("cleaner.output.count2", {S(announce_time)}));
}
if (Config->getValue<bool>({"Basic", "SendBroadcast"}, true)) {
TextPacket::createRawMessage(tr("cleaner.output.count2", {S(announce_time)})).sendToClients();
if (Announce) {
TextPacket::createRawMessage(tr("cleaner.info.prefix") + tr("cleaner.output.count2", {S(announce_time)}))
.sendToClients();
}
});
scheduler.add<DelayTask>(time_1, [] {
auto count = ExecuteClean();
if (Config->getValue<bool>({"Basic", "ConsoleLog"}, true)) {
if (ConsoleLog) {
logger.info(tr("cleaner.output.finish", {S(count)}));
}
if (Config->getValue<bool>({"Basic", "SendBroadcast"}, true)) {
TextPacket::createRawMessage(tr("cleaner.output.finish", {S(count)})).sendToClients();
if (Announce) {
TextPacket::createRawMessage(tr("cleaner.info.prefix") + tr("cleaner.output.finish", {S(count)}))
.sendToClients();
}
auto_clean_triggerred = false;
});
@@ -235,6 +241,8 @@ void loadCleaner() {
);
}
item_despawn_time = Config->getValue<int>({"ItemDespawn", "DespawnTime"}, 6000);
Announce = Config->getValue<bool>({"Basic", "SendBroadcast"}, true);
ConsoleLog = Config->getValue<bool>({"Basic", "ConsoleLog"}, true);
}
void unloadCleaner() {
+1 -1
View File
@@ -2,7 +2,7 @@
#include "Global.h"
std::string defaultLanguage_en_US = R"({
"cleaner.toast.title": "§e§lCleaner",
"cleaner.info.prefix": "§e§l[Cleaner] §r",
"cleaner.command.cleaner": "Cleaner admin command.",
"cleaner.command.despawnSuccess": "Successfully despawned %1$s entities.",
"cleaner.command.error.noTarget": "No targets matched the selector.",
+1 -1
View File
@@ -37,7 +37,7 @@ void RegCleanerCommand() {
logger.info(tr("cleaner.output.opClean"));
}
if (Config->getValue<bool>({"Basic", "SendBroadcast"}, true)) {
TextPacket::createRawMessage(tr("cleaner.output.opClean")).sendToClients();
TextPacket::createRawMessage(tr("cleaner.info.prefix") + tr("cleaner.output.opClean")).sendToClients();
}
return output.success(tr("cleaner.command.clean.output"));
}