1212import de .ntcomputer .minecraft .controllablemobs .implementation .CraftControllableMob ;
1313import de .ntcomputer .minecraft .controllablemobs .implementation .nativeinterfaces .NativeInterfaces ;
1414
15+ @ SuppressWarnings ("unchecked" )
1516public final class AIComponentHandlers {
1617 private static final Map <Class <? extends PathfinderGoal >, AIComponentListener <?>> handlerMap = new HashMap <Class <? extends PathfinderGoal >, AIComponentListener <?>>();
1718
1819 private AIComponentHandlers () {
1920 throw new AssertionError ();
2021 }
2122
22- private static <T extends PathfinderGoal > void add (Class <T > goalClass , AIComponentListener <? super T > listener ) {
23+ private static <T extends PathfinderGoal > void add (AIComponentListener <T > listener , Class <? extends T >... goalClasses ) {
24+ for (Class <? extends T > goalClass : goalClasses ) {
25+ handlerMap .put (goalClass , listener );
26+ }
27+ }
28+
29+ private static <T extends PathfinderGoal > void add (Class <? extends T > goalClass , AIComponentListener <T > listener ) {
2330 handlerMap .put (goalClass , listener );
2431 }
2532
@@ -36,8 +43,7 @@ public void onRemoved(CraftControllableMob<?> mob, PathfinderGoalDoorInteract go
3643 }
3744 }
3845 };
39- add (PathfinderGoalOpenDoor .class , closedDoorListener );
40- add (PathfinderGoalBreakDoor .class , closedDoorListener );
46+ add (closedDoorListener , PathfinderGoalOpenDoor .class , PathfinderGoalBreakDoor .class );
4147
4248 add (PathfinderGoalFloat .class , new AIComponentListener <PathfinderGoalFloat >() {
4349 @ Override
@@ -53,15 +59,13 @@ public void onRemoved(CraftControllableMob<?> mob, PathfinderGoalFloat goal) {
5359 });
5460 }
5561
56- @ SuppressWarnings ("unchecked" )
5762 static <T extends PathfinderGoal > void handleAdd (CraftControllableMob <?> mob , T goal ) {
5863 AIComponentListener <T > listener = (AIComponentListener <T >) handlerMap .get (goal .getClass ());
5964 if (listener !=null ) {
6065 listener .onAdd (mob , goal );
6166 }
6267 }
6368
64- @ SuppressWarnings ("unchecked" )
6569 static <T extends PathfinderGoal > void handleRemoved (CraftControllableMob <?> mob , T goal ) {
6670 AIComponentListener <T > listener = (AIComponentListener <T >) handlerMap .get (goal .getClass ());
6771 if (listener !=null ) {
0 commit comments