From 2f82603f65006498a3b7e62381de8229231068c5 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 19 Jul 2021 13:33:03 -0400 Subject: [PATCH] We don't need the sorted order that a List provides --- .../proxy/event/EventTypeTracker.java | 19 ++++++++++--------- .../proxy/event/VelocityEventManager.java | 3 ++- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/event/EventTypeTracker.java b/proxy/src/main/java/com/velocitypowered/proxy/event/EventTypeTracker.java index 636fd2300..35efbf70f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/event/EventTypeTracker.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/event/EventTypeTracker.java @@ -17,27 +17,28 @@ package com.velocitypowered.proxy.event; -import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ListMultimap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Multimap; import com.google.common.reflect.TypeToken; -import java.util.List; +import java.util.Collection; import java.util.stream.Collectors; class EventTypeTracker { - private final ListMultimap, Class> friends; + private final Multimap, Class> friends; public EventTypeTracker() { - this.friends = ArrayListMultimap.create(); + this.friends = HashMultimap.create(); } - public List> getFriendsOf(final Class eventType) { + public Collection> getFriendsOf(final Class eventType) { if (friends.containsKey(eventType)) { - return ImmutableList.copyOf(friends.get(eventType)); + return ImmutableSet.copyOf(friends.get(eventType)); } - final List> types = getEventTypes(eventType); + final Collection> types = getEventTypes(eventType); for (Class type : types) { if (type == eventType) { continue; @@ -48,7 +49,7 @@ class EventTypeTracker { return types; } - private static List> getEventTypes(final Class eventType) { + private static Collection> getEventTypes(final Class eventType) { return TypeToken.of(eventType).getTypes().rawTypes().stream() .filter(type -> type != Object.class) .collect(Collectors.toList()); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java b/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java index be1af1e20..ce8eb8c94 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java @@ -46,6 +46,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -175,7 +176,7 @@ public class VelocityEventManager implements EventManager { private @Nullable HandlersCache bakeHandlers(final Class eventType) { final List baked = new ArrayList<>(); - final List> types = eventTypeTracker.getFriendsOf(eventType); + final Collection> types = eventTypeTracker.getFriendsOf(eventType); lock.readLock().lock(); try {