mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-07 00:48:28 +01:00
hollow-cube/multiple-event-node-parents
Signed-off-by: mworzala <mattheworzala@gmail.com>
add `minestom.event.multiple-parents`
(cherry picked from commit 26b79904a6fcbce2459d12ae8165d47dd2c8f1b3)
(cherry picked from commit 560b5cb52d
)
This commit is contained in:
parent
e2b5fbd054
commit
351000e2cb
@ -7,3 +7,7 @@ Some of these are pending, some deserve PRs, others are just minor tweaks
|
|||||||
* **breaking** Add cursor position to block place and neighbor updates (`Moulberry/Minestom` @ `block_placement_rewrite_2`)
|
* **breaking** Add cursor position to block place and neighbor updates (`Moulberry/Minestom` @ `block_placement_rewrite_2`)
|
||||||
* Change `Entity#getInstance` to @UnknownNullability
|
* Change `Entity#getInstance` to @UnknownNullability
|
||||||
* Support custom component translator for serverside translation
|
* Support custom component translator for serverside translation
|
||||||
|
* **breaking** Replace permission system with a simple user pluggable alternative
|
||||||
|
* **breaking** Remove tinylog and MinestomTerminal implementation
|
||||||
|
* Add `Tag.Transient`
|
||||||
|
* Optionally allow multiple parents in event nodes
|
||||||
|
@ -18,6 +18,8 @@ import java.util.function.BiPredicate;
|
|||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
non-sealed class EventNodeImpl<T extends Event> implements EventNode<T> {
|
non-sealed class EventNodeImpl<T extends Event> implements EventNode<T> {
|
||||||
|
private static final boolean ALLOW_MULTIPLE_PARENTS = Boolean.getBoolean("minestom.event.multiple-parents");
|
||||||
|
|
||||||
static final Object GLOBAL_CHILD_LOCK = new Object();
|
static final Object GLOBAL_CHILD_LOCK = new Object();
|
||||||
|
|
||||||
private final Map<Class, Handle<T>> handleMap = new ConcurrentHashMap<>();
|
private final Map<Class, Handle<T>> handleMap = new ConcurrentHashMap<>();
|
||||||
@ -107,7 +109,7 @@ non-sealed class EventNodeImpl<T extends Event> implements EventNode<T> {
|
|||||||
public @NotNull EventNode<T> addChild(@NotNull EventNode<? extends T> child) {
|
public @NotNull EventNode<T> addChild(@NotNull EventNode<? extends T> child) {
|
||||||
synchronized (GLOBAL_CHILD_LOCK) {
|
synchronized (GLOBAL_CHILD_LOCK) {
|
||||||
final var childImpl = (EventNodeImpl<? extends T>) child;
|
final var childImpl = (EventNodeImpl<? extends T>) child;
|
||||||
Check.stateCondition(childImpl.parent != null, "Node already has a parent");
|
Check.stateCondition(!ALLOW_MULTIPLE_PARENTS && childImpl.parent != null, "Node already has a parent");
|
||||||
Check.stateCondition(Objects.equals(parent, child), "Cannot have a child as parent");
|
Check.stateCondition(Objects.equals(parent, child), "Cannot have a child as parent");
|
||||||
if (!children.add((EventNodeImpl<T>) childImpl)) return this; // Couldn't add the child (already present?)
|
if (!children.add((EventNodeImpl<T>) childImpl)) return this; // Couldn't add the child (already present?)
|
||||||
childImpl.parent = this;
|
childImpl.parent = this;
|
||||||
@ -218,6 +220,7 @@ non-sealed class EventNodeImpl<T extends Event> implements EventNode<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable EventNode<? super T> getParent() {
|
public @Nullable EventNode<? super T> getParent() {
|
||||||
|
Check.stateCondition(ALLOW_MULTIPLE_PARENTS, "Cannot use getParent when multiple parents are allowed");
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user