2828import java .io .IOException ;
2929import java .util .ArrayList ;
3030import java .util .Collection ;
31+ import java .util .List ;
3132import java .util .Optional ;
3233import java .util .UUID ;
34+ import java .util .concurrent .ExecutionException ;
3335
3436import de .bluecolored .bluemap .api .marker .Marker ;
3537import de .bluecolored .bluemap .api .marker .MarkerAPI ;
36- import de .bluecolored .bluemap .api .renderer .BlueMapMap ;
37- import de .bluecolored .bluemap .api .renderer .BlueMapWorld ;
3838import de .bluecolored .bluemap .api .renderer .RenderAPI ;
3939
4040/**
@@ -140,13 +140,26 @@ public static synchronized Optional<BlueMapAPI> getInstance() {
140140 * Used by BlueMap to register the API and call the listeners properly.
141141 * @param instance {@link BlueMapAPI}-instance
142142 */
143- protected static synchronized boolean registerInstance (BlueMapAPI instance ) {
143+ protected static synchronized boolean registerInstance (BlueMapAPI instance ) throws ExecutionException {
144144 if (BlueMapAPI .instance != null ) return false ;
145145
146146 BlueMapAPI .instance = instance ;
147147
148+ List <Exception > thrownExceptions = new ArrayList <>(0 );
148149 for (BlueMapAPIListener listener : BlueMapAPI .listener ) {
149- listener .onEnable (BlueMapAPI .instance );
150+ try {
151+ listener .onEnable (BlueMapAPI .instance );
152+ } catch (Exception ex ) {
153+ thrownExceptions .add (ex );
154+ }
155+ }
156+
157+ if (!thrownExceptions .isEmpty ()) {
158+ ExecutionException ex = new ExecutionException (thrownExceptions .get (0 ));
159+ for (int i = 1 ; i < thrownExceptions .size (); i ++) {
160+ ex .addSuppressed (thrownExceptions .get (i ));
161+ }
162+ throw ex ;
150163 }
151164
152165 return true ;
@@ -155,14 +168,27 @@ protected static synchronized boolean registerInstance(BlueMapAPI instance) {
155168 /**
156169 * Used by BlueMap to unregister the API and call the listeners properly.
157170 */
158- protected static synchronized boolean unregisterInstance (BlueMapAPI instance ) {
171+ protected static synchronized boolean unregisterInstance (BlueMapAPI instance ) throws ExecutionException {
159172 if (BlueMapAPI .instance != instance ) return false ;
160-
173+
174+ List <Exception > thrownExceptions = new ArrayList <>(0 );
161175 for (BlueMapAPIListener listener : BlueMapAPI .listener ) {
162- listener .onDisable (BlueMapAPI .instance );
176+ try {
177+ listener .onDisable (BlueMapAPI .instance );
178+ } catch (Exception ex ) {
179+ thrownExceptions .add (ex );
180+ }
163181 }
164182
165183 BlueMapAPI .instance = null ;
184+
185+ if (!thrownExceptions .isEmpty ()) {
186+ ExecutionException ex = new ExecutionException (thrownExceptions .get (0 ));
187+ for (int i = 1 ; i < thrownExceptions .size (); i ++) {
188+ ex .addSuppressed (thrownExceptions .get (i ));
189+ }
190+ throw ex ;
191+ }
166192
167193 return true ;
168194 }
0 commit comments