Compare commits
29 Commits
f85416b785
...
main
@@ -1,5 +1,23 @@
|
|||||||
Diagnostics:
|
Diagnostics:
|
||||||
Suppress: ["-Wmicrosoft-enum-forward-reference", "-Wc++11-narrowing", "-Wc++2b-extensions", "-Wmicrosoft-cast"]
|
Suppress:
|
||||||
|
- "-Wmicrosoft-enum-forward-reference"
|
||||||
|
- "-Wc++11-narrowing"
|
||||||
|
- "-Wc++2b-extensions"
|
||||||
|
- "-Wmicrosoft-cast"
|
||||||
|
- "-Wcxx20_deducing_this"
|
||||||
|
- "-Wundefined_internal_type"
|
||||||
|
- "-Wincomplete_member_access"
|
||||||
|
- "-Wsizeof_alignof_incomplete_or_sizeless_type"
|
||||||
|
- "-Wexplicit_spec_non_template"
|
||||||
|
- "-Wovl_no_viable_function_in_init"
|
||||||
CompileFlags:
|
CompileFlags:
|
||||||
Add: ["-ferror-limit=0", "-D__FUNCTION__=\"dummy\"", "-D_CRT_USE_BUILTIN_OFFSETOF", "-std=c++23"]
|
Add:
|
||||||
Remove: ["/Yu_HeaderOutputPredefine.h", "/FI_HeaderOutputPredefine.h"]
|
- "-Xclang"
|
||||||
|
- "-triple=x86_64-windows-msvc"
|
||||||
|
- "-ferror-limit=0"
|
||||||
|
- '-D__FUNCTION__="dummy"'
|
||||||
|
- "-Dnsel_CONFIG_SELECT_EXPECTED=nsel_EXPECTED_NONSTD"
|
||||||
|
- "-Xclang"
|
||||||
|
- "-std=c++23"
|
||||||
|
Remove:
|
||||||
|
- "-std"
|
||||||
@@ -16,7 +16,8 @@ jobs:
|
|||||||
|
|
||||||
- uses: xmake-io/github-action-setup-xmake@v1
|
- uses: xmake-io/github-action-setup-xmake@v1
|
||||||
with:
|
with:
|
||||||
xmake-version: latest
|
xmake-version: 3.0.0
|
||||||
|
|
||||||
- run: |
|
- run: |
|
||||||
xmake repo -u
|
xmake repo -u
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ jobs:
|
|||||||
|
|
||||||
- uses: xmake-io/github-action-setup-xmake@v1
|
- uses: xmake-io/github-action-setup-xmake@v1
|
||||||
with:
|
with:
|
||||||
xmake-version: latest
|
xmake-version: 3.0.0
|
||||||
|
|
||||||
- run: |
|
- run: |
|
||||||
xmake repo -u
|
xmake repo -u
|
||||||
|
|
||||||
|
|||||||
@@ -6,3 +6,5 @@
|
|||||||
/compile_commands.json
|
/compile_commands.json
|
||||||
/CMakeLists.txt
|
/CMakeLists.txt
|
||||||
/.vscode
|
/.vscode
|
||||||
|
/.idea
|
||||||
|
github_mirror.lua
|
||||||
|
|||||||
@@ -101,6 +101,13 @@
|
|||||||
"Cooldown": 120, // 投票冷却时间 单位:秒
|
"Cooldown": 120, // 投票冷却时间 单位:秒
|
||||||
"CheckDelay": 30, // 投票时长 单位:秒
|
"CheckDelay": 30, // 投票时长 单位:秒
|
||||||
"Percentage": 50 // 投票百分比(大于此值则清理)
|
"Percentage": 50 // 投票百分比(大于此值则清理)
|
||||||
|
},
|
||||||
|
"UnloadActorClean": { // 离线实体清理
|
||||||
|
"Enabled": false, // 是否启用
|
||||||
|
"CleanList": [ // 清理实体列表
|
||||||
|
"minecraft:iron_golem", // 铁傀儡
|
||||||
|
"minecraft:zombie_pigman" // 僵尸猪灵
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
+9
-1
@@ -2,12 +2,20 @@
|
|||||||
"name": "${modName}",
|
"name": "${modName}",
|
||||||
"entry": "${modFile}",
|
"entry": "${modFile}",
|
||||||
"type": "native",
|
"type": "native",
|
||||||
"version": "0.13.3",
|
"version": "0.16.1",
|
||||||
"author": "GroupMountain",
|
"author": "GroupMountain",
|
||||||
"description": "Clean Entities",
|
"description": "Clean Entities",
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
{
|
{
|
||||||
"name": "GMLIB"
|
"name": "GMLIB"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "iListenAttentively"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"optionalDependencies": [
|
||||||
|
{
|
||||||
|
"name": "ModAPI"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -91,5 +91,10 @@ struct Config {
|
|||||||
int CheckDelay = 30;
|
int CheckDelay = 30;
|
||||||
int Percentage = 50;
|
int Percentage = 50;
|
||||||
} VoteClean;
|
} VoteClean;
|
||||||
|
|
||||||
|
struct Unload_Actor_Clean {
|
||||||
|
bool Enabled = false;
|
||||||
|
std::vector<std::string> CleanList = {"minecraft:iron_golem", "minecraft:zombie_pigman"};
|
||||||
|
} UnloadActorClean;
|
||||||
};
|
};
|
||||||
} // namespace Cleaner
|
} // namespace Cleaner
|
||||||
+14
-9
@@ -1,5 +1,6 @@
|
|||||||
#include "Cleaner.h"
|
#include "Cleaner.h"
|
||||||
|
#include "mc/world/actor/provider/SynchedActorDataAccess.h"
|
||||||
|
#include "gmlib/mc/world/actor/Actor.h"
|
||||||
namespace Cleaner {
|
namespace Cleaner {
|
||||||
|
|
||||||
bool isMatch(std::string& A, std::string& B) {
|
bool isMatch(std::string& A, std::string& B) {
|
||||||
@@ -15,9 +16,11 @@ bool isMatch(std::string& A, std::string& B) {
|
|||||||
return (A == B);
|
return (A == B);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool shouldIgnore(GMLIB_Actor* ac) {
|
bool isTrust(Actor* ac) { return SynchedActorDataAccess::getActorFlag(ac->getEntityContext(), ::ActorFlags::Trusting); }
|
||||||
if (ac->isMob() || ac->isItemActor()) {
|
|
||||||
if (ac->isTame() || ac->isTrusting() || ac->getNameTag() != "" || ac->hasTag("cleaner:ignore")) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,7 +30,7 @@ bool shouldIgnore(GMLIB_Actor* ac) {
|
|||||||
bool ShouldClean(Actor* actor) {
|
bool ShouldClean(Actor* actor) {
|
||||||
// Players
|
// Players
|
||||||
auto& config = Cleaner::Entry::getInstance().getConfig();
|
auto& config = Cleaner::Entry::getInstance().getConfig();
|
||||||
auto en = (GMLIB_Actor*)actor;
|
auto en = (gmlib::GMActor*)actor;
|
||||||
if (en->isPlayer() || shouldIgnore(en)) {
|
if (en->isPlayer() || shouldIgnore(en)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -38,7 +41,7 @@ bool ShouldClean(Actor* actor) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Items
|
// Items
|
||||||
if (en->isItemActor()) {
|
if (en->hasCategory(::ActorCategory::Item)) {
|
||||||
if (config.CleanItem.Enabled) {
|
if (config.CleanItem.Enabled) {
|
||||||
auto itac = (ItemActor*)en;
|
auto itac = (ItemActor*)en;
|
||||||
if (itac->age() <= config.CleanItem.ExistTicks) {
|
if (itac->age() <= config.CleanItem.ExistTicks) {
|
||||||
@@ -56,7 +59,7 @@ bool ShouldClean(Actor* actor) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Mobs
|
// Mobs
|
||||||
else if (en->isMob()) {
|
else if (en->hasCategory(::ActorCategory::Mob)) {
|
||||||
if (config.CleanMobs.Enabled) {
|
if (config.CleanMobs.Enabled) {
|
||||||
auto blacklist = config.CleanMobs.BlackList;
|
auto blacklist = config.CleanMobs.BlackList;
|
||||||
for (auto& key : blacklist) {
|
for (auto& key : blacklist) {
|
||||||
@@ -94,8 +97,9 @@ bool ShouldClean(Actor* actor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ExecuteClean() {
|
int ExecuteClean() {
|
||||||
|
auto level = ll::service::getLevel();
|
||||||
int clean_count = 0;
|
int clean_count = 0;
|
||||||
auto all_entities = GMLIB_Level::getLevel()->getRuntimeActorList();
|
auto all_entities = level->getRuntimeActorList();
|
||||||
for (auto entity : all_entities) {
|
for (auto entity : all_entities) {
|
||||||
if (ShouldClean(entity)) {
|
if (ShouldClean(entity)) {
|
||||||
entity->despawn();
|
entity->despawn();
|
||||||
@@ -106,8 +110,9 @@ int ExecuteClean() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int CountEntities() {
|
int CountEntities() {
|
||||||
|
auto level = ll::service::getLevel();
|
||||||
int clean_count = 0;
|
int clean_count = 0;
|
||||||
auto all_entities = GMLIB_Level::getLevel()->getRuntimeActorList();
|
auto all_entities = level->getRuntimeActorList();
|
||||||
for (auto* entity : all_entities) {
|
for (auto* entity : all_entities) {
|
||||||
if (ShouldClean(entity)) {
|
if (ShouldClean(entity)) {
|
||||||
clean_count++;
|
clean_count++;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "Cleaner.h"
|
#include "Cleaner.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include "gmlib/mc/world/Level.h"
|
||||||
|
#include "gmlib/gm/data/TpsStatus.h"
|
||||||
namespace Cleaner {
|
namespace Cleaner {
|
||||||
|
|
||||||
static std::shared_ptr<bool> mAutoCleanTask = std::make_shared<bool>(false);
|
static std::shared_ptr<bool> mAutoCleanTask = std::make_shared<bool>(false);
|
||||||
@@ -13,8 +14,8 @@ void CleanTask() {
|
|||||||
auto& config = Cleaner::Entry::getInstance().getConfig();
|
auto& config = Cleaner::Entry::getInstance().getConfig();
|
||||||
auto time = config.Basic.Notice1;
|
auto time = config.Basic.Notice1;
|
||||||
auto announce_time = config.Basic.Notice2;
|
auto announce_time = config.Basic.Notice2;
|
||||||
auto time_1 = std::chrono::seconds::duration(time);
|
std::chrono::seconds time_1(time);
|
||||||
auto time_2 = std::chrono::seconds::duration(time - announce_time);
|
std::chrono::seconds time_2(time - announce_time);
|
||||||
if (config.Basic.ConsoleLog) {
|
if (config.Basic.ConsoleLog) {
|
||||||
ll::io::LoggerRegistry::getInstance().getOrCreate("Cleaner")->info(
|
ll::io::LoggerRegistry::getInstance().getOrCreate("Cleaner")->info(
|
||||||
tr("cleaner.output.count1", {S(time_1.count())})
|
tr("cleaner.output.count1", {S(time_1.count())})
|
||||||
@@ -59,7 +60,7 @@ void CleanTask() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AutoCleanTask(int seconds) {
|
void AutoCleanTask(int seconds) {
|
||||||
auto time = std::chrono::seconds::duration(seconds);
|
std::chrono::seconds time(seconds);
|
||||||
*mAutoCleanTask = true;
|
*mAutoCleanTask = true;
|
||||||
ll::coro::keepThis([time]() -> ll::coro::CoroTask<> {
|
ll::coro::keepThis([time]() -> ll::coro::CoroTask<> {
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -83,7 +84,9 @@ void CleanTaskCount(int max_entities) {
|
|||||||
if (count >= max_entities) {
|
if (count >= max_entities) {
|
||||||
auto_clean_triggerred = true;
|
auto_clean_triggerred = true;
|
||||||
if (config.Basic.ConsoleLog) {
|
if (config.Basic.ConsoleLog) {
|
||||||
ll::io::LoggerRegistry::getInstance().getOrCreate("Cleaner")->warn(tr("cleaner.output.triggerAutoCleanCount", {S(count)}));
|
ll::io::LoggerRegistry::getInstance().getOrCreate("Cleaner")->warn(
|
||||||
|
tr("cleaner.output.triggerAutoCleanCount", {S(count)})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (config.Basic.SendBroadcast) {
|
if (config.Basic.SendBroadcast) {
|
||||||
Helper::broadcastMessage(tr("cleaner.output.triggerAutoCleanCount", {S(count)}));
|
Helper::broadcastMessage(tr("cleaner.output.triggerAutoCleanCount", {S(count)}));
|
||||||
@@ -107,9 +110,9 @@ void CleanTaskTPS(float min_tps) {
|
|||||||
co_await 10s;
|
co_await 10s;
|
||||||
if (*mCleanTaskTPS == false) co_return;
|
if (*mCleanTaskTPS == false) co_return;
|
||||||
if (auto_clean_triggerred == false) {
|
if (auto_clean_triggerred == false) {
|
||||||
if (GMLIB_Level::getLevel()->getServerAverageTps() <= min_tps) {
|
if (gmlib::TpsStatus::getInstance().getLevelAverageTps() <= min_tps) {
|
||||||
auto_clean_triggerred = true;
|
auto_clean_triggerred = true;
|
||||||
auto mspt = S(GMLIB_Level::getLevel()->getServerAverageTps());
|
auto mspt = S(gmlib::TpsStatus::getInstance().getLevelAverageTps());
|
||||||
if (config.Basic.ConsoleLog) {
|
if (config.Basic.ConsoleLog) {
|
||||||
ll::io::LoggerRegistry::getInstance().getOrCreate("Cleaner")->warn(
|
ll::io::LoggerRegistry::getInstance().getOrCreate("Cleaner")->warn(
|
||||||
tr("cleaner.output.triggerAutoCleanTps", {mspt})
|
tr("cleaner.output.triggerAutoCleanTps", {mspt})
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ namespace Cleaner {
|
|||||||
|
|
||||||
void loadCleaner() {
|
void loadCleaner() {
|
||||||
auto& config = Cleaner::Entry::getInstance().getConfig();
|
auto& config = Cleaner::Entry::getInstance().getConfig();
|
||||||
|
if(config.UnloadActorClean.Enabled){
|
||||||
|
UnloadActorClean::cleanUnloadActor();
|
||||||
|
}
|
||||||
if (config.ScheduleClean.Enabled) {
|
if (config.ScheduleClean.Enabled) {
|
||||||
Cleaner::AutoCleanTask(config.ScheduleClean.CleanInterval);
|
Cleaner::AutoCleanTask(config.ScheduleClean.CleanInterval);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
|
||||||
|
#include <gmlib/mc/world/actor/UnloadedActor.h>
|
||||||
|
extern void MainForm(Player* player);
|
||||||
|
|
||||||
using namespace ll::chrono_literals;
|
using namespace ll::chrono_literals;
|
||||||
|
|
||||||
namespace Cleaner {
|
namespace Cleaner {
|
||||||
@@ -17,6 +20,7 @@ extern void CleanTask();
|
|||||||
extern void reloadCleaner();
|
extern void reloadCleaner();
|
||||||
extern void loadCleaner();
|
extern void loadCleaner();
|
||||||
extern void unloadCleaner();
|
extern void unloadCleaner();
|
||||||
|
extern bool shouldIgnore(gmlib::GMActor* ac);
|
||||||
|
|
||||||
extern bool isMatch(std::string& A, std::string& B);
|
extern bool isMatch(std::string& A, std::string& B);
|
||||||
|
|
||||||
@@ -27,3 +31,9 @@ namespace VoteClean {
|
|||||||
extern void voteCommandExecute(Player* pl);
|
extern void voteCommandExecute(Player* pl);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace UnloadActorClean {
|
||||||
|
|
||||||
|
extern void cleanUnloadActor();
|
||||||
|
|
||||||
|
}
|
||||||
+13
-17
@@ -1,26 +1,25 @@
|
|||||||
#include "Cleaner.h"
|
#include "Cleaner.h"
|
||||||
|
#include "gmlib/mc/world/Level.h"
|
||||||
|
#include "gmlib/mc/world/actor/Player.h"
|
||||||
namespace Cleaner {
|
namespace Cleaner {
|
||||||
|
void setShouldIgnore(gmlib::GMActor* ac) { ac->addTag("cleaner:ignore"); }
|
||||||
void setShouldIgnore(GMLIB_Actor* ac) { ac->addTag("cleaner:ignore"); }
|
|
||||||
|
|
||||||
void ListenEvents() {
|
void ListenEvents() {
|
||||||
auto& eventBus = ll::event::EventBus::getInstance();
|
auto& eventBus = ll::event::EventBus::getInstance();
|
||||||
auto& config = Cleaner::Entry::getInstance().getConfig();
|
auto& config = Cleaner::Entry::getInstance().getConfig();
|
||||||
// ItemSpawnEvent
|
// ItemSpawnEvent
|
||||||
eventBus.emplaceListener<GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent>(
|
eventBus.emplaceListener<ila::mc::SpawnItemActorAfterEvent>([&config](ila::mc::SpawnItemActorAfterEvent& event) {
|
||||||
[&config](GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent& event) {
|
auto& item = event.itemActor();
|
||||||
auto& item = event.getItemActor();
|
if (event.spawner()) {
|
||||||
if (event.getSpawner().has_value()) {
|
auto pl = (gmlib::GMPlayer*)event.spawner();
|
||||||
auto pl = (GMLIB_Player*)event.getSpawner().as_ptr();
|
|
||||||
if (pl->isPlayer() && !pl->isAlive()) { // Death Drop
|
if (pl->isPlayer() && !pl->isAlive()) { // Death Drop
|
||||||
auto ac = (GMLIB_Actor*)&item;
|
auto ac = (gmlib::GMActor*)&item;
|
||||||
setShouldIgnore(ac);
|
setShouldIgnore(ac);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (config.ItemDespawn.Enabled) {
|
if (config.ItemDespawn.Enabled) {
|
||||||
item.lifeTime() = config.ItemDespawn.DespawnTime;
|
// item.lifeTime() = config.ItemDespawn.DespawnTime;
|
||||||
auto list = config.ItemDespawn.WhiteList;
|
auto list = config.ItemDespawn.WhiteList;
|
||||||
auto type = item.item().getTypeName();
|
auto type = item.item().getTypeName();
|
||||||
for (auto& key : list) {
|
for (auto& key : list) {
|
||||||
@@ -30,15 +29,12 @@ void ListenEvents() {
|
|||||||
}
|
}
|
||||||
item.lifeTime() = config.ItemDespawn.DespawnTime;
|
item.lifeTime() = config.ItemDespawn.DespawnTime;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
);
|
|
||||||
// MobTakeItemEvent
|
// MobTakeItemEvent
|
||||||
eventBus.emplaceListener<GMLIB::Event::EntityEvent::MobPickupItemAfterEvent>(
|
eventBus.emplaceListener<ila::mc::ActorPickupItemAfterEvent>([](ila::mc::ActorPickupItemAfterEvent& event) {
|
||||||
[](GMLIB::Event::EntityEvent::MobPickupItemAfterEvent& event) {
|
auto mob = (gmlib::GMActor*)&event.self();
|
||||||
auto mob = (GMLIB_Actor*)&event.self();
|
|
||||||
setShouldIgnore(mob);
|
setShouldIgnore(mob);
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Cleaner
|
} // namespace Cleaner
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
#include "gmlib/mc/world/Level.h"
|
||||||
namespace Helper {
|
namespace Helper {
|
||||||
|
|
||||||
void broadcastMessage(std::string_view msg) {
|
void broadcastMessage(std::string_view msg) {
|
||||||
GMLIB_Level::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) {
|
void broadcastToast(std::string_view msg) {
|
||||||
GMLIB_Level::getInstance()->broadcastToast(tr("cleaner.info.prefix"), msg);
|
gmlib::GMLevel::getInstance()->broadcastToast(tr("cleaner.info.prefix"), msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Helper
|
} // namespace Helper
|
||||||
@@ -0,0 +1,288 @@
|
|||||||
|
#include "Cleaner.h"
|
||||||
|
#include "Global.h"
|
||||||
|
#include "Mod.h"
|
||||||
|
|
||||||
|
#include "ll/api/base/Containers.h"
|
||||||
|
#include "ll/api/service/Bedrock.h"
|
||||||
|
#include "mc/common/Globals.h"
|
||||||
|
#include "mc/world/level/Level.h"
|
||||||
|
#include <gmlib/mc/world/Level.h>
|
||||||
|
#include <gmlib/mc/world/actor/UnloadedActor.h>
|
||||||
|
#include <ll/api/form/CustomForm.h>
|
||||||
|
#include <ll/api/form/ModalForm.h>
|
||||||
|
#include <ll/api/form/SimpleForm.h>
|
||||||
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
|
#include <vector>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
using UnloadEntityMap = std::unordered_map<std::string, std::vector<gmlib::UnloadedActor>>;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
std::chrono::system_clock::time_point lastUpdate{};
|
||||||
|
std::atomic_bool isUpdating{false};
|
||||||
|
UnloadEntityMap offlineEntities{};
|
||||||
|
ll::SmallDenseSet<ActorUniqueID> waitedPlayers{};
|
||||||
|
std::atomic_bool requireUpdate{false};
|
||||||
|
|
||||||
|
std::mutex offlineEntitiesMutex; // ✅ 新增
|
||||||
|
} OfflineEntity;
|
||||||
|
|
||||||
|
auto typeNameToLocString(std::string const& typeName) {
|
||||||
|
return EntityTypeToLocString(
|
||||||
|
EntityTypeFromString(typeName),
|
||||||
|
ActorTypeNamespaceRules::ReturnWithoutNamespace
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto getAllEntityTypes() {
|
||||||
|
return std::ranges::to<ll::SmallDenseSet<std::string>>(
|
||||||
|
ll::service::getLevel()->getRuntimeActorList()
|
||||||
|
| std::views::transform(&Actor::getTypeName)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto getEntityCountByType(std::string const& typeName) {
|
||||||
|
return std::ranges::count_if(
|
||||||
|
ll::service::getLevel()->getRuntimeActorList(),
|
||||||
|
[&](const Actor* a) { return a && a->getTypeName() == typeName; }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfirmForm(Player& player, bool isOnline, const std::string& TypeName, bool needCondition) {
|
||||||
|
auto fm = ll::form::ModalForm(
|
||||||
|
tr("cleaner.form.confirm.title"),
|
||||||
|
tr(isOnline&&needCondition?"cleaner.form.confirm.important"
|
||||||
|
:"cleaner.form.confirm.warning",{
|
||||||
|
tr(typeNameToLocString(TypeName)),
|
||||||
|
TypeName,
|
||||||
|
std::to_string(
|
||||||
|
isOnline
|
||||||
|
? getEntityCountByType(TypeName)
|
||||||
|
: OfflineEntity.offlineEntities[TypeName].size()
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
tr("cleaner.form.confirm.confirm"),
|
||||||
|
tr("cleaner.form.confirm.cancel")
|
||||||
|
);
|
||||||
|
|
||||||
|
fm.sendTo(player, [isOnline, TypeName, needCondition](
|
||||||
|
const Player& player,
|
||||||
|
ll::form::ModalFormResult rst,
|
||||||
|
ll::form::FormCancelReason res
|
||||||
|
) {
|
||||||
|
if (res) return;
|
||||||
|
|
||||||
|
if (!rst || rst.value() != ll::form::ModalFormSelectedButton::Upper)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (isOnline) {
|
||||||
|
for (auto en : ll::service::getLevel()->getRuntimeActorList()) {
|
||||||
|
auto actor = (gmlib::GMActor*)en;
|
||||||
|
|
||||||
|
if (en->getTypeName() == TypeName &&
|
||||||
|
(!needCondition || !Cleaner::shouldIgnore(actor))) {
|
||||||
|
en->despawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!OfflineEntity.isUpdating.exchange(true)) {
|
||||||
|
std::thread([TypeName]() {
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(
|
||||||
|
OfflineEntity.offlineEntitiesMutex
|
||||||
|
);
|
||||||
|
|
||||||
|
auto it = OfflineEntity.offlineEntities.find(TypeName);
|
||||||
|
if (it != OfflineEntity.offlineEntities.end()) {
|
||||||
|
for (auto& en : it->second) {
|
||||||
|
if (en.isValid()) en.remove();
|
||||||
|
}
|
||||||
|
OfflineEntity.offlineEntities.erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
OfflineEntity.isUpdating.store(false);
|
||||||
|
}).detach();
|
||||||
|
} else {
|
||||||
|
player.sendMessage(tr(""));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void SettingCleanForm(Player& player, bool isOnline, const std::string& TypeName) {
|
||||||
|
if (!isOnline) {
|
||||||
|
ConfirmForm(player, isOnline, TypeName, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto fm = ll::form::CustomForm(tr("cleaner.form.setting.title"));
|
||||||
|
fm.appendLabel(
|
||||||
|
tr("cleaner.form.setting.content",{
|
||||||
|
tr(typeNameToLocString(TypeName)),
|
||||||
|
TypeName,
|
||||||
|
std::to_string(
|
||||||
|
isOnline
|
||||||
|
? getEntityCountByType(TypeName)
|
||||||
|
: OfflineEntity.offlineEntities[TypeName].size()
|
||||||
|
)
|
||||||
|
})
|
||||||
|
);
|
||||||
|
fm.appendToggle(
|
||||||
|
"cleanIgnoreActor",
|
||||||
|
tr("cleaner.form.setting.cleanIgnore"),
|
||||||
|
false,
|
||||||
|
tr("cleaner.form.setting.cleanIgnore.tip")
|
||||||
|
);
|
||||||
|
|
||||||
|
fm.sendTo(player, [TypeName, isOnline](
|
||||||
|
Player& player,
|
||||||
|
const ll::form::CustomFormResult& rst,
|
||||||
|
ll::form::FormCancelReason res
|
||||||
|
) {
|
||||||
|
if (!rst) return;
|
||||||
|
|
||||||
|
bool cleanIgnoreActor =
|
||||||
|
std::get<uint64>(rst->at("cleanIgnoreActor"));
|
||||||
|
|
||||||
|
ConfirmForm(player, isOnline, TypeName, !cleanIgnoreActor);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnlineEntityForm(Player& player) {
|
||||||
|
auto fm = ll::form::SimpleForm(tr("cleaner.form.runtime.title"), tr("cleaner.form.runtime.content"));
|
||||||
|
|
||||||
|
for (auto& entityID : getAllEntityTypes()) {
|
||||||
|
fm.appendButton(
|
||||||
|
typeNameToLocString(entityID),
|
||||||
|
[entityID](Player& player) {
|
||||||
|
SettingCleanForm(player, true, entityID);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fm.sendTo(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateUnloadEntityMap(const Player& player, bool notice = false) {
|
||||||
|
if (OfflineEntity.lastUpdate.time_since_epoch().count() == 0)
|
||||||
|
OfflineEntity.requireUpdate.store(true);
|
||||||
|
|
||||||
|
if (OfflineEntity.lastUpdate >=
|
||||||
|
std::chrono::system_clock::now() - std::chrono::minutes(10)) {
|
||||||
|
|
||||||
|
if (notice) player.sendMessage(tr("cleaner.unload.updated.warn"));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!OfflineEntity.isUpdating.exchange(true) &&
|
||||||
|
OfflineEntity.requireUpdate) {
|
||||||
|
|
||||||
|
std::thread([]() {
|
||||||
|
UnloadEntityMap offlineEntityMap{};
|
||||||
|
|
||||||
|
|
||||||
|
gmlib::UnloadedActor::foreachUnloadedActor(
|
||||||
|
[&](gmlib::UnloadedActor& actor) -> bool {
|
||||||
|
offlineEntityMap[actor.getTypeName()]
|
||||||
|
.emplace_back(std::move(actor));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(
|
||||||
|
OfflineEntity.offlineEntitiesMutex
|
||||||
|
);
|
||||||
|
|
||||||
|
for (auto& playerID : OfflineEntity.waitedPlayers) {
|
||||||
|
if (auto pl =
|
||||||
|
ll::service::getLevel()->getPlayer(playerID))
|
||||||
|
pl->sendMessage(tr("cleaner.unload.updated.msg"));
|
||||||
|
}
|
||||||
|
|
||||||
|
OfflineEntity.offlineEntities.swap(offlineEntityMap);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
OfflineEntity.lastUpdate = std::chrono::system_clock::now();
|
||||||
|
OfflineEntity.isUpdating.store(false);
|
||||||
|
}).detach();
|
||||||
|
|
||||||
|
} else if (notice) {
|
||||||
|
player.sendMessage(tr("cleaner.unload.update.warn"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OfflineEntityForm(Player& player) {
|
||||||
|
Cleaner::Entry::getInstance().getSelf().getLogger().info("preload");
|
||||||
|
updateUnloadEntityMap(player);
|
||||||
|
|
||||||
|
auto fm = ll::form::SimpleForm(tr("cleaner.form.unload.title"), tr("cleaner.form.unload.content"));
|
||||||
|
|
||||||
|
if (OfflineEntity.lastUpdate !=
|
||||||
|
std::chrono::system_clock::time_point{}) {
|
||||||
|
|
||||||
|
fm.appendLabel(
|
||||||
|
tr("cleaner.form.unload.updated",{std::format("{:%Y-%m-%d %H:%M}", OfflineEntity.lastUpdate)})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (OfflineEntity.isUpdating.load()) {
|
||||||
|
fm.appendLabel(
|
||||||
|
tr("cleaner.form.unload.updating")
|
||||||
|
);
|
||||||
|
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(
|
||||||
|
OfflineEntity.offlineEntitiesMutex
|
||||||
|
);
|
||||||
|
OfflineEntity.waitedPlayers.insert(
|
||||||
|
player.getOrCreateUniqueID()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fm.appendButton(tr("cleaner.form.unload.refresh"), [](Player& player) {
|
||||||
|
OfflineEntityForm(player);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
fm.appendButton(tr("cleaner.form.unload.refresh"), [](Player& player) {
|
||||||
|
OfflineEntity.requireUpdate.store(true);
|
||||||
|
updateUnloadEntityMap(player, true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(
|
||||||
|
OfflineEntity.offlineEntitiesMutex
|
||||||
|
);
|
||||||
|
|
||||||
|
for (auto& entity : OfflineEntity.offlineEntities) {
|
||||||
|
fm.appendButton(
|
||||||
|
typeNameToLocString(entity.first),
|
||||||
|
[typeName = entity.first](Player& player) {
|
||||||
|
SettingCleanForm(player, false, typeName);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fm.sendTo(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainForm(Player* player) {
|
||||||
|
auto fm = ll::form::SimpleForm(tr("cleaner.form.main.title"), tr("cleaner.form.main.context"));
|
||||||
|
|
||||||
|
fm.appendButton(tr("cleaner.form.main.runtime"), [](Player& player) {
|
||||||
|
OnlineEntityForm(player);
|
||||||
|
});
|
||||||
|
|
||||||
|
fm.appendButton(tr("cleaner.form.main.unload"), [](Player& player) {
|
||||||
|
OfflineEntityForm(player);
|
||||||
|
});
|
||||||
|
|
||||||
|
fm.sendTo(*player);
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#include "Cleaner.h"
|
||||||
|
#include "Global.h"
|
||||||
|
#include "gmlib/mc/world/actor/UnloadedActor.h"
|
||||||
|
|
||||||
|
namespace UnloadActorClean {
|
||||||
|
void cleanUnloadActor() {
|
||||||
|
auto& config = Cleaner::Entry::getInstance().getConfig();
|
||||||
|
std::thread([config]() {
|
||||||
|
gmlib::UnloadedActor::foreachUnloadedActor(
|
||||||
|
[config](gmlib::UnloadedActor& actor) -> bool {
|
||||||
|
for (auto& actorname : config.UnloadActorClean.CleanList) {
|
||||||
|
if (actor.getTypeName() == actorname) {
|
||||||
|
actor.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}).detach();
|
||||||
|
}
|
||||||
|
} // namespace UnloadActorClean
|
||||||
@@ -94,12 +94,12 @@ void voteClean(Player* pl) {
|
|||||||
}
|
}
|
||||||
sendVoteForm(pl);
|
sendVoteForm(pl);
|
||||||
ll::coro::keepThis([&config]() -> ll::coro::CoroTask<> {
|
ll::coro::keepThis([&config]() -> ll::coro::CoroTask<> {
|
||||||
co_await std::chrono::seconds::duration(config.VoteClean.Cooldown);
|
co_await std::chrono::seconds(config.VoteClean.Cooldown);
|
||||||
canVote = true;
|
canVote = true;
|
||||||
co_return;
|
co_return;
|
||||||
}).launch(ll::thread::ServerThreadExecutor::getDefault());
|
}).launch(ll::thread::ServerThreadExecutor::getDefault());
|
||||||
ll::coro::keepThis([&config]() -> ll::coro::CoroTask<> {
|
ll::coro::keepThis([&config]() -> ll::coro::CoroTask<> {
|
||||||
co_await std::chrono::seconds::duration(config.VoteClean.CheckDelay);
|
co_await std::chrono::seconds(config.VoteClean.CheckDelay);
|
||||||
checkVote();
|
checkVote();
|
||||||
co_return;
|
co_return;
|
||||||
}).launch(ll::thread::ServerThreadExecutor::getDefault());
|
}).launch(ll::thread::ServerThreadExecutor::getDefault());
|
||||||
|
|||||||
+5
-1
@@ -1,7 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
// IWYU pragma: begin_exports
|
||||||
#include "Mod.h"
|
#include "Mod.h"
|
||||||
#include <include_all.h>
|
|
||||||
|
#include "gmlib/include_ll.h"
|
||||||
|
#include "ila/include_all.h"
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
// IWYU pragma: end_exports
|
||||||
|
|
||||||
#define S(x) std::to_string(x)
|
#define S(x) std::to_string(x)
|
||||||
|
|
||||||
|
|||||||
+49
-1
@@ -35,6 +35,30 @@ std::string en_US = R"(
|
|||||||
cleaner.vote.title=Vote Cleaning
|
cleaner.vote.title=Vote Cleaning
|
||||||
cleaner.vote.voted=You have been voted!
|
cleaner.vote.voted=You have been voted!
|
||||||
cleaner.vote.voteMessage=%1$s lunched a clean vote. If you agree cleaning entities but did not received a form, please type command /voteclean to vote.
|
cleaner.vote.voteMessage=%1$s lunched a clean vote. If you agree cleaning entities but did not received a form, please type command /voteclean to vote.
|
||||||
|
cleaner.form.main.title=§e§lCleaner§r - Main Menu
|
||||||
|
cleaner.form.main.context=Select entity category to clean:
|
||||||
|
cleaner.form.main.runtime=Loaded Entities
|
||||||
|
cleaner.form.main.unload=Unloaded Entities
|
||||||
|
cleaner.form.runtime.title=§e§lCleaner§r - Loaded Entity Manager
|
||||||
|
cleaner.form.runtime.content=Select loaded entity to clean:
|
||||||
|
cleaner.form.unload.title=§e§lCleaner§r - Unloaded Entity Manager
|
||||||
|
cleaner.form.unload.content=Select unloaded entity to clean:
|
||||||
|
cleaner.form.unload.updating=§2Updating...§r\nIf your world contains many entities, this may take §b a long time (~20k entities/min)§r. You can close this panel first; you'll be notified when the update finishes.
|
||||||
|
cleaner.form.unload.updated=Last updated: §b%1$s§r\n§eData may be out of sync. Click "Refresh" to update. Max 1 refresh per 10 minutes.\n§c§lWarning: Cleaning unloaded entities will force-remove ALL of them, including named, tamed, and ignored ones. Proceed with caution.
|
||||||
|
cleaner.form.unload.refresh=Refresh
|
||||||
|
cleaner.unload.updated.msg=§e§lUnloaded entity list§r has finished loading
|
||||||
|
cleaner.unload.update.warn=§g§lUnloaded entity list is already updating, cannot trigger again§r
|
||||||
|
cleaner.unload.updated.warn=§g§lUnloaded entity list refresh too frequent (max once per 10 min)§r
|
||||||
|
cleaner.form.setting.title=§e§lCleaner§r - Clean Options
|
||||||
|
cleaner.form.setting.content=Deleting entities\n§b%1$s (%2$s)\n§eTotal: %3$s
|
||||||
|
cleaner.form.setting.cleanIgnore=Force Clean All Entities
|
||||||
|
cleaner.form.setting.cleanIgnore.tip=§c§lDangerous: §r§gThis will clean ALL entities including named, tamed, and config-ignored ones
|
||||||
|
cleaner.form.confirm.title=Confirmation
|
||||||
|
cleaner.form.confirm.warning=§c§lConfirm dangerous operation:§r\nConfirm §c§lforce §rdeletion of\n§b%1$s (%2$s)\n§eTotal: %3$s ?
|
||||||
|
cleaner.form.confirm.important=§u§lConfirm operation:§r\nConfirm deletion of\n§b%1$s (%2$s)\n§eTotal: %3$s ? This will force-remove ALL including named, tamed, config-ignored, etc. Proceed with caution.
|
||||||
|
cleaner.form.confirm.confirm=Confirm
|
||||||
|
cleaner.form.confirm.cancel=Cancel
|
||||||
|
cleaner.confirm.unload.warn=Form is updating, deletion temporarily unavailable
|
||||||
)";
|
)";
|
||||||
|
|
||||||
std::string zh_CN = R"(
|
std::string zh_CN = R"(
|
||||||
@@ -44,7 +68,7 @@ std::string zh_CN = R"(
|
|||||||
cleaner.command.error.noTarget=没有与选择器匹配的目标
|
cleaner.command.error.noTarget=没有与选择器匹配的目标
|
||||||
cleaner.command.error.playerOnly=该命令只能由玩家执行!
|
cleaner.command.error.playerOnly=该命令只能由玩家执行!
|
||||||
cleaner.command.tps.output=当前服务器实时TPS %1$s §r,平均TPS %2$s
|
cleaner.command.tps.output=当前服务器实时TPS %1$s §r,平均TPS %2$s
|
||||||
cleaner.command.mspt.output=当前服务器实MSPT %1$s
|
cleaner.command.mspt.output=当前服务器实时MSPT %1$s
|
||||||
cleaner.command.clean.output=已成功启动清理任务!
|
cleaner.command.clean.output=已成功启动清理任务!
|
||||||
cleaner.command.voteclean=发起实体清理投票。
|
cleaner.command.voteclean=发起实体清理投票。
|
||||||
cleaner.command.despawntime=已成功将物品消失时间设置为 %1$s 游戏刻
|
cleaner.command.despawntime=已成功将物品消失时间设置为 %1$s 游戏刻
|
||||||
@@ -71,4 +95,28 @@ std::string zh_CN = R"(
|
|||||||
cleaner.vote.title=投票清理
|
cleaner.vote.title=投票清理
|
||||||
cleaner.vote.voted=你已经投过票了!
|
cleaner.vote.voted=你已经投过票了!
|
||||||
cleaner.vote.voteMessage=%1$s 发起了服务器实体清理投票!如果同意清理但是未收到表单,请输入命令 /voteclean 投票。拒绝清理请忽略此信息。
|
cleaner.vote.voteMessage=%1$s 发起了服务器实体清理投票!如果同意清理但是未收到表单,请输入命令 /voteclean 投票。拒绝清理请忽略此信息。
|
||||||
|
cleaner.form.main.title=§e§lCleaner§r 主菜单
|
||||||
|
cleaner.form.main.context=选择你要清理的生物种类:
|
||||||
|
cleaner.form.main.runtime=已加载生物
|
||||||
|
cleaner.form.main.unload=未加载生物
|
||||||
|
cleaner.form.runtime.title=§e§lCleaner§r-已加载生物管理
|
||||||
|
cleaner.form.runtime.content=选择你要清理的已加载生物:
|
||||||
|
cleaner.form.unload.title=§e§lCleaner-未加载生物管理
|
||||||
|
cleaner.form.unload.content=选择你要清理的未加载生物:
|
||||||
|
cleaner.form.unload.updating=§2正在更新中...§r\n如果您存档中有较多实体,这可能花费§b较长时间(大约2w个生物/分钟)§r。你可以先关闭这个面板, 更新完成后将会通知您。
|
||||||
|
cleaner.form.unload.updated=数据最后更新时间:§b %1$s \n§e数据有时不同步,你可以点击刷新按钮进行刷新。每10分钟最多进行一次刷新\n§c§l注意, 清理未加载生物会全部强制清除, 包过有命名, 被驯服等, 请谨慎操作
|
||||||
|
cleaner.form.unload.refresh=刷新
|
||||||
|
cleaner.unload.updated.msg=§e§l离线生物列表§r已完成加载
|
||||||
|
cleaner.unload.update.warn=§g§l离线生物列表正在更新,不能重复触发§r
|
||||||
|
cleaner.unload.updated.warn=§g§l离线生物列表更新过频繁,每10分钟最多一次
|
||||||
|
cleaner.form.setting.title=§e§lCleaner-清理选项
|
||||||
|
cleaner.form.setting.content=正在删除生物\n§b%1$s (%2$s)\n§e共计: %3$s 个
|
||||||
|
cleaner.form.setting.cleanIgnore=强制清理全部生物
|
||||||
|
cleaner.form.setting.cleanIgnore.tip=§c§l危险操作: §r§g这会清理包过有命名, 被驯服, 配置忽略的所有生物
|
||||||
|
cleaner.form.confirm.title=确认消息
|
||||||
|
cleaner.form.confirm.warning=§c§l确认危险操作:§r\n确认§c§l强制§r删除生物\n§b%1$s (%2$s)\n§e共计: %3$s 个?
|
||||||
|
cleaner.form.confirm.important=§u§l确认操作:§r\n确认删除生物\n§b%1$s (%2$s)\n§e共计: %3$s 个?这会强制全部清除, 包过有命名, 被驯服, 配置忽略等, 请谨慎操作
|
||||||
|
cleaner.form.confirm.confirm=确认
|
||||||
|
cleaner.form.confirm.cancel=取消
|
||||||
|
cleaner.confirm.unload.warn=表单正在更新, 暂时无法删除
|
||||||
)";
|
)";
|
||||||
+21
-4
@@ -2,6 +2,11 @@
|
|||||||
#include "Features/Cleaner.h"
|
#include "Features/Cleaner.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "Language.h"
|
#include "Language.h"
|
||||||
|
#include "ll/api/utils/ErrorUtils.h"
|
||||||
|
#include "ll/api/memory/Hook.h"
|
||||||
|
#include "mc/world/actor/Actor.h"
|
||||||
|
#include "gmlib/mc/locale/I18nAPI.h"
|
||||||
|
#include "gmlib/gm/data/TpsStatus.h"
|
||||||
|
|
||||||
namespace Cleaner {
|
namespace Cleaner {
|
||||||
|
|
||||||
@@ -13,18 +18,25 @@ Entry& Entry::getInstance() {
|
|||||||
bool Entry::load() { return true; }
|
bool Entry::load() { return true; }
|
||||||
|
|
||||||
bool Entry::enable() {
|
bool Entry::enable() {
|
||||||
|
(void)gmlib::TpsStatus::getInstance();
|
||||||
mConfig.emplace();
|
mConfig.emplace();
|
||||||
|
try {
|
||||||
ll::config::loadConfig(*mConfig, getSelf().getConfigDir() / "config.json");
|
ll::config::loadConfig(*mConfig, getSelf().getConfigDir() / "config.json");
|
||||||
|
} catch (...) {
|
||||||
|
ll::error_utils::printCurrentException(getSelf().getLogger());
|
||||||
|
}
|
||||||
saveConfig();
|
saveConfig();
|
||||||
I18nAPI::updateOrCreateLanguageFile(getSelf().getLangDir(), "en_US", en_US);
|
gmlib::I18nAPI::updateOrCreateLanguageFile(getSelf().getLangDir(), "en_US", en_US);
|
||||||
I18nAPI::updateOrCreateLanguageFile(getSelf().getLangDir(), "zh_CN", zh_CN);
|
gmlib::I18nAPI::updateOrCreateLanguageFile(getSelf().getLangDir(), "zh_CN", zh_CN);
|
||||||
I18nAPI::loadLanguagesFromDirectory(getSelf().getLangDir());
|
gmlib::I18nAPI::loadLanguagesFromDirectory(getSelf().getLangDir());
|
||||||
|
gmlib::I18nAPI::chooseLanguage(Cleaner::Entry::getInstance().getConfig().language);
|
||||||
Cleaner::ListenEvents();
|
Cleaner::ListenEvents();
|
||||||
RegisterCommands();
|
RegisterCommands();
|
||||||
Cleaner::loadCleaner();
|
Cleaner::loadCleaner();
|
||||||
getSelf().getLogger().info("Cleaner Loaded!");
|
getSelf().getLogger().info("Cleaner Loaded!");
|
||||||
getSelf().getLogger().info("Author: GroupMountain");
|
getSelf().getLogger().info("Author: GroupMountain");
|
||||||
getSelf().getLogger().info("Repository: https://github.com/GroupMountain/Cleaner");
|
getSelf().getLogger().info("Repository: https://github.com/GroupMountain/Cleaner");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,6 +46,11 @@ bool Entry::disable() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Entry::unload() {
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Config& Entry::getConfig() { return mConfig.value(); }
|
Config& Entry::getConfig() { return mConfig.value(); }
|
||||||
|
|
||||||
void Entry::saveConfig() { ll::config::saveConfig(*mConfig, getSelf().getConfigDir() / "config.json"); }
|
void Entry::saveConfig() { ll::config::saveConfig(*mConfig, getSelf().getConfigDir() / "config.json"); }
|
||||||
@@ -43,5 +60,5 @@ void Entry::saveConfig() { ll::config::saveConfig(*mConfig, getSelf().getConfigD
|
|||||||
LL_REGISTER_MOD(Cleaner::Entry, Cleaner::Entry::getInstance());
|
LL_REGISTER_MOD(Cleaner::Entry, Cleaner::Entry::getInstance());
|
||||||
|
|
||||||
std::string tr(std::string const& key, std::vector<std::string> const& params) {
|
std::string tr(std::string const& key, std::vector<std::string> const& params) {
|
||||||
return I18nAPI::get(key, params, Cleaner::Entry::getInstance().getConfig().language);
|
return gmlib::I18nAPI::get(key, params);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public:
|
|||||||
|
|
||||||
// TODO: Implement this method if you need to unload the mod.
|
// TODO: Implement this method if you need to unload the mod.
|
||||||
// /// @return True if the mod is unloaded successfully.
|
// /// @return True if the mod is unloaded successfully.
|
||||||
// bool unload();
|
bool unload();
|
||||||
|
|
||||||
Config& getConfig();
|
Config& getConfig();
|
||||||
|
|
||||||
|
|||||||
+32
-19
@@ -1,8 +1,10 @@
|
|||||||
#include "Features/Cleaner.h"
|
#include "Features/Cleaner.h"
|
||||||
|
#include "gmlib/mc/world/Level.h"
|
||||||
|
#include "gmlib/gm/data/TpsStatus.h"
|
||||||
|
#include "mc/server/commands/CommandOutput.h"
|
||||||
struct CleanerParam {
|
struct CleanerParam {
|
||||||
enum class Despawn { despawn } despawn;
|
enum class Despawn { despawn } despawn;
|
||||||
enum class Action { tps, clean, reload, mspt } action;
|
enum class Action { gui ,tps, clean, reload, mspt } action;
|
||||||
enum class DespawnTime { despawntime } despawntime;
|
enum class DespawnTime { despawntime } despawntime;
|
||||||
int ticks;
|
int ticks;
|
||||||
CommandSelector<Actor> entity;
|
CommandSelector<Actor> entity;
|
||||||
@@ -10,27 +12,33 @@ struct CleanerParam {
|
|||||||
|
|
||||||
void RegCleanerCommand() {
|
void RegCleanerCommand() {
|
||||||
auto& config = Cleaner::Entry::getInstance().getConfig();
|
auto& config = Cleaner::Entry::getInstance().getConfig();
|
||||||
auto& cmd = ll::command::CommandRegistrar::getInstance().getOrCreateCommand(
|
auto& cmd = ll::command::CommandRegistrar::getInstance(false).getOrCreateCommand(
|
||||||
config.Basic.Command,
|
config.Basic.Command,
|
||||||
tr("cleaner.command.cleaner"),
|
tr("cleaner.command.cleaner"),
|
||||||
CommandPermissionLevel::GameDirectors
|
CommandPermissionLevel::GameDirectors
|
||||||
);
|
);
|
||||||
cmd.overload<CleanerParam>()
|
cmd.overload<CleanerParam>().required("despawn").required("entity").execute(
|
||||||
.required("despawn")
|
[&](CommandOrigin const& origin, CommandOutput& output, CleanerParam const& param) {
|
||||||
.required("entity")
|
|
||||||
.execute([&](CommandOrigin const& origin, CommandOutput& output, CleanerParam const& param) {
|
|
||||||
auto ens = param.entity.results(origin);
|
auto ens = param.entity.results(origin);
|
||||||
if (ens.empty()) {
|
if (ens.empty()) {
|
||||||
return output.error(tr("cleaner.command.error.noTarget"));
|
return output.error(tr("cleaner.command.error.noTarget"));
|
||||||
}
|
}
|
||||||
for (auto en : ens) {
|
for (auto en : ens) {
|
||||||
|
/*NO NEED
|
||||||
|
*Tip: Player don't exit through normal logic when despawn player
|
||||||
|
*That may cause other plugins crash,causing Levilamina crash
|
||||||
|
*if (en->hasCategory(ActorCategory::Player)) {
|
||||||
|
auto pl=(Player*)en;
|
||||||
|
pl->disconnect("You've been despawn by Cleaner");
|
||||||
|
continue;
|
||||||
|
}*/
|
||||||
en->despawn();
|
en->despawn();
|
||||||
}
|
}
|
||||||
return output.success(tr("cleaner.command.despawnSuccess", {S(ens.size())}));
|
return output.success(tr("cleaner.command.despawnSuccess", {S(ens.size())}));
|
||||||
});
|
}
|
||||||
cmd.overload<CleanerParam>()
|
);
|
||||||
.required("action")
|
cmd.overload<CleanerParam>().required("action").execute(
|
||||||
.execute([&](CommandOrigin const& origin, CommandOutput& output, CleanerParam const& param) {
|
[&](CommandOrigin const& origin, CommandOutput& output, CleanerParam const& param) {
|
||||||
switch (param.action) {
|
switch (param.action) {
|
||||||
case CleanerParam::Action::clean: {
|
case CleanerParam::Action::clean: {
|
||||||
Cleaner::CleanTask();
|
Cleaner::CleanTask();
|
||||||
@@ -46,23 +54,28 @@ void RegCleanerCommand() {
|
|||||||
return output.success(tr("cleaner.command.clean.output"));
|
return output.success(tr("cleaner.command.clean.output"));
|
||||||
}
|
}
|
||||||
case CleanerParam::Action::tps: {
|
case CleanerParam::Action::tps: {
|
||||||
return output.success(tr(
|
return output.success(
|
||||||
"cleaner.command.tps.output",
|
tr("cleaner.command.tps.output",
|
||||||
{S(GMLIB_Level::getLevel()->getServerCurrentTps()),
|
{S(gmlib::GMLevel::getInstance()->getServerCurrentTps()),
|
||||||
S(GMLIB_Level::getLevel()->getServerAverageTps())}
|
S(gmlib::TpsStatus::getInstance().getLevelAverageTps())})
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
case CleanerParam::Action::mspt: {
|
case CleanerParam::Action::mspt: {
|
||||||
return output.success(
|
return output.success(
|
||||||
tr("cleaner.command.mspt.output", {S(GMLIB_Level::getLevel()->getServerMspt())})
|
tr("cleaner.command.mspt.output", {S(gmlib::GMLevel::getInstance()->getServerMspt())})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
case CleanerParam::Action::reload: {
|
case CleanerParam::Action::reload: {
|
||||||
Cleaner::reloadCleaner();
|
Cleaner::reloadCleaner();
|
||||||
return output.success(tr("cleaner.output.reload"));
|
return output.success(tr("cleaner.output.reload"));
|
||||||
}
|
}
|
||||||
|
case CleanerParam::Action::gui:
|
||||||
|
if (origin.getOriginType()==CommandOriginType::Player)
|
||||||
|
MainForm((Player*)origin.getEntity());
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
);
|
||||||
cmd.overload<CleanerParam>()
|
cmd.overload<CleanerParam>()
|
||||||
.required("despawntime")
|
.required("despawntime")
|
||||||
.required("ticks")
|
.required("ticks")
|
||||||
@@ -74,7 +87,7 @@ void RegCleanerCommand() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void RegVoteCommand() {
|
void RegVoteCommand() {
|
||||||
auto& cmd = ll::command::CommandRegistrar::getInstance().getOrCreateCommand(
|
auto& cmd = ll::command::CommandRegistrar::getInstance(false).getOrCreateCommand(
|
||||||
Cleaner::Entry::getInstance().getConfig().VoteClean.VoteCleanCommand,
|
Cleaner::Entry::getInstance().getConfig().VoteClean.VoteCleanCommand,
|
||||||
tr("cleaner.command.voteclean"),
|
tr("cleaner.command.voteclean"),
|
||||||
CommandPermissionLevel::Any
|
CommandPermissionLevel::Any
|
||||||
|
|||||||
+39
-13
@@ -1,28 +1,54 @@
|
|||||||
{
|
{
|
||||||
"format_version": 2,
|
"format_version": 3,
|
||||||
|
"format_uuid": "289f771f-2c9a-4d73-9f3f-8492495a924d",
|
||||||
"tooth": "github.com/GroupMountain/Cleaner",
|
"tooth": "github.com/GroupMountain/Cleaner",
|
||||||
"version": "0.13.3",
|
"version": "0.16.1",
|
||||||
"info": {
|
"info": {
|
||||||
"name": "Cleaner",
|
"name": "Cleaner",
|
||||||
"description": "A Powerful Entities Cleaning up Mod for BDS",
|
"description": "A Powerful Entities Cleaning up Mod for BDS",
|
||||||
"author": "GroupMountain",
|
|
||||||
"source": "github.com/GroupMountain/Cleaner",
|
|
||||||
"tags": [
|
"tags": [
|
||||||
"levilamina",
|
"levilamina",
|
||||||
"cleaner",
|
"cleaner",
|
||||||
"gmlib"
|
"gmlib"
|
||||||
]
|
],
|
||||||
|
"avatar_url": ""
|
||||||
},
|
},
|
||||||
"asset_url": "https://github.com/GroupMountain/Cleaner/releases/download/v0.13.3/Cleaner-windows-x64.zip",
|
"variants": [
|
||||||
"dependencies": {
|
|
||||||
"github.com/GroupMountain/GMLIB": ">=0.13.10"
|
|
||||||
},
|
|
||||||
"files": {
|
|
||||||
"place": [
|
|
||||||
{
|
{
|
||||||
"src": "Cleaner/*",
|
"label": "",
|
||||||
"dest": "mods/Cleaner"
|
"platform": "win-x64",
|
||||||
|
"dependencies": {
|
||||||
|
"github.com/GroupMountain/GMLIB-Release": ">=1.9.0",
|
||||||
|
"github.com/GroupMountain/ModAPI-Release": ">=0.4.0",
|
||||||
|
"github.com/MiracleForest/iListenAttentively-Release": ">=0.11.0"
|
||||||
|
},
|
||||||
|
"assets": [
|
||||||
|
{
|
||||||
|
"type": "zip",
|
||||||
|
"urls": [
|
||||||
|
"https://github.com/GroupMountain/Cleaner/releases/download/v{{version}}/Cleaner-windows-x64.zip"
|
||||||
|
],
|
||||||
|
"placements": [
|
||||||
|
{
|
||||||
|
"type": "dir",
|
||||||
|
"src": "Cleaner/",
|
||||||
|
"dest": "plugins/Cleaner"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"preserve_files": [],
|
||||||
|
"remove_files": [],
|
||||||
|
"scripts": {
|
||||||
|
"pre_install": [],
|
||||||
|
"install": [],
|
||||||
|
"post_install": [],
|
||||||
|
"pre_pack": [],
|
||||||
|
"post_pack": [],
|
||||||
|
"pre_uninstall": [],
|
||||||
|
"uninstall": [],
|
||||||
|
"post_uninstall": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
@@ -2,15 +2,17 @@ add_rules("mode.debug", "mode.release", "mode.releasedbg")
|
|||||||
|
|
||||||
add_repositories("liteldev-repo https://github.com/LiteLDev/xmake-repo.git")
|
add_repositories("liteldev-repo https://github.com/LiteLDev/xmake-repo.git")
|
||||||
add_repositories("groupmountain-repo https://github.com/GroupMountain/xmake-repo.git")
|
add_repositories("groupmountain-repo https://github.com/GroupMountain/xmake-repo.git")
|
||||||
|
add_repositories("miracleforest https://github.com/MiracleForest/xmake-repo")
|
||||||
|
|
||||||
if not has_config("vs_runtime") then
|
if not has_config("vs_runtime") then
|
||||||
set_runtimes("MD")
|
set_runtimes("MD")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Option 1: Use the latest version of LeviLamina released on GitHub.
|
-- Option 1: Use the latest version of LeviLamina released on GitHub.
|
||||||
add_requires("levilamina")
|
add_requires("levilamina 26.10.5", {configs = {target_type = "server"}})
|
||||||
add_requires("levibuildscript")
|
add_requires("levibuildscript")
|
||||||
add_requires("gmlib")
|
add_requires("gmlib 26.10.0")
|
||||||
|
add_requires("ilistenattentively 0.12.0")
|
||||||
|
|
||||||
target("Cleaner") -- Change this to your mod name.
|
target("Cleaner") -- Change this to your mod name.
|
||||||
add_cxflags(
|
add_cxflags(
|
||||||
@@ -25,19 +27,20 @@ target("Cleaner") -- Change this to your mod name.
|
|||||||
)
|
)
|
||||||
add_packages(
|
add_packages(
|
||||||
"levilamina",
|
"levilamina",
|
||||||
"gmlib"
|
"gmlib",
|
||||||
|
"ilistenattentively"
|
||||||
)
|
)
|
||||||
add_defines(
|
add_defines(
|
||||||
"NOMINMAX",
|
"NOMINMAX",
|
||||||
"UNICODE",
|
"UNICODE",
|
||||||
"_HAS_CXX17",
|
"_HAS_CXX23=1"
|
||||||
"_HAS_CXX20",
|
|
||||||
"_HAS_CXX23"
|
|
||||||
)
|
)
|
||||||
|
add_defines("LL_PLAT_S") --TODO: check client compatibility
|
||||||
add_rules("@levibuildscript/linkrule")
|
add_rules("@levibuildscript/linkrule")
|
||||||
set_exceptions("none")
|
set_exceptions("none")
|
||||||
set_kind("shared")
|
set_kind("shared")
|
||||||
set_languages("cxx23")
|
set_languages("cxx20")
|
||||||
|
set_symbols("debug")
|
||||||
|
|
||||||
after_build(function (target)
|
after_build(function (target)
|
||||||
local mod_packer = import("scripts.after_build")
|
local mod_packer = import("scripts.after_build")
|
||||||
|
|||||||
Reference in New Issue
Block a user