mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-24 19:55:17 +01:00
Fixes compatibility issues with Java 10
Use non-deprecated methods still compatible with Java 8. These mostly just propagate Exceptions up when instantiating constructors when using the database functions. Reverted POM back to Java 8 so that compiled code will work on Java 8 as well.
This commit is contained in:
parent
95f8c81963
commit
10db4230b0
2
pom.xml
2
pom.xml
@ -43,7 +43,7 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
<java.version>1.10</java.version>
|
<java.version>1.8</java.version>
|
||||||
<powermock.version>1.7.4</powermock.version>
|
<powermock.version>1.7.4</powermock.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package world.bentobox.bentobox.api.addons;
|
package world.bentobox.bentobox.api.addons;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
@ -35,7 +36,7 @@ public class AddonClassLoader extends URLClassLoader {
|
|||||||
MalformedURLException,
|
MalformedURLException,
|
||||||
InvalidDescriptionException,
|
InvalidDescriptionException,
|
||||||
InstantiationException,
|
InstantiationException,
|
||||||
IllegalAccessException {
|
IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||||
super(new URL[]{path.toURI().toURL()}, parent);
|
super(new URL[]{path.toURI().toURL()}, parent);
|
||||||
|
|
||||||
loader = addonsManager;
|
loader = addonsManager;
|
||||||
@ -58,7 +59,7 @@ public class AddonClassLoader extends URLClassLoader {
|
|||||||
throw new InvalidAddonInheritException("Main class doesn't not extends super class 'Addon'");
|
throw new InvalidAddonInheritException("Main class doesn't not extends super class 'Addon'");
|
||||||
}
|
}
|
||||||
|
|
||||||
addon = addonClass.newInstance();
|
addon = addonClass.getDeclaredConstructor().newInstance();
|
||||||
addon.setDescription(asDescription(data));
|
addon.setDescription(asDescription(data));
|
||||||
// Set permissions
|
// Set permissions
|
||||||
if (data.isConfigurationSection("permissions")) {
|
if (data.isConfigurationSection("permissions")) {
|
||||||
|
@ -41,7 +41,8 @@ public class Config<T> {
|
|||||||
try {
|
try {
|
||||||
result = handler.loadObjects();
|
result = handler.loadObjects();
|
||||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
|
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
|
||||||
| InvocationTargetException | ClassNotFoundException | IntrospectionException e) {
|
| InvocationTargetException | ClassNotFoundException | IntrospectionException
|
||||||
|
| NoSuchMethodException | SecurityException e) {
|
||||||
logger.severe(() -> "Could not load config! Error: " + e.getMessage());
|
logger.severe(() -> "Could not load config! Error: " + e.getMessage());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@ -56,7 +57,7 @@ public class Config<T> {
|
|||||||
try {
|
try {
|
||||||
return handler.loadObject(uniqueId);
|
return handler.loadObject(uniqueId);
|
||||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
||||||
| ClassNotFoundException | IntrospectionException e) {
|
| ClassNotFoundException | IntrospectionException | NoSuchMethodException | SecurityException e) {
|
||||||
logger.severe(() -> "Could not load config object! " + e.getMessage());
|
logger.severe(() -> "Could not load config object! " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,16 +48,22 @@ public abstract class AbstractDatabaseHandler<T> {
|
|||||||
/**
|
/**
|
||||||
* Loads all the records in this table and returns a list of them
|
* Loads all the records in this table and returns a list of them
|
||||||
* @return list of <T>
|
* @return list of <T>
|
||||||
|
* @throws SecurityException
|
||||||
|
* @throws NoSuchMethodException
|
||||||
|
* @throws IllegalArgumentException
|
||||||
*/
|
*/
|
||||||
public abstract List<T> loadObjects() throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException;
|
public abstract List<T> loadObjects() throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException, IllegalArgumentException, NoSuchMethodException, SecurityException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a <T> filled with values from the corresponding
|
* Creates a <T> filled with values from the corresponding
|
||||||
* database file
|
* database file
|
||||||
* @param uniqueId - unique ID
|
* @param uniqueId - unique ID
|
||||||
* @return <T>
|
* @return <T>
|
||||||
|
* @throws SecurityException
|
||||||
|
* @throws NoSuchMethodException
|
||||||
|
* @throws IllegalArgumentException
|
||||||
*/
|
*/
|
||||||
public abstract T loadObject(String uniqueId) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException;
|
public abstract T loadObject(String uniqueId) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException, IllegalArgumentException, NoSuchMethodException, SecurityException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save T into the corresponding database
|
* Save T into the corresponding database
|
||||||
|
@ -49,7 +49,8 @@ public class Database<T> {
|
|||||||
try {
|
try {
|
||||||
result = handler.loadObjects();
|
result = handler.loadObjects();
|
||||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
|
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
|
||||||
| InvocationTargetException | ClassNotFoundException | IntrospectionException e) {
|
| InvocationTargetException | ClassNotFoundException | IntrospectionException
|
||||||
|
| NoSuchMethodException | SecurityException e) {
|
||||||
logger.severe(() -> "Could not load objects from database! Error: " + e.getMessage());
|
logger.severe(() -> "Could not load objects from database! Error: " + e.getMessage());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@ -65,7 +66,7 @@ public class Database<T> {
|
|||||||
try {
|
try {
|
||||||
result = handler.loadObject(uniqueId);
|
result = handler.loadObject(uniqueId);
|
||||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
||||||
| ClassNotFoundException | IntrospectionException e) {
|
| ClassNotFoundException | IntrospectionException | NoSuchMethodException | SecurityException e) {
|
||||||
logger.severe(() -> "Could not load object from database! " + e.getMessage());
|
logger.severe(() -> "Could not load object from database! " + e.getMessage());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -25,7 +25,7 @@ public class ConfigHandler<T> extends FlatFileDatabaseHandler<T> {
|
|||||||
saveObject(instance);
|
saveObject(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T loadSettings(String uniqueId, T dbConfig) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException {
|
public T loadSettings(String uniqueId, T dbConfig) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException, IllegalArgumentException, NoSuchMethodException, SecurityException {
|
||||||
if (dbConfig == null) {
|
if (dbConfig == null) {
|
||||||
return loadObject(uniqueId);
|
return loadObject(uniqueId);
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
* @see world.bentobox.bentobox.database.AbstractDatabaseHandler#loadObject(java.lang.String)
|
* @see world.bentobox.bentobox.database.AbstractDatabaseHandler#loadObject(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public T loadObject(String key) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException {
|
public T loadObject(String key) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException, IllegalArgumentException, NoSuchMethodException, SecurityException {
|
||||||
// Objects are loaded from a folder named after the simple name of the class being stored
|
// Objects are loaded from a folder named after the simple name of the class being stored
|
||||||
String path = DATABASE_FOLDER_NAME + File.separator + dataObject.getSimpleName();
|
String path = DATABASE_FOLDER_NAME + File.separator + dataObject.getSimpleName();
|
||||||
// This path and key can be overridden by the StoreAt annotation in the code
|
// This path and key can be overridden by the StoreAt annotation in the code
|
||||||
@ -97,7 +97,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
* @see world.bentobox.bentobox.database.AbstractDatabaseHandler#loadObjects()
|
* @see world.bentobox.bentobox.database.AbstractDatabaseHandler#loadObjects()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<T> loadObjects() throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException {
|
public List<T> loadObjects() throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException, IllegalArgumentException, NoSuchMethodException, SecurityException {
|
||||||
// In this case, all the objects of a specific type are being loaded.
|
// In this case, all the objects of a specific type are being loaded.
|
||||||
List<T> list = new ArrayList<>();
|
List<T> list = new ArrayList<>();
|
||||||
// Look for any files that end in .yml in the folder
|
// Look for any files that end in .yml in the folder
|
||||||
@ -135,10 +135,13 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
* @param config - YAML config file
|
* @param config - YAML config file
|
||||||
*
|
*
|
||||||
* @return <T> filled with values
|
* @return <T> filled with values
|
||||||
|
* @throws SecurityException
|
||||||
|
* @throws NoSuchMethodException
|
||||||
|
* @throws IllegalArgumentException
|
||||||
*/
|
*/
|
||||||
private T createObject(YamlConfiguration config) throws InstantiationException, IllegalAccessException, IntrospectionException, InvocationTargetException, ClassNotFoundException {
|
private T createObject(YamlConfiguration config) throws InstantiationException, IllegalAccessException, IntrospectionException, InvocationTargetException, ClassNotFoundException, IllegalArgumentException, NoSuchMethodException, SecurityException {
|
||||||
// Create a new instance of the dataObject of type T (which can be any class)
|
// Create a new instance of the dataObject of type T (which can be any class)
|
||||||
T instance = dataObject.newInstance();
|
T instance = dataObject.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
// Run through all the fields in the object
|
// Run through all the fields in the object
|
||||||
for (Field field : dataObject.getDeclaredFields()) {
|
for (Field field : dataObject.getDeclaredFields()) {
|
||||||
@ -167,7 +170,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
// Get the original value to be stored
|
// Get the original value to be stored
|
||||||
Object value = config.get(storageLocation);
|
Object value = config.get(storageLocation);
|
||||||
// Invoke the deserialization on this value
|
// Invoke the deserialization on this value
|
||||||
method.invoke(instance, ((AdapterInterface<?,?>)adapterNotation.value().newInstance()).deserialize(value));
|
method.invoke(instance, ((AdapterInterface<?,?>)adapterNotation.value().getDeclaredConstructor().newInstance()).deserialize(value));
|
||||||
// We are done here. If a custom adapter was defined, the rest of this method does not need to be run
|
// We are done here. If a custom adapter was defined, the rest of this method does not need to be run
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -354,8 +357,8 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) {
|
if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) {
|
||||||
// A conversion adapter has been defined
|
// A conversion adapter has been defined
|
||||||
try {
|
try {
|
||||||
config.set(storageLocation, ((AdapterInterface<?,?>)adapterNotation.value().newInstance()).serialize(value));
|
config.set(storageLocation, ((AdapterInterface<?,?>)adapterNotation.value().getDeclaredConstructor().newInstance()).serialize(value));
|
||||||
} catch (InstantiationException e) {
|
} catch (InstantiationException | IllegalArgumentException | NoSuchMethodException | SecurityException e) {
|
||||||
plugin.logError("Could not instatiate adapter " + adapterNotation.value().getName() + " " + e.getMessage());
|
plugin.logError("Could not instatiate adapter " + adapterNotation.value().getName() + " " + e.getMessage());
|
||||||
}
|
}
|
||||||
// We are done here
|
// We are done here
|
||||||
|
@ -24,12 +24,12 @@ public class MySQLDatabaseConnector implements DatabaseConnector {
|
|||||||
public MySQLDatabaseConnector(DatabaseConnectionSettingsImpl dbSettings) {
|
public MySQLDatabaseConnector(DatabaseConnectionSettingsImpl dbSettings) {
|
||||||
this.dbSettings = dbSettings;
|
this.dbSettings = dbSettings;
|
||||||
try {
|
try {
|
||||||
Class.forName("com.mysql.jdbc.Driver").newInstance();
|
Class.forName("com.mysql.jdbc.Driver").getDeclaredConstructor().newInstance();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Bukkit.getLogger().severe("Could not instantiate JDBC driver! " + e.getMessage());
|
Bukkit.getLogger().severe("Could not instantiate JDBC driver! " + e.getMessage());
|
||||||
}
|
}
|
||||||
// jdbc:mysql://localhost:3306/Peoples?autoReconnect=true&useSSL=false
|
connectionUrl = "jdbc:mysql://" + dbSettings.getHost() + ":" + dbSettings.getPort() + "/" + dbSettings.getDatabaseName()
|
||||||
connectionUrl = "jdbc:mysql://" + dbSettings.getHost() + ":" + dbSettings.getPort() + "/" + dbSettings.getDatabaseName() + "?autoReconnect=true&useSSL=false&allowMultiQueries=true";
|
+ "?autoReconnect=true&useSSL=false&allowMultiQueries=true";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user