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,9 +150,11 @@ public interface EventListener<T extends Event> {
|
|||||||
}
|
}
|
||||||
// Filtering
|
// Filtering
|
||||||
if (!filters.isEmpty()) {
|
if (!filters.isEmpty()) {
|
||||||
if (filters.stream().anyMatch(filter -> !filter.test(event))) {
|
for (var filter : filters) {
|
||||||
// Cancelled
|
if (!filter.test(event)) {
|
||||||
return Result.INVALID;
|
// Cancelled
|
||||||
|
return Result.INVALID;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Handler
|
// Handler
|
||||||
|
@ -327,12 +327,12 @@ public class EventNode<T extends Event> {
|
|||||||
}
|
}
|
||||||
synchronized (GLOBAL_CHILD_LOCK) {
|
synchronized (GLOBAL_CHILD_LOCK) {
|
||||||
List<EventNode<E>> result = new ArrayList<>();
|
List<EventNode<E>> result = new ArrayList<>();
|
||||||
this.children.forEach(child -> {
|
for (EventNode<T> child : children) {
|
||||||
if (EventNode.equals(child, name, eventType)) {
|
if (EventNode.equals(child, name, eventType)) {
|
||||||
result.add((EventNode<E>) child);
|
result.add((EventNode<E>) child);
|
||||||
}
|
}
|
||||||
result.addAll(child.findChildren(name, eventType));
|
result.addAll(child.findChildren(name, eventType));
|
||||||
});
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -362,14 +362,14 @@ public class EventNode<T extends Event> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
synchronized (GLOBAL_CHILD_LOCK) {
|
synchronized (GLOBAL_CHILD_LOCK) {
|
||||||
this.children.forEach(child -> {
|
for (EventNode<T> child : children) {
|
||||||
if (EventNode.equals(child, name, eventType)) {
|
if (EventNode.equals(child, name, eventType)) {
|
||||||
removeChild(child);
|
removeChild(child);
|
||||||
addChild(eventNode);
|
addChild(eventNode);
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
child.replaceChildren(name, eventType, eventNode);
|
child.replaceChildren(name, eventType, eventNode);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -396,13 +396,13 @@ public class EventNode<T extends Event> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
synchronized (GLOBAL_CHILD_LOCK) {
|
synchronized (GLOBAL_CHILD_LOCK) {
|
||||||
this.children.forEach(child -> {
|
for (EventNode<T> child : children) {
|
||||||
if (EventNode.equals(child, name, eventType)) {
|
if (EventNode.equals(child, name, eventType)) {
|
||||||
removeChild(child);
|
removeChild(child);
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
child.removeChildren(name, eventType);
|
child.removeChildren(name, eventType);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user