Compare commits
25 Commits
@@ -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"]
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 // 投票百分比(大于此值则清理)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
# 开源许可
|
||||
## 源代码可用性
|
||||
- 您可以自由地获取、使用和修改本插件的源代码,无论是个人使用还是商业目的。
|
||||
|
||||
-1
Submodule SDK-GMLIB deleted from c2b463ddb2
+5
-2
@@ -1,7 +1,10 @@
|
||||
{
|
||||
"name": "${pluginName}",
|
||||
"entry": "${pluginFile}",
|
||||
"name": "${modName}",
|
||||
"entry": "${modFile}",
|
||||
"type": "native",
|
||||
"version": "0.13.2",
|
||||
"author": "GroupMountain",
|
||||
"description": "Clean Entities",
|
||||
"dependencies": [
|
||||
{
|
||||
"name": "GMLIB"
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
+77
-86
@@ -1,38 +1,42 @@
|
||||
#pragma once
|
||||
#include "Global.h"
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
std::string defaultConfig = R"({
|
||||
"Basic": {
|
||||
"Language": "en_US",
|
||||
"Command": "cleaner",
|
||||
"Notice1": 20,
|
||||
"Notice2": 5,
|
||||
"ConsoleLog": true,
|
||||
"SendBroadcast": true,
|
||||
"SendToast": true
|
||||
},
|
||||
"IgnoreTags": [
|
||||
"ignore",
|
||||
"不清理"
|
||||
],
|
||||
"AutoCleanCount": {
|
||||
"Enabled": true,
|
||||
"TriggerCount": 900
|
||||
},
|
||||
"AutoCleanTPS": {
|
||||
"Enabled": false,
|
||||
"TriggerTPS": 15
|
||||
},
|
||||
"ItemDespawn": {
|
||||
"Enabled": true,
|
||||
"DespawnTime": 6000,
|
||||
"WhiteList": [
|
||||
"minecraft:elytra"
|
||||
]
|
||||
},
|
||||
"CleanInanimate": {
|
||||
"Enabled": true,
|
||||
"Blacklist": [
|
||||
struct Config {
|
||||
int version = 2;
|
||||
|
||||
std::string language = "zh_CN";
|
||||
|
||||
struct basic {
|
||||
std::string Command = "cleaner";
|
||||
int Notice1 = 20;
|
||||
int Notice2 = 5;
|
||||
bool ConsoleLog = true;
|
||||
bool SendBroadcast = true;
|
||||
bool SendToast = true;
|
||||
} Basic;
|
||||
|
||||
std::vector<std::string> IgnoreTags = {"ignore", "不清理"};
|
||||
|
||||
struct auto_clean_count {
|
||||
bool Enabled = true;
|
||||
int TriggerCount = 900;
|
||||
} AutoCleanCount;
|
||||
|
||||
struct auto_clean_tps {
|
||||
bool Enabled = true;
|
||||
int TriggerTPS = 15;
|
||||
} AutoCleanTPS;
|
||||
|
||||
struct item_despawn {
|
||||
bool Enabled = true;
|
||||
int DespawnTime = 6000;
|
||||
std::vector<std::string> WhiteList = {"minecraft:elytra"};
|
||||
} ItemDespawn;
|
||||
|
||||
struct Clean_Inanimate {
|
||||
bool Enabled = true;
|
||||
std::vector<std::string> Blacklist = {
|
||||
"minecraft:xp_orb",
|
||||
"minecraft:arrow",
|
||||
"minecraft:fireball",
|
||||
@@ -40,45 +44,30 @@ std::string defaultConfig = R"({
|
||||
"minecraft:wither_skull",
|
||||
"minecraft:wither_skull_dangerous",
|
||||
"minecraft:dragon_fireball"
|
||||
]
|
||||
},
|
||||
"CleanItem": {
|
||||
"Enabled": true,
|
||||
"ExistTicks": 0,
|
||||
"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": [
|
||||
};
|
||||
} CleanInanimate;
|
||||
|
||||
struct Clean_Item {
|
||||
bool Enabled = true;
|
||||
int ExistTicks = 0;
|
||||
std::vector<std::string> 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"
|
||||
};
|
||||
} CleanItem;
|
||||
|
||||
struct Clean_Mobs {
|
||||
bool Enabled = true;
|
||||
bool CleanMonstors = true;
|
||||
bool CleanPeacefulMobs = false;
|
||||
bool EnableAutoExclude = true;
|
||||
std::vector<std::string> BlackList = {"minecraft:guardian", "minecraft:zombie_pigman"};
|
||||
std::vector<std::string> Whitelist = {
|
||||
"minecraft:ender_dragon",
|
||||
"minecraft:shulker",
|
||||
"minecraft:wither",
|
||||
@@ -86,17 +75,19 @@ std::string defaultConfig = R"({
|
||||
"minecraft:piglin_brute",
|
||||
"minecraft:ender_pearl",
|
||||
"minecraft:phantom"
|
||||
]
|
||||
},
|
||||
"ScheduleClean": {
|
||||
"Enabled": true,
|
||||
"CleanInterval": 3600
|
||||
},
|
||||
"VoteClean": {
|
||||
"Enabled": true,
|
||||
"VoteCleanCommand": "voteclean",
|
||||
"Cooldown": 120,
|
||||
"CheckDelay": 30,
|
||||
"Percentage": 50
|
||||
}
|
||||
})";
|
||||
};
|
||||
} CleanMobs;
|
||||
|
||||
struct Schedule_Clean {
|
||||
bool Enabled = true;
|
||||
int CleanInterval = 3600;
|
||||
} ScheduleClean;
|
||||
|
||||
struct Vote_Clean {
|
||||
bool Enabled = true;
|
||||
std::string VoteCleanCommand = "voteclean";
|
||||
int Cooldown = 120;
|
||||
int CheckDelay = 30;
|
||||
int Percentage = 50;
|
||||
} VoteClean;
|
||||
};
|
||||
|
||||
+17
-22
@@ -17,11 +17,7 @@ bool isMatch(std::string& A, std::string& B) {
|
||||
|
||||
bool shouldIgnore(GMLIB_Actor* ac) {
|
||||
if (ac->isMob() || ac->isItemActor()) {
|
||||
if (ac->isTame() || ac->isTrusting() || ac->getNameTag() != "") {
|
||||
return true;
|
||||
}
|
||||
auto nbt = ac->getNbt();
|
||||
if (nbt->getByte("ShowBottom") == 1) { // End Crystal Used Only, if has this tag 1b, it is modified by cleaner.
|
||||
if (ac->isTame() || ac->isTrusting() || ac->getNameTag() != "" || ac->hasTag("cleaner:ignore")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -30,26 +26,26 @@ bool shouldIgnore(GMLIB_Actor* ac) {
|
||||
|
||||
bool ShouldClean(Actor* actor) {
|
||||
// Players
|
||||
auto en = (GMLIB_Actor*)actor;
|
||||
auto& config = Cleaner::Entry::getInstance().getConfig();
|
||||
auto en = (GMLIB_Actor*)actor;
|
||||
if (en->isPlayer() || shouldIgnore(en)) {
|
||||
return false;
|
||||
}
|
||||
auto type = en->getTypeName();
|
||||
auto tags = Config->getValue<std::vector<std::string>>({"IgnoreTags"}, {});
|
||||
for (auto& tag : tags) {
|
||||
for (auto& tag : config.IgnoreTags) {
|
||||
if (en->hasTag(tag)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Items
|
||||
if (en->isItemActor()) {
|
||||
if (Config->getValue<bool>({"CleanItem", "Enabled"}, false)) {
|
||||
if (config.CleanItem.Enabled) {
|
||||
auto itac = (ItemActor*)en;
|
||||
if (itac->age() <= Config->getValue<int>({"CleanItem", "ExistTicks"}, 0)) {
|
||||
if (itac->age() <= config.CleanItem.ExistTicks) {
|
||||
return false;
|
||||
}
|
||||
auto itemType = itac->item().getTypeName();
|
||||
auto whitelist = Config->getValue<std::vector<std::string>>({"CleanItem", "Whitelist"}, {});
|
||||
auto whitelist = config.CleanItem.Whitelist;
|
||||
for (auto& key : whitelist) {
|
||||
if (isMatch(itemType, key)) {
|
||||
return false;
|
||||
@@ -61,24 +57,23 @@ bool ShouldClean(Actor* actor) {
|
||||
}
|
||||
// Mobs
|
||||
else if (en->isMob()) {
|
||||
if (Config->getValue<bool>({"CleanMobs", "Enabled"}, false)) {
|
||||
auto blacklist = Config->getValue<std::vector<std::string>>({"CleanMobs", "Blacklist"}, {});
|
||||
if (config.CleanMobs.Enabled) {
|
||||
auto blacklist = config.CleanMobs.BlackList;
|
||||
for (auto& key : blacklist) {
|
||||
if (isMatch(type, key)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
auto whitelist = Config->getValue<std::vector<std::string>>({"CleanMobs", "Whitelist"}, {});
|
||||
auto whitelist = config.CleanMobs.Whitelist;
|
||||
for (auto& key : whitelist) {
|
||||
if (isMatch(type, key)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (Config->getValue<bool>({"CleanMobs", "CleanMonstors"}, false)
|
||||
&& en->hasCategory(ActorCategory::Monster)) {
|
||||
if (config.CleanMobs.CleanMonstors && en->hasCategory(ActorCategory::Monster)) {
|
||||
return true;
|
||||
}
|
||||
if (Config->getValue<bool>({"CleanMobs", "CleanPeacefulMobs"}, false)) {
|
||||
if (config.CleanMobs.CleanPeacefulMobs) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -86,8 +81,8 @@ bool ShouldClean(Actor* actor) {
|
||||
}
|
||||
// Others
|
||||
else {
|
||||
if (Config->getValue<bool>({"CleanInanimate", "Enabled"}, false)) {
|
||||
auto blacklist = Config->getValue<std::vector<std::string>>({"CleanInanimate", "Blacklist"}, {});
|
||||
if (config.CleanInanimate.Enabled) {
|
||||
auto blacklist = config.CleanInanimate.Blacklist;
|
||||
for (auto& key : blacklist) {
|
||||
if (isMatch(type, key)) {
|
||||
return true;
|
||||
@@ -100,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();
|
||||
@@ -112,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++;
|
||||
}
|
||||
|
||||
+30
-38
@@ -1,58 +1,48 @@
|
||||
#include "Cleaner.h"
|
||||
|
||||
namespace ConfigFile {
|
||||
|
||||
bool mConsoleLog = true;
|
||||
bool mAnnounce = true;
|
||||
bool mSendToast = true;
|
||||
|
||||
} // namespace ConfigFile
|
||||
|
||||
|
||||
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;
|
||||
|
||||
ServerTimeScheduler scheduler;
|
||||
|
||||
bool auto_clean_triggerred = false;
|
||||
|
||||
void CleanTask() {
|
||||
auto time = Config->getValue<int>({"Basic", "Notice1"}, 20);
|
||||
auto announce_time = Config->getValue<int>({"Basic", "Notice2"}, 5);
|
||||
auto time_1 = std::chrono::seconds::duration(time);
|
||||
auto time_2 = std::chrono::seconds::duration(time - announce_time);
|
||||
if (ConfigFile::mConsoleLog) {
|
||||
auto& config = Cleaner::Entry::getInstance().getConfig();
|
||||
auto time = config.Basic.Notice1;
|
||||
auto announce_time = config.Basic.Notice2;
|
||||
auto time_1 = std::chrono::seconds::duration(time);
|
||||
auto time_2 = std::chrono::seconds::duration(time - announce_time);
|
||||
if (config.Basic.ConsoleLog) {
|
||||
logger.info(tr("cleaner.output.count1", {S(time_1.count())}));
|
||||
}
|
||||
if (ConfigFile::mAnnounce) {
|
||||
if (config.Basic.SendBroadcast) {
|
||||
Helper::broadcastMessage(tr("cleaner.output.count1", {S(time_1.count())}));
|
||||
}
|
||||
if (ConfigFile::mSendToast) {
|
||||
if (config.Basic.SendToast) {
|
||||
Helper::broadcastToast(tr("cleaner.output.count2", {S(announce_time)}));
|
||||
}
|
||||
scheduler.add<DelayTask>(time_2, [announce_time] {
|
||||
if (ConfigFile::mConsoleLog) {
|
||||
Cleaner::Entry::getInstance().getScheduler().add<DelayTask>(time_2, [announce_time, &config] {
|
||||
if (config.Basic.ConsoleLog) {
|
||||
logger.info(tr("cleaner.output.count2", {S(announce_time)}));
|
||||
}
|
||||
if (ConfigFile::mAnnounce) {
|
||||
if (config.Basic.SendBroadcast) {
|
||||
Helper::broadcastMessage(tr("cleaner.output.count2", {S(announce_time)}));
|
||||
}
|
||||
if (ConfigFile::mSendToast) {
|
||||
if (config.Basic.SendToast) {
|
||||
Helper::broadcastToast(tr("cleaner.output.count2", {S(announce_time)}));
|
||||
}
|
||||
});
|
||||
scheduler.add<DelayTask>(time_1, [] {
|
||||
Cleaner::Entry::getInstance().getScheduler().add<DelayTask>(time_1, [&config] {
|
||||
auto count = ExecuteClean();
|
||||
if (ConfigFile::mConsoleLog) {
|
||||
if (config.Basic.ConsoleLog) {
|
||||
logger.info(tr("cleaner.output.finish", {S(count)}));
|
||||
}
|
||||
if (ConfigFile::mAnnounce) {
|
||||
if (config.Basic.SendBroadcast) {
|
||||
Helper::broadcastMessage(tr("cleaner.output.finish", {S(count)}));
|
||||
}
|
||||
if (ConfigFile::mSendToast) {
|
||||
if (config.Basic.SendToast) {
|
||||
Helper::broadcastToast(tr("cleaner.output.finish", {S(count)}));
|
||||
}
|
||||
auto_clean_triggerred = false;
|
||||
@@ -61,22 +51,23 @@ void CleanTask() {
|
||||
|
||||
void AutoCleanTask(int seconds) {
|
||||
auto time = std::chrono::seconds::duration(seconds);
|
||||
mAutoCleanTask = scheduler.add<RepeatTask>(time, [] { CleanTask(); });
|
||||
mAutoCleanTask = Cleaner::Entry::getInstance().getScheduler().add<RepeatTask>(time, [] { CleanTask(); });
|
||||
}
|
||||
|
||||
void CleanTaskCount(int max_entities) {
|
||||
mCleanTaskCount = scheduler.add<RepeatTask>(10s, [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 (ConfigFile::mConsoleLog) {
|
||||
if (config.Basic.ConsoleLog) {
|
||||
logger.warn(tr("cleaner.output.triggerAutoCleanCount", {S(count)}));
|
||||
}
|
||||
if (ConfigFile::mAnnounce) {
|
||||
if (config.Basic.SendBroadcast) {
|
||||
Helper::broadcastMessage(tr("cleaner.output.triggerAutoCleanCount", {S(count)}));
|
||||
}
|
||||
if (ConfigFile::mSendToast) {
|
||||
if (config.Basic.SendToast) {
|
||||
Helper::broadcastToast(tr("cleaner.output.triggerAutoCleanCount", {S(count)}));
|
||||
}
|
||||
CleanTask();
|
||||
@@ -86,18 +77,19 @@ void CleanTaskCount(int max_entities) {
|
||||
}
|
||||
|
||||
void CleanTaskTPS(float min_tps) {
|
||||
mCleanTaskTPS = scheduler.add<RepeatTask>(10s, [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 (ConfigFile::mConsoleLog) {
|
||||
if (config.Basic.ConsoleLog) {
|
||||
logger.warn(tr("cleaner.output.triggerAutoCleanTps", {mspt}));
|
||||
}
|
||||
if (ConfigFile::mAnnounce) {
|
||||
if (config.Basic.SendBroadcast) {
|
||||
Helper::broadcastMessage(tr("cleaner.output.triggerAutoCleanTps", {mspt}));
|
||||
}
|
||||
if (ConfigFile::mSendToast) {
|
||||
if (config.Basic.SendToast) {
|
||||
Helper::broadcastToast(tr("cleaner.output.triggerAutoCleanTps", {mspt}));
|
||||
}
|
||||
CleanTask();
|
||||
@@ -109,15 +101,15 @@ void CleanTaskTPS(float min_tps) {
|
||||
void stopAllTasks() {
|
||||
if (!mCleanTaskCount) {
|
||||
mCleanTaskTPS->cancel();
|
||||
scheduler.remove(mCleanTaskTPS);
|
||||
Cleaner::Entry::getInstance().getScheduler().remove(mCleanTaskTPS);
|
||||
}
|
||||
if (mCleanTaskCount) {
|
||||
mCleanTaskCount->cancel();
|
||||
scheduler.remove(mCleanTaskCount);
|
||||
Cleaner::Entry::getInstance().getScheduler().remove(mCleanTaskCount);
|
||||
}
|
||||
if (mAutoCleanTask) {
|
||||
mAutoCleanTask->cancel();
|
||||
scheduler.remove(mAutoCleanTask);
|
||||
Cleaner::Entry::getInstance().getScheduler().remove(mAutoCleanTask);
|
||||
}
|
||||
}
|
||||
} // namespace Cleaner
|
||||
|
||||
@@ -3,30 +3,23 @@
|
||||
namespace Cleaner {
|
||||
|
||||
void loadCleaner() {
|
||||
if (Config->getValue<bool>({"ScheduleClean", "Enabled"}, false)) {
|
||||
Cleaner::AutoCleanTask(Config->getValue<int>({"ScheduleClean", "CleanInterval"}, 3000));
|
||||
auto& config = Cleaner::Entry::getInstance().getConfig();
|
||||
if (config.ScheduleClean.Enabled) {
|
||||
Cleaner::AutoCleanTask(config.ScheduleClean.CleanInterval);
|
||||
}
|
||||
if (Config->getValue<bool>({"AutoCleanCount", "Enabled"}, false)) {
|
||||
Cleaner::CleanTaskCount(Config->getValue<int>({"AutoCleanCount", "TriggerCount"}, 900));
|
||||
if (config.AutoCleanCount.Enabled) {
|
||||
Cleaner::CleanTaskCount(config.AutoCleanCount.TriggerCount);
|
||||
}
|
||||
if (Config->getValue<bool>({"AutoCleanTPS", "Enabled"}, false)) {
|
||||
Cleaner::CleanTaskTPS(Config->getValue<float>({"AutoCleanTPS", "TriggerTPS"}, 15.0f));
|
||||
if (config.AutoCleanTPS.Enabled) {
|
||||
Cleaner::CleanTaskTPS(config.AutoCleanTPS.TriggerTPS);
|
||||
}
|
||||
ConfigFile::mItemDespawnTicks = Config->getValue<int>({"ItemDespawn", "DespawnTime"}, 6000);
|
||||
ConfigFile::mAnnounce = Config->getValue<bool>({"Basic", "SendBroadcast"}, true);
|
||||
ConfigFile::mConsoleLog = Config->getValue<bool>({"Basic", "ConsoleLog"}, true);
|
||||
ConfigFile::mSendToast = Config->getValue<bool>({"Basic", "SendToast"}, true);
|
||||
}
|
||||
|
||||
void unloadCleaner() { stopAllTasks(); }
|
||||
|
||||
void reloadCleaner() {
|
||||
unloadCleaner();
|
||||
Config->reload();
|
||||
std::string languageCode = Config->getValue<std::string>({"Basic", "Language"}, "en_US");
|
||||
Language->reloadAllLanguages();
|
||||
Language->chooseLanguage(languageCode);
|
||||
loadCleaner();
|
||||
Cleaner::Entry::getInstance().disable();
|
||||
Cleaner::Entry::getInstance().enable();
|
||||
}
|
||||
|
||||
} // namespace Cleaner
|
||||
@@ -6,8 +6,6 @@ using namespace ll::chrono_literals;
|
||||
|
||||
namespace Cleaner {
|
||||
|
||||
extern ServerTimeScheduler scheduler;
|
||||
|
||||
extern int ExecuteClean();
|
||||
extern int CountEntities();
|
||||
|
||||
|
||||
+9
-19
@@ -1,44 +1,34 @@
|
||||
#include "Cleaner.h"
|
||||
|
||||
namespace ConfigFile {
|
||||
|
||||
int mItemDespawnTicks = 3000;
|
||||
|
||||
} // namespace ConfigFile
|
||||
|
||||
|
||||
namespace Cleaner {
|
||||
|
||||
void setShouldIgnore(GMLIB_Actor* ac) {
|
||||
auto nbt = ac->getNbt();
|
||||
nbt->put("ShowBottom", ByteTag(1));
|
||||
ac->setNbt(*nbt);
|
||||
}
|
||||
void setShouldIgnore(GMLIB_Actor* ac) { ac->addTag("cleaner:ignore"); }
|
||||
|
||||
void ListenEvents() {
|
||||
auto& eventBus = ll::event::EventBus::getInstance();
|
||||
auto& config = Cleaner::Entry::getInstance().getConfig();
|
||||
// ItemSpawnEvent
|
||||
eventBus.emplaceListener<GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent>(
|
||||
[](GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent& event) {
|
||||
[&config](GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent& event) {
|
||||
auto& item = event.getItemActor();
|
||||
auto pl = (GMLIB_Player*)event.getSpawner();
|
||||
if (pl) {
|
||||
if (event.getSpawner().has_value()) {
|
||||
auto pl = (GMLIB_Player*)event.getSpawner().as_ptr();
|
||||
if (pl->isPlayer() && !pl->isAlive()) { // Death Drop
|
||||
auto ac = (GMLIB_Actor*)&item;
|
||||
setShouldIgnore(ac);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (Config->getValue<bool>({"ItemDespawn", "Enabled"}, true)) {
|
||||
item.lifeTime() = ConfigFile::mItemDespawnTicks;
|
||||
auto list = Config->getValue<std::vector<std::string>>({"ItemDespawn", "WhiteList"}, {});
|
||||
if (config.ItemDespawn.Enabled) {
|
||||
item.lifeTime() = config.ItemDespawn.DespawnTime;
|
||||
auto list = config.ItemDespawn.WhiteList;
|
||||
auto type = item.item().getTypeName();
|
||||
for (auto& key : list) {
|
||||
if (isMatch(type, key)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
item.lifeTime() = ConfigFile::mItemDespawnTicks;
|
||||
item.lifeTime() = config.ItemDespawn.DespawnTime;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@@ -2,8 +2,12 @@
|
||||
|
||||
namespace Helper {
|
||||
|
||||
void broadcastMessage(std::string_view msg) { GMLIB_Level::broadcast(tr("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(tr("cleaner.info.prefix"), msg); }
|
||||
void broadcastToast(std::string_view msg) {
|
||||
GMLIB_Level::getInstance()->broadcastToast(tr("cleaner.info.prefix"), msg);
|
||||
}
|
||||
|
||||
} // namespace Helper
|
||||
+41
-35
@@ -30,20 +30,22 @@ void sendVoteForm(Player* pl) {
|
||||
tr("cleaner.vote.no")
|
||||
);
|
||||
ll::service::getLevel()->forEachPlayer([&](Player& pl) -> bool {
|
||||
fm.sendTo(pl, [](Player& player, ll::form::ModalForm::SelectedButton button) {
|
||||
switch (button) {
|
||||
case ll::form::ModalForm::SelectedButton::Upper: {
|
||||
voteList[player.getUuid()] = true;
|
||||
player.sendMessage(tr("cleaner.vote.accept"));
|
||||
return;
|
||||
}
|
||||
case ll::form::ModalForm::SelectedButton::Lower: {
|
||||
voteList[player.getUuid()] = false;
|
||||
player.sendMessage(tr("cleaner.vote.deny"));
|
||||
return;
|
||||
}
|
||||
default:
|
||||
return;
|
||||
fm.sendTo(pl, [](Player& player, ll::form::ModalFormResult result, ll::form::FormCancelReason reason) {
|
||||
if (result.has_value()) {
|
||||
switch (result.value()) {
|
||||
case ll::form::ModalFormSelectedButton::Upper: {
|
||||
voteList[player.getUuid()] = true;
|
||||
player.sendMessage(tr("cleaner.vote.accept"));
|
||||
return;
|
||||
}
|
||||
case ll::form::ModalFormSelectedButton::Lower: {
|
||||
voteList[player.getUuid()] = false;
|
||||
player.sendMessage(tr("cleaner.vote.deny"));
|
||||
return;
|
||||
}
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
@@ -51,7 +53,8 @@ void sendVoteForm(Player* pl) {
|
||||
}
|
||||
|
||||
void checkVote() {
|
||||
float percentage = Config->getValue<float>({"VoteClean", "Percentage"}, 50.0f) / 100.0f;
|
||||
auto& config = Cleaner::Entry::getInstance().getConfig();
|
||||
float percentage = config.VoteClean.Percentage / 100.0f;
|
||||
int voteCount = 0;
|
||||
for (auto& key : voteList) {
|
||||
if (key.second == true) {
|
||||
@@ -60,18 +63,18 @@ void checkVote() {
|
||||
}
|
||||
float result = ((float)voteCount) / ((float)playerCount);
|
||||
if (result >= percentage) {
|
||||
if (ConfigFile::mAnnounce) {
|
||||
if (config.Basic.SendBroadcast) {
|
||||
Helper::broadcastMessage(tr("cleaner.vote.succeed"));
|
||||
}
|
||||
if (ConfigFile::mSendToast) {
|
||||
if (config.Basic.SendToast) {
|
||||
Helper::broadcastToast(tr("cleaner.vote.succeed"));
|
||||
}
|
||||
Cleaner::CleanTask();
|
||||
} else {
|
||||
if (ConfigFile::mAnnounce) {
|
||||
if (config.Basic.SendBroadcast) {
|
||||
Helper::broadcastMessage(tr("cleaner.vote.failed"));
|
||||
}
|
||||
if (ConfigFile::mSendToast) {
|
||||
if (config.Basic.SendToast) {
|
||||
Helper::broadcastToast(tr("cleaner.vote.failed"));
|
||||
}
|
||||
}
|
||||
@@ -80,21 +83,22 @@ void checkVote() {
|
||||
}
|
||||
|
||||
void voteClean(Player* pl) {
|
||||
auto& config = Cleaner::Entry::getInstance().getConfig();
|
||||
voteList.clear();
|
||||
canVote = false;
|
||||
hasVote = true;
|
||||
playerCount = getPlayerCount();
|
||||
if (ConfigFile::mAnnounce) {
|
||||
if (config.Basic.SendBroadcast) {
|
||||
Helper::broadcastMessage(tr("cleaner.vote.voteMessage", {pl->getRealName()}));
|
||||
}
|
||||
if (ConfigFile::mSendToast) {
|
||||
if (config.Basic.SendToast) {
|
||||
Helper::broadcastToast(tr("cleaner.vote.voteMessage", {pl->getRealName()}));
|
||||
}
|
||||
sendVoteForm(pl);
|
||||
auto cooldown = std::chrono::seconds::duration(Config->getValue<int>({"VoteClean", "Cooldown"}, 120));
|
||||
auto waitTime = std::chrono::seconds::duration(Config->getValue<int>({"VoteClean", "CheckDelay"}, 30));
|
||||
Cleaner::scheduler.add<DelayTask>(cooldown, [] { canVote = false; });
|
||||
Cleaner::scheduler.add<DelayTask>(waitTime, [] { checkVote(); });
|
||||
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(); });
|
||||
}
|
||||
|
||||
void confirmForm(Player* pl) {
|
||||
@@ -104,16 +108,18 @@ void confirmForm(Player* pl) {
|
||||
tr("cleaner.vote.confirmOk"),
|
||||
tr("cleaner.vote.confirmNo")
|
||||
);
|
||||
fm.sendTo(*pl, [](Player& player, ll::form::ModalForm::SelectedButton button) {
|
||||
switch (button) {
|
||||
case ll::form::ModalForm::SelectedButton::Upper: {
|
||||
return voteClean(&player);
|
||||
}
|
||||
case ll::form::ModalForm::SelectedButton::Lower: {
|
||||
return player.sendMessage(tr("cleaner.vote.cancel"));
|
||||
}
|
||||
default:
|
||||
return;
|
||||
fm.sendTo(*pl, [](Player& player, ll::form::ModalFormResult result, ll::form::FormCancelReason reason) {
|
||||
if (result.has_value()) {
|
||||
switch (result.value()) {
|
||||
case ll::form::ModalFormSelectedButton::Upper: {
|
||||
return voteClean(&player);
|
||||
}
|
||||
case ll::form::ModalFormSelectedButton::Lower: {
|
||||
return player.sendMessage(tr("cleaner.vote.cancel"));
|
||||
}
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+2
-13
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "Plugin.h"
|
||||
#include "Mod.h"
|
||||
#include <include_all.h>
|
||||
#include <regex>
|
||||
|
||||
@@ -7,22 +7,11 @@
|
||||
|
||||
extern ll::Logger logger;
|
||||
|
||||
extern GMLIB::Files::JsonConfig* Config;
|
||||
extern GMLIB::Files::I18n::JsonI18n* Language;
|
||||
|
||||
extern void RegisterCommands();
|
||||
extern void initPlugin();
|
||||
|
||||
namespace ConfigFile {
|
||||
extern int mItemDespawnTicks;
|
||||
extern bool mConsoleLog;
|
||||
extern bool mAnnounce;
|
||||
extern bool mSendToast;
|
||||
} // namespace ConfigFile
|
||||
|
||||
namespace Helper {
|
||||
extern void broadcastMessage(std::string_view msg);
|
||||
extern void broadcastToast(std::string_view msg);
|
||||
} // namespace Helper
|
||||
|
||||
extern std::string tr(std::string key, std::vector<std::string> data = {});
|
||||
extern std::string tr(std::string const& key, std::vector<std::string> const& params = {});
|
||||
@@ -1,21 +0,0 @@
|
||||
#include "Config.h"
|
||||
#include "Global.h"
|
||||
#include "Language.h"
|
||||
|
||||
GMLIB::Files::JsonConfig* Config = nullptr;
|
||||
GMLIB::Files::I18n::JsonI18n* Language = nullptr;
|
||||
int commandPermissionLevel = 4;
|
||||
|
||||
void initPlugin() {
|
||||
Config = new GMLIB::Files::JsonConfig("./plugins/Cleaner/config/config.json", defaultConfig);
|
||||
Config->init();
|
||||
std::string langPath = "./plugins/Cleaner/language/";
|
||||
std::string languageCode = Config->getValue<std::string>({"Basic", "Language"}, "en_US");
|
||||
Language = new GMLIB::Files::I18n::JsonI18n(langPath, languageCode);
|
||||
Language->updateOrCreateLanguage("en_US", defaultLanguage_en_US);
|
||||
Language->updateOrCreateLanguage("zh_CN", defaultLanguage_zh_CN);
|
||||
Language->loadAllLanguages();
|
||||
Language->chooseLanguage(languageCode);
|
||||
}
|
||||
|
||||
std::string tr(std::string key, std::vector<std::string> data) { return Language->translate(key, data); }
|
||||
+70
-70
@@ -1,74 +1,74 @@
|
||||
#pragma once
|
||||
#include "Global.h"
|
||||
|
||||
std::string defaultLanguage_en_US = R"({
|
||||
"cleaner.info.prefix": "§e§l[Cleaner] §r",
|
||||
"cleaner.command.cleaner": "Cleaner admin command.",
|
||||
"cleaner.command.despawnSuccess": "Successfully despawned %1$s entities.",
|
||||
"cleaner.command.error.noTarget": "No targets matched the selector.",
|
||||
"cleaner.command.error.playerOnly": "This command can only be executed by players!",
|
||||
"cleaner.command.tps.output": "Current server real-time TPS %1$s §r, average TPS %2$s.",
|
||||
"cleaner.command.mspt.output": "Current server MSPT %1$s.",
|
||||
"cleaner.command.clean.output": "Clean task successfully initiated!",
|
||||
"cleaner.command.voteclean": "Initiate entity clean vote.",
|
||||
"cleaner.command.despawntime": "Despawn time for items set to %1$s game ticks.",
|
||||
"cleaner.output.count1": "The system will automatically clean server entities in %1$s seconds!",
|
||||
"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.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...",
|
||||
"cleaner.vote.cancel": "Vote canceled!",
|
||||
"cleaner.vote.confirmNo": "Think again",
|
||||
"cleaner.vote.confirmOk": "Initiate vote",
|
||||
"cleaner.vote.confirmTubtitle": "Do you want to initiate a clean vote?",
|
||||
"cleaner.vote.accept": "You have agreed to entity cleaning.",
|
||||
"cleaner.vote.deny": "You have declined entity cleaning.",
|
||||
"cleaner.vote.no": "Deny",
|
||||
"cleaner.vote.ok": "Agree",
|
||||
"cleaner.vote.subtitle": "%1$s lunched a clean vote.\n\n Do you agree to clean server entities now?",
|
||||
"cleaner.vote.timeout": "Vote has expired!",
|
||||
"cleaner.vote.succeed": "Vote cleaning successful!",
|
||||
"cleaner.vote.failed": "Vote cleaning did not passed!",
|
||||
"cleaner.vote.title": "Vote Cleaning",
|
||||
"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."
|
||||
})";
|
||||
std::string en_US = R"(
|
||||
cleaner.info.prefix=§e§l[Cleaner] §r
|
||||
cleaner.command.cleaner=Cleaner admin command.
|
||||
cleaner.command.despawnSuccess=Successfully despawned %1$s entities.
|
||||
cleaner.command.error.noTarget=No targets matched the selector.
|
||||
cleaner.command.error.playerOnly=This command can only be executed by players!
|
||||
cleaner.command.tps.output=Current server real-time TPS %1$s §r, average TPS %2$s.
|
||||
cleaner.command.mspt.output=Current server MSPT %1$s.
|
||||
cleaner.command.clean.output=Clean task successfully initiated!
|
||||
cleaner.command.voteclean=Initiate entity clean vote.
|
||||
cleaner.command.despawntime=Despawn time for items set to %1$s game ticks.
|
||||
cleaner.output.count1=The system will automatically clean server entities in %1$s seconds!
|
||||
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 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...
|
||||
cleaner.vote.cancel=Vote canceled!
|
||||
cleaner.vote.confirmNo=Think again
|
||||
cleaner.vote.confirmOk=Initiate vote
|
||||
cleaner.vote.confirmTubtitle=Do you want to initiate a clean vote?
|
||||
cleaner.vote.accept=You have agreed to entity cleaning.
|
||||
cleaner.vote.deny=You have declined entity cleaning.
|
||||
cleaner.vote.no=Deny
|
||||
cleaner.vote.ok=Agree
|
||||
cleaner.vote.subtitle=%1$s lunched a clean vote.\n\n Do you agree to clean server entities now?
|
||||
cleaner.vote.timeout=Vote has expired!
|
||||
cleaner.vote.succeed=Vote cleaning successful!
|
||||
cleaner.vote.failed=Vote cleaning did not passed!
|
||||
cleaner.vote.title=Vote Cleaning
|
||||
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.
|
||||
)";
|
||||
|
||||
std::string defaultLanguage_zh_CN = R"({
|
||||
"cleaner.toast.title": "§e§lCleaner",
|
||||
"cleaner.command.cleaner": "Cleaner管理员命令。",
|
||||
"cleaner.command.despawnSuccess": "已成功清除了 %1$s 个实体",
|
||||
"cleaner.command.error.noTarget": "没有与选择器匹配的目标",
|
||||
"cleaner.command.error.playerOnly": "该命令只能由玩家执行!",
|
||||
"cleaner.command.tps.output": "当前服务器实时TPS %1$s §r,平均TPS %2$s",
|
||||
"cleaner.command.mspt.output": "当前服务器实MSPT %1$s",
|
||||
"cleaner.command.clean.output": "已成功启动清理任务!",
|
||||
"cleaner.command.voteclean": "发起实体清理投票。",
|
||||
"cleaner.command.despawntime" : "已成功将物品消失时间设置为 %1$s 游戏刻",
|
||||
"cleaner.output.count1": "系统将在 %1$s 秒后自动清理服务器实体!",
|
||||
"cleaner.output.count2": "请注意!系统将在 %1$s 秒后自动清理服务器实体!",
|
||||
"cleaner.output.finish": "清理完成!本次总共清理了 %1$s 个实体。",
|
||||
"cleaner.output.opClean": "管理员启用了服务器实体清理。",
|
||||
"cleaner.output.reload": "已重载Cleaner插件,部分配置可能需要重启服务器才能生效。",
|
||||
"cleaner.output.triggerAutoCleanCount": "检测到服务器实体过多!!当前服务器存在 %1$s 个可清理实体,已启动自动清理程序。",
|
||||
"cleaner.output.triggerAutoCleanTps": "当前服务器TPS过低!!服务器平均TPS %1$s\n系统已启动清理程序。",
|
||||
"cleaner.vote.cooldown": "投票清理正在冷却...",
|
||||
"cleaner.vote.cancel": "投票已取消!",
|
||||
"cleaner.vote.confirmNo": "我再想想",
|
||||
"cleaner.vote.confirmOk": "发起投票",
|
||||
"cleaner.vote.confirmTubtitle": "你是否要发起投票清理?",
|
||||
"cleaner.vote.accept": "你已同意实体清理。",
|
||||
"cleaner.vote.deny": "你已拒绝实体清理。",
|
||||
"cleaner.vote.no": "拒绝",
|
||||
"cleaner.vote.ok": "同意",
|
||||
"cleaner.vote.subtitle": "%1$s 发起了服务器实体清理投票!\n\n你是否同意现在清理服务器实体?",
|
||||
"cleaner.vote.timeout": "投票已过期!",
|
||||
"cleaner.vote.succeed": "投票清理成功!",
|
||||
"cleaner.vote.failed": "投票清理未通过。",
|
||||
"cleaner.vote.title": "投票清理",
|
||||
"cleaner.vote.voted": "你已经投过票了!",
|
||||
"cleaner.vote.voteMessage": "%1$s 发起了服务器实体清理投票!如果同意清理但是未收到表单,请输入命令 /voteclean 投票。拒绝清理请忽略此信息。"
|
||||
})";
|
||||
std::string zh_CN = R"(
|
||||
cleaner.info.prefix=§e§l[Cleaner] §r
|
||||
cleaner.command.cleaner=Cleaner管理员命令。
|
||||
cleaner.command.despawnSuccess=已成功清除了 %1$s 个实体
|
||||
cleaner.command.error.noTarget=没有与选择器匹配的目标
|
||||
cleaner.command.error.playerOnly=该命令只能由玩家执行!
|
||||
cleaner.command.tps.output=当前服务器实时TPS %1$s §r,平均TPS %2$s
|
||||
cleaner.command.mspt.output=当前服务器实MSPT %1$s
|
||||
cleaner.command.clean.output=已成功启动清理任务!
|
||||
cleaner.command.voteclean=发起实体清理投票。
|
||||
cleaner.command.despawntime=已成功将物品消失时间设置为 %1$s 游戏刻
|
||||
cleaner.output.count1=系统将在 %1$s 秒后自动清理服务器实体!
|
||||
cleaner.output.count2=请注意!系统将在 %1$s 秒后自动清理服务器实体!
|
||||
cleaner.output.finish=清理完成!本次总共清理了 %1$s 个实体。
|
||||
cleaner.output.opClean=管理员启用了服务器实体清理。
|
||||
cleaner.output.reload=已重载Cleaner插件,部分配置可能需要重启服务器才能生效。
|
||||
cleaner.output.triggerAutoCleanCount=检测到服务器实体过多!!当前服务器存在 %1$s 个可清理实体,已启动自动清理程序。
|
||||
cleaner.output.triggerAutoCleanTps=当前服务器TPS过低!!服务器平均TPS %1$s\n系统已启动清理程序。
|
||||
cleaner.vote.cooldown=投票清理正在冷却...
|
||||
cleaner.vote.cancel=投票已取消!
|
||||
cleaner.vote.confirmNo=我再想想
|
||||
cleaner.vote.confirmOk=发起投票
|
||||
cleaner.vote.confirmTubtitle=你是否要发起投票清理?
|
||||
cleaner.vote.accept=你已同意实体清理。
|
||||
cleaner.vote.deny=你已拒绝实体清理。
|
||||
cleaner.vote.no=拒绝
|
||||
cleaner.vote.ok=同意
|
||||
cleaner.vote.subtitle=%1$s 发起了服务器实体清理投票!\n\n你是否同意现在清理服务器实体?
|
||||
cleaner.vote.timeout=投票已过期!
|
||||
cleaner.vote.succeed=投票清理成功!
|
||||
cleaner.vote.failed=投票清理未通过。
|
||||
cleaner.vote.title=投票清理
|
||||
cleaner.vote.voted=你已经投过票了!
|
||||
cleaner.vote.voteMessage=%1$s 发起了服务器实体清理投票!如果同意清理但是未收到表单,请输入命令 /voteclean 投票。拒绝清理请忽略此信息。
|
||||
)";
|
||||
@@ -0,0 +1,7 @@
|
||||
// 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
|
||||
|
||||
#include <ll/api/memory/MemoryOperators.h>
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
#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; }
|
||||
|
||||
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);
|
||||
I18nAPI::updateOrCreateLanguageFile(getSelf().getLangDir(), "zh_CN", zh_CN);
|
||||
I18nAPI::loadLanguagesFromDirectory(getSelf().getLangDir());
|
||||
Cleaner::ListenEvents();
|
||||
RegisterCommands();
|
||||
Cleaner::loadCleaner();
|
||||
logger.info("Cleaner Loaded!");
|
||||
logger.info("Author: GroupMountain");
|
||||
logger.info("Repository: https://github.com/GroupMountain/Cleaner");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Entry::disable() {
|
||||
mConfig.reset();
|
||||
Cleaner::unloadCleaner();
|
||||
mScheduler.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
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_MOD(Cleaner::Entry, Cleaner::instance);
|
||||
|
||||
std::string tr(std::string const& key, std::vector<std::string> const& params) {
|
||||
return I18nAPI::get(key, params, Cleaner::Entry::getInstance().getConfig().language);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include "Config.h"
|
||||
#include <ll/api/mod/NativeMod.h>
|
||||
#include <ll/api/schedule/Scheduler.h>
|
||||
|
||||
namespace Cleaner {
|
||||
|
||||
using namespace ll::schedule;
|
||||
|
||||
class Entry {
|
||||
|
||||
public:
|
||||
static Entry& getInstance();
|
||||
|
||||
Entry(ll::mod::NativeMod& self) : mSelf(self) {}
|
||||
|
||||
[[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();
|
||||
|
||||
ServerTimeScheduler& getScheduler();
|
||||
|
||||
private:
|
||||
ll::mod::NativeMod& mSelf;
|
||||
std::optional<Config> mConfig;
|
||||
std::optional<ServerTimeScheduler> mScheduler;
|
||||
};
|
||||
|
||||
} // namespace Cleaner
|
||||
@@ -1,30 +0,0 @@
|
||||
#include "Features/Cleaner.h"
|
||||
#include "Global.h"
|
||||
|
||||
ll::Logger logger("Cleaner");
|
||||
|
||||
namespace plugin {
|
||||
|
||||
Plugin::Plugin(ll::plugin::NativePlugin& self) : mSelf(self) {
|
||||
// Code for loading the plugin goes here.
|
||||
initPlugin();
|
||||
}
|
||||
|
||||
bool Plugin::enable() {
|
||||
Cleaner::ListenEvents();
|
||||
RegisterCommands();
|
||||
Cleaner::loadCleaner();
|
||||
logger.info("Cleaner Loaded!");
|
||||
logger.info("Author: GroupMountain");
|
||||
logger.info("Repository: https://github.com/GroupMountain/Cleaner");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Plugin::disable() {
|
||||
// Code for disabling the plugin goes here.
|
||||
Cleaner::unloadCleaner();
|
||||
logger.info("Cleaner Disabled!");
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace plugin
|
||||
@@ -1,28 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <ll/api/plugin/NativePlugin.h>
|
||||
|
||||
namespace plugin {
|
||||
|
||||
class Plugin {
|
||||
public:
|
||||
explicit Plugin(ll::plugin::NativePlugin& self);
|
||||
|
||||
Plugin(Plugin&&) = delete;
|
||||
Plugin(const Plugin&) = delete;
|
||||
Plugin& operator=(Plugin&&) = delete;
|
||||
Plugin& operator=(const Plugin&) = delete;
|
||||
|
||||
~Plugin() = default;
|
||||
|
||||
/// @return True if the plugin is enabled successfully.
|
||||
bool enable();
|
||||
|
||||
/// @return True if the plugin is disabled successfully.
|
||||
bool disable();
|
||||
|
||||
private:
|
||||
ll::plugin::NativePlugin& mSelf;
|
||||
};
|
||||
|
||||
} // namespace plugin
|
||||
+20
-17
@@ -1,5 +1,5 @@
|
||||
#include "Features/Cleaner.h"
|
||||
#include "Global.h"
|
||||
#include "Mod.h"
|
||||
|
||||
struct CleanerParam {
|
||||
enum class Despawn { despawn } despawn;
|
||||
@@ -10,8 +10,9 @@ struct CleanerParam {
|
||||
};
|
||||
|
||||
void RegCleanerCommand() {
|
||||
auto& cmd = ll::command::CommandRegistrar::getInstance().getOrCreateCommand(
|
||||
Config->getValue<std::string>({"Basic", "Command"}, "cleaner"),
|
||||
auto& config = Cleaner::Entry::getInstance().getConfig();
|
||||
auto& cmd = ll::command::CommandRegistrar::getInstance().getOrCreateCommand(
|
||||
config.Basic.Command,
|
||||
tr("cleaner.command.cleaner"),
|
||||
CommandPermissionLevel::GameDirectors
|
||||
);
|
||||
@@ -34,26 +35,28 @@ void RegCleanerCommand() {
|
||||
switch (param.action) {
|
||||
case CleanerParam::Action::clean: {
|
||||
Cleaner::CleanTask();
|
||||
if (ConfigFile::mConsoleLog) {
|
||||
if (Cleaner::Entry::getInstance().getConfig().Basic.ConsoleLog) {
|
||||
logger.info(tr("cleaner.output.opClean"));
|
||||
}
|
||||
if (ConfigFile::mAnnounce) {
|
||||
if (Cleaner::Entry::getInstance().getConfig().Basic.SendBroadcast) {
|
||||
Helper::broadcastMessage(tr("cleaner.output.opClean"));
|
||||
}
|
||||
if (ConfigFile::mSendToast) {
|
||||
if (Cleaner::Entry::getInstance().getConfig().Basic.SendToast) {
|
||||
Helper::broadcastToast(tr("cleaner.output.opClean"));
|
||||
}
|
||||
return output.success(tr("cleaner.command.clean.output"));
|
||||
}
|
||||
case CleanerParam::Action::tps: {
|
||||
return output.success(
|
||||
tr("cleaner.command.tps.output",
|
||||
{S(GMLIB_Level::getLevel()->getServerCurrentTps()),
|
||||
S(GMLIB_Level::getLevel()->getServerAverageTps())})
|
||||
);
|
||||
return output.success(tr(
|
||||
"cleaner.command.tps.output",
|
||||
{S(GMLIB_Level::getLevel()->getServerCurrentTps()),
|
||||
S(GMLIB_Level::getLevel()->getServerAverageTps())}
|
||||
));
|
||||
}
|
||||
case CleanerParam::Action::mspt: {
|
||||
return output.success(tr("cleaner.command.mspt.output", {S(GMLIB_Level::getLevel()->getServerMspt())}));
|
||||
return output.success(
|
||||
tr("cleaner.command.mspt.output", {S(GMLIB_Level::getLevel()->getServerMspt())})
|
||||
);
|
||||
}
|
||||
case CleanerParam::Action::reload: {
|
||||
Cleaner::reloadCleaner();
|
||||
@@ -65,15 +68,15 @@ void RegCleanerCommand() {
|
||||
.required("despawntime")
|
||||
.required("ticks")
|
||||
.execute<[&](CommandOrigin const& origin, CommandOutput& output, CleanerParam const& param) {
|
||||
ConfigFile::mItemDespawnTicks = param.ticks;
|
||||
Config->setValue({"ItemDespawn", "DespawnTime"}, ConfigFile::mItemDespawnTicks);
|
||||
return output.success(tr("cleaner.command.despawntime", {S(ConfigFile::mItemDespawnTicks)}));
|
||||
Cleaner::Entry::getInstance().getConfig().ItemDespawn.DespawnTime = param.ticks;
|
||||
Cleaner::Entry::getInstance().saveConfig();
|
||||
return output.success(tr("cleaner.command.despawntime", {S(param.ticks)}));
|
||||
}>();
|
||||
};
|
||||
|
||||
void RegVoteCommand() {
|
||||
auto& cmd = ll::command::CommandRegistrar::getInstance().getOrCreateCommand(
|
||||
Config->getValue<std::string>({"VoteClean", "VoteCleanCommand"}, "voteclean"),
|
||||
Cleaner::Entry::getInstance().getConfig().VoteClean.VoteCleanCommand,
|
||||
tr("cleaner.command.voteclean"),
|
||||
CommandPermissionLevel::Any
|
||||
);
|
||||
@@ -88,7 +91,7 @@ void RegVoteCommand() {
|
||||
|
||||
void RegisterCommands() {
|
||||
RegCleanerCommand();
|
||||
if (Config->getValue<bool>({"VoteClean", "Enabled"}, false)) {
|
||||
if (Cleaner::Entry::getInstance().getConfig().VoteClean.Enabled) {
|
||||
RegVoteCommand();
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
#include <memory>
|
||||
|
||||
#include <ll/api/plugin/NativePlugin.h>
|
||||
|
||||
#include "Plugin.h"
|
||||
|
||||
namespace plugin {
|
||||
|
||||
// The global plugin instance.
|
||||
std::unique_ptr<Plugin> plugin = nullptr;
|
||||
|
||||
extern "C" {
|
||||
_declspec(dllexport) bool ll_plugin_load(ll::plugin::NativePlugin& self) {
|
||||
plugin = std::make_unique<plugin::Plugin>(self);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// @warning Unloading the plugin may cause a crash if the plugin has not released all of its
|
||||
/// resources. If you are unsure, keep this function commented out.
|
||||
// _declspec(dllexport) bool ll_plugin_unload(ll::plugin::Plugin&) {
|
||||
// plugin.reset();
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
|
||||
_declspec(dllexport) bool ll_plugin_enable(ll::plugin::NativePlugin&) { return plugin->enable(); }
|
||||
|
||||
_declspec(dllexport) bool ll_plugin_disable(ll::plugin::NativePlugin&) { return plugin->disable(); }
|
||||
}
|
||||
|
||||
} // namespace plugin
|
||||
+5
-5
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"format_version": 2,
|
||||
"tooth": "github.com/GroupMountain/Cleaner",
|
||||
"version": "0.9.0",
|
||||
"version": "0.13.2",
|
||||
"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,15 +13,15 @@
|
||||
"gmlib"
|
||||
]
|
||||
},
|
||||
"asset_url": "https://github.com/GroupMountain/Cleaner/releases/download/v0.9.0/Cleaner-windows-x64.zip",
|
||||
"asset_url": "https://github.com/GroupMountain/Cleaner/releases/download/v0.13.2/Cleaner-windows-x64.zip",
|
||||
"dependencies": {
|
||||
"github.com/GroupMountain/GMLIB": ">=0.9.4"
|
||||
"github.com/GroupMountain/GMLIB": ">=0.13.7"
|
||||
},
|
||||
"files": {
|
||||
"place": [
|
||||
{
|
||||
"src": "Cleaner/*",
|
||||
"dest": "plugins/Cleaner"
|
||||
"dest": "mods/Cleaner"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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,9 @@ end
|
||||
|
||||
-- Option 1: Use the latest version of LeviLamina released on GitHub.
|
||||
add_requires("levilamina")
|
||||
add_requires("gmlib 0.13.7")
|
||||
|
||||
target("Cleaner") -- Change this to your plugin name.
|
||||
target("Cleaner") -- Change this to your mod name.
|
||||
add_cxflags(
|
||||
"/EHa",
|
||||
"/utf-8"
|
||||
@@ -17,15 +19,12 @@ 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"
|
||||
@@ -35,12 +34,12 @@ target("Cleaner") -- Change this to your plugin name.
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user