adapt: adapt to GMLIB v0.13.7

This commit is contained in:
子沐呀
2024-11-10 16:49:36 +08:00
Unverified
parent 572cce7956
commit 33f7d2294a
11 changed files with 133 additions and 30 deletions
+104
View File
@@ -1,6 +1,110 @@
# Cleaner # Cleaner
服务器实体清理插件 服务器实体清理插件
## 配置文件
```jsonc
{
"version": 2, // 配置文件版本(勿动)
"language": "zh_CN", // 语言(目前支持zh_CN和en_US)
"Basic": { // 基础配置
"Command": "cleaner", // 清理命令
"Notice1": 20, // 提示1发送时间(剩余时间) (单位:秒)
"Notice2": 5, // 提示2发送时间(剩余时间) (单位:秒)
"ConsoleLog": true, // 是否在控制台输出清理日志
"SendBroadcast": true, // 是否发送广播
"SendToast": true // 是否发送Toast(屏幕上方)
},
"IgnoreTags": [ // 忽略的实体标签
"ignore",
"不清理"
],
"AutoCleanCount": { // 自动清理数量配置
"Enabled": true, // 是否启用
"TriggerCount": 900 // 触发清理最低数量
},
"AutoCleanTPS": { // 自动清理TPS配置
"Enabled": true, // 是否启用
"TriggerTPS": 15 // 触发清理最低TPS
},
"ItemDespawn": { // 掉落物自然刷新配置
"Enabled": true, // 是否启用
"DespawnTime": 6000, // 刷新时间(单位:tick)
"WhiteList": [ // 白名单
"minecraft:elytra"
]
},
"CleanInanimate": { // 非生物实体清理配置
"Enabled": true, // 是否启用
"Blacklist": [ // 黑名单
"minecraft:xp_orb",
"minecraft:arrow",
"minecraft:fireball",
"minecraft:small_fireball",
"minecraft:wither_skull",
"minecraft:wither_skull_dangerous",
"minecraft:dragon_fireball"
]
},
"CleanItem": { // 掉落物清理配置
"Enabled": true, // 是否启用
"ExistTicks": 0, // 安全时间(掉落物存在时间小于这个时间则不会清理) 单位:tick
"Whitelist": [ // 白名单
"minecraft:netherite_helmet",
"minecraft:netherite_sword",
"minecraft:netherite_chestplate",
"minecraft:diamond_helmet",
"minecraft:netherite_leggings",
"minecraft:undyed_shulker_box",
"minecraft:netherite_boots",
"minecraft:shulker_box",
"minecraft:elytra",
"minecraft:dragon_egg",
"minecraft:nether_star",
"minecraft:diamond_sword",
"minecraft:diamond_chestplate",
"minecraft:diamond_boots",
"minecraft:diamond_leggings",
"minecraft:diamond_hoe",
"minecraft:netherite_hoe",
"minecraft:diamond_axe",
"minecraft:netherite_axe",
"minecraft:netherite_pickaxe",
"minecraft:diamond_pickaxe"
]
},
"CleanMobs": { // 生物实体清理配置
"Enabled": true, // 是否启用
"CleanMonstors": true, // 是否清理怪物
"CleanPeacefulMobs": false, // 是否清理和平生物
"EnableAutoExclude": true, // 无用
"BlackList": [ // 黑名单
"minecraft:guardian",
"minecraft:zombie_pigman"
],
"Whitelist": [ // 白名单
"minecraft:ender_dragon",
"minecraft:shulker",
"minecraft:wither",
"minecraft:elder_guardian",
"minecraft:piglin_brute",
"minecraft:ender_pearl",
"minecraft:phantom"
]
},
"ScheduleClean": { // 定时清理配置
"Enabled": true, // 是否启用
"CleanInterval": 3600 // 清理间隔 单位:秒
},
"VoteClean": { // 投票清理配置
"Enabled": true, // 是否启用
"VoteCleanCommand": "voteclean", // 投票清理指令
"Cooldown": 120, // 投票冷却时间 单位:秒
"CheckDelay": 30, // 投票时长 单位:秒
"Percentage": 50 // 投票百分比(大于此值则清理)
}
}
```
# 开源许可 # 开源许可
## 源代码可用性 ## 源代码可用性
- 您可以自由地获取、使用和修改本插件的源代码,无论是个人使用还是商业目的。 - 您可以自由地获取、使用和修改本插件的源代码,无论是个人使用还是商业目的。
+1 -1
View File
@@ -2,7 +2,7 @@
"name": "${modName}", "name": "${modName}",
"entry": "${modFile}", "entry": "${modFile}",
"type": "native", "type": "native",
"version": "0.13.8", "version": "0.13.2",
"author": "GroupMountain", "author": "GroupMountain",
"description": "Clean Entities", "description": "Clean Entities",
"dependencies": [ "dependencies": [
+4 -4
View File
@@ -15,7 +15,7 @@ bool isMatch(std::string& A, std::string& B) {
return (A == B); return (A == B);
} }
bool shouldIgnore(gmlib::world::Actor* ac) { bool shouldIgnore(GMLIB_Actor* ac) {
if (ac->isMob() || ac->isItemActor()) { if (ac->isMob() || ac->isItemActor()) {
if (ac->isTame() || ac->isTrusting() || ac->getNameTag() != "" || ac->hasTag("cleaner:ignore")) { if (ac->isTame() || ac->isTrusting() || ac->getNameTag() != "" || ac->hasTag("cleaner:ignore")) {
return true; return true;
@@ -27,7 +27,7 @@ bool shouldIgnore(gmlib::world::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::world::Actor*)actor; auto en = (GMLIB_Actor*)actor;
if (en->isPlayer() || shouldIgnore(en)) { if (en->isPlayer() || shouldIgnore(en)) {
return false; return false;
} }
@@ -95,7 +95,7 @@ bool ShouldClean(Actor* actor) {
int ExecuteClean() { int ExecuteClean() {
int clean_count = 0; int clean_count = 0;
auto all_entities = gmlib::world::Level::getLevel()->getRuntimeActorList(); auto all_entities = GMLIB_Level::getLevel()->getRuntimeActorList();
for (auto entity : all_entities) { for (auto entity : all_entities) {
if (ShouldClean(entity)) { if (ShouldClean(entity)) {
entity->despawn(); entity->despawn();
@@ -107,7 +107,7 @@ int ExecuteClean() {
int CountEntities() { int CountEntities() {
int clean_count = 0; int clean_count = 0;
auto all_entities = gmlib::world::Level::getLevel()->getRuntimeActorList(); auto all_entities = GMLIB_Level::getLevel()->getRuntimeActorList();
for (auto* entity : all_entities) { for (auto* entity : all_entities) {
if (ShouldClean(entity)) { if (ShouldClean(entity)) {
clean_count++; clean_count++;
+2 -2
View File
@@ -80,9 +80,9 @@ void CleanTaskTPS(float min_tps) {
auto& config = Cleaner::Entry::getInstance().getConfig(); auto& config = Cleaner::Entry::getInstance().getConfig();
mCleanTaskTPS = Cleaner::Entry::getInstance().getScheduler().add<RepeatTask>(10s, [min_tps, &config] { mCleanTaskTPS = Cleaner::Entry::getInstance().getScheduler().add<RepeatTask>(10s, [min_tps, &config] {
if (auto_clean_triggerred == false) { if (auto_clean_triggerred == false) {
if (gmlib::world::Level::getLevel()->getServerAverageTps() <= min_tps) { if (GMLIB_Level::getLevel()->getServerAverageTps() <= min_tps) {
auto_clean_triggerred = true; auto_clean_triggerred = true;
auto mspt = S(gmlib::world::Level::getLevel()->getServerAverageTps()); auto mspt = S(GMLIB_Level::getLevel()->getServerAverageTps());
if (config.Basic.ConsoleLog) { if (config.Basic.ConsoleLog) {
logger.warn(tr("cleaner.output.triggerAutoCleanTps", {mspt})); logger.warn(tr("cleaner.output.triggerAutoCleanTps", {mspt}));
} }
+8 -8
View File
@@ -2,19 +2,19 @@
namespace Cleaner { namespace Cleaner {
void setShouldIgnore(gmlib::world::Actor* 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::entity::ItemActorSpawnAfterEvent>( eventBus.emplaceListener<GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent>(
[&config](gmlib::event::entity::ItemActorSpawnAfterEvent& event) { [&config](GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent& event) {
auto& item = event.getItemActor(); auto& item = event.getItemActor();
if (event.getSpawner().has_value()) { if (event.getSpawner().has_value()) {
auto pl = (gmlib::world::Player*)event.getSpawner().as_ptr(); 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::world::Actor*)&item; auto ac = (GMLIB_Actor*)&item;
setShouldIgnore(ac); setShouldIgnore(ac);
return; return;
} }
@@ -33,9 +33,9 @@ void ListenEvents() {
} }
); );
// MobTakeItemEvent // MobTakeItemEvent
eventBus.emplaceListener<gmlib::event::entity::MobPickupItemAfterEvent>( eventBus.emplaceListener<GMLIB::Event::EntityEvent::MobPickupItemAfterEvent>(
[](gmlib::event::entity::MobPickupItemAfterEvent& event) { [](GMLIB::Event::EntityEvent::MobPickupItemAfterEvent& event) {
auto mob = (gmlib::world::Actor*)&event.self(); auto mob = (GMLIB_Actor*)&event.self();
setShouldIgnore(mob); setShouldIgnore(mob);
} }
); );
+2 -2
View File
@@ -3,11 +3,11 @@
namespace Helper { namespace Helper {
void broadcastMessage(std::string_view msg) { void broadcastMessage(std::string_view msg) {
gmlib::world::Level::getInstance()->broadcast(tr("cleaner.info.prefix") + std::string(msg)); GMLIB_Level::getInstance()->broadcast(tr("cleaner.info.prefix") + std::string(msg));
} }
void broadcastToast(std::string_view msg) { void broadcastToast(std::string_view msg) {
gmlib::world::Level::getInstance()->broadcastToast(tr("cleaner.info.prefix"), msg); GMLIB_Level::getInstance()->broadcastToast(tr("cleaner.info.prefix"), msg);
} }
} // namespace Helper } // namespace Helper
+1 -1
View File
@@ -1,6 +1,6 @@
#pragma once #pragma once
#include "Mod.h" #include "Mod.h"
#include <headers/include_all.h> #include <include_all.h>
#include <regex> #include <regex>
#define S(x) std::to_string(x) #define S(x) std::to_string(x)
+4 -4
View File
@@ -17,9 +17,9 @@ bool Entry::enable() {
mScheduler.emplace(); mScheduler.emplace();
ll::config::loadConfig(*mConfig, getSelf().getConfigDir() / "config.json"); ll::config::loadConfig(*mConfig, getSelf().getConfigDir() / "config.json");
saveConfig(); saveConfig();
gmlib::world::I18nAPI::updateOrCreateLanguageFile(getSelf().getLangDir(), "en_US", en_US); I18nAPI::updateOrCreateLanguageFile(getSelf().getLangDir(), "en_US", en_US);
gmlib::world::I18nAPI::updateOrCreateLanguageFile(getSelf().getLangDir(), "zh_CN", zh_CN); I18nAPI::updateOrCreateLanguageFile(getSelf().getLangDir(), "zh_CN", zh_CN);
gmlib::world::I18nAPI::loadLanguagesFromDirectory(getSelf().getLangDir()); I18nAPI::loadLanguagesFromDirectory(getSelf().getLangDir());
Cleaner::ListenEvents(); Cleaner::ListenEvents();
RegisterCommands(); RegisterCommands();
Cleaner::loadCleaner(); Cleaner::loadCleaner();
@@ -47,5 +47,5 @@ ServerTimeScheduler& Entry::getScheduler() { return mScheduler.value(); }
LL_REGISTER_MOD(Cleaner::Entry, Cleaner::instance); LL_REGISTER_MOD(Cleaner::Entry, Cleaner::instance);
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 gmlib::world::I18nAPI::get(key, params, Cleaner::Entry::getInstance().getConfig().language); return I18nAPI::get(key, params, Cleaner::Entry::getInstance().getConfig().language);
} }
+3 -4
View File
@@ -1,6 +1,5 @@
#include "Features/Cleaner.h" #include "Features/Cleaner.h"
#include "Mod.h" #include "Mod.h"
#include "gmlib/world/Level.h"
struct CleanerParam { struct CleanerParam {
enum class Despawn { despawn } despawn; enum class Despawn { despawn } despawn;
@@ -50,13 +49,13 @@ void RegCleanerCommand() {
case CleanerParam::Action::tps: { case CleanerParam::Action::tps: {
return output.success(tr( return output.success(tr(
"cleaner.command.tps.output", "cleaner.command.tps.output",
{S(gmlib::world::Level::getLevel()->getServerCurrentTps()), {S(GMLIB_Level::getLevel()->getServerCurrentTps()),
S(gmlib::world::Level::getLevel()->getServerAverageTps())} S(GMLIB_Level::getLevel()->getServerAverageTps())}
)); ));
} }
case CleanerParam::Action::mspt: { case CleanerParam::Action::mspt: {
return output.success( return output.success(
tr("cleaner.command.mspt.output", {S(gmlib::world::Level::getLevel()->getServerMspt())}) tr("cleaner.command.mspt.output", {S(GMLIB_Level::getLevel()->getServerMspt())})
); );
} }
case CleanerParam::Action::reload: { case CleanerParam::Action::reload: {
+3 -3
View File
@@ -1,7 +1,7 @@
{ {
"format_version": 2, "format_version": 2,
"tooth": "github.com/GroupMountain/Cleaner", "tooth": "github.com/GroupMountain/Cleaner",
"version": "0.13.1", "version": "0.13.2",
"info": { "info": {
"name": "Cleaner", "name": "Cleaner",
"description": "A Powerful Entities Cleaning up Mod for BDS", "description": "A Powerful Entities Cleaning up Mod for BDS",
@@ -13,9 +13,9 @@
"gmlib" "gmlib"
] ]
}, },
"asset_url": "https://github.com/GroupMountain/Cleaner/releases/download/v0.13.1/Cleaner-windows-x64.zip", "asset_url": "https://github.com/GroupMountain/Cleaner/releases/download/v0.13.2/Cleaner-windows-x64.zip",
"dependencies": { "dependencies": {
"github.com/GroupMountain/GMLIB": ">=0.13.1" "github.com/GroupMountain/GMLIB": ">=0.13.7"
}, },
"files": { "files": {
"place": [ "place": [
+1 -1
View File
@@ -9,7 +9,7 @@ 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")
add_requires("gmlib") add_requires("gmlib 0.13.7")
target("Cleaner") -- Change this to your mod name. target("Cleaner") -- Change this to your mod name.
add_cxflags( add_cxflags(