Skip to content

Commit eeb0c99

Browse files
committed
Catch thrown errors by API-Users
1 parent 51ea1fe commit eeb0c99

File tree

6 files changed

+40
-11
lines changed

6 files changed

+40
-11
lines changed

src/main/java/de/bluecolored/bluemap/api/BlueMapAPI.java

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
import java.io.IOException;
2929
import java.util.ArrayList;
3030
import java.util.Collection;
31+
import java.util.List;
3132
import java.util.Optional;
3233
import java.util.UUID;
34+
import java.util.concurrent.ExecutionException;
3335

3436
import de.bluecolored.bluemap.api.marker.Marker;
3537
import de.bluecolored.bluemap.api.marker.MarkerAPI;
36-
import de.bluecolored.bluemap.api.renderer.BlueMapMap;
37-
import de.bluecolored.bluemap.api.renderer.BlueMapWorld;
3838
import 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
}

src/main/java/de/bluecolored/bluemap/api/renderer/BlueMapMap.java renamed to src/main/java/de/bluecolored/bluemap/api/BlueMapMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
* THE SOFTWARE.
2424
*/
25-
package de.bluecolored.bluemap.api.renderer;
25+
package de.bluecolored.bluemap.api;
2626

2727
import com.flowpowered.math.vector.Vector2i;
2828
import com.flowpowered.math.vector.Vector3d;

src/main/java/de/bluecolored/bluemap/api/renderer/BlueMapWorld.java renamed to src/main/java/de/bluecolored/bluemap/api/BlueMapWorld.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
* THE SOFTWARE.
2424
*/
25-
package de.bluecolored.bluemap.api.renderer;
25+
package de.bluecolored.bluemap.api;
2626

2727
import java.nio.file.Path;
2828
import java.util.Collection;

src/main/java/de/bluecolored/bluemap/api/marker/Marker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
import com.flowpowered.math.vector.Vector3d;
3030

31-
import de.bluecolored.bluemap.api.renderer.BlueMapMap;
31+
import de.bluecolored.bluemap.api.BlueMapMap;
3232

3333
/**
3434
* A marker that is displayed on one of the maps in the web-app.

src/main/java/de/bluecolored/bluemap/api/marker/MarkerSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
import com.flowpowered.math.vector.Vector3d;
3131

32-
import de.bluecolored.bluemap.api.renderer.BlueMapMap;
32+
import de.bluecolored.bluemap.api.BlueMapMap;
3333

3434
/**
3535
* A set of {@link Marker}s that are displayed on the maps in the web-app.

src/main/java/de/bluecolored/bluemap/api/renderer/RenderAPI.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
import com.flowpowered.math.vector.Vector2i;
3030
import com.flowpowered.math.vector.Vector3i;
3131

32+
import de.bluecolored.bluemap.api.BlueMapMap;
33+
import de.bluecolored.bluemap.api.BlueMapWorld;
34+
3235
/**
3336
* The {@link RenderAPI} is used to schedule tile-renders and process them on a number of different threads.
3437
*/

0 commit comments

Comments
 (0)