Compare commits

20 Commits

22 changed files with 356 additions and 214 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
Diagnostics:
Suppress: ["-Wmicrosoft-enum-forward-reference", "-Wc++11-narrowing", "-Wc++2b-extensions", "-Wmicrosoft-cast"]
CompileFlags:
Add: ["-ferror-limit=0", "-D__FUNCTION__=\"dummy\"", "-D_CRT_USE_BUILTIN_OFFSETOF", "-std:c++latest"]
Add: ["-ferror-limit=0", "-D__FUNCTION__=\"dummy\"", "-D_CRT_USE_BUILTIN_OFFSETOF", "-std=c++23"]
Remove: ["/Yu_HeaderOutputPredefine.h", "/FI_HeaderOutputPredefine.h"]
+3 -2
View File
@@ -15,7 +15,8 @@ jobs:
- uses: actions/checkout@v4
- uses: xmake-io/github-action-setup-xmake@v1
with:
xmake-version: latest
- run: |
xmake repo -u
@@ -25,7 +26,7 @@ jobs:
- run: |
xmake -w -y
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }}
path: |
+4 -3
View File
@@ -15,7 +15,8 @@ jobs:
- uses: actions/checkout@v4
- uses: xmake-io/github-action-setup-xmake@v1
with:
xmake-version: latest
- run: |
xmake repo -u
@@ -25,7 +26,7 @@ jobs:
- run: |
xmake -w -y
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }}
path: |
@@ -40,7 +41,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }}
path: release/
+104
View File
@@ -1,6 +1,110 @@
# 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 // 投票百分比(大于此值则清理)
}
}
```
# 开源许可
## 源代码可用性
- 您可以自由地获取、使用和修改本插件的源代码,无论是个人使用还是商业目的。
Submodule SDK-GMLIB deleted from e4f3e2a188
+4 -4
View File
@@ -1,8 +1,8 @@
{
"name": "${pluginName}",
"entry": "${pluginFile}",
"name": "${modName}",
"entry": "${modFile}",
"type": "native",
"version": "0.12.0",
"version": "0.13.3",
"author": "GroupMountain",
"description": "Clean Entities",
"dependencies": [
@@ -10,4 +10,4 @@
"name": "GMLIB"
}
]
}
}
+7 -7
View File
@@ -82,16 +82,16 @@ function string_formatter(str, variables)
end)
end
function pack_plugin(target,plugin_define)
function pack_mod(target,mod_define)
import("lib.detect.find_file")
local manifest_path = find_file("manifest.json", os.projectdir())
if manifest_path then
local manifest = io.readfile(manifest_path)
local bindir = path.join(os.projectdir(), "bin")
local outputdir = path.join(bindir, plugin_define.pluginName)
local targetfile = path.join(outputdir, plugin_define.pluginFile)
local pdbfile = path.join(outputdir, path.basename(plugin_define.pluginFile) .. ".pdb")
local outputdir = path.join(bindir, mod_define.modName)
local targetfile = path.join(outputdir, mod_define.modFile)
local pdbfile = path.join(outputdir, path.basename(mod_define.modFile) .. ".pdb")
local manifestfile = path.join(outputdir, "manifest.json")
local oritargetfile = target:targetfile()
local oripdbfile = path.join(path.directory(oritargetfile), path.basename(oritargetfile) .. ".pdb")
@@ -102,9 +102,9 @@ function pack_plugin(target,plugin_define)
os.cp(oripdbfile, pdbfile)
end
formattedmanifest = string_formatter(manifest, plugin_define)
formattedmanifest = string_formatter(manifest, mod_define)
io.writefile(manifestfile,formattedmanifest)
cprint("${bright green}[Plugin Packer]: ${reset}plugin already generated to " .. outputdir)
cprint("${bright green}[Mod Packer]: ${reset}mod already generated to " .. outputdir)
else
cprint("${bright yellow}warn: ${reset}not found manifest.json in root dir!")
end
@@ -112,7 +112,7 @@ end
return {
pack_plugin = pack_plugin,
pack_mod = pack_mod,
beautify_json = beautify_json,
string_formatter = string_formatter
}
+6 -2
View File
@@ -1,9 +1,12 @@
#pragma once
#include <iostream>
#include <string>
#include <vector>
namespace Cleaner {
struct Config {
int version = 1;
int version = 2;
std::string language = "zh_CN";
struct basic {
std::string Command = "cleaner";
@@ -89,3 +92,4 @@ struct Config {
int Percentage = 50;
} VoteClean;
};
} // namespace Cleaner
+3 -3
View File
@@ -95,7 +95,7 @@ bool ShouldClean(Actor* actor) {
int ExecuteClean() {
int clean_count = 0;
auto all_entities = GMLIB_Level::getLevel()->getAllEntities();
auto all_entities = GMLIB_Level::getLevel()->getRuntimeActorList();
for (auto entity : all_entities) {
if (ShouldClean(entity)) {
entity->despawn();
@@ -107,8 +107,8 @@ int ExecuteClean() {
int CountEntities() {
int clean_count = 0;
auto all_entities = GMLIB_Level::getLevel()->getAllEntities();
for (auto entity : all_entities) {
auto all_entities = GMLIB_Level::getLevel()->getRuntimeActorList();
for (auto* entity : all_entities) {
if (ShouldClean(entity)) {
clean_count++;
}
+84 -56
View File
@@ -1,10 +1,11 @@
#include "Cleaner.h"
#include <memory>
namespace Cleaner {
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;
static std::shared_ptr<bool> mAutoCleanTask = std::make_shared<bool>(false);
static std::shared_ptr<bool> mCleanTaskCount = std::make_shared<bool>(false);
static std::shared_ptr<bool> mCleanTaskTPS = std::make_shared<bool>(false);
bool auto_clean_triggerred = false;
@@ -15,101 +16,128 @@ void CleanTask() {
auto time_1 = std::chrono::seconds::duration(time);
auto time_2 = std::chrono::seconds::duration(time - announce_time);
if (config.Basic.ConsoleLog) {
logger.info(I18nAPI::get("cleaner.output.count1", {S(time_1.count())}));
ll::io::LoggerRegistry::getInstance().getOrCreate("Cleaner")->info(
tr("cleaner.output.count1", {S(time_1.count())})
);
}
if (config.Basic.SendBroadcast) {
Helper::broadcastMessage(I18nAPI::get("cleaner.output.count1", {S(time_1.count())}));
Helper::broadcastMessage(tr("cleaner.output.count1", {S(time_1.count())}));
}
if (config.Basic.SendToast) {
Helper::broadcastToast(I18nAPI::get("cleaner.output.count2", {S(announce_time)}));
Helper::broadcastToast(tr("cleaner.output.count2", {S(announce_time)}));
}
Cleaner::Entry::getInstance().getScheduler().add<DelayTask>(time_2, [announce_time, &config] {
ll::coro::keepThis([announce_time, &config, time_2]() -> ll::coro::CoroTask<> {
co_await time_2;
if (config.Basic.ConsoleLog) {
logger.info(I18nAPI::get("cleaner.output.count2", {S(announce_time)}));
ll::io::LoggerRegistry::getInstance().getOrCreate("Cleaner")->info(
tr("cleaner.output.count2", {S(announce_time)})
);
}
if (config.Basic.SendBroadcast) {
Helper::broadcastMessage(I18nAPI::get("cleaner.output.count2", {S(announce_time)}));
Helper::broadcastMessage(tr("cleaner.output.count2", {S(announce_time)}));
}
if (config.Basic.SendToast) {
Helper::broadcastToast(I18nAPI::get("cleaner.output.count2", {S(announce_time)}));
Helper::broadcastToast(tr("cleaner.output.count2", {S(announce_time)}));
}
});
Cleaner::Entry::getInstance().getScheduler().add<DelayTask>(time_1, [&config] {
co_return;
}).launch(ll::thread::ServerThreadExecutor::getDefault());
ll::coro::keepThis([announce_time, &config, time_1]() -> ll::coro::CoroTask<> {
co_await time_1;
auto count = ExecuteClean();
if (config.Basic.ConsoleLog) {
logger.info(I18nAPI::get("cleaner.output.finish", {S(count)}));
ll::io::LoggerRegistry::getInstance().getOrCreate("Cleaner")->info(tr("cleaner.output.finish", {S(count)}));
}
if (config.Basic.SendBroadcast) {
Helper::broadcastMessage(I18nAPI::get("cleaner.output.finish", {S(count)}));
Helper::broadcastMessage(tr("cleaner.output.finish", {S(count)}));
}
if (config.Basic.SendToast) {
Helper::broadcastToast(I18nAPI::get("cleaner.output.finish", {S(count)}));
Helper::broadcastToast(tr("cleaner.output.finish", {S(count)}));
}
auto_clean_triggerred = false;
});
co_return;
}).launch(ll::thread::ServerThreadExecutor::getDefault());
}
void AutoCleanTask(int seconds) {
auto time = std::chrono::seconds::duration(seconds);
mAutoCleanTask = Cleaner::Entry::getInstance().getScheduler().add<RepeatTask>(time, [] { CleanTask(); });
auto time = std::chrono::seconds::duration(seconds);
*mAutoCleanTask = true;
ll::coro::keepThis([time]() -> ll::coro::CoroTask<> {
while (true) {
co_await time;
if (*mAutoCleanTask == false) co_return;
CleanTask();
}
co_return;
}).launch(ll::thread::ServerThreadExecutor::getDefault());
}
void CleanTaskCount(int max_entities) {
auto& config = Cleaner::Entry::getInstance().getConfig();
mCleanTaskCount = Cleaner::Entry::getInstance().getScheduler().add<RepeatTask>(10s, [max_entities, &config] {
auto count = CountEntities();
if (auto_clean_triggerred == false) {
if (count >= max_entities) {
auto_clean_triggerred = true;
if (config.Basic.ConsoleLog) {
logger.warn(I18nAPI::get("cleaner.output.triggerAutoCleanCount", {S(count)}));
auto& config = Cleaner::Entry::getInstance().getConfig();
*mCleanTaskCount = true;
ll::coro::keepThis([max_entities, &config]() -> ll::coro::CoroTask<> {
while (true) {
co_await 10s;
if (*mCleanTaskCount == false) co_return;
auto count = CountEntities();
if (auto_clean_triggerred == false) {
if (count >= max_entities) {
auto_clean_triggerred = true;
if (config.Basic.ConsoleLog) {
ll::io::LoggerRegistry::getInstance().getOrCreate("Cleaner")->warn(tr("cleaner.output.triggerAutoCleanCount", {S(count)}));
}
if (config.Basic.SendBroadcast) {
Helper::broadcastMessage(tr("cleaner.output.triggerAutoCleanCount", {S(count)}));
}
if (config.Basic.SendToast) {
Helper::broadcastToast(tr("cleaner.output.triggerAutoCleanCount", {S(count)}));
}
CleanTask();
}
if (config.Basic.SendBroadcast) {
Helper::broadcastMessage(I18nAPI::get("cleaner.output.triggerAutoCleanCount", {S(count)}));
}
if (config.Basic.SendToast) {
Helper::broadcastToast(I18nAPI::get("cleaner.output.triggerAutoCleanCount", {S(count)}));
}
CleanTask();
}
}
});
co_return;
}).launch(ll::thread::ServerThreadExecutor::getDefault());
}
void CleanTaskTPS(float min_tps) {
auto& config = Cleaner::Entry::getInstance().getConfig();
mCleanTaskTPS = Cleaner::Entry::getInstance().getScheduler().add<RepeatTask>(10s, [min_tps, &config] {
if (auto_clean_triggerred == false) {
if (GMLIB_Level::getLevel()->getServerAverageTps() <= min_tps) {
auto_clean_triggerred = true;
auto mspt = S(GMLIB_Level::getLevel()->getServerAverageTps());
if (config.Basic.ConsoleLog) {
logger.warn(I18nAPI::get("cleaner.output.triggerAutoCleanTps", {mspt}));
auto& config = Cleaner::Entry::getInstance().getConfig();
*mCleanTaskTPS = true;
ll::coro::keepThis([min_tps, &config]() -> ll::coro::CoroTask<> {
while (true) {
co_await 10s;
if (*mCleanTaskTPS == false) co_return;
if (auto_clean_triggerred == false) {
if (GMLIB_Level::getLevel()->getServerAverageTps() <= min_tps) {
auto_clean_triggerred = true;
auto mspt = S(GMLIB_Level::getLevel()->getServerAverageTps());
if (config.Basic.ConsoleLog) {
ll::io::LoggerRegistry::getInstance().getOrCreate("Cleaner")->warn(
tr("cleaner.output.triggerAutoCleanTps", {mspt})
);
}
if (config.Basic.SendBroadcast) {
Helper::broadcastMessage(tr("cleaner.output.triggerAutoCleanTps", {mspt}));
}
if (config.Basic.SendToast) {
Helper::broadcastToast(tr("cleaner.output.triggerAutoCleanTps", {mspt}));
}
CleanTask();
}
if (config.Basic.SendBroadcast) {
Helper::broadcastMessage(I18nAPI::get("cleaner.output.triggerAutoCleanTps", {mspt}));
}
if (config.Basic.SendToast) {
Helper::broadcastToast(I18nAPI::get("cleaner.output.triggerAutoCleanTps", {mspt}));
}
CleanTask();
}
}
});
co_return;
}).launch(ll::thread::ServerThreadExecutor::getDefault());
}
void stopAllTasks() {
if (!mCleanTaskCount) {
mCleanTaskTPS->cancel();
Cleaner::Entry::getInstance().getScheduler().remove(mCleanTaskTPS);
*mCleanTaskTPS = false;
}
if (mCleanTaskCount) {
mCleanTaskCount->cancel();
Cleaner::Entry::getInstance().getScheduler().remove(mCleanTaskCount);
*mCleanTaskCount = false;
}
if (mAutoCleanTask) {
mAutoCleanTask->cancel();
Cleaner::Entry::getInstance().getScheduler().remove(mAutoCleanTask);
*mAutoCleanTask = false;
}
}
} // namespace Cleaner
-1
View File
@@ -1,7 +1,6 @@
#pragma once
#include "Global.h"
using namespace ll::schedule;
using namespace ll::chrono_literals;
namespace Cleaner {
+6 -2
View File
@@ -2,8 +2,12 @@
namespace Helper {
void broadcastMessage(std::string_view msg) { GMLIB_Level::broadcast(I18nAPI::get("cleaner.info.prefix") + std::string(msg)); }
void broadcastMessage(std::string_view msg) {
GMLIB_Level::getInstance()->broadcast(tr("cleaner.info.prefix") + std::string(msg));
}
void broadcastToast(std::string_view msg) { GMLIB_Level::broadcastToast(I18nAPI::get("cleaner.info.prefix"), msg); }
void broadcastToast(std::string_view msg) {
GMLIB_Level::getInstance()->broadcastToast(tr("cleaner.info.prefix"), msg);
}
} // namespace Helper
+30 -26
View File
@@ -9,8 +9,6 @@ int playerCount = 0;
std::unordered_map<mce::UUID, bool> voteList;
static std::shared_ptr<ll::schedule::task::Task<ll::chrono::ServerClock>> mAutoCleanTask;
int getPlayerCount() {
int result = 0;
ll::service::getLevel()->forEachPlayer([&](Player& pl) -> bool {
@@ -24,10 +22,10 @@ int getPlayerCount() {
void sendVoteForm(Player* pl) {
auto fm = ll::form::ModalForm(
I18nAPI::get("cleaner.vote.title"),
I18nAPI::get("cleaner.vote.subtitle", {pl->getRealName()}),
I18nAPI::get("cleaner.vote.ok"),
I18nAPI::get("cleaner.vote.no")
tr("cleaner.vote.title"),
tr("cleaner.vote.subtitle", {pl->getRealName()}),
tr("cleaner.vote.ok"),
tr("cleaner.vote.no")
);
ll::service::getLevel()->forEachPlayer([&](Player& pl) -> bool {
fm.sendTo(pl, [](Player& player, ll::form::ModalFormResult result, ll::form::FormCancelReason reason) {
@@ -35,12 +33,12 @@ void sendVoteForm(Player* pl) {
switch (result.value()) {
case ll::form::ModalFormSelectedButton::Upper: {
voteList[player.getUuid()] = true;
player.sendMessage(I18nAPI::get("cleaner.vote.accept"));
player.sendMessage(tr("cleaner.vote.accept"));
return;
}
case ll::form::ModalFormSelectedButton::Lower: {
voteList[player.getUuid()] = false;
player.sendMessage(I18nAPI::get("cleaner.vote.deny"));
player.sendMessage(tr("cleaner.vote.deny"));
return;
}
default:
@@ -64,18 +62,18 @@ void checkVote() {
float result = ((float)voteCount) / ((float)playerCount);
if (result >= percentage) {
if (config.Basic.SendBroadcast) {
Helper::broadcastMessage(I18nAPI::get("cleaner.vote.succeed"));
Helper::broadcastMessage(tr("cleaner.vote.succeed"));
}
if (config.Basic.SendToast) {
Helper::broadcastToast(I18nAPI::get("cleaner.vote.succeed"));
Helper::broadcastToast(tr("cleaner.vote.succeed"));
}
Cleaner::CleanTask();
} else {
if (config.Basic.SendBroadcast) {
Helper::broadcastMessage(I18nAPI::get("cleaner.vote.failed"));
Helper::broadcastMessage(tr("cleaner.vote.failed"));
}
if (config.Basic.SendToast) {
Helper::broadcastToast(I18nAPI::get("cleaner.vote.failed"));
Helper::broadcastToast(tr("cleaner.vote.failed"));
}
}
hasVote = false;
@@ -89,24 +87,30 @@ void voteClean(Player* pl) {
hasVote = true;
playerCount = getPlayerCount();
if (config.Basic.SendBroadcast) {
Helper::broadcastMessage(I18nAPI::get("cleaner.vote.voteMessage", {pl->getRealName()}));
Helper::broadcastMessage(tr("cleaner.vote.voteMessage", {pl->getRealName()}));
}
if (config.Basic.SendToast) {
Helper::broadcastToast(I18nAPI::get("cleaner.vote.voteMessage", {pl->getRealName()}));
Helper::broadcastToast(tr("cleaner.vote.voteMessage", {pl->getRealName()}));
}
sendVoteForm(pl);
auto cooldown = std::chrono::seconds::duration(config.VoteClean.Cooldown);
auto waitTime = std::chrono::seconds::duration(config.VoteClean.CheckDelay);
Cleaner::Entry::getInstance().getScheduler().add<DelayTask>(cooldown, [] { canVote = false; });
Cleaner::Entry::getInstance().getScheduler().add<DelayTask>(waitTime, [] { checkVote(); });
ll::coro::keepThis([&config]() -> ll::coro::CoroTask<> {
co_await std::chrono::seconds::duration(config.VoteClean.Cooldown);
canVote = true;
co_return;
}).launch(ll::thread::ServerThreadExecutor::getDefault());
ll::coro::keepThis([&config]() -> ll::coro::CoroTask<> {
co_await std::chrono::seconds::duration(config.VoteClean.CheckDelay);
checkVote();
co_return;
}).launch(ll::thread::ServerThreadExecutor::getDefault());
}
void confirmForm(Player* pl) {
auto fm = ll::form::ModalForm(
I18nAPI::get("cleaner.vote.title"),
I18nAPI::get("cleaner.vote.confirmTubtitle"),
I18nAPI::get("cleaner.vote.confirmOk"),
I18nAPI::get("cleaner.vote.confirmNo")
tr("cleaner.vote.title"),
tr("cleaner.vote.confirmTubtitle"),
tr("cleaner.vote.confirmOk"),
tr("cleaner.vote.confirmNo")
);
fm.sendTo(*pl, [](Player& player, ll::form::ModalFormResult result, ll::form::FormCancelReason reason) {
if (result.has_value()) {
@@ -115,7 +119,7 @@ void confirmForm(Player* pl) {
return voteClean(&player);
}
case ll::form::ModalFormSelectedButton::Lower: {
return player.sendMessage(I18nAPI::get("cleaner.vote.cancel"));
return player.sendMessage(tr("cleaner.vote.cancel"));
}
default:
return;
@@ -129,14 +133,14 @@ void voteCommandExecute(Player* pl) {
if (canVote) {
confirmForm(pl);
} else {
pl->sendMessage(I18nAPI::get("cleaner.vote.cooldown"));
pl->sendMessage(tr("cleaner.vote.cooldown"));
}
} else {
if (voteList.count(pl->getUuid())) {
pl->sendMessage(I18nAPI::get("cleaner.vote.voted"));
pl->sendMessage(tr("cleaner.vote.voted"));
} else {
voteList[pl->getUuid()] = true;
pl->sendMessage(I18nAPI::get("cleaner.vote.accept"));
pl->sendMessage(tr("cleaner.vote.accept"));
}
}
}
+4 -4
View File
@@ -1,15 +1,15 @@
#pragma once
#include "Plugin.h"
#include "Mod.h"
#include <include_all.h>
#include <regex>
#define S(x) std::to_string(x)
extern ll::Logger logger;
extern void RegisterCommands();
namespace Helper {
extern void broadcastMessage(std::string_view msg);
extern void broadcastToast(std::string_view msg);
} // namespace Helper
} // namespace Helper
extern std::string tr(std::string const& key, std::vector<std::string> const& params = {});
+1 -1
View File
@@ -16,7 +16,7 @@ std::string en_US = R"(
cleaner.output.count2=Attention! The system will automatically clean server entities in %1$s seconds!
cleaner.output.finish=Cleaning complete! A total of %1$s entities have been cleaned this time.
cleaner.output.opClean=Admin has enabled server entity cleaning.
cleaner.output.reload=Cleaner plugin reloaded. Some configurations may require a server restart to take effect.
cleaner.output.reload=Cleaner mod reloaded. Some configurations may require a server restart to take effect.
cleaner.output.triggerAutoCleanCount=Too many server entities detected! There are %1$s cleanable entities currently on the server. Auto-clean program has been activated.
cleaner.output.triggerAutoCleanTps=Low TPS detected! Server average TPS %1$s\nClean program has been initiated.
cleaner.vote.cooldown=Vote cleaning cooldown...
+2 -2
View File
@@ -1,5 +1,5 @@
// This file will make your plugin use LeviLamina's memory operators by default.
// This improves the memory management of your plugin and is recommended to use.
// This file will make your mod use LeviLamina's memory operators by default.
// This improves the memory management of your mod and is recommended to use.
// You should not modify anything in this file.
#define LL_MEMORY_OPERATORS
+13 -13
View File
@@ -1,20 +1,19 @@
#include "Mod.h"
#include "Features/Cleaner.h"
#include "Global.h"
#include "Language.h"
ll::Logger logger("Cleaner");
namespace Cleaner {
static std::unique_ptr<Entry> instance;
Entry& Entry::getInstance() { return *instance; }
Entry& Entry::getInstance() {
static Entry instance;
return instance;
}
bool Entry::load() { return true; }
bool Entry::enable() {
mConfig.emplace();
mScheduler.emplace();
ll::config::loadConfig(*mConfig, getSelf().getConfigDir() / "config.json");
saveConfig();
I18nAPI::updateOrCreateLanguageFile(getSelf().getLangDir(), "en_US", en_US);
@@ -23,16 +22,15 @@ bool Entry::enable() {
Cleaner::ListenEvents();
RegisterCommands();
Cleaner::loadCleaner();
logger.info("Cleaner Loaded!");
logger.info("Author: GroupMountain");
logger.info("Repository: https://github.com/GroupMountain/Cleaner");
getSelf().getLogger().info("Cleaner Loaded!");
getSelf().getLogger().info("Author: GroupMountain");
getSelf().getLogger().info("Repository: https://github.com/GroupMountain/Cleaner");
return true;
}
bool Entry::disable() {
mConfig.reset();
Cleaner::unloadCleaner();
mScheduler.reset();
return true;
}
@@ -40,8 +38,10 @@ Config& Entry::getConfig() { return mConfig.value(); }
void Entry::saveConfig() { ll::config::saveConfig(*mConfig, getSelf().getConfigDir() / "config.json"); }
ServerTimeScheduler& Entry::getScheduler() { return mScheduler.value(); }
} // namespace Cleaner
LL_REGISTER_PLUGIN(Cleaner::Entry, Cleaner::instance);
LL_REGISTER_MOD(Cleaner::Entry, Cleaner::Entry::getInstance());
std::string tr(std::string const& key, std::vector<std::string> const& params) {
return I18nAPI::get(key, params, Cleaner::Entry::getInstance().getConfig().language);
}
+39
View File
@@ -0,0 +1,39 @@
#pragma once
#include "Config.h"
#include <ll/api/mod/NativeMod.h>
namespace Cleaner {
class Entry {
public:
static Entry& getInstance();
Entry() : mSelf(*ll::mod::NativeMod::current()) {}
[[nodiscard]] ll::mod::NativeMod& getSelf() const { return mSelf; }
/// @return True if the mod is loaded successfully.
bool load();
/// @return True if the mod is enabled successfully.
bool enable();
/// @return True if the mod is disabled successfully.
bool disable();
// TODO: Implement this method if you need to unload the mod.
// /// @return True if the mod is unloaded successfully.
// bool unload();
Config& getConfig();
void saveConfig();
private:
ll::mod::NativeMod& mSelf;
std::optional<Config> mConfig;
};
} // namespace Cleaner
-45
View File
@@ -1,45 +0,0 @@
#pragma once
#include "Config.h"
#include <ll/api/plugin/NativePlugin.h>
#include <ll/api/schedule/Scheduler.h>
namespace Cleaner {
using namespace ll::schedule;
class Entry {
public:
static Entry& getInstance();
Entry(ll::plugin::NativePlugin& self) : mSelf(self) {}
[[nodiscard]] ll::plugin::NativePlugin& getSelf() const { return mSelf; }
/// @return True if the plugin is loaded successfully.
bool load();
/// @return True if the plugin is enabled successfully.
bool enable();
/// @return True if the plugin is disabled successfully.
bool disable();
// TODO: Implement this method if you need to unload the plugin.
// /// @return True if the plugin is unloaded successfully.
// bool unload();
Config& getConfig();
void saveConfig();
ServerTimeScheduler& getScheduler();
private:
ll::plugin::NativePlugin& mSelf;
std::optional<Config> mConfig;
std::optional<ServerTimeScheduler> mScheduler;
};
} // namespace Cleaner
+21 -22
View File
@@ -1,5 +1,4 @@
#include "Features/Cleaner.h"
#include "Plugin.h"
struct CleanerParam {
enum class Despawn { despawn } despawn;
@@ -13,41 +12,41 @@ void RegCleanerCommand() {
auto& config = Cleaner::Entry::getInstance().getConfig();
auto& cmd = ll::command::CommandRegistrar::getInstance().getOrCreateCommand(
config.Basic.Command,
I18nAPI::get("cleaner.command.cleaner"),
tr("cleaner.command.cleaner"),
CommandPermissionLevel::GameDirectors
);
cmd.overload<CleanerParam>()
.required("despawn")
.required("entity")
.execute<[&](CommandOrigin const& origin, CommandOutput& output, CleanerParam const& param) {
.execute([&](CommandOrigin const& origin, CommandOutput& output, CleanerParam const& param) {
auto ens = param.entity.results(origin);
if (ens.empty()) {
return output.error(I18nAPI::get("cleaner.command.error.noTarget"));
return output.error(tr("cleaner.command.error.noTarget"));
}
for (auto en : ens) {
en->despawn();
}
return output.success(I18nAPI::get("cleaner.command.despawnSuccess", {S(ens.size())}));
}>();
return output.success(tr("cleaner.command.despawnSuccess", {S(ens.size())}));
});
cmd.overload<CleanerParam>()
.required("action")
.execute<[&](CommandOrigin const& origin, CommandOutput& output, CleanerParam const& param) {
.execute([&](CommandOrigin const& origin, CommandOutput& output, CleanerParam const& param) {
switch (param.action) {
case CleanerParam::Action::clean: {
Cleaner::CleanTask();
if (Cleaner::Entry::getInstance().getConfig().Basic.ConsoleLog) {
logger.info(I18nAPI::get("cleaner.output.opClean"));
ll::io::LoggerRegistry::getInstance().getOrCreate("Cleaner")->info(tr("cleaner.output.opClean"));
}
if (Cleaner::Entry::getInstance().getConfig().Basic.SendBroadcast) {
Helper::broadcastMessage(I18nAPI::get("cleaner.output.opClean"));
Helper::broadcastMessage(tr("cleaner.output.opClean"));
}
if (Cleaner::Entry::getInstance().getConfig().Basic.SendToast) {
Helper::broadcastToast(I18nAPI::get("cleaner.output.opClean"));
Helper::broadcastToast(tr("cleaner.output.opClean"));
}
return output.success(I18nAPI::get("cleaner.command.clean.output"));
return output.success(tr("cleaner.command.clean.output"));
}
case CleanerParam::Action::tps: {
return output.success(I18nAPI::get(
return output.success(tr(
"cleaner.command.tps.output",
{S(GMLIB_Level::getLevel()->getServerCurrentTps()),
S(GMLIB_Level::getLevel()->getServerAverageTps())}
@@ -55,38 +54,38 @@ void RegCleanerCommand() {
}
case CleanerParam::Action::mspt: {
return output.success(
I18nAPI::get("cleaner.command.mspt.output", {S(GMLIB_Level::getLevel()->getServerMspt())})
tr("cleaner.command.mspt.output", {S(GMLIB_Level::getLevel()->getServerMspt())})
);
}
case CleanerParam::Action::reload: {
Cleaner::reloadCleaner();
return output.success(I18nAPI::get("cleaner.output.reload"));
return output.success(tr("cleaner.output.reload"));
}
}
}>();
});
cmd.overload<CleanerParam>()
.required("despawntime")
.required("ticks")
.execute<[&](CommandOrigin const& origin, CommandOutput& output, CleanerParam const& param) {
.execute([&](CommandOrigin const& origin, CommandOutput& output, CleanerParam const& param) {
Cleaner::Entry::getInstance().getConfig().ItemDespawn.DespawnTime = param.ticks;
Cleaner::Entry::getInstance().saveConfig();
return output.success(I18nAPI::get("cleaner.command.despawntime", {S(param.ticks)}));
}>();
return output.success(tr("cleaner.command.despawntime", {S(param.ticks)}));
});
};
void RegVoteCommand() {
auto& cmd = ll::command::CommandRegistrar::getInstance().getOrCreateCommand(
Cleaner::Entry::getInstance().getConfig().VoteClean.VoteCleanCommand,
I18nAPI::get("cleaner.command.voteclean"),
tr("cleaner.command.voteclean"),
CommandPermissionLevel::Any
);
cmd.overload().execute<[&](CommandOrigin const& origin, CommandOutput& output) {
cmd.overload().execute([&](CommandOrigin const& origin, CommandOutput& output) {
if (origin.getOriginType() == CommandOriginType::Player) {
auto pl = (Player*)origin.getEntity();
return VoteClean::voteCommandExecute(pl);
}
return output.error(I18nAPI::get("cleaner.command.error.playerOnly"));
}>();
return output.error(tr("cleaner.command.error.playerOnly"));
});
}
void RegisterCommands() {
+6 -6
View File
@@ -1,10 +1,10 @@
{
"format_version": 2,
"tooth": "github.com/GroupMountain/Cleaner",
"version": "0.12.0",
"version": "0.13.3",
"info": {
"name": "Cleaner",
"description": "A Powerful Entities Cleaning up Plugin for BDS",
"description": "A Powerful Entities Cleaning up Mod for BDS",
"author": "GroupMountain",
"source": "github.com/GroupMountain/Cleaner",
"tags": [
@@ -13,16 +13,16 @@
"gmlib"
]
},
"asset_url": "https://github.com/GroupMountain/Cleaner/releases/download/v0.12.0/Cleaner-windows-x64.zip",
"asset_url": "https://github.com/GroupMountain/Cleaner/releases/download/v0.13.3/Cleaner-windows-x64.zip",
"dependencies": {
"github.com/GroupMountain/GMLIB": ">=0.12.1"
"github.com/GroupMountain/GMLIB": ">=0.13.10"
},
"files": {
"place": [
{
"src": "Cleaner/*",
"dest": "plugins/Cleaner"
"dest": "mods/Cleaner"
}
]
}
}
}
+18 -13
View File
@@ -1,6 +1,7 @@
add_rules("mode.debug", "mode.release", "mode.releasedbg")
add_repositories("liteldev-repo https://github.com/LiteLDev/xmake-repo.git")
add_repositories("groupmountain-repo https://github.com/GroupMountain/xmake-repo.git")
if not has_config("vs_runtime") then
set_runtimes("MD")
@@ -8,8 +9,10 @@ end
-- Option 1: Use the latest version of LeviLamina released on GitHub.
add_requires("levilamina")
add_requires("levibuildscript")
add_requires("gmlib")
target("Cleaner") -- Change this to your plugin name.
target("Cleaner") -- Change this to your mod name.
add_cxflags(
"/EHa",
"/utf-8"
@@ -17,30 +20,32 @@ target("Cleaner") -- Change this to your plugin name.
add_files(
"src/**.cpp"
)
add_links(
"SDK-GMLIB/Lib/GMLIB"
)
add_includedirs(
"SDK-GMLIB",
"src"
)
add_packages(
"levilamina"
"levilamina",
"gmlib"
)
add_shflags(
"/DELAYLOAD:bedrock_server.dll"
add_defines(
"NOMINMAX",
"UNICODE",
"_HAS_CXX17",
"_HAS_CXX20",
"_HAS_CXX23"
)
add_rules("@levibuildscript/linkrule")
set_exceptions("none")
set_kind("shared")
set_languages("cxx23")
after_build(function (target)
local plugin_packer = import("scripts.after_build")
local mod_packer = import("scripts.after_build")
local plugin_define = {
pluginName = target:name(),
pluginFile = path.filename(target:targetfile()),
local mod_define = {
modName = target:name(),
modFile = path.filename(target:targetfile()),
}
plugin_packer.pack_plugin(target,plugin_define)
mod_packer.pack_mod(target,mod_define)
end)