Skip to content

Commit

Permalink
fix: fix refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Apr 12, 2024
1 parent c66e7f6 commit 8f116d8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
34 changes: 16 additions & 18 deletions src/data/PlayerStateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
#include <ll/api/event/player/PlayerUseItemOnEvent.h>

#include <ll/api/service/Bedrock.h>
#include <ll/api/utils/ErrorUtils.h>
#include <mc/world/item/VanillaItemNames.h>
#include <mc/world/level/BlockSource.h>
#include <mc/world/level/Level.h>
#include <mc/world/level/block/actor/BlockActor.h>
#include <mc/world/level/dimension/Dimension.h>
#include <ll/api/utils/ErrorUtils.h>

namespace we {

static auto saveDelayTime = 1h;
static auto saveDelayTime = 72h;

PlayerStateManager::PlayerStateManager()
: storagedState(WorldEdit::getInstance().getSelf().getDataDir() / u8"player_states") {
Expand Down Expand Up @@ -63,16 +63,13 @@ PlayerStateManager::PlayerStateManager()
WorldEdit::getInstance().geServerScheduler().add<ll::schedule::DelayTask>(
1_tick,
[dst = WithDim<BlockPos>{ev.pos(), ev.self().getDimensionId()}] {
auto dim = ll::service::getLevel()->getDimension(dst.dim);
if (dim) {
return;
}
auto blockActor =
dim->getBlockSourceFromMainChunkSource().getBlockEntity(
dst.pos
);
if (blockActor) {
blockActor->refresh(dim->getBlockSourceFromMainChunkSource());
if (auto dim = ll::service::getLevel()->getDimension(dst.dim);
dim) {
auto& blockSource = dim->getBlockSourceFromMainChunkSource();
if (auto blockActor = blockSource.getBlockEntity(dst.pos);
blockActor) {
blockActor->refresh(blockSource);
}
}
}
);
Expand Down Expand Up @@ -142,7 +139,7 @@ PlayerStateManager::PlayerStateManager()
false,
ev.item(),
{ev.blockPos(), ev.self().getDimensionId()},
(FacingID)ev.face()
ev.face()
));
})
);
Expand Down Expand Up @@ -199,11 +196,7 @@ std::shared_ptr<PlayerState> PlayerStateManager::getOrCreate(mce::UUID const& uu
}
res = std::make_shared<PlayerState>(uuid);
if (nbt) {
try{
res->deserialize(*CompoundTag::fromBinaryNbt(*nbt));
}catch(...){
ll::error_utils::printCurrentException(WorldEdit::getInstance().getLogger());
}
res->deserialize(CompoundTag::fromBinaryNbt(*nbt).value());
}
ctor(uuid, res);
}
Expand All @@ -227,6 +220,11 @@ bool PlayerStateManager::release(mce::UUID const& uuid) {
});
}

void PlayerStateManager::remove(mce::UUID const& uuid) {
playerStates.erase(uuid);
std::unique_lock lock{dbmutex};
storagedState.del(uuid.asString());
}

bool PlayerStateManager::playerLeftClick(
Player& player,
Expand Down
2 changes: 2 additions & 0 deletions src/data/PlayerStateManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ class PlayerStateManager : public std::enable_shared_from_this<PlayerStateManage
~PlayerStateManager();

std::shared_ptr<PlayerState> getOrCreate(mce::UUID const& uuid);

void remove(mce::UUID const& uuid);
};
} // namespace we
2 changes: 1 addition & 1 deletion src/worldedit/WorldEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ bool WorldEdit::load() {
getLogger().playerLevel = getConfig().log.player_log_level;
getLogger().setPlayerOutputFunc([this](std::string_view msg) {
getTickPool().addTask([pkt = TextPacket::createRawMessage(msg)] {
const_cast<TextPacket&>(pkt).sendToClients();
pkt.sendToClients();
});
});
return true;
Expand Down

0 comments on commit 8f116d8

Please sign in to comment.