diff --git a/event/src/main/java/net/md_5/bungee/event/EventBus.java b/event/src/main/java/net/md_5/bungee/event/EventBus.java index b3effc8aa..d3c6ea9d1 100644 --- a/event/src/main/java/net/md_5/bungee/event/EventBus.java +++ b/event/src/main/java/net/md_5/bungee/event/EventBus.java @@ -88,18 +88,8 @@ public class EventBus } ); continue; } - Map> prioritiesMap = handler.get( params[0] ); - if ( prioritiesMap == null ) - { - prioritiesMap = new HashMap<>(); - handler.put( params[0], prioritiesMap ); - } - Set priority = prioritiesMap.get( annotation.priority() ); - if ( priority == null ) - { - priority = new HashSet<>(); - prioritiesMap.put( annotation.priority(), priority ); - } + Map> prioritiesMap = handler.computeIfAbsent( params[0], k -> new HashMap<>() ); + Set priority = prioritiesMap.computeIfAbsent( annotation.priority(), k -> new HashSet<>() ); priority.add( m ); } } @@ -114,20 +104,10 @@ public class EventBus { for ( Map.Entry, Map>> e : handler.entrySet() ) { - Map> prioritiesMap = byListenerAndPriority.get( e.getKey() ); - if ( prioritiesMap == null ) - { - prioritiesMap = new HashMap<>(); - byListenerAndPriority.put( e.getKey(), prioritiesMap ); - } + Map> prioritiesMap = byListenerAndPriority.computeIfAbsent( e.getKey(), k -> new HashMap<>() ); for ( Map.Entry> entry : e.getValue().entrySet() ) { - Map currentPriorityMap = prioritiesMap.get( entry.getKey() ); - if ( currentPriorityMap == null ) - { - currentPriorityMap = new HashMap<>(); - prioritiesMap.put( entry.getKey(), currentPriorityMap ); - } + Map currentPriorityMap = prioritiesMap.computeIfAbsent( entry.getKey(), k -> new HashMap<>() ); currentPriorityMap.put( listener, entry.getValue().toArray( new Method[ 0 ] ) ); } bakeHandlers( e.getKey() );