Added NotReadyException to DataExtension API (0.0.5)

This commit is contained in:
Rsl1122 2019-05-10 14:21:52 +03:00
parent 51dcba13b5
commit 6d788ba61a
8 changed files with 52 additions and 10 deletions

View File

@ -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')

View File

@ -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<Capability> getByName(String name) {
if (name == null) {

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.extension;
/**
* Exception to throw inside DataExtension if a method is not ready to be called (Data is not available etc).
* <p>
* This Exception will not cause Plan to "yell" about the exception.
* <p>
* Requires {@link com.djrapitops.plan.capability.Capability#DATA_EXTENSION_NOT_READY_EXCEPTION}.
*
* @author Rsl1122
*/
public class NotReadyException extends IllegalStateException {
/**
* Construct the exception.
* <p>
* The Exception is not logged (Fails silently) so no message is available.
*/
public NotReadyException() {
}
}

View File

@ -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<T> 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);
}
}

View File

@ -104,7 +104,7 @@ class DoubleAndPercentageProviderValueGatherer {
MethodWrapper<Double> method = doubleProvider.getMethod();
Double result = getMethodResult(methodCaller.apply(method), method);
if (result == null) {
return;
return; // Error during call
}
database.executeTransaction(new StoreIconTransaction(providerInformation.getIcon()));

View File

@ -99,7 +99,7 @@ class NumberProviderValueGatherer {
MethodWrapper<Long> method = numberProvider.getMethod();
Long result = getMethodResult(methodCaller.apply(method), method);
if (result == null) {
return;
return; // Error during call
}
FormatType formatType = NumberDataProvider.getFormatType(numberProvider);

View File

@ -100,7 +100,7 @@ class StringProviderValueGatherer {
MethodWrapper<String> method = stringProvider.getMethod();
String result = getMethodResult(methodCaller.apply(method), method);
if (result == null) {
return;
return; // Error during call
}
result = StringUtils.truncate(result, 50);

View File

@ -101,7 +101,7 @@ class TableProviderValueGatherer {
MethodWrapper<Table> method = tableProvider.getMethod();
Table result = getMethodResult(methodCaller.apply(method), method);
if (result == null) {
return;
return; // Error during call
}
for (Icon icon : result.getIcons()) {