adapt: adapt to GMLIB v0.13.8

This commit is contained in:
子沐呀
2024-10-31 12:59:20 +08:00
Unverified
parent eecf9a6469
commit d710acceb0
14 changed files with 57 additions and 56 deletions
+3 -3
View File
@@ -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": [
+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
}
+5 -5
View File
@@ -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++;
}
+2 -2
View File
@@ -80,9 +80,9 @@ 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) {
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}));
}
+8 -8
View File
@@ -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<GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent>(
[&config](GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent& event) {
eventBus.emplaceListener<gmlib::event::entity::ItemActorSpawnAfterEvent>(
[&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>(
[](GMLIB::Event::EntityEvent::MobPickupItemAfterEvent& event) {
auto mob = (GMLIB_Actor*)&event.self();
eventBus.emplaceListener<gmlib::event::entity::MobPickupItemAfterEvent>(
[](gmlib::event::entity::MobPickupItemAfterEvent& event) {
auto mob = (gmlib::world::Actor*)&event.self();
setShouldIgnore(mob);
}
);
+2 -2
View File
@@ -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
+2 -2
View File
@@ -1,6 +1,6 @@
#pragma once
#include "Plugin.h"
#include <include_all.h>
#include "Mod.h"
#include <headers/include_all.h>
#include <regex>
#define S(x) std::to_string(x)
+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
+4 -4
View File
@@ -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<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);
}
+5 -5
View File
@@ -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();
+5 -4
View File
@@ -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: {
+5 -5
View File
@@ -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"
}
]
}
+6 -6
View File
@@ -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)