Skip to content

Commit

Permalink
refactor: support LeviLamina 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrBox committed Dec 31, 2024
1 parent 5026050 commit e1db78e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 76 deletions.
2 changes: 1 addition & 1 deletion src/API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "Event.h"
#include "LLMoney.h"
#include "LegacyMoney.h"
#include "ll/api/Logger.h"
#include "ll/api/io/Logger.h"
#include "ll/api/service/PlayerInfo.h"
#include "sqlitecpp/SQLiteCpp.h"
#include <memory>
Expand Down
3 changes: 1 addition & 2 deletions src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

namespace legacy_money {
struct MoneyConfig {
int version = 1;
std::string language = "en";
int version = 2;
int def_money = 0;
float pay_tax = 0.0;
bool enable_commands = true;
Expand Down
20 changes: 12 additions & 8 deletions src/LegacyMoney.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
#include "Config.h"
#include "LLMoney.h"
#include "ll/api/Config.h"
#include "ll/api/Logger.h"
#include "ll/api/io/Logger.h"
#include "ll/api/command/CommandHandle.h"
#include "ll/api/command/CommandRegistrar.h"
#include "ll/api/i18n/I18n.h"
#include "ll/api/mod/NativeMod.h"
#include "ll/api/mod/RegisterHelper.h"
#include "ll/api/service/PlayerInfo.h"
#include "ll/api/utils/ErrorUtils.h"
#include "mc/common/wrapper/optional_ref.h"
#include "mc/deps/core/utility/optional_ref.h"
#include "mc/server/commands/CommandOriginType.h"
#include "mc/server/commands/CommandOutput.h"
#include "mc/server/commands/CommandPermissionLevel.h"
Expand Down Expand Up @@ -375,8 +375,10 @@ void RegisterMoneyCommands() {

namespace legacy_money {

static std::unique_ptr<LegacyMoney> instance;
LegacyMoney& LegacyMoney::getInstance() { return *instance; }
LegacyMoney& LegacyMoney::getInstance() {
static LegacyMoney instance;
return instance;
}
MoneyConfig config;

bool loadConfig() {
Expand Down Expand Up @@ -416,9 +418,11 @@ bool LegacyMoney::load() {
if (!loadConfig() || !initDatabase()) {
return false;
}
ll::i18n::getInstance() = std::make_unique<ll::i18n::MultiFileI18N>(
ll::i18n::MultiFileI18N(getSelf().getLangDir(), legacy_money::getConfig().language)
);
if (auto res = ll::i18n::getInstance().load(getSelf().getLangDir()); !res) {
getSelf().getLogger().error("Failed to load language file");
ll::error_utils::printCurrentException(getSelf().getLogger());
return false;
}
return true;
}

Expand All @@ -431,6 +435,6 @@ bool LegacyMoney::enable() {

bool LegacyMoney::disable() { return true; }

LL_REGISTER_MOD(LegacyMoney, instance);
LL_REGISTER_MOD(LegacyMoney, LegacyMoney::getInstance());

} // namespace legacy_money
2 changes: 1 addition & 1 deletion src/LegacyMoney.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class LegacyMoney {
public:
static LegacyMoney& getInstance();

LegacyMoney(ll::mod::NativeMod& self) : mSelf(self) {}
LegacyMoney() : mSelf(*ll::mod::NativeMod::current()) {}

[[nodiscard]] ll::mod::NativeMod& getSelf() const { return mSelf; }

Expand Down
95 changes: 31 additions & 64 deletions xmake.lua
Original file line number Diff line number Diff line change
@@ -1,75 +1,42 @@
add_rules("mode.debug", "mode.release")

add_repositories("liteldev-repo https://github.com/LiteLDev/xmake-repo.git")
add_requires("levilamina 0.13.5")

if is_config("target_type", "server") then
add_requires("levilamina develop", {configs = {target_type = "server"}})
else
add_requires("levilamina develop", {configs = {target_type = "client"}})
end

add_requires("levibuildscript")
add_requires("sqlitecpp 3.2.1")
add_requires("openssl 1.1.1-t")

if not has_config("vs_runtime") then
set_runtimes("MD")
end

option("target_type")
set_default("server")
set_showmenu(true)
set_values("server", "client")
option_end()

target("LegacyMoney")
add_cxflags(
"/utf-8",
"/permissive-",
"/EHa",
"/W4",
"/w44265",
"/w44289",
"/w44296",
"/w45263",
"/w44738",
"/w45204"
)
add_cxxflags(
"-Wno-c++2b-extensions",
"-Wno-microsoft-cast",
"-Wno-pragma-system-header-outside-header",
{tools = {"clang_cl"}}
)
add_defines(
"_AMD64_",
"_CRT_SECURE_NO_WARNINGS",
"_ENABLE_CONSTEXPR_MUTEX_CONSTRUCTOR",
"NOMINMAX",
"UNICODE",
"WIN32_LEAN_AND_MEAN",
"ENTT_PACKED_PAGE=128",
"LLMONEY_EXPORTS"
)
add_files(
"src/**.cpp"
)
add_includedirs(
"src"
)
add_packages(
"levilamina",
"sqlitecpp",
"openssl"
)
add_rules(
"mode.release",
"mode.releasedbg"
)
add_shflags(
"/DELAYLOAD:bedrock_server.dll"
)
add_undefines(
"_DEBUG"
)
add_rules("@levibuildscript/linkrule")
add_rules("@levibuildscript/modpacker")
add_cxflags( "/EHa", "/utf-8", "/W4", "/w44265", "/w44289", "/w44296", "/w45263", "/w44738", "/w45204")
add_defines("NOMINMAX", "UNICODE", "LLMONEY_EXPORTS")
add_packages("levilamina", "sqlitecpp")
set_exceptions("none")
set_kind("shared")
set_languages("cxx20")
set_strip("all")

after_build(function (target)
local plugin_packer = import("scripts.plugin_packer")

local plugin_define = {
pluginName = target:name(),
pluginFile = path.filename(target:targetfile()),
}

plugin_packer.pack_plugin(target,plugin_define)
end)
set_languages("c++20")
set_symbols("debug")
add_files("src/**.cpp")
add_includedirs("src")
-- if is_config("target_type", "server") then
-- add_includedirs("src-server")
-- add_files("src-server/**.cpp")
-- else
-- add_includedirs("src-client")
-- add_files("src-client/**.cpp")
-- end

0 comments on commit e1db78e

Please sign in to comment.