Fixed extension column appearing multiple times

This commit is contained in:
Rsl1122 2019-05-12 13:23:40 +03:00
parent ad48a016a3
commit ef35312844

View File

@ -34,7 +34,6 @@ import com.djrapitops.plan.utilities.html.icon.Family;
import com.djrapitops.plan.utilities.html.icon.Icon; import com.djrapitops.plan.utilities.html.icon.Icon;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* Parsing utility for creating jQuery Datatables JSON for a Players Table. * Parsing utility for creating jQuery Datatables JSON for a Players Table.
@ -70,11 +69,11 @@ public class PlayersTableJSONParser {
// Data // Data
this.players = players; this.players = players;
this.extensionData = extensionData; this.extensionData = extensionData;
extensionDescriptives = extensionData.values().stream()
.map(ExtensionTabData::getDescriptives) extensionDescriptives = new ArrayList<>();
.flatMap(Collection::stream) addExtensionDescriptives(extensionData);
.distinct().sorted((one, two) -> String.CASE_INSENSITIVE_ORDER.compare(one.getName(), two.getName())) extensionDescriptives.sort((one, two) -> String.CASE_INSENSITIVE_ORDER.compare(one.getName(), two.getName()));
.collect(Collectors.toList());
// Settings // Settings
this.maxPlayers = maxPlayers; this.maxPlayers = maxPlayers;
this.activeMsThreshold = activeMsThreshold; this.activeMsThreshold = activeMsThreshold;
@ -90,6 +89,18 @@ public class PlayersTableJSONParser {
this.decimalFormatter = formatters.decimals(); this.decimalFormatter = formatters.decimals();
} }
private void addExtensionDescriptives(Map<UUID, ExtensionTabData> extensionData) {
Set<String> foundDescriptives = new HashSet<>();
for (ExtensionTabData tabData : extensionData.values()) {
for (ExtensionDescriptive descriptive : tabData.getDescriptives()) {
if (!foundDescriptives.contains(descriptive.getName())) {
extensionDescriptives.add(descriptive);
foundDescriptives.add(descriptive.getName());
}
}
}
}
public String toJSONString() { public String toJSONString() {
String data = parseData(); String data = parseData();
String columnHeaders = parseColumnHeaders(); String columnHeaders = parseColumnHeaders();