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 8c1e6596..2afbbbd7 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 @@ -17,7 +17,7 @@ import java.util.logging.Logger; public class EventBus { - private final Map, Map>> byListenerAndPriority = new HashMap<>(); + private final Map, Map>> byListenerAndPriority = new HashMap<>(); private final Map, EventHandlerMethod[]> byEventBaked = new HashMap<>(); private final ReadWriteLock lock = new ReentrantReadWriteLock(); private final Logger logger; @@ -63,9 +63,9 @@ public class EventBus } } - private Map, Map>> findHandlers(Object listener) + private Map, Map>> findHandlers(Object listener) { - Map, Map>> handler = new HashMap<>(); + Map, Map>> handler = new HashMap<>(); for ( Method m : listener.getClass().getDeclaredMethods() ) { EventHandler annotation = m.getAnnotation( EventHandler.class ); @@ -80,7 +80,7 @@ public class EventBus } ); continue; } - Map> prioritiesMap = handler.get( params[0] ); + Map> prioritiesMap = handler.get( params[0] ); if ( prioritiesMap == null ) { prioritiesMap = new HashMap<>(); @@ -100,19 +100,19 @@ public class EventBus public void register(Object listener) { - Map, Map>> handler = findHandlers( listener ); + Map, Map>> handler = findHandlers( listener ); lock.writeLock().lock(); try { - for ( Map.Entry, Map>> e : handler.entrySet() ) + for ( Map.Entry, Map>> e : handler.entrySet() ) { - Map> prioritiesMap = byListenerAndPriority.get( e.getKey() ); + Map> prioritiesMap = byListenerAndPriority.get( e.getKey() ); if ( prioritiesMap == null ) { prioritiesMap = new HashMap<>(); byListenerAndPriority.put( e.getKey(), prioritiesMap ); } - for ( Map.Entry> entry : e.getValue().entrySet() ) + for ( Map.Entry> entry : e.getValue().entrySet() ) { Map currentPriorityMap = prioritiesMap.get( entry.getKey() ); if ( currentPriorityMap == null ) @@ -133,16 +133,16 @@ public class EventBus public void unregister(Object listener) { - Map, Map>> handler = findHandlers( listener ); + Map, Map>> handler = findHandlers( listener ); lock.writeLock().lock(); try { - for ( Map.Entry, Map>> e : handler.entrySet() ) + for ( Map.Entry, Map>> e : handler.entrySet() ) { - Map> prioritiesMap = byListenerAndPriority.get( e.getKey() ); + Map> prioritiesMap = byListenerAndPriority.get( e.getKey() ); if ( prioritiesMap != null ) { - for ( EventPriority priority : e.getValue().keySet() ) + for ( Byte priority : e.getValue().keySet() ) { Map currentPriority = prioritiesMap.get( priority ); if ( currentPriority != null ) @@ -174,11 +174,11 @@ public class EventBus */ private void bakeHandlers(Class eventClass) { - Map> handlersByPriority = byListenerAndPriority.get( eventClass ); + Map> handlersByPriority = byListenerAndPriority.get( eventClass ); if ( handlersByPriority != null ) { List handlersList = new ArrayList<>( handlersByPriority.size() * 2 ); - for ( EventPriority value : EventPriority.values() ) + for ( byte value = Byte.MIN_VALUE; value < Byte.MAX_VALUE; value++ ) { Map handlersByListener = handlersByPriority.get( value ); if ( handlersByListener != null ) diff --git a/event/src/main/java/net/md_5/bungee/event/EventHandler.java b/event/src/main/java/net/md_5/bungee/event/EventHandler.java index eb09e81b..c8f1d786 100644 --- a/event/src/main/java/net/md_5/bungee/event/EventHandler.java +++ b/event/src/main/java/net/md_5/bungee/event/EventHandler.java @@ -20,8 +20,7 @@ public @interface EventHandler *
  • NORMAL
  • *
  • HIGH
  • *
  • HIGHEST
  • - *
  • MONITOR
  • * */ - EventPriority priority() default EventPriority.NORMAL; + byte priority() default EventPriority.NORMAL; } diff --git a/event/src/main/java/net/md_5/bungee/event/EventHandlerMethod.java b/event/src/main/java/net/md_5/bungee/event/EventHandlerMethod.java index fb72c438..ad19c020 100644 --- a/event/src/main/java/net/md_5/bungee/event/EventHandlerMethod.java +++ b/event/src/main/java/net/md_5/bungee/event/EventHandlerMethod.java @@ -5,10 +5,6 @@ import java.lang.reflect.Method; import lombok.AllArgsConstructor; import lombok.Getter; -/** - * - * @author daboross - */ @AllArgsConstructor public class EventHandlerMethod { diff --git a/event/src/main/java/net/md_5/bungee/event/EventPriority.java b/event/src/main/java/net/md_5/bungee/event/EventPriority.java index f8aac6a8..0d4cf877 100644 --- a/event/src/main/java/net/md_5/bungee/event/EventPriority.java +++ b/event/src/main/java/net/md_5/bungee/event/EventPriority.java @@ -1,45 +1,19 @@ package net.md_5.bungee.event; -import lombok.AllArgsConstructor; -import lombok.Getter; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; /** * Importance of the {@link EventHandler}. When executing an Event, the handlers * are called in order of their Priority. */ -@AllArgsConstructor -public enum EventPriority +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class EventPriority { - /** - * Lowest EventPriority. Use this priority to allow other plugins to further - * customize the outcome. - */ - LOWEST( 0 ), - /** - * Higher than lowest, lower than normal. - */ - LOW( 1 ), - /** - * Default EventPriority - */ - NORMAL( 2 ), - /** - * High EventPriority. Use this priority to have more verdict on the - * outcome. - */ - HIGH( 3 ), - /** - * Most important EventPriorty for changes. Use this priority to have - * absolute verdict of the outcome of this event. - */ - HIGHEST( 4 ), - /** - * Logging/Monitor EventPriority. This priority is for read only - * event handlers. Do not change the outcome of the event in this priority. - * Intended for logging purposes. - */ - MONITOR( 5 ); - @Getter - private final int priority; + public static final byte LOWEST = -64; + public static final byte LOW = -32; + public static final byte NORMAL = 0; + public static final byte HIGH = 32; + public static final byte HIGHEST = 64; } diff --git a/event/src/test/java/net/md_5/bungee/event/UnregisteringListenerTest.java b/event/src/test/java/net/md_5/bungee/event/UnregisteringListenerTest.java index 6dcab45d..fbfbd546 100644 --- a/event/src/test/java/net/md_5/bungee/event/UnregisteringListenerTest.java +++ b/event/src/test/java/net/md_5/bungee/event/UnregisteringListenerTest.java @@ -1,15 +1,8 @@ -/* - * Copyright (C) 2013 Dabo Ross - */ package net.md_5.bungee.event; import org.junit.Assert; import org.junit.Test; -/** - * - * @author daboross - */ public class UnregisteringListenerTest {