11 Commits

9 changed files with 69 additions and 40 deletions
+3
View File
@@ -2,6 +2,9 @@
"name": "${pluginName}",
"entry": "${pluginFile}",
"type": "native",
"version": "0.10.0",
"author": "GroupMountain",
"description": "Clean Entities",
"dependencies": [
{
"name": "GMLIB"
+3 -8
View File
@@ -17,11 +17,7 @@ bool isMatch(std::string& A, std::string& B) {
bool shouldIgnore(GMLIB_Actor* ac) {
if (ac->isMob() || ac->isItemActor()) {
if (ac->isTame() || ac->isTrusting() || ac->getNameTag() != "") {
return true;
}
auto nbt = ac->getNbt();
if (nbt->getByte("ShowBottom") == 1) { // End Crystal Used Only, if has this tag 1b, it is modified by cleaner.
if (ac->isTame() || ac->isTrusting() || ac->getNameTag() != "" || ac->hasTag("cleaner:ignore")) {
return true;
}
}
@@ -35,8 +31,7 @@ bool ShouldClean(Actor* actor) {
return false;
}
auto type = en->getTypeName();
auto tags = Config->getValue<std::vector<std::string>>({"IgnoreTags"}, {});
for (auto& tag : tags) {
for (auto& tag : ConfigFile::mIgnoreTags) {
if (en->hasTag(tag)) {
return false;
}
@@ -62,7 +57,7 @@ bool ShouldClean(Actor* actor) {
// Mobs
else if (en->isMob()) {
if (Config->getValue<bool>({"CleanMobs", "Enabled"}, false)) {
auto blacklist = Config->getValue<std::vector<std::string>>({"CleanMobs", "Blacklist"}, {});
auto blacklist = Config->getValue<std::vector<std::string>>({"CleanMobs", "BlackList"}, {});
for (auto& key : blacklist) {
if (isMatch(type, key)) {
return true;
+27 -8
View File
@@ -5,14 +5,16 @@ namespace ConfigFile {
bool mConsoleLog = true;
bool mAnnounce = true;
bool mSendToast = true;
std::vector<std::string> mIgnoreTags = {};
} // namespace ConfigFile
namespace Cleaner {
static std::shared_ptr<ll::schedule::task::Task<ll::chrono::ServerClock>> mAutoCleanTask;
static std::shared_ptr<ll::schedule::task::Task<ll::chrono::ServerClock>> mCheckCleanTask;
static std::shared_ptr<ll::schedule::task::Task<ll::chrono::ServerClock>> mAutoCleanTask = nullptr;
static std::shared_ptr<ll::schedule::task::Task<ll::chrono::ServerClock>> mCleanTaskCount = nullptr;
static std::shared_ptr<ll::schedule::task::Task<ll::chrono::ServerClock>> mCleanTaskTPS = nullptr;
ServerTimeScheduler scheduler;
@@ -63,8 +65,8 @@ void AutoCleanTask(int seconds) {
mAutoCleanTask = scheduler.add<RepeatTask>(time, [] { CleanTask(); });
}
void CheckCleanTask(int max_entities, float min_tps) {
mCheckCleanTask = scheduler.add<RepeatTask>(10s, [max_entities, min_tps] {
void CleanTaskCount(int max_entities) {
mCleanTaskCount = scheduler.add<RepeatTask>(10s, [max_entities] {
auto count = CountEntities();
if (auto_clean_triggerred == false) {
if (count >= max_entities) {
@@ -79,7 +81,15 @@ void CheckCleanTask(int max_entities, float min_tps) {
Helper::broadcastToast(tr("cleaner.output.triggerAutoCleanCount", {S(count)}));
}
CleanTask();
} else if (GMLIB_Level::getLevel()->getServerAverageTps() <= min_tps) {
}
}
});
}
void CleanTaskTPS(float min_tps) {
mCleanTaskTPS = scheduler.add<RepeatTask>(10s, [min_tps] {
if (auto_clean_triggerred == false) {
if (GMLIB_Level::getLevel()->getServerAverageTps() <= min_tps) {
auto_clean_triggerred = true;
auto mspt = S(GMLIB_Level::getLevel()->getServerAverageTps());
if (ConfigFile::mConsoleLog) {
@@ -98,8 +108,17 @@ void CheckCleanTask(int max_entities, float min_tps) {
}
void stopAllTasks() {
mCheckCleanTask->cancel();
mAutoCleanTask->cancel();
if (!mCleanTaskCount) {
mCleanTaskTPS->cancel();
scheduler.remove(mCleanTaskTPS);
}
if (mCleanTaskCount) {
mCleanTaskCount->cancel();
scheduler.remove(mCleanTaskCount);
}
if (mAutoCleanTask) {
mAutoCleanTask->cancel();
scheduler.remove(mAutoCleanTask);
}
}
} // namespace Cleaner
+6 -6
View File
@@ -6,17 +6,17 @@ void loadCleaner() {
if (Config->getValue<bool>({"ScheduleClean", "Enabled"}, false)) {
Cleaner::AutoCleanTask(Config->getValue<int>({"ScheduleClean", "CleanInterval"}, 3000));
}
if (Config->getValue<bool>({"AutoCleanCount", "Enabled"}, false)
|| Config->getValue<bool>({"AutoCleanTPS", "Enabled"}, false)) {
Cleaner::CheckCleanTask(
Config->getValue<int>({"AutoCleanCount", "TriggerCount"}, 900),
Config->getValue<int>({"AutoCleanTPS", "TriggerTPS"}, 15)
);
if (Config->getValue<bool>({"AutoCleanCount", "Enabled"}, false)) {
Cleaner::CleanTaskCount(Config->getValue<int>({"AutoCleanCount", "TriggerCount"}, 900));
}
if (Config->getValue<bool>({"AutoCleanTPS", "Enabled"}, false)) {
Cleaner::CleanTaskTPS(Config->getValue<float>({"AutoCleanTPS", "TriggerTPS"}, 15.0f));
}
ConfigFile::mItemDespawnTicks = Config->getValue<int>({"ItemDespawn", "DespawnTime"}, 6000);
ConfigFile::mAnnounce = Config->getValue<bool>({"Basic", "SendBroadcast"}, true);
ConfigFile::mConsoleLog = Config->getValue<bool>({"Basic", "ConsoleLog"}, true);
ConfigFile::mSendToast = Config->getValue<bool>({"Basic", "SendToast"}, true);
ConfigFile::mIgnoreTags = Config->getValue<std::vector<std::string>>({"IgnoreTags"}, {});
}
void unloadCleaner() { stopAllTasks(); }
+4 -1
View File
@@ -12,7 +12,8 @@ extern int ExecuteClean();
extern int CountEntities();
extern void AutoCleanTask(int seconds);
extern void CheckCleanTask(int max_entities, float min_tps);
extern void CleanTaskCount(int max_entities);
extern void CleanTaskTPS(float min_tps);
extern void ListenEvents();
extern void stopAllTasks();
extern void CleanTask();
@@ -20,6 +21,8 @@ extern void reloadCleaner();
extern void loadCleaner();
extern void unloadCleaner();
extern bool isMatch(std::string& A, std::string& B);
} // namespace Cleaner
namespace VoteClean {
+13 -7
View File
@@ -9,11 +9,7 @@ int mItemDespawnTicks = 3000;
namespace Cleaner {
void setShouldIgnore(GMLIB_Actor* ac) {
auto nbt = ac->getNbt();
nbt->put("ShowBottom", ByteTag(1));
ac->setNbt(*nbt);
}
void setShouldIgnore(GMLIB_Actor* ac) { ac->addTag("cleaner:ignore"); }
void ListenEvents() {
auto& eventBus = ll::event::EventBus::getInstance();
@@ -21,15 +17,25 @@ void ListenEvents() {
eventBus.emplaceListener<GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent>(
[](GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent& event) {
auto& item = event.getItemActor();
auto pl = (GMLIB_Player*)event.getSpawner();
if (pl) {
if (event.getSpawner().has_value()) {
auto pl = (GMLIB_Player*)event.getSpawner().as_ptr();
if (pl->isPlayer() && !pl->isAlive()) { // Death Drop
auto ac = (GMLIB_Actor*)&item;
setShouldIgnore(ac);
return;
}
}
if (Config->getValue<bool>({"ItemDespawn", "Enabled"}, true)) {
item.lifeTime() = ConfigFile::mItemDespawnTicks;
auto list = Config->getValue<std::vector<std::string>>({"ItemDespawn", "WhiteList"}, {});
auto type = item.item().getTypeName();
for (auto& key : list) {
if (isMatch(type, key)) {
return;
}
}
item.lifeTime() = ConfigFile::mItemDespawnTicks;
}
}
);
// MobTakeItemEvent
+1
View File
@@ -18,6 +18,7 @@ extern int mItemDespawnTicks;
extern bool mConsoleLog;
extern bool mAnnounce;
extern bool mSendToast;
extern std::vector<std::string> mIgnoreTags;
} // namespace ConfigFile
namespace Helper {
+7 -5
View File
@@ -1,19 +1,21 @@
{
"format_version": 2,
"tooth": "github.com/GroupMountain/Cleaner",
"version": "0.8.1",
"version": "0.10.0",
"info": {
"name": "Cleaner",
"description": "A Powerful Entities Cleaning up Plugin for BDS",
"author": "GroupMountain",
"source": "github.com/GroupMountain/Cleaner",
"tags": [
"LeviLamina",
"Cleaner"
"levilamina",
"cleaner",
"gmlib"
]
},
"asset_url": "https://github.com/GroupMountain/Cleaner/releases/download/v0.8.1/Cleaner-windows-x64.zip",
"asset_url": "https://github.com/GroupMountain/Cleaner/releases/download/v0.10.0/Cleaner-windows-x64.zip",
"dependencies": {
"github.com/GroupMountain/GMLIB": ">=0.8.2"
"github.com/GroupMountain/GMLIB": ">=0.10.0"
},
"files": {
"place": [