mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-10-01 16:17:30 +02:00
Added equals to User class
Added null check for FlatFileDB Handler.
This commit is contained in:
parent
5a3a557cf2
commit
b043e641a1
@ -291,4 +291,39 @@ public class User {
|
|||||||
return player.performCommand(cmd);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,19 +196,21 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
}
|
}
|
||||||
// TODO: this may not work with all keys. Further serialization may be required.
|
// TODO: this may not work with all keys. Further serialization may be required.
|
||||||
Map<Object,Object> value = new HashMap<>();
|
Map<Object,Object> value = new HashMap<>();
|
||||||
for (String key : config.getConfigurationSection(storageLocation).getKeys(false)) {
|
if (config.getConfigurationSection(storageLocation) != null) {
|
||||||
// Keys cannot be null - skip if they exist
|
for (String key : config.getConfigurationSection(storageLocation).getKeys(false)) {
|
||||||
Object mapKey = deserialize(key,Class.forName(keyType.getTypeName()));
|
// Keys cannot be null - skip if they exist
|
||||||
if (mapKey == null) {
|
Object mapKey = deserialize(key,Class.forName(keyType.getTypeName()));
|
||||||
continue;
|
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);
|
method.invoke(instance, value);
|
||||||
} else if (Set.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
|
} else if (Set.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
|
||||||
|
Loading…
Reference in New Issue
Block a user