Fixed LogEntryListAdapter

Fixes #486
This commit is contained in:
Florian CUNY 2019-01-26 16:05:55 +01:00
parent b07d7ba3af
commit afdfc285cc
2 changed files with 29 additions and 2 deletions

View File

@ -100,7 +100,7 @@ public class Island implements DataObject {
//// Island History ////
@Adapter(LogEntryListAdapter.class)
//FIXME: see https://github.com/BentoBoxWorld/BentoBox/issues/482
@Expose
private List<LogEntry> history = new LinkedList<>();
@Expose

View File

@ -1,11 +1,14 @@
package world.bentobox.bentobox.database.objects.adapters;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.logs.LogEntry;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
* @author Poslovitch
@ -63,11 +66,35 @@ public class LogEntryListAdapter implements AdapterInterface<List<LogEntry>, Lis
Map<String, Object> value = new LinkedHashMap<>();
value.put(TIMESTAMP, logEntry.getTimestamp());
value.put(TYPE, logEntry.getType());
value.put(DATA, logEntry.getData());
if (logEntry.getData() != null) {
value.put(DATA, tidy(logEntry.getData()));
}
result.add(value);
});
return result;
}
/**
* Returns a "data" map that contains "tidied up" values, as some types are not safe to store 'as is'.
* See https://github.com/BentoBoxWorld/BentoBox/issues/486
* @param data the data map to tidy up
* @return the tidied up data map
* @since 1.1.1
*/
@NonNull
private Map<String, Object> tidy(@NonNull Map<String, Object> data) {
Map<String, Object> result = new HashMap<>();
for (Map.Entry<String, Object> entry : data.entrySet()) {
if (entry.getValue() instanceof UUID) {
// UUIDs need some special handling
result.put(entry.getKey(), entry.getValue().toString());
} else {
result.put(entry.getKey(), entry.getValue());
}
}
return result;
}
}