mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-27 03:27:37 +01:00
Split server page plugin players table creation into a separate class
This commit is contained in:
parent
2f886ac124
commit
1efa9f7f9d
@ -18,7 +18,7 @@ import java.util.List;
|
||||
*/
|
||||
public class TableContainer {
|
||||
|
||||
private final String[] header;
|
||||
protected final String[] header;
|
||||
private List<Serializable[]> values;
|
||||
|
||||
private boolean jqueryDatatable;
|
||||
|
@ -9,7 +9,7 @@ import com.djrapitops.plan.data.element.InspectContainer;
|
||||
import com.djrapitops.plan.data.plugin.PluginData;
|
||||
import com.djrapitops.plan.utilities.analysis.Analysis;
|
||||
import com.djrapitops.plan.utilities.comparators.PluginDataNameComparator;
|
||||
import com.djrapitops.plan.utilities.html.tables.PlayersTableCreator;
|
||||
import com.djrapitops.plan.utilities.html.tables.PluginPlayersTable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -73,8 +73,7 @@ public class AnalysisPluginsTabContentCreator {
|
||||
"<div class=\"card\">" +
|
||||
"<div class=\"header\"><h2><i class=\"fa fa-users\"></i> Plugin Data</h2></div>" +
|
||||
"<div class=\"body\">" +
|
||||
"<div class=\"table-responsive\">" +
|
||||
PlayersTableCreator.createPluginsTable(containers, Analysis.getServerProfile().getPlayers()) +
|
||||
new PluginPlayersTable(containers, Analysis.getServerProfile().getPlayers()).parseHtml() +
|
||||
"</div></div></div>" +
|
||||
"</div></div></div>";
|
||||
|
||||
|
@ -3,18 +3,14 @@ package com.djrapitops.plan.utilities.html.tables;
|
||||
import com.djrapitops.plan.api.PlanAPI;
|
||||
import com.djrapitops.plan.data.PlayerProfile;
|
||||
import com.djrapitops.plan.data.calculation.ActivityIndex;
|
||||
import com.djrapitops.plan.data.element.AnalysisContainer;
|
||||
import com.djrapitops.plan.data.element.TableContainer;
|
||||
import com.djrapitops.plan.data.plugin.PluginData;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.utilities.FormatUtils;
|
||||
import com.djrapitops.plan.utilities.html.Html;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
@ -84,67 +80,4 @@ public class PlayersTableCreator {
|
||||
|
||||
return html.toString();
|
||||
}
|
||||
|
||||
public static String createPluginsTable(Map<PluginData, AnalysisContainer> containers, Collection<PlayerProfile> players) {
|
||||
TreeMap<String, Map<UUID, ? extends Serializable>> data = new TreeMap<>();
|
||||
for (AnalysisContainer container : containers.values()) {
|
||||
if (!container.hasPlayerTableValues()) {
|
||||
continue;
|
||||
}
|
||||
data.putAll(container.getPlayerTableValues());
|
||||
}
|
||||
|
||||
List<String> header = new ArrayList<>(data.keySet());
|
||||
Collections.sort(header);
|
||||
|
||||
int size = header.size();
|
||||
TableContainer tableContainer = new TableContainer(true, header.toArray(new String[size]));
|
||||
|
||||
try {
|
||||
if (players.isEmpty()) {
|
||||
tableContainer.addRow("<b>No Players</b>");
|
||||
throw new IllegalArgumentException("No players");
|
||||
}
|
||||
|
||||
Map<UUID, String[]> sortedData = new HashMap<>();
|
||||
|
||||
for (PlayerProfile profile : players) {
|
||||
UUID uuid = profile.getUuid();
|
||||
String[] playerdata = new String[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
String label = header.get(i);
|
||||
Map<UUID, ? extends Serializable> playerSpecificData = data.getOrDefault(label, new HashMap<>());
|
||||
Serializable value = playerSpecificData.get(uuid);
|
||||
if (value != null) {
|
||||
playerdata[i] = value.toString();
|
||||
} else {
|
||||
playerdata[i] = "-";
|
||||
}
|
||||
}
|
||||
sortedData.put(uuid, playerdata);
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
int maxPlayers = Settings.MAX_PLAYERS.getNumber();
|
||||
if (maxPlayers <= 0) {
|
||||
maxPlayers = 2000;
|
||||
}
|
||||
for (PlayerProfile profile : players) {
|
||||
if (i >= maxPlayers) {
|
||||
break;
|
||||
}
|
||||
UUID uuid = profile.getUuid();
|
||||
String link = Html.LINK_EXTERNAL.parse(PlanAPI.getInstance().getPlayerInspectPageLink(profile.getName()), profile.getName());
|
||||
|
||||
String[] playerData = FormatUtils.mergeArrays(new String[]{link}, sortedData.getOrDefault(uuid, new String[]{}));
|
||||
tableContainer.addRow(ArrayUtils.addAll(playerData));
|
||||
|
||||
i++;
|
||||
}
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
return tableContainer.parseHtml().replace(Html.TABLE_SCROLL.parse(), "<table class=\"table table-bordered table-striped table-hover player-table dataTable\">");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,105 @@
|
||||
package com.djrapitops.plan.utilities.html.tables;
|
||||
|
||||
import com.djrapitops.plan.api.PlanAPI;
|
||||
import com.djrapitops.plan.data.PlayerProfile;
|
||||
import com.djrapitops.plan.data.element.AnalysisContainer;
|
||||
import com.djrapitops.plan.data.element.TableContainer;
|
||||
import com.djrapitops.plan.data.plugin.PluginData;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.utilities.FormatUtils;
|
||||
import com.djrapitops.plan.utilities.html.Html;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* TableContainer that creates the html table for per player plugins values.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PluginPlayersTable extends TableContainer {
|
||||
|
||||
private Collection<PlayerProfile> players;
|
||||
|
||||
public PluginPlayersTable(Map<PluginData, AnalysisContainer> containers, Collection<PlayerProfile> players) {
|
||||
this(getPluginDataSet(containers), players);
|
||||
}
|
||||
|
||||
private PluginPlayersTable(TreeMap<String, Map<UUID, ? extends Serializable>> pluginDataSet, Collection<PlayerProfile> players) {
|
||||
super(true, getHeaders(pluginDataSet.keySet()));
|
||||
|
||||
this.players = players;
|
||||
|
||||
useJqueryDataTables();
|
||||
|
||||
if (players.isEmpty()) {
|
||||
addRow("No Players");
|
||||
} else {
|
||||
Map<UUID, String[]> rows = getRows(pluginDataSet);
|
||||
addValues(rows);
|
||||
}
|
||||
}
|
||||
|
||||
private static String[] getHeaders(Set<String> columnNames) {
|
||||
List<String> header = new ArrayList<>(columnNames);
|
||||
Collections.sort(header);
|
||||
return header.toArray(new String[0]);
|
||||
}
|
||||
|
||||
private static TreeMap<String, Map<UUID, ? extends Serializable>> getPluginDataSet(Map<PluginData, AnalysisContainer> containers) {
|
||||
TreeMap<String, Map<UUID, ? extends Serializable>> data = new TreeMap<>();
|
||||
for (AnalysisContainer container : containers.values()) {
|
||||
if (!container.hasPlayerTableValues()) {
|
||||
continue;
|
||||
}
|
||||
data.putAll(container.getPlayerTableValues());
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private void addValues(Map<UUID, String[]> rows) {
|
||||
int i = 0;
|
||||
int maxPlayers = Settings.MAX_PLAYERS.getNumber();
|
||||
if (maxPlayers <= 0) {
|
||||
maxPlayers = 2000;
|
||||
}
|
||||
for (PlayerProfile profile : players) {
|
||||
if (i >= maxPlayers) {
|
||||
break;
|
||||
}
|
||||
UUID uuid = profile.getUuid();
|
||||
String link = Html.LINK_EXTERNAL.parse(PlanAPI.getInstance().getPlayerInspectPageLink(profile.getName()), profile.getName());
|
||||
|
||||
String[] playerData = FormatUtils.mergeArrays(new String[]{link}, rows.getOrDefault(uuid, new String[]{}));
|
||||
addRow(ArrayUtils.addAll(playerData));
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
private Map<UUID, String[]> getRows(TreeMap<String, Map<UUID, ? extends Serializable>> data) {
|
||||
Map<UUID, String[]> rows = new HashMap<>();
|
||||
|
||||
int size = header.length - 1;
|
||||
for (PlayerProfile profile : players) {
|
||||
UUID uuid = profile.getUuid();
|
||||
|
||||
String[] row = new String[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
String label = header[i + 1];
|
||||
|
||||
Map<UUID, ? extends Serializable> playerSpecificData = data.getOrDefault(label, new HashMap<>());
|
||||
Serializable value = playerSpecificData.get(uuid);
|
||||
if (value != null) {
|
||||
row[i] = value.toString();
|
||||
} else {
|
||||
row[i] = "-";
|
||||
}
|
||||
}
|
||||
rows.put(uuid, row);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user