Added equals to User class

Added null check for FlatFileDB Handler.
This commit is contained in:
Tastybento 2018-02-24 21:29:51 -08:00
parent 5a3a557cf2
commit b043e641a1
2 changed files with 49 additions and 12 deletions

View File

@ -291,4 +291,39 @@ public class User {
return player.performCommand(cmd);
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((playerUUID == null) ? 0 : playerUUID.hashCode());
return result;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof User)) {
return false;
}
User other = (User) obj;
if (playerUUID == null) {
if (other.playerUUID != null) {
return false;
}
} else if (!playerUUID.equals(other.playerUUID)) {
return false;
}
return true;
}
}

View File

@ -196,19 +196,21 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
}
// TODO: this may not work with all keys. Further serialization may be required.
Map<Object,Object> value = new HashMap<>();
for (String key : config.getConfigurationSection(storageLocation).getKeys(false)) {
// Keys cannot be null - skip if they exist
Object mapKey = deserialize(key,Class.forName(keyType.getTypeName()));
if (mapKey == null) {
continue;
if (config.getConfigurationSection(storageLocation) != null) {
for (String key : config.getConfigurationSection(storageLocation).getKeys(false)) {
// Keys cannot be null - skip if they exist
Object mapKey = deserialize(key,Class.forName(keyType.getTypeName()));
if (mapKey == null) {
continue;
}
// Map values can be null - it is allowed here
Object mapValue = deserialize(config.get(storageLocation + "." + key), Class.forName(valueType.getTypeName()));
if (DEBUG) {
plugin.getLogger().info(() -> "DEBUG: mapKey = " + mapKey + " (" + mapKey.getClass().getCanonicalName() + ")");
plugin.getLogger().info(() -> "DEBUG: mapValue = " + mapValue);
}
value.put(mapKey, mapValue);
}
// Map values can be null - it is allowed here
Object mapValue = deserialize(config.get(storageLocation + "." + key), Class.forName(valueType.getTypeName()));
if (DEBUG) {
plugin.getLogger().info(() -> "DEBUG: mapKey = " + mapKey + " (" + mapKey.getClass().getCanonicalName() + ")");
plugin.getLogger().info(() -> "DEBUG: mapValue = " + mapValue);
}
value.put(mapKey, mapValue);
}
method.invoke(instance, value);
} else if (Set.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {