ListFlag#merge should not allow duplicates (Fixes #3157) (#3265)

This commit is contained in:
Pierre Maurice Schwang 2021-10-01 21:52:30 +02:00 committed by NotMyFault
parent 20c2f36f6c
commit 541255fe7e
No known key found for this signature in database
GPG Key ID: 158F5701A6AAD00C

View File

@ -43,8 +43,18 @@ public abstract class ListFlag<V, F extends PlotFlag<List<V>, F>> extends PlotFl
@Override
public F merge(@NonNull List<V> newValue) {
final List<V> mergedList = new ArrayList<>();
mergedList.addAll(getValue());
mergedList.addAll(newValue);
// If a server already used PS before this fix, we remove all present duplicates on an eventual merge
for (final V v : getValue()) {
if (!mergedList.contains(v)) {
mergedList.add(v);
}
}
// Only add new values if not already present from #getValue()
for (final V v : newValue) {
if (!mergedList.contains(v)) {
mergedList.add(v);
}
}
return this.flagOf(mergedList);
}