mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-08 17:37:42 +01:00
Avoid foreach for sensitive code
This commit is contained in:
parent
6ef40e08c7
commit
3b80335134
@ -150,11 +150,13 @@ public interface EventListener<T extends Event> {
|
||||
}
|
||||
// Filtering
|
||||
if (!filters.isEmpty()) {
|
||||
if (filters.stream().anyMatch(filter -> !filter.test(event))) {
|
||||
for (var filter : filters) {
|
||||
if (!filter.test(event)) {
|
||||
// Cancelled
|
||||
return Result.INVALID;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Handler
|
||||
if (handler != null) {
|
||||
handler.accept(event);
|
||||
|
@ -327,12 +327,12 @@ public class EventNode<T extends Event> {
|
||||
}
|
||||
synchronized (GLOBAL_CHILD_LOCK) {
|
||||
List<EventNode<E>> result = new ArrayList<>();
|
||||
this.children.forEach(child -> {
|
||||
for (EventNode<T> child : children) {
|
||||
if (EventNode.equals(child, name, eventType)) {
|
||||
result.add((EventNode<E>) child);
|
||||
}
|
||||
result.addAll(child.findChildren(name, eventType));
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -362,14 +362,14 @@ public class EventNode<T extends Event> {
|
||||
return;
|
||||
}
|
||||
synchronized (GLOBAL_CHILD_LOCK) {
|
||||
this.children.forEach(child -> {
|
||||
for (EventNode<T> child : children) {
|
||||
if (EventNode.equals(child, name, eventType)) {
|
||||
removeChild(child);
|
||||
addChild(eventNode);
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
child.replaceChildren(name, eventType, eventNode);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -396,13 +396,13 @@ public class EventNode<T extends Event> {
|
||||
return;
|
||||
}
|
||||
synchronized (GLOBAL_CHILD_LOCK) {
|
||||
this.children.forEach(child -> {
|
||||
for (EventNode<T> child : children) {
|
||||
if (EventNode.equals(child, name, eventType)) {
|
||||
removeChild(child);
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
child.removeChildren(name, eventType);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user