Skip to content

Commit

Permalink
feat: support LeviLamina 0.13.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrBox committed Jul 23, 2024
1 parent fd18e55 commit b625155
Show file tree
Hide file tree
Showing 29 changed files with 132 additions and 133 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "native",
"description": "A plugin engine for running LLSE plugins on LeviLamina",
"author": "LiteLDev",
"version": "0.8.3",
"version": "0.8.4",
"dependencies": [
{
"name": "LegacyMoney"
Expand Down
1 change: 1 addition & 0 deletions src/legacy/api/APIHelp.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <mc/world/level/Level.h>
#include <string>


// 输出异常信息
inline void PrintException(const script::Exception& e) {
lse::getSelfPluginInstance().getLogger().error("script::Exception: {0}\n{1}", e.message(), e.stacktrace());
Expand Down
1 change: 0 additions & 1 deletion src/legacy/api/ContainerAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "api/ItemAPI.h"
#include "api/NativeAPI.h"
#include "ll/api/utils/StringUtils.h"
#include "mc/nbt/CompoundTag.h"
#include "mc/world/item/registry/ItemStack.h"

//////////////////// Class Definition ////////////////////
Expand Down
1 change: 1 addition & 0 deletions src/legacy/api/DatabaseAPI.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "api/DatabaseAPI.h"

using namespace DB;

#define CATCH_AND_THROW(LOG) \
Expand Down
23 changes: 12 additions & 11 deletions src/legacy/api/LlAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

#include "api/APIHelp.h"
#include "engine/GlobalShareData.h"
#include "ll/api/plugin/PluginManager.h"
#include "ll/api/plugin/PluginManagerRegistry.h"
#include "ll/api/service/ServerInfo.h"
#include "ll/api/utils/WinUtils.h"
#include "ll/api/Versions.h"
#include "ll/api/mod/Mod.h"
#include "ll/api/mod/ModManager.h"
#include "ll/api/mod/ModManagerRegistry.h"
#include "ll/api/utils/SystemUtils.h"
#include "lse/PluginManager.h"

#include <string>
Expand Down Expand Up @@ -55,14 +56,14 @@ ClassDefine<void> VersionClassBuilder = defineClass("Version")

Local<Value> LlClass::getLanguage() {
try {
return String::newString(ll::win_utils::getSystemLocaleName());
return String::newString(ll::sys_utils::getSystemLocaleName());
}
CATCH("Fail in LLSEGetLanguage")
}

Local<Value> LlClass::isWine() {
try {
return Boolean::newBoolean(ll::win_utils::isWine());
return Boolean::newBoolean(ll::sys_utils::isWine());
}
CATCH("Fail in LLSEIsWine")
}
Expand Down Expand Up @@ -124,7 +125,7 @@ Local<Value> LlClass::getVersionStatus() { return Number::newNumber(0); }
Local<Value> LlClass::registerPlugin(const Arguments& args) { return Boolean::newBoolean(true); }
Local<Value> LlClass::getPluginInfo(const Arguments& args) {
try {
auto plugin = lse::getPluginManager().getPlugin(args[0].asString().toString());
auto plugin = lse::getPluginManager().getMod(args[0].asString().toString());
if (plugin) {
auto result = Object::newObject();

Expand Down Expand Up @@ -167,8 +168,8 @@ Local<Value> LlClass::requireVersion(const Arguments& args) { return Boolean::ne
Local<Value> LlClass::getAllPluginInfo(const Arguments& args) {
try {
Local<Array> plugins = Array::newArray();
ll::plugin::PluginManagerRegistry::getInstance().forEachPluginWithType(
[&](std::string_view type, std::string_view name, ll::plugin::Plugin& plugin) {
ll::mod::ModManagerRegistry::getInstance().forEachModWithType(
[&](std::string_view type, std::string_view name, ll::mod::Mod& plugin) {
// Create plugin object
auto pluginObject = Object::newObject();

Expand Down Expand Up @@ -208,8 +209,8 @@ Local<Value> LlClass::getAllPluginInfo(const Arguments& args) {
Local<Value> LlClass::listPlugins(const Arguments& args) {
try {
Local<Array> plugins = Array::newArray();
ll::plugin::PluginManagerRegistry::getInstance().forEachPluginWithType(
[&](std::string_view type, std::string_view name, ll::plugin::Plugin&) {
ll::mod::ModManagerRegistry::getInstance().forEachModWithType(
[&](std::string_view type, std::string_view name, ll::mod::Mod&) {
plugins.add(String::newString(name));
return true;
}
Expand Down
60 changes: 29 additions & 31 deletions src/legacy/api/NbtAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ ClassDefine<NbtCompoundClass> NbtCompoundClassBuilder =
void TagToJson_Compound_Helper(ordered_json& res, CompoundTag* nbt);

void TagToJson_List_Helper(ordered_json& res, ListTag* nbt) {
auto& list = nbt->mList;
for (auto& tag : list) {
for (auto& tag : *nbt) {
switch (tag->getId()) {
case Tag::Type::Byte:
tag->as<ByteTag>() = 4;
Expand All @@ -188,10 +187,10 @@ void TagToJson_List_Helper(ordered_json& res, ListTag* nbt) {
res.push_back(tag->as<DoubleTag>().data);
break;
case Tag::Type::String:
res.push_back(tag->as<StringTag>().data);
res.push_back(tag->as<StringTag>());
break;
case Tag::Type::ByteArray: {
auto& bytes = tag->as<ByteArrayTag>().data;
auto& bytes = tag->as<ByteArrayTag>();
char tmpData[1024];
for (unsigned int i = 0; i < bytes.size(); ++i) {
tmpData[i] = bytes[i];
Expand Down Expand Up @@ -243,10 +242,10 @@ void TagToJson_Compound_Helper(ordered_json& res, CompoundTag* nbt) {
res.push_back({key, tag.as<DoubleTag>().data});
break;
case Tag::Type::String:
res.push_back({key, tag.as<StringTag>().data});
res.push_back({key, tag.as<StringTag>()});
break;
case Tag::Type::ByteArray: {
auto& bytes = tag.as<ByteArrayTag>().data;
auto& bytes = tag.as<ByteArrayTag>();
char tmpData[1024];
for (unsigned int i = 0; i < bytes.size(); ++i) {
tmpData[i] = bytes[i];
Expand Down Expand Up @@ -299,10 +298,10 @@ std::string TagToJson(Tag* nbt, int formatIndent) {
result = std::to_string(nbt->as<DoubleTag>().data);
break;
case Tag::Type::String:
result = nbt->as<StringTag>().data;
result = nbt->as<StringTag>();
break;
case Tag::Type::ByteArray: {
auto& bytes = nbt->as<ByteArrayTag>().data;
auto& bytes = nbt->as<ByteArrayTag>();
std::string tmpData;
for (uchar data : bytes) {
tmpData.push_back(data);
Expand Down Expand Up @@ -813,7 +812,7 @@ Local<Value> NbtStringClass::getType(const Arguments& args) { return Number::new

Local<Value> NbtStringClass::get(const Arguments& args) {
try {
return String::newString(nbt->data);
return String::newString(nbt->toString());
}
CATCH("Fail in NbtValueGet!")
}
Expand All @@ -831,7 +830,7 @@ Local<Value> NbtStringClass::set(const Arguments& args) {
CHECK_ARGS_COUNT(args, 1);

try {
nbt->data = args[0].toStr();
*nbt = args[0].toStr();
return Boolean::newBoolean(true);
}
CATCH("Fail in NbtValueSet!")
Expand All @@ -855,7 +854,7 @@ NbtByteArrayClass* NbtByteArrayClass::constructor(const Arguments& args) {

std::unique_ptr<ByteArrayTag> arrayTag = std::make_unique<ByteArrayTag>(ByteArrayTag());
for (char c : buf.describeUtf8()) {
arrayTag->data.push_back(c);
arrayTag->push_back(c);
}
return new NbtByteArrayClass(args.thiz(), std::move(arrayTag));
}
Expand Down Expand Up @@ -893,7 +892,7 @@ Local<Value> NbtByteArrayClass::getType(const Arguments& args) { return Number::

Local<Value> NbtByteArrayClass::get(const Arguments& args) {
try {
auto& data = nbt->data;
auto& data = *nbt;
char buf[1024];
for (unsigned int i = 0; i < data.size(); ++i) {
buf[i] = data[i];
Expand All @@ -918,7 +917,7 @@ Local<Value> NbtByteArrayClass::set(const Arguments& args) {
try {
Local<ByteBuffer> buf = args[0].asByteBuffer();
for (char c : buf.describeUtf8()) {
nbt->data.push_back(c);
nbt->push_back(c);
}
return Boolean::newBoolean(true);
}
Expand Down Expand Up @@ -1205,7 +1204,7 @@ Local<Value> NbtListClass::setString(const Arguments& args) {
} else if (list[0].getId() != Tag::Type::String) {
LOG_ERROR_WITH_SCRIPT_INFO("Set wrong type of element into NBT List!");
} else {
list[index].as_ptr<StringTag>()->data = args[1].toStr();
list[index].as<StringTag>() = args[1].toStr();
}

return this->getScriptObject();
Expand All @@ -1229,7 +1228,7 @@ Local<Value> NbtListClass::setByteArray(const Arguments& args) {
} else {
auto data = args[1].asByteBuffer();
for (char c : data.describeUtf8()) {
list[index].as_ptr<ByteArrayTag>()->data.push_back(c);
list[index].as_ptr<ByteArrayTag>()->push_back(c);
}
}
return this->getScriptObject();
Expand All @@ -1242,7 +1241,7 @@ Local<Value> NbtListClass::setTag(const Arguments& args) {
CHECK_ARG_TYPE(args[0], ValueKind::kNumber);

try {
auto& list = nbt->mList;
auto& list = *nbt;
auto index = args[0].toInt();

if (index >= list.size() || index < 0) {
Expand Down Expand Up @@ -1317,15 +1316,15 @@ Local<Value> NbtListClass::removeTag(const Arguments& args) {
CHECK_ARG_TYPE(args[0], ValueKind::kNumber);

try {
auto& list = nbt->mList;
auto& list = *nbt;
auto index = args[0].toInt();

if (index >= list.size() || index < 0) {
LOG_ERROR_WITH_SCRIPT_INFO("Bad Index of NBT List!");
return Local<Value>();
}

list.erase(list.begin() + index); //===== delete?
list.erase(index);
return this->getScriptObject();
}
CATCH("Fail in NBT SetTag!");
Expand Down Expand Up @@ -1415,10 +1414,9 @@ Local<Value> NbtListClass::getTag(const Arguments& args) {

Local<Value> NbtListClass::toArray(const Arguments& args) {
try {
auto& list = nbt->mList;
Local<Array> arr = Array::newArray();
Local<Array> arr = Array::newArray();

for (auto& tag : list) {
for (auto& tag : *nbt) {
arr.add(Tag2Value(tag.get(), true));
}
return arr;
Expand Down Expand Up @@ -1680,7 +1678,7 @@ Local<Value> NbtCompoundClass::setByteArray(const Arguments& args) {
auto data = args[1].asByteBuffer();
ByteArrayTag baTag;
for (char c : data.describeUtf8()) {
baTag.data.push_back(c);
baTag.push_back(c);
}
nbt->at(key) = baTag;
return this->getScriptObject();
Expand Down Expand Up @@ -1924,7 +1922,7 @@ Local<Value> NbtStatic::newTag(const Arguments& args) {
case Tag::Type::String: {
StringTag tag;
if (args.size() >= 2 && args[1].isString()) {
tag.data = args[1].toStr();
tag = args[1].toStr();
}
res = NbtStringClass::pack(std::move(&tag));
break;
Expand All @@ -1934,7 +1932,7 @@ Local<Value> NbtStatic::newTag(const Arguments& args) {
if (args.size() >= 2 && args[1].isByteBuffer()) {
Local<ByteBuffer> buf = args[1].asByteBuffer();
for (char data : buf.describeUtf8()) {
tag.data.push_back(data);
tag.push_back(data);
}
}
res = NbtByteArrayClass::pack(std::move(&tag));
Expand Down Expand Up @@ -2010,7 +2008,7 @@ Local<Value> Tag2Value_CompoundHelper(CompoundTag* nbt, bool autoExpansion = fal
Local<Value> Tag2Value_ListHelper(ListTag* nbt, bool autoExpansion = false) {
Local<Array> res = Array::newArray();

auto& list = nbt->as_ptr<ListTag>()->mList;
auto& list = nbt->as<ListTag>();
for (auto& tag : list) {
switch (tag->getId()) {
case Tag::Type::Byte:
Expand All @@ -2032,10 +2030,10 @@ Local<Value> Tag2Value_ListHelper(ListTag* nbt, bool autoExpansion = false) {
res.add(Number::newNumber(tag->as_ptr<DoubleTag>()->data));
break;
case Tag::Type::String:
res.add(String::newString(tag->as_ptr<StringTag>()->data));
res.add(String::newString(tag->as<StringTag>()));
break;
case Tag::Type::ByteArray: {
auto& data = tag->as_ptr<ByteArrayTag>()->data;
auto& data = tag->as<ByteArrayTag>();
char buf[1024];
for (unsigned int i = 0; i < data.size(); ++i) {
buf[i] = data[i];
Expand Down Expand Up @@ -2084,10 +2082,10 @@ Local<Value> Tag2Value_CompoundHelper(CompoundTag* nbt, bool autoExpansion) {
res.set(key, Number::newNumber(tag.get().as_ptr<DoubleTag>()->data));
break;
case Tag::Type::String:
res.set(key, String::newString(tag.get().as_ptr<StringTag>()->data));
res.set(key, String::newString(tag.get().as<StringTag>()));
break;
case Tag::Type::ByteArray: {
auto& data = tag.get().as_ptr<ByteArrayTag>()->data;
auto& data = tag.get().as<ByteArrayTag>();
char buf[1024];
for (unsigned int i = 0; i < data.size(); ++i) {
buf[i] = data[i];
Expand Down Expand Up @@ -2134,10 +2132,10 @@ Local<Value> Tag2Value(Tag* nbt, bool autoExpansion) {
value = Number::newNumber(nbt->as_ptr<DoubleTag>()->data);
break;
case Tag::Type::String:
value = String::newString(nbt->as_ptr<StringTag>()->data);
value = String::newString(nbt->as<StringTag>());
break;
case Tag::Type::ByteArray: {
auto& data = nbt->as_ptr<ByteArrayTag>()->data;
auto& data = nbt->as<ByteArrayTag>();
char buf[1024];
for (unsigned int i = 0; i < data.size(); ++i) {
buf[i] = data[i];
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/api/ServerAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include "api/APIHelp.h"
#include "api/McAPI.h"
#include "ll/api/service/Bedrock.h"
#include "ll/api/utils/RandomUtils.h"
#include "main/SafeGuardRecord.h"
#include "mc/network/ServerNetworkHandler.h"
#include "mc/network/packet/SetTimePacket.h"

Expand Down
8 changes: 3 additions & 5 deletions src/legacy/engine/EngineOwnData.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#pragma once

#include "dyncall/dyncall.h"
#include "ll/api/Logger.h"
#include "ll/api/i18n/I18n.h"
#include "main/Configs.h"
#include "utils/UsingScriptX.h"

#include <fstream>
#include <expected>
#include <ll/api/Logger.h>
#include <ll/api/i18n/I18n.h>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>

Expand Down
4 changes: 2 additions & 2 deletions src/legacy/engine/OperationCount.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "engine/OperationCount.h"

#include "engine/GlobalShareData.h"
#include "ll/api/plugin/PluginManager.h"
#include "ll/api/mod/ModManager.h"
#include "main/Configs.h"

#include <vector>
Expand Down Expand Up @@ -46,7 +46,7 @@ int OperationCount::get() {
bool OperationCount::hasReachCount(int count) { return get() >= count; }

bool OperationCount::hasReachMaxEngineCount() {
return hasReachCount(lse::getPluginManager().getPluginCount());
return hasReachCount(lse::getPluginManager().getModCount());
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/legacy/legacyapi/command/DynamicCommand.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "DynamicCommand.h"

#include "fmt/core.h"
#include "ll/api/Logger.h"
#include "ll/api/command/CommandRegistrar.h"
#include "ll/api/memory/Closure.h"
#include "ll/api/memory/Memory.h"
#include "ll/api/utils/ErrorUtils.h"
Expand Down Expand Up @@ -37,6 +35,8 @@
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <expected>
#include <ll/api/Logger.h>
#include <ll/api/command/CommandRegistrar.h>
#include <memory>
#include <sstream>
Expand Down
4 changes: 3 additions & 1 deletion src/legacy/legacyapi/db/ConnParams.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "legacyapi/db/ConnParams.h"

#include "ll/api/Logger.h"
#include "ll/api/utils/StringUtils.h"

#include <expected>
#include <ll/api/Logger.h>

namespace DB {

#pragma region URL_Parser
Expand Down
Loading

0 comments on commit b625155

Please sign in to comment.