feat: adapt gmlib 1.0.0
This commit is contained in:
@@ -18,7 +18,7 @@ bool isMatch(std::string& A, std::string& B) {
|
||||
|
||||
bool isTrust(Actor* ac) { return SynchedActorDataAccess::getActorFlag(ac->getEntityContext(), ::ActorFlags::Trusting); }
|
||||
|
||||
bool shouldIgnore(gmlib::world::actor::GMActor* ac) {
|
||||
bool shouldIgnore(gmlib::GMActor* ac) {
|
||||
if (ac->hasCategory(::ActorCategory::Mob) || ac->hasCategory(::ActorCategory::Item)) {
|
||||
if (ac->isTame() || isTrust(ac) || ac->getNameTag() != "" || ac->hasTag("cleaner:ignore")) {
|
||||
return true;
|
||||
@@ -30,7 +30,7 @@ bool shouldIgnore(gmlib::world::actor::GMActor* ac) {
|
||||
bool ShouldClean(Actor* actor) {
|
||||
// Players
|
||||
auto& config = Cleaner::Entry::getInstance().getConfig();
|
||||
auto en = (gmlib::world::actor::GMActor*)actor;
|
||||
auto en = (gmlib::GMActor*)actor;
|
||||
if (en->isPlayer() || shouldIgnore(en)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -109,9 +109,9 @@ void CleanTaskTPS(float min_tps) {
|
||||
co_await 10s;
|
||||
if (*mCleanTaskTPS == false) co_return;
|
||||
if (auto_clean_triggerred == false) {
|
||||
if (gmlib::world::GMLevel::getInstance()->getServerAverageTps() <= min_tps) {
|
||||
if (gmlib::GMLevel::getInstance()->getServerAverageTps() <= min_tps) {
|
||||
auto_clean_triggerred = true;
|
||||
auto mspt = S(gmlib::world::GMLevel::getInstance()->getServerAverageTps());
|
||||
auto mspt = S(gmlib::GMLevel::getInstance()->getServerAverageTps());
|
||||
if (config.Basic.ConsoleLog) {
|
||||
ll::io::LoggerRegistry::getInstance().getOrCreate("Cleaner")->warn(
|
||||
tr("cleaner.output.triggerAutoCleanTps", {mspt})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "Cleaner.h"
|
||||
|
||||
namespace Cleaner {
|
||||
void setShouldIgnore(gmlib::world::actor::GMActor* ac) { ac->addTag("cleaner:ignore"); }
|
||||
void setShouldIgnore(gmlib::GMActor* ac) { ac->addTag("cleaner:ignore"); }
|
||||
|
||||
void ListenEvents() {
|
||||
auto& eventBus = ll::event::EventBus::getInstance();
|
||||
@@ -10,28 +10,28 @@ void ListenEvents() {
|
||||
eventBus.emplaceListener<ila::mc::SpawnItemActorAfterEvent>([&config](ila::mc::SpawnItemActorAfterEvent& event) {
|
||||
auto& item = event.itemActor();
|
||||
if (event.spawner()) {
|
||||
auto pl = (gmlib::world::actor::GMPlayer*)event.spawner();
|
||||
auto pl = (gmlib::GMPlayer*)event.spawner();
|
||||
if (pl->isPlayer() && !pl->isAlive()) { // Death Drop
|
||||
auto ac = (gmlib::world::actor::GMActor*)&item;
|
||||
auto ac = (gmlib::GMActor*)&item;
|
||||
setShouldIgnore(ac);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (config.ItemDespawn.Enabled) {
|
||||
item->lifeTime() = config.ItemDespawn.DespawnTime;
|
||||
item.lifeTime() = config.ItemDespawn.DespawnTime;
|
||||
auto list = config.ItemDespawn.WhiteList;
|
||||
auto type = item->item().getTypeName();
|
||||
auto type = item.item().getTypeName();
|
||||
for (auto& key : list) {
|
||||
if (isMatch(type, key)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
item->lifeTime() = config.ItemDespawn.DespawnTime;
|
||||
item.lifeTime() = config.ItemDespawn.DespawnTime;
|
||||
}
|
||||
});
|
||||
// MobTakeItemEvent
|
||||
eventBus.emplaceListener<ila::mc::ActorPickupItemAfterEvent>([](ila::mc::ActorPickupItemAfterEvent& event) {
|
||||
auto mob = (gmlib::world::actor::GMActor*)&event.self();
|
||||
auto mob = (gmlib::GMActor*)&event.self();
|
||||
setShouldIgnore(mob);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
namespace Helper {
|
||||
|
||||
void broadcastMessage(std::string_view msg) {
|
||||
gmlib::world::GMLevel::getInstance()->broadcast(tr("cleaner.info.prefix") + std::string(msg));
|
||||
gmlib::GMLevel::getInstance()->broadcast(tr("cleaner.info.prefix") + std::string(msg));
|
||||
}
|
||||
|
||||
void broadcastToast(std::string_view msg) {
|
||||
gmlib::world::GMLevel::getInstance()->broadcastToast(tr("cleaner.info.prefix"), msg);
|
||||
gmlib::GMLevel::getInstance()->broadcastToast(tr("cleaner.info.prefix"), msg);
|
||||
}
|
||||
|
||||
} // namespace Helper
|
||||
@@ -5,8 +5,8 @@
|
||||
namespace UnloadActorClean {
|
||||
void cleanUnloadActor() {
|
||||
auto& config = Cleaner::Entry::getInstance().getConfig();
|
||||
gmlib::world::actor::UnloadedActor::foreachUnloadedActor(
|
||||
[config](gmlib::world::actor::UnloadedActor& actor) -> bool {
|
||||
gmlib::UnloadedActor::foreachUnloadedActor(
|
||||
[config](gmlib::UnloadedActor& actor) -> bool {
|
||||
for (auto& actorname : config.UnloadActorClean.CleanList) {
|
||||
if (actor.getTypeName() == actorname) {
|
||||
actor.remove();
|
||||
|
||||
Reference in New Issue
Block a user