Remove LinkedList usage

https://twitter.com/joshbloch/status/583813919019573248
This commit is contained in:
AnimeGitB
2022-11-05 17:04:15 +10:30
parent 09f392bb5b
commit 1ceda2a455
7 changed files with 51 additions and 65 deletions

View File

@@ -181,7 +181,7 @@ public final class PluginManager {
// Add the plugin to the list of loaded plugins.
this.plugins.put(identifier.name, plugin);
// Create a collection for the plugin's listeners.
this.listeners.put(plugin, new LinkedList<>());
this.listeners.put(plugin, new ArrayList<>());
// Call the plugin's onLoad method.
try {
@@ -242,18 +242,14 @@ public final class PluginManager {
* @param priority The priority to call for.
*/
private void checkAndFilter(Event event, HandlerPriority priority) {
// Create a collection of listeners.
List<EventHandler<? extends Event>> listeners = new LinkedList<>();
// Add all listeners from every plugin.
this.listeners.values().forEach(listeners::addAll);
listeners.stream()
this.listeners.values().stream()
.flatMap(Collection::stream)
// Filter the listeners by priority.
.filter(handler -> handler.handles().isInstance(event))
.filter(handler -> handler.getPriority() == priority)
// Invoke the event.
.toList().forEach(handler -> this.invokeHandler(event, handler));
.forEach(handler -> this.invokeHandler(event, handler));
}
/**