feat: migrate to LeviLamina
This commit is contained in:
+33
-46
@@ -5,15 +5,13 @@
|
||||
#include <GMLIB/Server/PlayerAPI.h>
|
||||
#include <regex>
|
||||
|
||||
GMLIB::Files::JsonConfig* Config = nullptr;
|
||||
nlohmann::json Language;
|
||||
|
||||
using namespace ll::schedule;
|
||||
using namespace ll::chrono_literals;
|
||||
|
||||
int item_despawn_time = 3000;
|
||||
|
||||
// ServerTimeAsyncScheduler scheduler;
|
||||
bool auto_clean_triggerred = false;
|
||||
ServerTimeAsyncScheduler scheduler;
|
||||
bool auto_clean_triggerred = false;
|
||||
|
||||
namespace Cleaner {
|
||||
|
||||
@@ -130,43 +128,42 @@ int CountEntities() {
|
||||
return clean_count;
|
||||
}
|
||||
|
||||
void CleanTask(int time, int announce_time) {
|
||||
auto time_1 = std::chrono::seconds::duration(time);
|
||||
auto time_2 = std::chrono::seconds::duration(time - announce_time);
|
||||
void CleanTask() {
|
||||
auto time = Config->getValue<int>({"Basic", "Notice1"}, 20);
|
||||
auto announce_time = Config->getValue<int>({"Basic", "Notice2"}, 15);
|
||||
auto time_1 = std::chrono::seconds::duration(time);
|
||||
auto time_2 = std::chrono::seconds::duration(time - announce_time);
|
||||
logger.info(tr("cleaner.output.count1", {S(time_1.count())}));
|
||||
// scheduler.add<DelayTask>(time_2, [announce_time] {
|
||||
logger.info(tr("cleaner.output.count2", {S(announce_time)}));
|
||||
//});
|
||||
// scheduler.add<DelayTask>(time_1, [] {
|
||||
auto count = ExecuteClean();
|
||||
logger.info(tr("cleaner.output.finish", {S(count)}));
|
||||
auto_clean_triggerred = false;
|
||||
//});
|
||||
scheduler.add<DelayTask>(time_2, [announce_time] { logger.info(tr("cleaner.output.count2", {S(announce_time)})); });
|
||||
scheduler.add<DelayTask>(time_1, [] {
|
||||
auto count = ExecuteClean();
|
||||
logger.info(tr("cleaner.output.finish", {S(count)}));
|
||||
auto_clean_triggerred = false;
|
||||
});
|
||||
}
|
||||
|
||||
void AutoCleanTask(int seconds) {
|
||||
auto time = std::chrono::seconds::duration(seconds);
|
||||
// mAutoCleanTask = scheduler.add<RepeatTask>(time, [] {
|
||||
CleanTask(Config->getValue<int>({"Basic", "Notice1"}, 20), Config->getValue<int>({"Basic", "Notice2"}, 15));
|
||||
//});
|
||||
auto time = std::chrono::seconds::duration(seconds);
|
||||
mAutoCleanTask = scheduler.add<RepeatTask>(time, [] { CleanTask(); });
|
||||
}
|
||||
|
||||
void CheckCleanTask(int max_entities, float min_tps) {
|
||||
// mCheckCleanTask = scheduler.add<RepeatTask>(10s, [max_entities, min_tps] {
|
||||
auto count = CountEntities();
|
||||
if (auto_clean_triggerred == false) {
|
||||
if (count >= max_entities) {
|
||||
auto_clean_triggerred = true;
|
||||
logger.warn(tr("cleaner.output.triggerAutoCleanCount", {S(count)}));
|
||||
CleanTask(Config->getValue<int>({"Basic", "Notice1"}, 20), Config->getValue<int>({"Basic", "Notice2"}, 15));
|
||||
} else if (GMLIB_Level::getLevel()->getServerAverageTps() <= min_tps) {
|
||||
auto_clean_triggerred = true;
|
||||
logger.warn(tr("cleaner.output.triggerAutoCleanCount", {S(GMLIB_Level::getLevel()->getServerAverageTps())})
|
||||
);
|
||||
CleanTask(Config->getValue<int>({"Basic", "Notice1"}, 20), Config->getValue<int>({"Basic", "Notice2"}, 15));
|
||||
mCheckCleanTask = scheduler.add<RepeatTask>(10s, [max_entities, min_tps] {
|
||||
auto count = CountEntities();
|
||||
if (auto_clean_triggerred == false) {
|
||||
if (count >= max_entities) {
|
||||
auto_clean_triggerred = true;
|
||||
logger.warn(tr("cleaner.output.triggerAutoCleanCount", {S(count)}));
|
||||
CleanTask();
|
||||
} else if (GMLIB_Level::getLevel()->getServerAverageTps() <= min_tps) {
|
||||
auto_clean_triggerred = true;
|
||||
logger.warn(
|
||||
tr("cleaner.output.triggerAutoCleanCount", {S(GMLIB_Level::getLevel()->getServerAverageTps())})
|
||||
);
|
||||
CleanTask();
|
||||
}
|
||||
}
|
||||
}
|
||||
//});
|
||||
});
|
||||
}
|
||||
|
||||
void setShouldIgnore(GMLIB_Actor* ac) {
|
||||
@@ -207,12 +204,6 @@ void reloadCleaner() {
|
||||
loadCleaner();
|
||||
}
|
||||
|
||||
void loadConfig() {
|
||||
Config = new GMLIB::Files::JsonConfig("./plugins/Cleaner/config/config.json", defaultConfig);
|
||||
Config->initConfig();
|
||||
Language = GMLIB::Files::JsonLanguage::initLanguage("./plugins/Cleaner/config/language.json", defaultLanguage);
|
||||
}
|
||||
|
||||
void loadCleaner() {
|
||||
ListenEvents();
|
||||
RegisterCommands();
|
||||
@@ -226,17 +217,13 @@ void loadCleaner() {
|
||||
Config->getValue<int>({"AutoCleanTPS", "TriggerTPS"}, 15)
|
||||
);
|
||||
}
|
||||
item_despawn_time = Config->getValue<int>({"ItemDespawn", "DespawnTime"}, 6000);
|
||||
}
|
||||
|
||||
void unloadCleaner() {
|
||||
mAutoCleanTask->cancel();
|
||||
mCheckCleanTask->cancel();
|
||||
// UnregisterCommands();
|
||||
delete Config;
|
||||
}
|
||||
|
||||
} // namespace Cleaner
|
||||
|
||||
std::string tr(std::string key, std::vector<std::string> data) {
|
||||
return GMLIB::Files::JsonLanguage::translate(Language, key, data);
|
||||
}
|
||||
} // namespace Cleaner
|
||||
Reference in New Issue
Block a user