Merge pull request #18 from zimuya4153/main
adapt: adapt to GMLIB v0.13.8
This commit is contained in:
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "${pluginName}",
|
"name": "${modName}",
|
||||||
"entry": "${pluginFile}",
|
"entry": "${modFile}",
|
||||||
"type": "native",
|
"type": "native",
|
||||||
"version": "0.13.0",
|
"version": "0.13.1",
|
||||||
"author": "GroupMountain",
|
"author": "GroupMountain",
|
||||||
"description": "Clean Entities",
|
"description": "Clean Entities",
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
|
|||||||
@@ -82,16 +82,16 @@ function string_formatter(str, variables)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function pack_plugin(target,plugin_define)
|
function pack_mod(target,mod_define)
|
||||||
import("lib.detect.find_file")
|
import("lib.detect.find_file")
|
||||||
|
|
||||||
local manifest_path = find_file("manifest.json", os.projectdir())
|
local manifest_path = find_file("manifest.json", os.projectdir())
|
||||||
if manifest_path then
|
if manifest_path then
|
||||||
local manifest = io.readfile(manifest_path)
|
local manifest = io.readfile(manifest_path)
|
||||||
local bindir = path.join(os.projectdir(), "bin")
|
local bindir = path.join(os.projectdir(), "bin")
|
||||||
local outputdir = path.join(bindir, plugin_define.pluginName)
|
local outputdir = path.join(bindir, mod_define.modName)
|
||||||
local targetfile = path.join(outputdir, plugin_define.pluginFile)
|
local targetfile = path.join(outputdir, mod_define.modFile)
|
||||||
local pdbfile = path.join(outputdir, path.basename(plugin_define.pluginFile) .. ".pdb")
|
local pdbfile = path.join(outputdir, path.basename(mod_define.modFile) .. ".pdb")
|
||||||
local manifestfile = path.join(outputdir, "manifest.json")
|
local manifestfile = path.join(outputdir, "manifest.json")
|
||||||
local oritargetfile = target:targetfile()
|
local oritargetfile = target:targetfile()
|
||||||
local oripdbfile = path.join(path.directory(oritargetfile), path.basename(oritargetfile) .. ".pdb")
|
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)
|
os.cp(oripdbfile, pdbfile)
|
||||||
end
|
end
|
||||||
|
|
||||||
formattedmanifest = string_formatter(manifest, plugin_define)
|
formattedmanifest = string_formatter(manifest, mod_define)
|
||||||
io.writefile(manifestfile,formattedmanifest)
|
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
|
else
|
||||||
cprint("${bright yellow}warn: ${reset}not found manifest.json in root dir!")
|
cprint("${bright yellow}warn: ${reset}not found manifest.json in root dir!")
|
||||||
end
|
end
|
||||||
@@ -112,7 +112,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pack_plugin = pack_plugin,
|
pack_mod = pack_mod,
|
||||||
beautify_json = beautify_json,
|
beautify_json = beautify_json,
|
||||||
string_formatter = string_formatter
|
string_formatter = string_formatter
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ bool isMatch(std::string& A, std::string& B) {
|
|||||||
return (A == B);
|
return (A == B);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool shouldIgnore(GMLIB_Actor* ac) {
|
bool shouldIgnore(gmlib::world::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_Actor* ac) {
|
|||||||
bool ShouldClean(Actor* actor) {
|
bool ShouldClean(Actor* actor) {
|
||||||
// Players
|
// Players
|
||||||
auto& config = Cleaner::Entry::getInstance().getConfig();
|
auto& config = Cleaner::Entry::getInstance().getConfig();
|
||||||
auto en = (GMLIB_Actor*)actor;
|
auto en = (gmlib::world::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_Level::getLevel()->getAllEntities();
|
auto all_entities = gmlib::world::Level::getLevel()->getRuntimeActorList();
|
||||||
for (auto entity : all_entities) {
|
for (auto entity : all_entities) {
|
||||||
if (ShouldClean(entity)) {
|
if (ShouldClean(entity)) {
|
||||||
entity->despawn();
|
entity->despawn();
|
||||||
@@ -107,8 +107,8 @@ int ExecuteClean() {
|
|||||||
|
|
||||||
int CountEntities() {
|
int CountEntities() {
|
||||||
int clean_count = 0;
|
int clean_count = 0;
|
||||||
auto all_entities = GMLIB_Level::getLevel()->getAllEntities();
|
auto all_entities = gmlib::world::Level::getLevel()->getRuntimeActorList();
|
||||||
for (auto entity : all_entities) {
|
for (auto* entity : all_entities) {
|
||||||
if (ShouldClean(entity)) {
|
if (ShouldClean(entity)) {
|
||||||
clean_count++;
|
clean_count++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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_Level::getLevel()->getServerAverageTps() <= min_tps) {
|
if (gmlib::world::Level::getLevel()->getServerAverageTps() <= min_tps) {
|
||||||
auto_clean_triggerred = true;
|
auto_clean_triggerred = true;
|
||||||
auto mspt = S(GMLIB_Level::getLevel()->getServerAverageTps());
|
auto mspt = S(gmlib::world::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}));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,19 +2,19 @@
|
|||||||
|
|
||||||
namespace Cleaner {
|
namespace Cleaner {
|
||||||
|
|
||||||
void setShouldIgnore(GMLIB_Actor* ac) { ac->addTag("cleaner:ignore"); }
|
void setShouldIgnore(gmlib::world::Actor* ac) { ac->addTag("cleaner:ignore"); }
|
||||||
|
|
||||||
void ListenEvents() {
|
void ListenEvents() {
|
||||||
auto& eventBus = ll::event::EventBus::getInstance();
|
auto& eventBus = ll::event::EventBus::getInstance();
|
||||||
auto& config = Cleaner::Entry::getInstance().getConfig();
|
auto& config = Cleaner::Entry::getInstance().getConfig();
|
||||||
// ItemSpawnEvent
|
// ItemSpawnEvent
|
||||||
eventBus.emplaceListener<GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent>(
|
eventBus.emplaceListener<gmlib::event::entity::ItemActorSpawnAfterEvent>(
|
||||||
[&config](GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent& event) {
|
[&config](gmlib::event::entity::ItemActorSpawnAfterEvent& event) {
|
||||||
auto& item = event.getItemActor();
|
auto& item = event.getItemActor();
|
||||||
if (event.getSpawner().has_value()) {
|
if (event.getSpawner().has_value()) {
|
||||||
auto pl = (GMLIB_Player*)event.getSpawner().as_ptr();
|
auto pl = (gmlib::world::Player*)event.getSpawner().as_ptr();
|
||||||
if (pl->isPlayer() && !pl->isAlive()) { // Death Drop
|
if (pl->isPlayer() && !pl->isAlive()) { // Death Drop
|
||||||
auto ac = (GMLIB_Actor*)&item;
|
auto ac = (gmlib::world::Actor*)&item;
|
||||||
setShouldIgnore(ac);
|
setShouldIgnore(ac);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -33,9 +33,9 @@ void ListenEvents() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
// MobTakeItemEvent
|
// MobTakeItemEvent
|
||||||
eventBus.emplaceListener<GMLIB::Event::EntityEvent::MobPickupItemAfterEvent>(
|
eventBus.emplaceListener<gmlib::event::entity::MobPickupItemAfterEvent>(
|
||||||
[](GMLIB::Event::EntityEvent::MobPickupItemAfterEvent& event) {
|
[](gmlib::event::entity::MobPickupItemAfterEvent& event) {
|
||||||
auto mob = (GMLIB_Actor*)&event.self();
|
auto mob = (gmlib::world::Actor*)&event.self();
|
||||||
setShouldIgnore(mob);
|
setShouldIgnore(mob);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,11 +3,11 @@
|
|||||||
namespace Helper {
|
namespace Helper {
|
||||||
|
|
||||||
void broadcastMessage(std::string_view msg) {
|
void broadcastMessage(std::string_view msg) {
|
||||||
GMLIB_Level::getInstance()->broadcast(tr("cleaner.info.prefix") + std::string(msg));
|
gmlib::world::Level::getInstance()->broadcast(tr("cleaner.info.prefix") + std::string(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
void broadcastToast(std::string_view msg) {
|
void broadcastToast(std::string_view msg) {
|
||||||
GMLIB_Level::getInstance()->broadcastToast(tr("cleaner.info.prefix"), msg);
|
gmlib::world::Level::getInstance()->broadcastToast(tr("cleaner.info.prefix"), msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Helper
|
} // namespace Helper
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Plugin.h"
|
#include "Mod.h"
|
||||||
#include <include_all.h>
|
#include <headers/include_all.h>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
#define S(x) std::to_string(x)
|
#define S(x) std::to_string(x)
|
||||||
|
|||||||
+1
-1
@@ -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.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.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.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.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.output.triggerAutoCleanTps=Low TPS detected! Server average TPS %1$s\nClean program has been initiated.
|
||||||
cleaner.vote.cooldown=Vote cleaning cooldown...
|
cleaner.vote.cooldown=Vote cleaning cooldown...
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// This file will make your plugin use LeviLamina's memory operators by default.
|
// This file will make your mod use LeviLamina's memory operators by default.
|
||||||
// This improves the memory management of your plugin and is recommended to use.
|
// This improves the memory management of your mod and is recommended to use.
|
||||||
// You should not modify anything in this file.
|
// You should not modify anything in this file.
|
||||||
|
|
||||||
#define LL_MEMORY_OPERATORS
|
#define LL_MEMORY_OPERATORS
|
||||||
|
|||||||
@@ -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();
|
||||||
I18nAPI::updateOrCreateLanguageFile(getSelf().getLangDir(), "en_US", en_US);
|
gmlib::world::I18nAPI::updateOrCreateLanguageFile(getSelf().getLangDir(), "en_US", en_US);
|
||||||
I18nAPI::updateOrCreateLanguageFile(getSelf().getLangDir(), "zh_CN", zh_CN);
|
gmlib::world::I18nAPI::updateOrCreateLanguageFile(getSelf().getLangDir(), "zh_CN", zh_CN);
|
||||||
I18nAPI::loadLanguagesFromDirectory(getSelf().getLangDir());
|
gmlib::world::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 I18nAPI::get(key, params, Cleaner::Entry::getInstance().getConfig().language);
|
return gmlib::world::I18nAPI::get(key, params, Cleaner::Entry::getInstance().getConfig().language);
|
||||||
}
|
}
|
||||||
@@ -17,17 +17,17 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] ll::mod::NativeMod& getSelf() const { return mSelf; }
|
[[nodiscard]] ll::mod::NativeMod& getSelf() const { return mSelf; }
|
||||||
|
|
||||||
/// @return True if the plugin is loaded successfully.
|
/// @return True if the mod is loaded successfully.
|
||||||
bool load();
|
bool load();
|
||||||
|
|
||||||
/// @return True if the plugin is enabled successfully.
|
/// @return True if the mod is enabled successfully.
|
||||||
bool enable();
|
bool enable();
|
||||||
|
|
||||||
/// @return True if the plugin is disabled successfully.
|
/// @return True if the mod is disabled successfully.
|
||||||
bool disable();
|
bool disable();
|
||||||
|
|
||||||
// TODO: Implement this method if you need to unload the plugin.
|
// TODO: Implement this method if you need to unload the mod.
|
||||||
// /// @return True if the plugin is unloaded successfully.
|
// /// @return True if the mod is unloaded successfully.
|
||||||
// bool unload();
|
// bool unload();
|
||||||
|
|
||||||
Config& getConfig();
|
Config& getConfig();
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "Features/Cleaner.h"
|
#include "Features/Cleaner.h"
|
||||||
#include "Plugin.h"
|
#include "Mod.h"
|
||||||
|
#include "gmlib/world/Level.h"
|
||||||
|
|
||||||
struct CleanerParam {
|
struct CleanerParam {
|
||||||
enum class Despawn { despawn } despawn;
|
enum class Despawn { despawn } despawn;
|
||||||
@@ -49,13 +50,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_Level::getLevel()->getServerCurrentTps()),
|
{S(gmlib::world::Level::getLevel()->getServerCurrentTps()),
|
||||||
S(GMLIB_Level::getLevel()->getServerAverageTps())}
|
S(gmlib::world::Level::getLevel()->getServerAverageTps())}
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
case CleanerParam::Action::mspt: {
|
case CleanerParam::Action::mspt: {
|
||||||
return output.success(
|
return output.success(
|
||||||
tr("cleaner.command.mspt.output", {S(GMLIB_Level::getLevel()->getServerMspt())})
|
tr("cleaner.command.mspt.output", {S(gmlib::world::Level::getLevel()->getServerMspt())})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
case CleanerParam::Action::reload: {
|
case CleanerParam::Action::reload: {
|
||||||
|
|||||||
+5
-5
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"format_version": 2,
|
"format_version": 2,
|
||||||
"tooth": "github.com/GroupMountain/Cleaner",
|
"tooth": "github.com/GroupMountain/Cleaner",
|
||||||
"version": "0.13.0",
|
"version": "0.13.1",
|
||||||
"info": {
|
"info": {
|
||||||
"name": "Cleaner",
|
"name": "Cleaner",
|
||||||
"description": "A Powerful Entities Cleaning up Plugin for BDS",
|
"description": "A Powerful Entities Cleaning up Mod for BDS",
|
||||||
"author": "GroupMountain",
|
"author": "GroupMountain",
|
||||||
"source": "github.com/GroupMountain/Cleaner",
|
"source": "github.com/GroupMountain/Cleaner",
|
||||||
"tags": [
|
"tags": [
|
||||||
@@ -13,15 +13,15 @@
|
|||||||
"gmlib"
|
"gmlib"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"asset_url": "https://github.com/GroupMountain/Cleaner/releases/download/v0.13.0/Cleaner-windows-x64.zip",
|
"asset_url": "https://github.com/GroupMountain/Cleaner/releases/download/v0.13.1/Cleaner-windows-x64.zip",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"github.com/GroupMountain/GMLIB": ">=0.13.0"
|
"github.com/GroupMountain/GMLIB": ">=0.13.1"
|
||||||
},
|
},
|
||||||
"files": {
|
"files": {
|
||||||
"place": [
|
"place": [
|
||||||
{
|
{
|
||||||
"src": "Cleaner/*",
|
"src": "Cleaner/*",
|
||||||
"dest": "plugins/Cleaner"
|
"dest": "mods/Cleaner"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ end
|
|||||||
add_requires("levilamina")
|
add_requires("levilamina")
|
||||||
add_requires("gmlib")
|
add_requires("gmlib")
|
||||||
|
|
||||||
target("Cleaner") -- Change this to your plugin name.
|
target("Cleaner") -- Change this to your mod name.
|
||||||
add_cxflags(
|
add_cxflags(
|
||||||
"/EHa",
|
"/EHa",
|
||||||
"/utf-8"
|
"/utf-8"
|
||||||
@@ -34,12 +34,12 @@ target("Cleaner") -- Change this to your plugin name.
|
|||||||
set_languages("cxx23")
|
set_languages("cxx23")
|
||||||
|
|
||||||
after_build(function (target)
|
after_build(function (target)
|
||||||
local plugin_packer = import("scripts.after_build")
|
local mod_packer = import("scripts.after_build")
|
||||||
|
|
||||||
local plugin_define = {
|
local mod_define = {
|
||||||
pluginName = target:name(),
|
modName = target:name(),
|
||||||
pluginFile = path.filename(target:targetfile()),
|
modFile = path.filename(target:targetfile()),
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin_packer.pack_plugin(target,plugin_define)
|
mod_packer.pack_mod(target,mod_define)
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user