feat: add some features

This commit is contained in:
Tsubasa6848
2024-01-05 10:41:22 +08:00
Unverified
parent 5df234806a
commit 4bed07ca14
10 changed files with 866 additions and 46 deletions
+93 -1
View File
@@ -2,6 +2,98 @@
"files.associations": { "files.associations": {
"xtr1common": "cpp", "xtr1common": "cpp",
"vector": "cpp", "vector": "cpp",
"unordered_map": "cpp" "unordered_map": "cpp",
"iostream": "cpp",
"pointers": "cpp",
"algorithm": "cpp",
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"exception": "cpp",
"expected": "cpp",
"filesystem": "cpp",
"format": "cpp",
"forward_list": "cpp",
"fstream": "cpp",
"functional": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"list": "cpp",
"locale": "cpp",
"map": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"numeric": "cpp",
"optional": "cpp",
"ostream": "cpp",
"queue": "cpp",
"random": "cpp",
"ranges": "cpp",
"ratio": "cpp",
"regex": "cpp",
"set": "cpp",
"shared_mutex": "cpp",
"source_location": "cpp",
"span": "cpp",
"sstream": "cpp",
"stack": "cpp",
"stacktrace": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"string": "cpp",
"system_error": "cpp",
"thread": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"unordered_set": "cpp",
"utility": "cpp",
"valarray": "cpp",
"variant": "cpp",
"xfacet": "cpp",
"xhash": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xstring": "cpp",
"xtree": "cpp",
"xutility": "cpp"
} }
} }
+5 -5
View File
@@ -16,7 +16,7 @@ target_include_directories(Cleaner PRIVATE
src src
) )
target_include_directories(Cleaner PRIVATE target_include_directories(Cleaner PRIVATE
C:/Users/yang/AppData/Local/.xmake/packages/l/levilamina/0.2.2/54d4541cae36448ab8d89ba7ff29fe49/include C:/Users/yang/AppData/Local/.xmake/packages/l/levilamina/0.3.0/59a288d9257e463883bf6b863a7de723/include
C:/Users/yang/AppData/Local/.xmake/packages/c/ctre/3.8.1/6aca3e546d064397b0970026de72d808/include C:/Users/yang/AppData/Local/.xmake/packages/c/ctre/3.8.1/6aca3e546d064397b0970026de72d808/include
C:/Users/yang/AppData/Local/.xmake/packages/e/entt/v3.12.2/5748c075ebf044f9b53ef5be15be7e68/include C:/Users/yang/AppData/Local/.xmake/packages/e/entt/v3.12.2/5748c075ebf044f9b53ef5be15be7e68/include
C:/Users/yang/AppData/Local/.xmake/packages/f/fmt/10.1.1/adc308aa1dfc472ab92a30abb14e2d6f/include C:/Users/yang/AppData/Local/.xmake/packages/f/fmt/10.1.1/adc308aa1dfc472ab92a30abb14e2d6f/include
@@ -53,22 +53,22 @@ if(MSVC)
endif() endif()
target_link_libraries(Cleaner PRIVATE target_link_libraries(Cleaner PRIVATE
LeviLamina LeviLamina
bedrock_server_api
bedrock_server_var
fmt fmt
leveldb leveldb
snappy snappy
PreLoader PreLoader
SymbolProvider SymbolProvider
bedrock_server_api
bedrock_server_var
) )
target_link_directories(Cleaner PRIVATE target_link_directories(Cleaner PRIVATE
C:/Users/yang/AppData/Local/.xmake/packages/l/levilamina/0.2.2/54d4541cae36448ab8d89ba7ff29fe49/lib C:/Users/yang/AppData/Local/.xmake/packages/l/levilamina/0.3.0/59a288d9257e463883bf6b863a7de723/lib
C:/Users/yang/AppData/Local/.xmake/packages/b/bdslibrary/1.20.50.03/ed5b31d060e14f9fa04590d78581d780/lib
C:/Users/yang/AppData/Local/.xmake/packages/f/fmt/10.1.1/adc308aa1dfc472ab92a30abb14e2d6f/lib C:/Users/yang/AppData/Local/.xmake/packages/f/fmt/10.1.1/adc308aa1dfc472ab92a30abb14e2d6f/lib
C:/Users/yang/AppData/Local/.xmake/packages/l/leveldb/1.23/bd4e0156f5854fe28ddb7800bcdf5a2d/lib C:/Users/yang/AppData/Local/.xmake/packages/l/leveldb/1.23/bd4e0156f5854fe28ddb7800bcdf5a2d/lib
C:/Users/yang/AppData/Local/.xmake/packages/s/snappy/1.1.10/849445e2a764471789906fbaf94e9a02/lib C:/Users/yang/AppData/Local/.xmake/packages/s/snappy/1.1.10/849445e2a764471789906fbaf94e9a02/lib
C:/Users/yang/AppData/Local/.xmake/packages/p/preloader/v1.4.0/e087d05f0e95498c9a4b89f94139b1cd/lib C:/Users/yang/AppData/Local/.xmake/packages/p/preloader/v1.4.0/e087d05f0e95498c9a4b89f94139b1cd/lib
C:/Users/yang/AppData/Local/.xmake/packages/s/symbolprovider/v1.1.0/ca5041352577410f83705b4b2abb93f7/lib C:/Users/yang/AppData/Local/.xmake/packages/s/symbolprovider/v1.1.0/ca5041352577410f83705b4b2abb93f7/lib
C:/Users/yang/AppData/Local/.xmake/packages/b/bdslibrary/1.20.50.03/ed5b31d060e14f9fa04590d78581d780/lib
) )
target_link_options(Cleaner PRIVATE target_link_options(Cleaner PRIVATE
/DELAYLOAD:bedrock_server.dll /DELAYLOAD:bedrock_server.dll
+71 -3
View File
@@ -1,14 +1,71 @@
#include "Global.h" #include "Global.h"
using namespace ll::schedule;
using namespace ll::chrono_literals;
GameTimeScheduler scheduler;
namespace Cleaner { namespace Cleaner {
bool isDeathDrop(ItemActor* itac) {
// Todo
return false;
}
bool shouldIgnoreMob(Mob* mob) {
// Todo
return false;
}
bool ShouldClean(Actor* en) { bool ShouldClean(Actor* en) {
// Players
if (en->isType(ActorType::Player)) { if (en->isType(ActorType::Player)) {
return false; return false;
} }
// 过滤 // Tag
if (en->hasTag("testtag")) {
// Todo // Todo
}
auto type = en->getTypeName();
// Items
if (en->hasCategory(ActorCategory::Item)) {
if (true) { // Todo Config Toggle
auto itac = (ItemActor*)en;
if (isDeathDrop(itac)) {
return false;
}
auto itemType = itac->item().getTypeName();
if (true) { // Todo Config WhiteList
return true; return true;
return false;
}
return true;
}
return false;
}
// Mobs
else if (en->hasCategory(ActorCategory::Mob)) {
if (true) { // Todo Config Toggle
auto mob = (Mob*)en;
if (shouldIgnoreMob(mob)) {
return false;
}
if (true) { // Todo WhiteList
return true;
return false;
}
}
return false;
}
// Others
else {
if (true) { // Todo Config Toggle
if (true) { // BlackList
return true;
}
}
return false;
}
} }
int ExecuteClean() { int ExecuteClean() {
@@ -34,10 +91,21 @@ int CountEntities() {
return clean_count; return clean_count;
} }
void CleanSchedule() { using namespace ll::schedule;
using namespace ll::chrono_literals;
void CleanTask() {
// Todo Schedule // Todo Schedule
logger.info("clean will in {}", 20s);
scheduler.add<DelayTask>(20s, [] {
auto count = ExecuteClean(); auto count = ExecuteClean();
// Todo Notice & Console Log logger.info("Successfully cleaned {} entities", count);
});
}
void CountEntitiesTask() {
//
} }
} // namespace Cleaner } // namespace Cleaner
+4 -12
View File
@@ -1,19 +1,11 @@
#pragma once #pragma once
#include "Plugin.h" #include "Plugin.h"
#include <ll/api/command/DynamicCommand.h> #include "include_all.h"
#include <ll/api/event/EventBus.h>
#include <ll/api/event/ListenerBase.h>
#include <ll/api/event/command/SetupCommandEvent.h>
#include <ll/api/plugin/NativePlugin.h>
#include <ll/api/memory/Hook.h>
#include <ll/api/service/Bedrock.h>
#include <ll/api/schedule/Scheduler.h>
#include <ll/api/schedule/Task.h>
#include "include_mcapi.h"
extern ll::Logger logger; extern ll::Logger logger;
extern void RegisterCommand(CommandRegistry &registry); extern void RegisterCommands();
extern void UnregisterCommands();
namespace Cleaner { namespace Cleaner {
extern void CleanSchedule(int seconds, int notice_time); extern void CleanTask();
} }
+1
View File
@@ -0,0 +1 @@
#include "Global.h"
+2 -7
View File
@@ -6,14 +6,10 @@ namespace plugin {
Plugin::Plugin(ll::plugin::NativePlugin& self) : mSelf(self) { Plugin::Plugin(ll::plugin::NativePlugin& self) : mSelf(self) {
// Code for loading the plugin goes here. // Code for loading the plugin goes here.
auto& eventBus = ll::event::EventBus::getInstance();
mSetupCommandEventListener = eventBus.emplaceListener<ll::event::command::SetupCommandEvent>([](ll::event::command::SetupCommandEvent& event) {
RegisterCommand(event.registry());
});
} }
bool Plugin::enable() { bool Plugin::enable() {
auto& logger = mSelf.getLogger(); RegisterCommands();
logger.info("Cleaner Loaded!"); logger.info("Cleaner Loaded!");
logger.info("Author: Tsubasa6848"); logger.info("Author: Tsubasa6848");
logger.info("Repository: https://github.com/GroupMountain/Cleaner"); logger.info("Repository: https://github.com/GroupMountain/Cleaner");
@@ -21,10 +17,9 @@ bool Plugin::enable() {
} }
bool Plugin::disable() { bool Plugin::disable() {
auto& logger = mSelf.getLogger();
logger.info("Disabling Cleaner..."); logger.info("Disabling Cleaner...");
// Code for disabling the plugin goes here. // Code for disabling the plugin goes here.
UnregisterCommands();
logger.info("Cleaner Disabled!"); logger.info("Cleaner Disabled!");
return true; return true;
} }
+1 -3
View File
@@ -1,13 +1,12 @@
#pragma once #pragma once
#include <ll/api/plugin/NativePlugin.h> #include <ll/api/plugin/NativePlugin.h>
#include <ll/api/event/ListenerBase.h>
namespace plugin { namespace plugin {
class Plugin { class Plugin {
public: public:
Plugin(ll::plugin::NativePlugin& self); explicit Plugin(ll::plugin::NativePlugin& self);
Plugin(Plugin&&) = delete; Plugin(Plugin&&) = delete;
Plugin(const Plugin&) = delete; Plugin(const Plugin&) = delete;
@@ -24,7 +23,6 @@ public:
private: private:
ll::plugin::NativePlugin& mSelf; ll::plugin::NativePlugin& mSelf;
ll::event::ListenerPtr mSetupCommandEventListener;
}; };
} // namespace plugin } // namespace plugin
+14 -7
View File
@@ -21,25 +21,25 @@ void RegCleanCommand(CommandRegistry& registry) {
CommandOrigin const& origin, CommandOrigin const& origin,
CommandOutput& output, CommandOutput& output,
std::unordered_map<std::string, DynamicCommand::Result>& result) { std::unordered_map<std::string, DynamicCommand::Result>& result) {
Cleaner::CleanSchedule(20, 5); Cleaner::CleanTask();
}); });
DynamicCommand::setup(registry, std::move(command)); DynamicCommand::setup(registry, std::move(command));
} }
void RegReloadCommand(CommandRegistry& registry) { void RegConfigCommand(CommandRegistry& registry) {
auto command = DynamicCommand::createCommand(registry, "cleane", "Clean entities", CommandPermissionLevel::Any); auto command = DynamicCommand::createCommand(registry, "cleaner", "Cleaner plugin settings", CommandPermissionLevel::Any);
command->addOverload(); command->addOverload();
command->setCallback([](DynamicCommand const& cmd, command->setCallback([](DynamicCommand const& cmd,
CommandOrigin const& origin, CommandOrigin const& origin,
CommandOutput& output, CommandOutput& output,
std::unordered_map<std::string, DynamicCommand::Result>& result) { std::unordered_map<std::string, DynamicCommand::Result>& result) {
// reload command // reload & config
}); });
DynamicCommand::setup(registry, std::move(command)); DynamicCommand::setup(registry, std::move(command));
} }
void RegDespawnCommand(CommandRegistry& registry) { void RegDespawnCommand(CommandRegistry& registry) {
auto command = DynamicCommand::createCommand(registry, "cleanee", "Clean entities", CommandPermissionLevel::Any); auto command = DynamicCommand::createCommand(registry, "despawn", "despawn entities", CommandPermissionLevel::Any);
command->mandatory("target", ParamType::Actor); command->mandatory("target", ParamType::Actor);
command->addOverload({"target"}); command->addOverload({"target"});
command->addOverload(); command->addOverload();
@@ -51,11 +51,18 @@ void RegDespawnCommand(CommandRegistry& registry) {
for (auto en : ens) { for (auto en : ens) {
en->despawn(); en->despawn();
} }
// despawn command
}); });
DynamicCommand::setup(registry, std::move(command)); DynamicCommand::setup(registry, std::move(command));
} }
void RegisterCommand(CommandRegistry &registry) { void RegisterCommands() {
auto registry = ll::service::bedrock::getCommandRegistry();
RegCleanCommand(registry); RegCleanCommand(registry);
RegDespawnCommand(registry);
}
void UnregisterCommands() {
auto registry = ll::service::bedrock::getCommandRegistry();
registry->unregisterCommand("clean");
registry->unregisterCommand("despawn");
} }
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1,7 +1,7 @@
add_rules("mode.debug", "mode.release", "mode.releasedbg") add_rules("mode.debug", "mode.release", "mode.releasedbg")
add_repositories("liteldev-repo https://github.com/LiteLDev/xmake-repo.git") add_repositories("liteldev-repo https://github.com/LiteLDev/xmake-repo.git")
add_requires("levilamina 0.2.2") -- or add_requires("levilamina x.x.x") to specify target LeviLamina version add_requires("levilamina 0.3.0") -- or add_requires("levilamina x.x.x") to specify target LeviLamina version
target("Cleaner") -- Change this to your plugin name. target("Cleaner") -- Change this to your plugin name.
add_cxflags( add_cxflags(