mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-13 11:41:34 +01:00
Added NotReadyException to DataExtension API (0.0.5)
This commit is contained in:
parent
51dcba13b5
commit
6d788ba61a
@ -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')
|
||||
|
@ -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) {
|
||||
|
@ -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() {
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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()));
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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()) {
|
||||
|
Loading…
Reference in New Issue
Block a user