LeviLamina
Loading...
Searching...
No Matches
Cancellable.h
1#pragma once
2
3#include "ll/api/base/Macro.h"
4#include "ll/api/event/Event.h"
5
6namespace ll::event {
7template <class T>
8class Cancellable : public T {
9protected:
10 using T::T;
11
12 static_assert(std::derived_from<T, Event>);
13
14 static_assert(
15 !traits::is_derived_from_specialization_of_v<T, Cancellable>,
16 "can't be derived from Cancellable twice"
17 );
18
19public:
20 void serialize(CompoundTag& nbt) const override {
21 T::serialize(nbt);
22 Event::serializeWithCancel(nbt);
23 }
24 void deserialize(CompoundTag const& nbt) override {
25 Event::deserializeWithCancel(nbt);
26 T::deserialize(nbt);
27 }
28
29 [[nodiscard]] constexpr bool isCancelled() { return Event::mCancelled; }
30
31 constexpr void setCancelled(bool cancelled) { Event::mCancelled = cancelled; }
32
33 constexpr void cancel() { setCancelled(true); }
34};
35} // namespace ll::event
Definition CompoundTag.h:13
Definition serialize.h:11