Skip to content

Commit

Permalink
refactor: update event
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Jun 18, 2024
1 parent d743221 commit c6a003e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
35 changes: 13 additions & 22 deletions src/data/PlayerStateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include <ll/api/event/player/PlayerInteractBlockEvent.h>
#include <ll/api/event/player/PlayerPlaceBlockEvent.h>
#include <ll/api/event/player/PlayerUseItemEvent.h>
#include <ll/api/event/player/PlayerUseItemOnEvent.h>

#include <ll/api/service/Bedrock.h>
#include <ll/api/service/ServerInfo.h>
#include <ll/api/utils/ErrorUtils.h>
#include <mc/server/commands/CommandOrigin.h>
#include <mc/world/level/block/actor/BlockActor.h>
Expand All @@ -22,6 +22,14 @@ namespace we {
PlayerStateManager::PlayerStateManager()
: storagedState(WorldEdit::getInstance().getSelf().getDataDir() / u8"player_states") {
using namespace ll::event;
if (ll::getServerStatus() == ll::ServerStatus::Running && ll::service::getLevel()) {
ll::service::getLevel()->forEachPlayer([this](Player& player) {
if (!player.isSimulated()) {
getOrCreate(player.getUuid());
}
return true;
});
}
auto& bus = EventBus::getInstance();
listeners.emplace_back(
bus.emplaceListener<PlayerConnectEvent>([this](PlayerConnectEvent& ev) {
Expand Down Expand Up @@ -98,23 +106,6 @@ PlayerStateManager::PlayerStateManager()
);
})
);
listeners.emplace_back(bus.emplaceListener<PlayerInteractBlockEvent>(
[this](PlayerInteractBlockEvent& ev) {
if (!ev.self().isOperator() || !ev.self().isCreative()) {
return;
}
ev.setCancelled(
ClickState::Hold
== playerRightClick(
ev.self(),
false,
ev.self().getSelectedItem(),
{ev.pos(), ev.self().getDimensionId()},
FacingID::Unknown
)
);
}
));
listeners.emplace_back(
bus.emplaceListener<PlayerPlacingBlockEvent>([this](PlayerPlacingBlockEvent& ev) {
if (!ev.self().isOperator() || !ev.self().isCreative()) {
Expand All @@ -132,8 +123,8 @@ PlayerStateManager::PlayerStateManager()
);
})
);
listeners.emplace_back(
bus.emplaceListener<PlayerUseItemOnEvent>([this](PlayerUseItemOnEvent& ev) {
listeners.emplace_back(bus.emplaceListener<PlayerInteractBlockEvent>(
[this](PlayerInteractBlockEvent& ev) {
if (!ev.self().isOperator() || !ev.self().isCreative()) {
return;
}
Expand All @@ -147,8 +138,8 @@ PlayerStateManager::PlayerStateManager()
ev.face()
)
);
})
);
}
));
listeners.emplace_back(
bus.emplaceListener<PlayerUseItemEvent>([this](PlayerUseItemEvent& ev) {
if (!ev.self().isOperator() || !ev.self().isCreative()) {
Expand Down
3 changes: 3 additions & 0 deletions src/region/LoftRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ bool LoftRegion::setMainPos(BlockPos const& pos) {
return true;
}
bool LoftRegion::setOffPos(BlockPos const& pos) {
if (loftPoints.empty()) {
return false;
}
loftPoints.back().push_back(pos);
maxPointCount = std::max(maxPointCount, loftPoints.back().size());
updateBoundingBox();
Expand Down

0 comments on commit c6a003e

Please sign in to comment.