From d710acceb00a061353e4242d091cbe4d62cc38bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=90=E6=B2=90=E5=91=80?= <163636894+zimuya4153@users.noreply.github.com> Date: Thu, 31 Oct 2024 12:59:20 +0800 Subject: [PATCH] adapt: adapt to GMLIB v0.13.8 --- manifest.json | 6 +++--- scripts/after_build.lua | 14 +++++++------- src/Features/Clean.cpp | 10 +++++----- src/Features/CleanTask.cpp | 4 ++-- src/Features/Events.cpp | 16 ++++++++-------- src/Features/Helper.cpp | 4 ++-- src/Global.h | 4 ++-- src/Language.h | 2 +- src/MemoryOperators.cpp | 4 ++-- src/{Plugin.cpp => Mod.cpp} | 8 ++++---- src/{Plugin.h => Mod.h} | 10 +++++----- src/RegisterCommand.cpp | 9 +++++---- tooth.json | 10 +++++----- xmake.lua | 12 ++++++------ 14 files changed, 57 insertions(+), 56 deletions(-) rename src/{Plugin.cpp => Mod.cpp} (76%) rename src/{Plugin.h => Mod.h} (69%) diff --git a/manifest.json b/manifest.json index bcde5fc..430e933 100644 --- a/manifest.json +++ b/manifest.json @@ -1,8 +1,8 @@ { - "name": "${pluginName}", - "entry": "${pluginFile}", + "name": "${modName}", + "entry": "${modFile}", "type": "native", - "version": "0.13.0", + "version": "0.13.1", "author": "GroupMountain", "description": "Clean Entities", "dependencies": [ diff --git a/scripts/after_build.lua b/scripts/after_build.lua index 9475b5a..2a9731c 100644 --- a/scripts/after_build.lua +++ b/scripts/after_build.lua @@ -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 } diff --git a/src/Features/Clean.cpp b/src/Features/Clean.cpp index 8b27f15..94e85c8 100644 --- a/src/Features/Clean.cpp +++ b/src/Features/Clean.cpp @@ -15,7 +15,7 @@ bool isMatch(std::string& A, std::string& B) { return (A == B); } -bool shouldIgnore(GMLIB_Actor* ac) { +bool shouldIgnore(gmlib::world::Actor* ac) { if (ac->isMob() || ac->isItemActor()) { if (ac->isTame() || ac->isTrusting() || ac->getNameTag() != "" || ac->hasTag("cleaner:ignore")) { return true; @@ -27,7 +27,7 @@ bool shouldIgnore(GMLIB_Actor* ac) { bool ShouldClean(Actor* actor) { // Players auto& config = Cleaner::Entry::getInstance().getConfig(); - auto en = (GMLIB_Actor*)actor; + auto en = (gmlib::world::Actor*)actor; if (en->isPlayer() || shouldIgnore(en)) { return false; } @@ -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::world::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::world::Level::getLevel()->getRuntimeActorList(); + for (auto* entity : all_entities) { if (ShouldClean(entity)) { clean_count++; } diff --git a/src/Features/CleanTask.cpp b/src/Features/CleanTask.cpp index 1935a43..8fcded7 100644 --- a/src/Features/CleanTask.cpp +++ b/src/Features/CleanTask.cpp @@ -80,9 +80,9 @@ void CleanTaskTPS(float min_tps) { auto& config = Cleaner::Entry::getInstance().getConfig(); mCleanTaskTPS = Cleaner::Entry::getInstance().getScheduler().add(10s, [min_tps, &config] { 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 mspt = S(GMLIB_Level::getLevel()->getServerAverageTps()); + auto mspt = S(gmlib::world::Level::getLevel()->getServerAverageTps()); if (config.Basic.ConsoleLog) { logger.warn(tr("cleaner.output.triggerAutoCleanTps", {mspt})); } diff --git a/src/Features/Events.cpp b/src/Features/Events.cpp index 74db49f..c499823 100644 --- a/src/Features/Events.cpp +++ b/src/Features/Events.cpp @@ -2,19 +2,19 @@ namespace Cleaner { -void setShouldIgnore(GMLIB_Actor* ac) { ac->addTag("cleaner:ignore"); } +void setShouldIgnore(gmlib::world::Actor* ac) { ac->addTag("cleaner:ignore"); } void ListenEvents() { auto& eventBus = ll::event::EventBus::getInstance(); auto& config = Cleaner::Entry::getInstance().getConfig(); // ItemSpawnEvent - eventBus.emplaceListener( - [&config](GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent& event) { + eventBus.emplaceListener( + [&config](gmlib::event::entity::ItemActorSpawnAfterEvent& event) { auto& item = event.getItemActor(); 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 - auto ac = (GMLIB_Actor*)&item; + auto ac = (gmlib::world::Actor*)&item; setShouldIgnore(ac); return; } @@ -33,9 +33,9 @@ void ListenEvents() { } ); // MobTakeItemEvent - eventBus.emplaceListener( - [](GMLIB::Event::EntityEvent::MobPickupItemAfterEvent& event) { - auto mob = (GMLIB_Actor*)&event.self(); + eventBus.emplaceListener( + [](gmlib::event::entity::MobPickupItemAfterEvent& event) { + auto mob = (gmlib::world::Actor*)&event.self(); setShouldIgnore(mob); } ); diff --git a/src/Features/Helper.cpp b/src/Features/Helper.cpp index 8805e3a..802f20b 100644 --- a/src/Features/Helper.cpp +++ b/src/Features/Helper.cpp @@ -3,11 +3,11 @@ namespace Helper { 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) { - GMLIB_Level::getInstance()->broadcastToast(tr("cleaner.info.prefix"), msg); + gmlib::world::Level::getInstance()->broadcastToast(tr("cleaner.info.prefix"), msg); } } // namespace Helper \ No newline at end of file diff --git a/src/Global.h b/src/Global.h index 3982287..946a5ef 100644 --- a/src/Global.h +++ b/src/Global.h @@ -1,6 +1,6 @@ #pragma once -#include "Plugin.h" -#include +#include "Mod.h" +#include #include #define S(x) std::to_string(x) diff --git a/src/Language.h b/src/Language.h index cd42671..d419f27 100644 --- a/src/Language.h +++ b/src/Language.h @@ -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... diff --git a/src/MemoryOperators.cpp b/src/MemoryOperators.cpp index f7c918a..970989b 100644 --- a/src/MemoryOperators.cpp +++ b/src/MemoryOperators.cpp @@ -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 diff --git a/src/Plugin.cpp b/src/Mod.cpp similarity index 76% rename from src/Plugin.cpp rename to src/Mod.cpp index f6bf58d..5a067e7 100644 --- a/src/Plugin.cpp +++ b/src/Mod.cpp @@ -17,9 +17,9 @@ bool Entry::enable() { 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()); + gmlib::world::I18nAPI::updateOrCreateLanguageFile(getSelf().getLangDir(), "en_US", en_US); + gmlib::world::I18nAPI::updateOrCreateLanguageFile(getSelf().getLangDir(), "zh_CN", zh_CN); + gmlib::world::I18nAPI::loadLanguagesFromDirectory(getSelf().getLangDir()); Cleaner::ListenEvents(); RegisterCommands(); Cleaner::loadCleaner(); @@ -47,5 +47,5 @@ ServerTimeScheduler& Entry::getScheduler() { return mScheduler.value(); } LL_REGISTER_MOD(Cleaner::Entry, Cleaner::instance); std::string tr(std::string const& key, std::vector const& params) { - return I18nAPI::get(key, params, Cleaner::Entry::getInstance().getConfig().language); + return gmlib::world::I18nAPI::get(key, params, Cleaner::Entry::getInstance().getConfig().language); } diff --git a/src/Plugin.h b/src/Mod.h similarity index 69% rename from src/Plugin.h rename to src/Mod.h index 1cd5405..0b16579 100644 --- a/src/Plugin.h +++ b/src/Mod.h @@ -17,17 +17,17 @@ public: [[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(); - /// @return True if the plugin is enabled successfully. + /// @return True if the mod is enabled successfully. bool enable(); - /// @return True if the plugin is disabled successfully. + /// @return True if the mod is disabled successfully. bool disable(); - // TODO: Implement this method if you need to unload the plugin. - // /// @return True if the plugin is unloaded successfully. + // TODO: Implement this method if you need to unload the mod. + // /// @return True if the mod is unloaded successfully. // bool unload(); Config& getConfig(); diff --git a/src/RegisterCommand.cpp b/src/RegisterCommand.cpp index a7a1468..3966072 100644 --- a/src/RegisterCommand.cpp +++ b/src/RegisterCommand.cpp @@ -1,5 +1,6 @@ #include "Features/Cleaner.h" -#include "Plugin.h" +#include "Mod.h" +#include "gmlib/world/Level.h" struct CleanerParam { enum class Despawn { despawn } despawn; @@ -49,13 +50,13 @@ void RegCleanerCommand() { case CleanerParam::Action::tps: { return output.success(tr( "cleaner.command.tps.output", - {S(GMLIB_Level::getLevel()->getServerCurrentTps()), - S(GMLIB_Level::getLevel()->getServerAverageTps())} + {S(gmlib::world::Level::getLevel()->getServerCurrentTps()), + S(gmlib::world::Level::getLevel()->getServerAverageTps())} )); } case CleanerParam::Action::mspt: { 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: { diff --git a/tooth.json b/tooth.json index fa080f7..97b7fa5 100644 --- a/tooth.json +++ b/tooth.json @@ -1,10 +1,10 @@ { "format_version": 2, "tooth": "github.com/GroupMountain/Cleaner", - "version": "0.13.0", + "version": "0.13.1", "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.13.0/Cleaner-windows-x64.zip", + "asset_url": "https://github.com/GroupMountain/Cleaner/releases/download/v0.13.1/Cleaner-windows-x64.zip", "dependencies": { - "github.com/GroupMountain/GMLIB": ">=0.13.0" + "github.com/GroupMountain/GMLIB": ">=0.13.1" }, "files": { "place": [ { "src": "Cleaner/*", - "dest": "plugins/Cleaner" + "dest": "mods/Cleaner" } ] } diff --git a/xmake.lua b/xmake.lua index bb4e1fc..66b74c7 100644 --- a/xmake.lua +++ b/xmake.lua @@ -11,7 +11,7 @@ end add_requires("levilamina") add_requires("gmlib") -target("Cleaner") -- Change this to your plugin name. +target("Cleaner") -- Change this to your mod name. add_cxflags( "/EHa", "/utf-8" @@ -34,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)