Catch thrown errors by API-Users
This commit is contained in:
parent
51ea1fe8d1
commit
eeb0c99c8b
|
@ -28,13 +28,13 @@ import java.awt.image.BufferedImage;
|
|||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import de.bluecolored.bluemap.api.marker.Marker;
|
||||
import de.bluecolored.bluemap.api.marker.MarkerAPI;
|
||||
import de.bluecolored.bluemap.api.renderer.BlueMapMap;
|
||||
import de.bluecolored.bluemap.api.renderer.BlueMapWorld;
|
||||
import de.bluecolored.bluemap.api.renderer.RenderAPI;
|
||||
|
||||
/**
|
||||
|
@ -140,13 +140,26 @@ public abstract class BlueMapAPI {
|
|||
* Used by BlueMap to register the API and call the listeners properly.
|
||||
* @param instance {@link BlueMapAPI}-instance
|
||||
*/
|
||||
protected static synchronized boolean registerInstance(BlueMapAPI instance) {
|
||||
protected static synchronized boolean registerInstance(BlueMapAPI instance) throws ExecutionException {
|
||||
if (BlueMapAPI.instance != null) return false;
|
||||
|
||||
BlueMapAPI.instance = instance;
|
||||
|
||||
List<Exception> thrownExceptions = new ArrayList<>(0);
|
||||
for (BlueMapAPIListener listener : BlueMapAPI.listener) {
|
||||
listener.onEnable(BlueMapAPI.instance);
|
||||
try {
|
||||
listener.onEnable(BlueMapAPI.instance);
|
||||
} catch (Exception ex) {
|
||||
thrownExceptions.add(ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (!thrownExceptions.isEmpty()) {
|
||||
ExecutionException ex = new ExecutionException(thrownExceptions.get(0));
|
||||
for (int i = 1; i < thrownExceptions.size(); i++) {
|
||||
ex.addSuppressed(thrownExceptions.get(i));
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -155,14 +168,27 @@ public abstract class BlueMapAPI {
|
|||
/**
|
||||
* Used by BlueMap to unregister the API and call the listeners properly.
|
||||
*/
|
||||
protected static synchronized boolean unregisterInstance(BlueMapAPI instance) {
|
||||
protected static synchronized boolean unregisterInstance(BlueMapAPI instance) throws ExecutionException {
|
||||
if (BlueMapAPI.instance != instance) return false;
|
||||
|
||||
|
||||
List<Exception> thrownExceptions = new ArrayList<>(0);
|
||||
for (BlueMapAPIListener listener : BlueMapAPI.listener) {
|
||||
listener.onDisable(BlueMapAPI.instance);
|
||||
try {
|
||||
listener.onDisable(BlueMapAPI.instance);
|
||||
} catch (Exception ex) {
|
||||
thrownExceptions.add(ex);
|
||||
}
|
||||
}
|
||||
|
||||
BlueMapAPI.instance = null;
|
||||
|
||||
if (!thrownExceptions.isEmpty()) {
|
||||
ExecutionException ex = new ExecutionException(thrownExceptions.get(0));
|
||||
for (int i = 1; i < thrownExceptions.size(); i++) {
|
||||
ex.addSuppressed(thrownExceptions.get(i));
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package de.bluecolored.bluemap.api.renderer;
|
||||
package de.bluecolored.bluemap.api;
|
||||
|
||||
import com.flowpowered.math.vector.Vector2i;
|
||||
import com.flowpowered.math.vector.Vector3d;
|
|
@ -22,7 +22,7 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package de.bluecolored.bluemap.api.renderer;
|
||||
package de.bluecolored.bluemap.api;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
|
@ -28,7 +28,7 @@ import java.util.Optional;
|
|||
|
||||
import com.flowpowered.math.vector.Vector3d;
|
||||
|
||||
import de.bluecolored.bluemap.api.renderer.BlueMapMap;
|
||||
import de.bluecolored.bluemap.api.BlueMapMap;
|
||||
|
||||
/**
|
||||
* A marker that is displayed on one of the maps in the web-app.
|
||||
|
|
|
@ -29,7 +29,7 @@ import java.util.Optional;
|
|||
|
||||
import com.flowpowered.math.vector.Vector3d;
|
||||
|
||||
import de.bluecolored.bluemap.api.renderer.BlueMapMap;
|
||||
import de.bluecolored.bluemap.api.BlueMapMap;
|
||||
|
||||
/**
|
||||
* A set of {@link Marker}s that are displayed on the maps in the web-app.
|
||||
|
|
|
@ -29,6 +29,9 @@ import java.util.UUID;
|
|||
import com.flowpowered.math.vector.Vector2i;
|
||||
import com.flowpowered.math.vector.Vector3i;
|
||||
|
||||
import de.bluecolored.bluemap.api.BlueMapMap;
|
||||
import de.bluecolored.bluemap.api.BlueMapWorld;
|
||||
|
||||
/**
|
||||
* The {@link RenderAPI} is used to schedule tile-renders and process them on a number of different threads.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue