mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-28 05:35:44 +01:00
Fixed some code smells
This commit is contained in:
parent
102ad864e1
commit
2eb46b0c2c
@ -48,22 +48,16 @@ public abstract class AbstractDatabaseHandler<T> {
|
||||
/**
|
||||
* Loads all the records in this table and returns a list of them
|
||||
* @return list of <T>
|
||||
* @throws SecurityException
|
||||
* @throws NoSuchMethodException
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
public abstract List<T> loadObjects() throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException, IllegalArgumentException, NoSuchMethodException, SecurityException;
|
||||
public abstract List<T> loadObjects() throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException, NoSuchMethodException;
|
||||
|
||||
/**
|
||||
* Creates a <T> filled with values from the corresponding
|
||||
* database file
|
||||
* @param uniqueId - unique ID
|
||||
* @return <T>
|
||||
* @throws SecurityException
|
||||
* @throws NoSuchMethodException
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
public abstract T loadObject(String uniqueId) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException, IllegalArgumentException, NoSuchMethodException, SecurityException;
|
||||
public abstract T loadObject(String uniqueId) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException, NoSuchMethodException;
|
||||
|
||||
/**
|
||||
* Save T into the corresponding database
|
||||
|
@ -25,7 +25,7 @@ public class ConfigHandler<T> extends FlatFileDatabaseHandler<T> {
|
||||
saveObject(instance);
|
||||
}
|
||||
|
||||
public T loadSettings(String uniqueId, T dbConfig) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException, IllegalArgumentException, NoSuchMethodException, SecurityException {
|
||||
public T loadSettings(String uniqueId, T dbConfig) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException, NoSuchMethodException {
|
||||
if (dbConfig == null) {
|
||||
return loadObject(uniqueId);
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
* @see world.bentobox.bentobox.database.AbstractDatabaseHandler#loadObject(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public T loadObject(String key) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException, IllegalArgumentException, NoSuchMethodException, SecurityException {
|
||||
public T loadObject(String key) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException, NoSuchMethodException {
|
||||
// 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();
|
||||
// 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()
|
||||
*/
|
||||
@Override
|
||||
public List<T> loadObjects() throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException, IllegalArgumentException, NoSuchMethodException, SecurityException {
|
||||
public List<T> loadObjects() throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException, NoSuchMethodException {
|
||||
// In this case, all the objects of a specific type are being loaded.
|
||||
List<T> list = new ArrayList<>();
|
||||
// Look for any files that end in .yml in the folder
|
||||
@ -139,7 +139,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
* @throws NoSuchMethodException
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
private T createObject(YamlConfiguration config) throws InstantiationException, IllegalAccessException, IntrospectionException, InvocationTargetException, ClassNotFoundException, IllegalArgumentException, NoSuchMethodException, SecurityException {
|
||||
private T createObject(YamlConfiguration config) throws InstantiationException, IllegalAccessException, IntrospectionException, InvocationTargetException, ClassNotFoundException, NoSuchMethodException {
|
||||
// Create a new instance of the dataObject of type T (which can be any class)
|
||||
T instance = dataObject.getDeclaredConstructor().newInstance();
|
||||
|
||||
|
@ -185,8 +185,7 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
preparedStatement.setString(1, "\"" + uniqueId + "\"");
|
||||
try (ResultSet resultSet = preparedStatement.executeQuery()) {
|
||||
if (resultSet.next()) {
|
||||
boolean result = resultSet.getBoolean(1);
|
||||
return result;
|
||||
return resultSet.getBoolean(1);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
|
@ -58,16 +58,17 @@ public class BreakBlocksListener extends AbstractFlagListener {
|
||||
|
||||
// Look along player's sight line to see if any blocks are skulls
|
||||
try {
|
||||
BlockIterator iter = new BlockIterator(e.getPlayer(), 10);
|
||||
Block lastBlock = iter.next();
|
||||
while (iter.hasNext()) {
|
||||
lastBlock = iter.next();
|
||||
BlockIterator iterator = new BlockIterator(e.getPlayer(), 10);
|
||||
while (iterator.hasNext()) {
|
||||
Block lastBlock = iterator.next();
|
||||
if (lastBlock.getType().toString().endsWith("_SKULL") || (lastBlock.getType().toString().endsWith("_HEAD") && !lastBlock.getType().equals(Material.PISTON_HEAD))) {
|
||||
checkIsland(e, lastBlock.getLocation(), Flags.BREAK_BLOCKS);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
} catch (Exception ignored) {
|
||||
// We can ignore this exception
|
||||
}
|
||||
|
||||
switch (e.getClickedBlock().getType()) {
|
||||
case CAKE:
|
||||
|
@ -233,12 +233,11 @@ public class AddonsManager {
|
||||
}
|
||||
// Load dependencies or soft dependencies
|
||||
Map<String,Addon> sortedAddons = new LinkedHashMap<>();
|
||||
List<Addon> remaining = new ArrayList<>();
|
||||
// Start with nodes with no dependencies
|
||||
addons.stream().filter(a -> a.getDescription().getDependencies().isEmpty() && a.getDescription().getSoftDependencies().isEmpty())
|
||||
.forEach(a -> sortedAddons.put(a.getDescription().getName(), a));
|
||||
// Fill remaining
|
||||
remaining = addons.stream().filter(a -> !sortedAddons.containsKey(a.getDescription().getName())).collect(Collectors.toList());
|
||||
List<Addon> remaining = addons.stream().filter(a -> !sortedAddons.containsKey(a.getDescription().getName())).collect(Collectors.toList());
|
||||
|
||||
// Run through remaining addons
|
||||
int index = 0;
|
||||
@ -257,7 +256,7 @@ public class AddonsManager {
|
||||
depIt.remove();
|
||||
}
|
||||
}
|
||||
if (deps.stream().allMatch(s -> !a.getDescription().getDependencies().contains(s))) {
|
||||
if (deps.stream().noneMatch(s -> a.getDescription().getDependencies().contains(s))) {
|
||||
// Add addons loaded
|
||||
sortedAddons.put(a.getDescription().getName(), a);
|
||||
it.remove();
|
||||
|
Loading…
Reference in New Issue
Block a user