From 3b80335134e94935048cd28ddb5dea014bb3b4c5 Mon Sep 17 00:00:00 2001 From: TheMode Date: Thu, 10 Jun 2021 11:53:50 +0200 Subject: [PATCH] Avoid foreach for sensitive code --- .../net/minestom/server/event/EventListener.java | 8 +++++--- .../net/minestom/server/event/EventNode.java | 16 ++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/minestom/server/event/EventListener.java b/src/main/java/net/minestom/server/event/EventListener.java index ee70640fb..df6d7a1bd 100644 --- a/src/main/java/net/minestom/server/event/EventListener.java +++ b/src/main/java/net/minestom/server/event/EventListener.java @@ -150,9 +150,11 @@ public interface EventListener { } // Filtering if (!filters.isEmpty()) { - if (filters.stream().anyMatch(filter -> !filter.test(event))) { - // Cancelled - return Result.INVALID; + for (var filter : filters) { + if (!filter.test(event)) { + // Cancelled + return Result.INVALID; + } } } // Handler diff --git a/src/main/java/net/minestom/server/event/EventNode.java b/src/main/java/net/minestom/server/event/EventNode.java index 0557fbcea..7f8b14692 100644 --- a/src/main/java/net/minestom/server/event/EventNode.java +++ b/src/main/java/net/minestom/server/event/EventNode.java @@ -327,12 +327,12 @@ public class EventNode { } synchronized (GLOBAL_CHILD_LOCK) { List> result = new ArrayList<>(); - this.children.forEach(child -> { + for (EventNode child : children) { if (EventNode.equals(child, name, eventType)) { result.add((EventNode) child); } result.addAll(child.findChildren(name, eventType)); - }); + } return result; } } @@ -362,14 +362,14 @@ public class EventNode { return; } synchronized (GLOBAL_CHILD_LOCK) { - this.children.forEach(child -> { + for (EventNode 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 { return; } synchronized (GLOBAL_CHILD_LOCK) { - this.children.forEach(child -> { + for (EventNode child : children) { if (EventNode.equals(child, name, eventType)) { removeChild(child); - return; + continue; } child.removeChildren(name, eventType); - }); + } } }