diff --git a/CHANGELOG.md b/CHANGELOG.md index 5279e87..cd3294d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.9.3] - 2025-01-30 + +### Fixed + +- Fixed Player::clearItem [#216] + ## [0.9.2] - 2025-01-29 ### Fixed @@ -745,7 +751,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#214]: https://github.com/LiteLDev/LegacyScriptEngine/issues/214 -[Unreleased]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.9.2...HEAD +[#216]: https://github.com/LiteLDev/LegacyScriptEngine/issues/216 + +[Unreleased]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.9.3...HEAD + +[0.9.3]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.9.2...v0.9.3 [0.9.2]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.9.1...v0.9.2 diff --git a/src/legacy/api/DataAPI.cpp b/src/legacy/api/DataAPI.cpp index 3593f63..024dbb8 100644 --- a/src/legacy/api/DataAPI.cpp +++ b/src/legacy/api/DataAPI.cpp @@ -532,7 +532,8 @@ Local MoneyClass::set(const Arguments& args) { CHECK_ARG_TYPE(args[1], ValueKind::kNumber); try { - return Boolean::newBoolean(EconomySystem::setMoney(args[0].asString().toString(), args[1].asNumber().toInt64()) + return Boolean::newBoolean( + EconomySystem::setMoney(args[0].asString().toString(), args[1].asNumber().toInt64()) ); } catch (const std::invalid_argument& e) { lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("Bad argument in MoneySet!"); @@ -570,7 +571,8 @@ Local MoneyClass::add(const Arguments& args) { CHECK_ARG_TYPE(args[1], ValueKind::kNumber); try { - return Boolean::newBoolean(EconomySystem::addMoney(args[0].asString().toString(), args[1].asNumber().toInt64()) + return Boolean::newBoolean( + EconomySystem::addMoney(args[0].asString().toString(), args[1].asNumber().toInt64()) ); } catch (const std::invalid_argument& e) { lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("Bad argument in MoneyAdd!"); @@ -614,12 +616,14 @@ Local MoneyClass::trans(const Arguments& args) { try { string note = ""; if (args.size() >= 4 && args[3].getKind() == ValueKind::kString) note = args[3].asString().toString(); - return Boolean::newBoolean(EconomySystem::transMoney( - args[0].asString().toString(), - args[1].asString().toString(), - args[2].asNumber().toInt64(), - note - )); + return Boolean::newBoolean( + EconomySystem::transMoney( + args[0].asString().toString(), + args[1].asString().toString(), + args[2].asNumber().toInt64(), + note + ) + ); } catch (const std::invalid_argument& e) { lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("Bad argument in MoneyTrans!"); ll::error_utils::printException(e, lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); @@ -759,8 +763,6 @@ Local DataClass::xuid2uuid(const Arguments& args) { } Local DataClass::getAllPlayerInfo(const Arguments& args) { - CHECK_ARGS_COUNT(args, 0); - try { auto arr = Array::newArray(); auto level = ll::service::getLevel(); diff --git a/src/legacy/api/NetworkAPI.cpp b/src/legacy/api/NetworkAPI.cpp index 731aab4..6c2bc29 100644 --- a/src/legacy/api/NetworkAPI.cpp +++ b/src/legacy/api/NetworkAPI.cpp @@ -154,15 +154,16 @@ void WSClientClass::initListeners() { } }); - ws->OnBinaryReceived([nowList{&listeners[int(WSClientEvents::onBinaryReceived)] - }](WebSocketClient&, vector data) { - if (!nowList->empty()) - for (auto& listener : *nowList) { - if (!EngineManager::isValid(listener.engine)) return; - EngineScope enter(listener.engine); - NewTimeout(listener.func.get(), {ByteBuffer::newByteBuffer(data.data(), data.size())}, 1); - } - }); + ws->OnBinaryReceived( + [nowList{&listeners[int(WSClientEvents::onBinaryReceived)]}](WebSocketClient&, vector data) { + if (!nowList->empty()) + for (auto& listener : *nowList) { + if (!EngineManager::isValid(listener.engine)) return; + EngineScope enter(listener.engine); + NewTimeout(listener.func.get(), {ByteBuffer::newByteBuffer(data.data(), data.size())}, 1); + } + } + ); ws->OnError([nowList{&listeners[int(WSClientEvents::onError)]}](WebSocketClient&, string msg) { if (!nowList->empty()) @@ -366,7 +367,8 @@ Local WSClientClass::connectAsync(const Arguments& args) { if (callback.isEmpty()) return; NewTimeout(callback.get(), {Boolean::newBoolean(result)}, 0); } catch (...) { - lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("WSClientClass::connectAsync Failed!" + lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error( + "WSClientClass::connectAsync Failed!" ); ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("In Plugin: " + pluginName); @@ -778,8 +780,6 @@ Local HttpServerClass::listen(const Arguments& args) { } Local HttpServerClass::stop(const Arguments& args) { - CHECK_ARGS_COUNT(args, 0); - try { RecordOperation(getEngineOwnData()->pluginName, "StopHttpServer", ""); svr->stop(); @@ -789,8 +789,6 @@ Local HttpServerClass::stop(const Arguments& args) { } Local HttpServerClass::isRunning(const Arguments& args) { - CHECK_ARGS_COUNT(args, 0); - try { return Boolean::newBoolean(svr->is_running()); } diff --git a/src/legacy/api/PlayerAPI.cpp b/src/legacy/api/PlayerAPI.cpp index e02b7fa..d2855bf 100644 --- a/src/legacy/api/PlayerAPI.cpp +++ b/src/legacy/api/PlayerAPI.cpp @@ -2906,60 +2906,33 @@ Local PlayerClass::clearItem(const Arguments& args) { if (!player) { return {}; } - unsigned int clearCount = 1; + int clearCount = 1; if (args.size() > 1) { CHECK_ARG_TYPE(args[1], ValueKind::kNumber); clearCount = args[1].asNumber().toInt32(); } - int result = 0; - auto& inventorySlots = player->getInventory().getSlots(); - for (unsigned short slot = 0; slot < inventorySlots.size(); ++slot) { - if (clearCount <= 0) { - break; - } - if (inventorySlots[slot]->getTypeName() == args[0].asString().toString()) { - if (inventorySlots[slot]->mCount < clearCount) { - result += inventorySlots[slot]->mCount; - clearCount -= inventorySlots[slot]->mCount; - } else { - result += clearCount; - clearCount = 0; - } - player->getInventory().removeItem(slot, clearCount); - } - } - auto& handSlots = ActorEquipment::getHandContainer(player->getEntityContext()).getSlots(); - for (unsigned short slot = 0; slot < handSlots.size(); ++slot) { - if (clearCount <= 0) { - break; - } - if (handSlots[slot]->getTypeName() == args[0].asString().toString()) { - if (handSlots[slot]->mCount < clearCount) { - result += handSlots[slot]->mCount; - clearCount -= handSlots[slot]->mCount; - } else { - result += clearCount; - clearCount = 0; - } - ActorEquipment::getHandContainer(player->getEntityContext()).removeItem(slot, clearCount); - } - } - auto& armorSlots = ActorEquipment::getArmorContainer(player->getEntityContext()).getSlots(); - for (unsigned short slot = 0; slot < armorSlots.size(); ++slot) { - if (clearCount <= 0) { - break; - } - if (armorSlots[slot]->getTypeName() == args[0].asString().toString()) { - if (armorSlots[slot]->mCount < clearCount) { - result += armorSlots[slot]->mCount; - clearCount -= armorSlots[slot]->mCount; - } else { - result += clearCount; - clearCount = 0; + int result = 0; + std::string typeName = args[0].asString().toString(); + auto clearFunction = [&result, &typeName, &clearCount](Container& container) { + auto slots = container.getSlots(); + for (size_t slot = 0; slot < slots.size() && clearCount > 0; ++slot) { + if (slots[slot]->getTypeName() == typeName) { + auto count = slots[slot]->mCount; + if (count <= clearCount) { + result += count; + clearCount -= count; + container.setItem(slot, ItemStack::EMPTY_ITEM()); + } else { + result += clearCount; + container.removeItem(slot, clearCount); + clearCount = 0; + } } - ActorEquipment::getArmorContainer(player->getEntityContext()).removeItem(slot, clearCount); } - } + }; + clearFunction(player->getInventory()); + clearFunction(ActorEquipment::getHandContainer(player->getEntityContext())); + clearFunction(ActorEquipment::getArmorContainer(player->getEntityContext())); player->refreshInventory(); return Number::newNumber(result); } @@ -2967,8 +2940,6 @@ Local PlayerClass::clearItem(const Arguments& args) { } Local PlayerClass::isSprinting(const Arguments& args) { - CHECK_ARGS_COUNT(args, 0); - try { Player* player = get(); if (!player) return Local(); diff --git a/tooth.lua.json b/tooth.lua.json index 03f484d..7f2c486 100644 --- a/tooth.lua.json +++ b/tooth.lua.json @@ -1,7 +1,7 @@ { "format_version": 2, "tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-lua", - "version": "0.9.2", + "version": "0.9.3", "info": { "name": "LegacyScriptEngine with Lua backend", "description": "A plugin engine for running LLSE plugins on LeviLamina", diff --git a/tooth.nodejs.json b/tooth.nodejs.json index 7f6e6e4..0e6c818 100644 --- a/tooth.nodejs.json +++ b/tooth.nodejs.json @@ -1,7 +1,7 @@ { "format_version": 2, "tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-nodejs", - "version": "0.9.2", + "version": "0.9.3", "info": { "name": "LegacyScriptEngine with NodeJs backend", "description": "A plugin engine for running LLSE plugins on LeviLamina", diff --git a/tooth.python.json b/tooth.python.json index 279e035..2786e7e 100644 --- a/tooth.python.json +++ b/tooth.python.json @@ -1,7 +1,7 @@ { "format_version": 2, "tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-python", - "version": "0.9.2", + "version": "0.9.3", "info": { "name": "LegacyScriptEngine with Python backend", "description": "A plugin engine for running LLSE plugins on LeviLamina", diff --git a/tooth.quickjs.json b/tooth.quickjs.json index a8da329..c81a6c2 100644 --- a/tooth.quickjs.json +++ b/tooth.quickjs.json @@ -1,7 +1,7 @@ { "format_version": 2, "tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-quickjs", - "version": "0.9.2", + "version": "0.9.3", "info": { "name": "LegacyScriptEngine with QuickJs backend", "description": "A plugin engine for running LLSE plugins on LeviLamina",