From 6d788ba61a80cb9196d5edf97831dffffe63aeda Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Fri, 10 May 2019 14:21:52 +0300 Subject: [PATCH] Added NotReadyException to DataExtension API (0.0.5) --- Plan/api/build.gradle | 2 +- .../plan/capability/Capability.java | 6 ++- .../plan/extension/NotReadyException.java | 37 +++++++++++++++++++ .../providers/MethodWrapper.java | 9 +++-- ...bleAndPercentageProviderValueGatherer.java | 2 +- .../NumberProviderValueGatherer.java | 2 +- .../StringProviderValueGatherer.java | 2 +- .../gathering/TableProviderValueGatherer.java | 2 +- 8 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 Plan/api/src/main/java/com/djrapitops/plan/extension/NotReadyException.java diff --git a/Plan/api/build.gradle b/Plan/api/build.gradle index 465a78ecd..540a9b763 100644 --- a/Plan/api/build.gradle +++ b/Plan/api/build.gradle @@ -2,7 +2,7 @@ plugins { id "com.jfrog.bintray" version "1.8.4" } -ext.apiVersion = '0.0.4' +ext.apiVersion = '0.0.5' bintray { user = System.getenv('BINTRAY_USER') diff --git a/Plan/api/src/main/java/com/djrapitops/plan/capability/Capability.java b/Plan/api/src/main/java/com/djrapitops/plan/capability/Capability.java index 0ea9a689f..2fbb46b2a 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/capability/Capability.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/capability/Capability.java @@ -40,7 +40,11 @@ enum Capability { /** * DataExtension API table package, TableProvider, Table and Table.Factory */ - DATA_EXTENSION_TABLES; + DATA_EXTENSION_TABLES, + /** + * DataExtension API + */ + DATA_EXTENSION_NOT_READY_EXCEPTION; static Optional getByName(String name) { if (name == null) { diff --git a/Plan/api/src/main/java/com/djrapitops/plan/extension/NotReadyException.java b/Plan/api/src/main/java/com/djrapitops/plan/extension/NotReadyException.java new file mode 100644 index 000000000..b675994bb --- /dev/null +++ b/Plan/api/src/main/java/com/djrapitops/plan/extension/NotReadyException.java @@ -0,0 +1,37 @@ +/* + * This file is part of Player Analytics (Plan). + * + * Plan is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License v3 as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Plan is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Plan. If not, see . + */ +package com.djrapitops.plan.extension; + +/** + * Exception to throw inside DataExtension if a method is not ready to be called (Data is not available etc). + *

+ * This Exception will not cause Plan to "yell" about the exception. + *

+ * Requires {@link com.djrapitops.plan.capability.Capability#DATA_EXTENSION_NOT_READY_EXCEPTION}. + * + * @author Rsl1122 + */ +public class NotReadyException extends IllegalStateException { + + /** + * Construct the exception. + *

+ * The Exception is not logged (Fails silently) so no message is available. + */ + public NotReadyException() { + } +} \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/MethodWrapper.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/MethodWrapper.java index 358d8795f..d15597108 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/MethodWrapper.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/MethodWrapper.java @@ -18,6 +18,7 @@ package com.djrapitops.plan.extension.implementation.providers; import com.djrapitops.plan.extension.DataExtension; import com.djrapitops.plan.extension.Group; +import com.djrapitops.plan.extension.NotReadyException; import com.djrapitops.plan.extension.implementation.MethodType; import java.io.Serializable; @@ -78,11 +79,11 @@ public class MethodWrapper implements Serializable { default: throw new IllegalArgumentException(method.getDeclaringClass() + " method " + method.getName() + " had invalid parameters."); } + } catch (NotReadyException notReadyToBeCalled) { + /* Data or API not available to make the call. */ + return null; } catch (InvocationTargetException | IllegalAccessException e) { - Throwable cause = e.getCause(); - boolean hasCause = cause != null; - throw new IllegalArgumentException(method.getDeclaringClass() + " method " + method.getName() + " had invalid parameters; caused " + - (hasCause ? cause.toString() : e.toString())); + throw new IllegalArgumentException(method.getDeclaringClass() + " method " + method.getName() + " could not be called: " + e.getMessage(), e); } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/DoubleAndPercentageProviderValueGatherer.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/DoubleAndPercentageProviderValueGatherer.java index 3e3c668c5..b1d9a73d8 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/DoubleAndPercentageProviderValueGatherer.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/DoubleAndPercentageProviderValueGatherer.java @@ -104,7 +104,7 @@ class DoubleAndPercentageProviderValueGatherer { MethodWrapper method = doubleProvider.getMethod(); Double result = getMethodResult(methodCaller.apply(method), method); if (result == null) { - return; + return; // Error during call } database.executeTransaction(new StoreIconTransaction(providerInformation.getIcon())); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/NumberProviderValueGatherer.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/NumberProviderValueGatherer.java index 9fb06efed..c768146cb 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/NumberProviderValueGatherer.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/NumberProviderValueGatherer.java @@ -99,7 +99,7 @@ class NumberProviderValueGatherer { MethodWrapper method = numberProvider.getMethod(); Long result = getMethodResult(methodCaller.apply(method), method); if (result == null) { - return; + return; // Error during call } FormatType formatType = NumberDataProvider.getFormatType(numberProvider); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/StringProviderValueGatherer.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/StringProviderValueGatherer.java index 74fd5f99a..74ddc6405 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/StringProviderValueGatherer.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/StringProviderValueGatherer.java @@ -100,7 +100,7 @@ class StringProviderValueGatherer { MethodWrapper method = stringProvider.getMethod(); String result = getMethodResult(methodCaller.apply(method), method); if (result == null) { - return; + return; // Error during call } result = StringUtils.truncate(result, 50); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/TableProviderValueGatherer.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/TableProviderValueGatherer.java index 12477548e..f5c4349af 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/TableProviderValueGatherer.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/TableProviderValueGatherer.java @@ -101,7 +101,7 @@ class TableProviderValueGatherer { MethodWrapper method = tableProvider.getMethod(); Table result = getMethodResult(methodCaller.apply(method), method); if (result == null) { - return; + return; // Error during call } for (Icon icon : result.getIcons()) {