mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-08-26 22:49:51 +02:00
[Debt] Created HtmlTable factory for Table creation
Inject HtmlTables to access the factory. Abstracted away details of TableContainer creation in the factory. Each table class is now package private, and present as TableContainers. Removed MapComparator as it became obsolete. Affected issues: none
This commit is contained in:
parent
fac06e7d80
commit
b4f7053936
|
@ -27,10 +27,7 @@ import com.djrapitops.plan.utilities.html.graphs.stack.StackGraph;
|
|||
import com.djrapitops.plan.utilities.html.structure.AnalysisPluginsTabContentCreator;
|
||||
import com.djrapitops.plan.utilities.html.structure.RecentLoginList;
|
||||
import com.djrapitops.plan.utilities.html.structure.SessionAccordion;
|
||||
import com.djrapitops.plan.utilities.html.tables.CommandUseTable;
|
||||
import com.djrapitops.plan.utilities.html.tables.PingTable;
|
||||
import com.djrapitops.plan.utilities.html.tables.PlayersTable;
|
||||
import com.djrapitops.plan.utilities.html.tables.ServerSessionTable;
|
||||
import com.djrapitops.plan.utilities.html.tables.HtmlTables;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
|
||||
import java.util.*;
|
||||
|
@ -55,6 +52,7 @@ public class AnalysisContainer extends DataContainer {
|
|||
private Database database;
|
||||
private ServerProperties serverProperties;
|
||||
private Graphs graphs;
|
||||
private HtmlTables tables;
|
||||
|
||||
private Formatter<DateHolder> yearFormatter;
|
||||
private Formatter<Long> secondLongFormatter;
|
||||
|
@ -160,10 +158,10 @@ public class AnalysisContainer extends DataContainer {
|
|||
);
|
||||
putSupplier(AnalysisKeys.OPERATORS, () -> serverContainer.getValue(ServerKeys.OPERATORS).map(List::size).orElse(0));
|
||||
putSupplier(AnalysisKeys.PLAYERS_TABLE, () ->
|
||||
PlayersTable.forServerPage(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).all()).parseHtml()
|
||||
tables.playerTableForServerPage(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).all()).parseHtml()
|
||||
);
|
||||
putSupplier(AnalysisKeys.PING_TABLE, () ->
|
||||
new PingTable(
|
||||
tables.pingTable(
|
||||
getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)
|
||||
.getPingPerCountry(serverContainer.getUnsafe(ServerKeys.SERVER_UUID))
|
||||
).parseHtml()
|
||||
|
@ -283,7 +281,7 @@ public class AnalysisContainer extends DataContainer {
|
|||
serverContainer.getValue(ServerKeys.PLAYERS).orElse(new ArrayList<>())
|
||||
).toHtml()
|
||||
);
|
||||
putSupplier(AnalysisKeys.SESSION_TABLE, () -> new ServerSessionTable(
|
||||
putSupplier(AnalysisKeys.SESSION_TABLE, () -> tables.serverSessionTable(
|
||||
getUnsafe(AnalysisKeys.PLAYER_NAMES), getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).all()).parseHtml()
|
||||
);
|
||||
|
||||
|
@ -422,7 +420,7 @@ public class AnalysisContainer extends DataContainer {
|
|||
}
|
||||
|
||||
private void addCommandSuppliers() {
|
||||
putSupplier(AnalysisKeys.COMMAND_USAGE_TABLE, () -> new CommandUseTable(serverContainer).parseHtml());
|
||||
putSupplier(AnalysisKeys.COMMAND_USAGE_TABLE, () -> tables.commandUseTable(serverContainer).parseHtml());
|
||||
putSupplier(AnalysisKeys.COMMAND_COUNT_UNIQUE, () -> serverContainer.getValue(ServerKeys.COMMAND_USAGE).map(Map::size).orElse(0));
|
||||
putSupplier(AnalysisKeys.COMMAND_COUNT, () -> CommandUseMutator.forContainer(serverContainer).commandUsageCount());
|
||||
}
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
package com.djrapitops.plan.utilities.comparators;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class MapComparator {
|
||||
|
||||
/**
|
||||
* Constructor used to hide the public constructor
|
||||
*/
|
||||
private MapComparator() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts a Map of String, Integer by the Values of the Map.
|
||||
*
|
||||
* @param map Map to sort
|
||||
* @return List with String Array, where first value is the value and second
|
||||
* is the key.
|
||||
*/
|
||||
public static List<String[]> sortByValue(Map<String, Integer> map) {
|
||||
List<String[]> sortedList = new ArrayList<>();
|
||||
map.keySet().forEach(key -> sortedList.add(new String[]{String.valueOf(map.get(key)), key}));
|
||||
sortedList.sort(Comparator.comparingInt(strings -> Integer.parseInt(strings[0])));
|
||||
return sortedList;
|
||||
}
|
||||
|
||||
}
|
|
@ -29,7 +29,7 @@ import com.djrapitops.plan.utilities.html.graphs.calendar.PlayerCalendar;
|
|||
import com.djrapitops.plan.utilities.html.graphs.pie.WorldPie;
|
||||
import com.djrapitops.plan.utilities.html.structure.ServerAccordion;
|
||||
import com.djrapitops.plan.utilities.html.structure.SessionAccordion;
|
||||
import com.djrapitops.plan.utilities.html.tables.*;
|
||||
import com.djrapitops.plan.utilities.html.tables.HtmlTables;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.benchmarking.Timings;
|
||||
|
||||
|
@ -48,6 +48,7 @@ public class InspectPage implements Page {
|
|||
|
||||
private final PlanConfig config;
|
||||
private final Graphs graphs;
|
||||
private final HtmlTables tables;
|
||||
private final ServerInfo serverInfo;
|
||||
private final Timings timings;
|
||||
|
||||
|
@ -60,13 +61,16 @@ public class InspectPage implements Page {
|
|||
PlayerContainer player, Map<UUID, String> serverNames,
|
||||
PlanConfig config,
|
||||
Graphs graphs,
|
||||
Formatters formatters, ServerInfo serverInfo,
|
||||
HtmlTables tables,
|
||||
Formatters formatters,
|
||||
ServerInfo serverInfo,
|
||||
Timings timings
|
||||
) {
|
||||
this.player = player;
|
||||
this.serverNames = serverNames;
|
||||
this.config = config;
|
||||
this.graphs = graphs;
|
||||
this.tables = tables;
|
||||
this.serverInfo = serverInfo;
|
||||
this.timings = timings;
|
||||
|
||||
|
@ -134,10 +138,10 @@ public class InspectPage implements Page {
|
|||
String favoriteServer = serverNames.getOrDefault(perServerMutator.favoriteServer(), "Unknown");
|
||||
replacer.put("favoriteServer", favoriteServer);
|
||||
|
||||
replacer.put("tableBodyNicknames", new NicknameTable(
|
||||
player.getValue(PlayerKeys.NICKNAMES).orElse(new ArrayList<>()), serverNames)
|
||||
.parseBody());
|
||||
replacer.put("tableBodyIPs", new GeoInfoTable(player.getValue(PlayerKeys.GEO_INFO).orElse(new ArrayList<>())).parseBody());
|
||||
replacer.put("tableBodyNicknames",
|
||||
tables.nicknameTable(player.getValue(PlayerKeys.NICKNAMES).orElse(new ArrayList<>()), serverNames).parseBody()
|
||||
);
|
||||
replacer.put("tableBodyIPs", tables.geoInfoTable(player.getValue(PlayerKeys.GEO_INFO).orElse(new ArrayList<>())).parseBody());
|
||||
|
||||
PingMutator pingMutator = PingMutator.forContainer(player);
|
||||
double averagePing = pingMutator.average();
|
||||
|
@ -157,7 +161,7 @@ public class InspectPage implements Page {
|
|||
replacer.put("accordionSessions", "<div class=\"body\">" + "<p>No Sessions</p>" + "</div>");
|
||||
} else {
|
||||
if (config.isTrue(Settings.DISPLAY_SESSIONS_AS_TABLE)) {
|
||||
replacer.put("accordionSessions", new PlayerSessionTable(playerName, allSessions).parseHtml());
|
||||
replacer.put("accordionSessions", tables.playerSessionTable(playerName, allSessions).parseHtml());
|
||||
} else {
|
||||
SessionAccordion sessionAccordion = SessionAccordion.forPlayer(allSessions, () -> serverNames);
|
||||
replacer.put("accordionSessions", sessionAccordion.toHtml());
|
||||
|
@ -285,8 +289,8 @@ public class InspectPage implements Page {
|
|||
}
|
||||
|
||||
private void pvpAndPve(PlaceholderReplacer replacer, SessionsMutator sessionsMutator, SessionsMutator weekSessionsMutator, SessionsMutator monthSessionsMutator) {
|
||||
String playerKillsTable = new KillsTable(sessionsMutator.toPlayerKillList()).parseHtml();
|
||||
String playerDeathTable = new DeathsTable(sessionsMutator.toPlayerDeathList()).parseHtml();
|
||||
String playerKillsTable = tables.killsTable(sessionsMutator.toPlayerKillList(), "red").parseHtml();
|
||||
String playerDeathTable = tables.deathsTable(sessionsMutator.toPlayerDeathList()).parseHtml();
|
||||
|
||||
PvpInfoMutator pvpInfoMutator = PvpInfoMutator.forMutator(sessionsMutator);
|
||||
PvpInfoMutator pvpInfoMutatorMonth = PvpInfoMutator.forMutator(monthSessionsMutator);
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.djrapitops.plan.system.info.server.ServerInfo;
|
|||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.plan.utilities.html.graphs.Graphs;
|
||||
import com.djrapitops.plan.utilities.html.tables.HtmlTables;
|
||||
import com.djrapitops.plugin.benchmarking.Timings;
|
||||
import com.djrapitops.plugin.logging.debug.DebugLogger;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
|
@ -34,6 +35,7 @@ public class PageFactory {
|
|||
private final Lazy<ServerInfo> serverInfo;
|
||||
private final Lazy<ConnectionSystem> connectionSystem;
|
||||
private final Lazy<Graphs> graphs;
|
||||
private final Lazy<HtmlTables> tables;
|
||||
private final Lazy<Formatters> formatters;
|
||||
private final Lazy<DebugLogger> debugLogger;
|
||||
private final Lazy<Timings> timings;
|
||||
|
@ -47,6 +49,7 @@ public class PageFactory {
|
|||
Lazy<ServerInfo> serverInfo,
|
||||
Lazy<ConnectionSystem> connectionSystem,
|
||||
Lazy<Graphs> graphs,
|
||||
Lazy<HtmlTables> tables,
|
||||
Lazy<Formatters> formatters,
|
||||
Lazy<DebugLogger> debugLogger,
|
||||
Lazy<Timings> timings,
|
||||
|
@ -58,6 +61,7 @@ public class PageFactory {
|
|||
this.serverInfo = serverInfo;
|
||||
this.connectionSystem = connectionSystem;
|
||||
this.graphs = graphs;
|
||||
this.tables = tables;
|
||||
this.formatters = formatters;
|
||||
this.debugLogger = debugLogger;
|
||||
this.timings = timings;
|
||||
|
@ -73,11 +77,12 @@ public class PageFactory {
|
|||
}
|
||||
|
||||
public PlayersPage playersPage() {
|
||||
return new PlayersPage(version, config.get(), database.get(), serverInfo.get(), timings.get());
|
||||
return new PlayersPage(version, config.get(), database.get(), serverInfo.get(), tables.get(), timings.get());
|
||||
}
|
||||
|
||||
public AnalysisPage analysisPage(UUID serverUUID) {
|
||||
return new AnalysisPage(new AnalysisContainer(database.get().fetch().getServerContainer(serverUUID)), decimalFormatter);
|
||||
AnalysisContainer analysisContainer = new AnalysisContainer(database.get().fetch().getServerContainer(serverUUID));
|
||||
return new AnalysisPage(analysisContainer, formatters.get().decimals());
|
||||
}
|
||||
|
||||
public InspectPage inspectPage(UUID uuid) {
|
||||
|
@ -85,7 +90,7 @@ public class PageFactory {
|
|||
Map<UUID, String> serverNames = database.get().fetch().getServerNames();
|
||||
return new InspectPage(
|
||||
player, serverNames,
|
||||
config.get(), graphs.get(), formatters.get(), serverInfo.get(), timings.get()
|
||||
config.get(), graphs.get(), tables.get(), formatters.get(), serverInfo.get(), timings.get()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,13 +2,13 @@ package com.djrapitops.plan.utilities.html.pages;
|
|||
|
||||
import com.djrapitops.plan.api.exceptions.ParseException;
|
||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
||||
import com.djrapitops.plan.utilities.formatting.PlaceholderReplacer;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.utilities.file.FileUtil;
|
||||
import com.djrapitops.plan.utilities.html.tables.PlayersTable;
|
||||
import com.djrapitops.plan.utilities.formatting.PlaceholderReplacer;
|
||||
import com.djrapitops.plan.utilities.html.tables.HtmlTables;
|
||||
import com.djrapitops.plugin.api.Check;
|
||||
import com.djrapitops.plugin.benchmarking.Timings;
|
||||
|
||||
|
@ -26,6 +26,8 @@ public class PlayersPage implements Page {
|
|||
private final Database database;
|
||||
private final ServerInfo serverInfo;
|
||||
|
||||
private final HtmlTables tables;
|
||||
|
||||
private final Timings timings;
|
||||
|
||||
PlayersPage(
|
||||
|
@ -33,12 +35,14 @@ public class PlayersPage implements Page {
|
|||
PlanConfig config,
|
||||
Database database,
|
||||
ServerInfo serverInfo,
|
||||
HtmlTables tables,
|
||||
Timings timings
|
||||
) {
|
||||
this.version = version;
|
||||
this.config = config;
|
||||
this.database = database;
|
||||
this.serverInfo = serverInfo;
|
||||
this.tables = tables;
|
||||
this.timings = timings;
|
||||
}
|
||||
|
||||
|
@ -56,7 +60,7 @@ public class PlayersPage implements Page {
|
|||
|
||||
timings.start("Players page players table parsing");
|
||||
List<PlayerContainer> playerContainers = database.fetch().getAllPlayerContainers();
|
||||
placeholderReplacer.put("playersTable", PlayersTable.forPlayersPage(playerContainers).parseHtml());
|
||||
placeholderReplacer.put("playersTable", tables.playerTableForPlayersPage(playerContainers).parseHtml());
|
||||
timings.end("Pages", "Players page players table parsing");
|
||||
|
||||
return placeholderReplacer.apply(FileUtil.getStringFromResource("web/players.html"));
|
||||
|
|
|
@ -11,7 +11,7 @@ import com.djrapitops.plan.data.plugin.HookHandler;
|
|||
import com.djrapitops.plan.data.plugin.PluginData;
|
||||
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
||||
import com.djrapitops.plan.utilities.comparators.PluginDataNameComparator;
|
||||
import com.djrapitops.plan.utilities.html.tables.PluginPlayersTable;
|
||||
import com.djrapitops.plan.utilities.html.tables.HtmlTables;
|
||||
import com.djrapitops.plugin.StaticHolder;
|
||||
import com.djrapitops.plugin.api.Benchmark;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
|
@ -76,13 +76,15 @@ public class AnalysisPluginsTabContentCreator {
|
|||
|
||||
generalTab.append("</div></div>");
|
||||
|
||||
HtmlTables tables = null; // TODO Use HtmlTables
|
||||
|
||||
String playerListTab = "<div class=\"tab\">" +
|
||||
"<div class=\"row clearfix\">" +
|
||||
"<div class=\"col-lg-12 col-md-12 col-sm-12 col-xs-12\">" +
|
||||
"<div class=\"card\">" +
|
||||
"<div class=\"header\"><h2><i class=\"fa fa-users\"></i> Plugin Data</h2></div>" +
|
||||
"<div class=\"body\">" +
|
||||
new PluginPlayersTable(containers, mutator.all()).parseHtml() +
|
||||
tables.pluginPlayersTable(containers, mutator.all()).parseHtml() +
|
||||
"</div></div></div>" +
|
||||
"</div></div>";
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.djrapitops.plan.utilities.html.structure;
|
||||
|
||||
import com.djrapitops.plan.api.PlanAPI;
|
||||
import com.djrapitops.plan.data.container.PlayerKill;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.store.keys.SessionKeys;
|
||||
import com.djrapitops.plan.data.store.objects.DateHolder;
|
||||
|
@ -14,7 +15,7 @@ import com.djrapitops.plan.utilities.html.HtmlStructure;
|
|||
import com.djrapitops.plan.utilities.html.graphs.Graphs;
|
||||
import com.djrapitops.plan.utilities.html.graphs.pie.WorldPie;
|
||||
import com.djrapitops.plan.utilities.html.icon.Icons;
|
||||
import com.djrapitops.plan.utilities.html.tables.KillsTable;
|
||||
import com.djrapitops.plan.utilities.html.tables.HtmlTables;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Supplier;
|
||||
|
@ -39,6 +40,7 @@ public class SessionAccordion extends AbstractAccordion {
|
|||
// TODO
|
||||
private Theme theme;
|
||||
private Graphs graphs;
|
||||
private HtmlTables tables;
|
||||
private Formatter<DateHolder> yearFormatter;
|
||||
private Formatter<Long> timeAmountFormatter;
|
||||
|
||||
|
@ -142,7 +144,8 @@ public class SessionAccordion extends AbstractAccordion {
|
|||
.append(worldHtmlID).append("gmseries")
|
||||
.append(");");
|
||||
|
||||
String leftBottom = new KillsTable(session.getValue(SessionKeys.PLAYER_KILLS).orElse(new ArrayList<>()), null).parseHtml();
|
||||
List<PlayerKill> kills = session.getValue(SessionKeys.PLAYER_KILLS).orElse(new ArrayList<>());
|
||||
String leftBottom = tables.killsTable(kills, null).parseHtml();
|
||||
|
||||
String link = PlanAPI.getInstance().getPlayerInspectPageLink(playerName);
|
||||
String rightBottom = "<a target=\"_blank\" href=\"" + link + "\"><button href=\"" + link +
|
||||
|
@ -213,7 +216,8 @@ public class SessionAccordion extends AbstractAccordion {
|
|||
.append(worldHtmlID).append("gmseries")
|
||||
.append(");");
|
||||
|
||||
String leftBottom = new KillsTable(session.getValue(SessionKeys.PLAYER_KILLS).orElse(new ArrayList<>()), null).parseHtml();
|
||||
List<PlayerKill> kills = session.getValue(SessionKeys.PLAYER_KILLS).orElse(new ArrayList<>());
|
||||
String leftBottom = tables.killsTable(kills, null).parseHtml();
|
||||
|
||||
addElement(new AccordionElement(htmlID, title)
|
||||
.setColor(theme.getValue(ThemeVal.PARSED_SESSION_ACCORDION))
|
||||
|
|
|
@ -3,27 +3,26 @@ package com.djrapitops.plan.utilities.html.tables;
|
|||
import com.djrapitops.plan.data.element.TableContainer;
|
||||
import com.djrapitops.plan.data.store.containers.DataContainer;
|
||||
import com.djrapitops.plan.data.store.keys.ServerKeys;
|
||||
import com.djrapitops.plan.utilities.comparators.MapComparator;
|
||||
import com.djrapitops.plan.utilities.html.HtmlUtils;
|
||||
import com.djrapitops.plan.utilities.html.icon.Icon;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Html table that displays how many times each command is used.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class CommandUseTable extends TableContainer {
|
||||
class CommandUseTable extends TableContainer {
|
||||
|
||||
public CommandUseTable(DataContainer container) {
|
||||
this(container.getValue(ServerKeys.COMMAND_USAGE).orElse(new HashMap<>()));
|
||||
}
|
||||
|
||||
public CommandUseTable(Map<String, Integer> commandUse) {
|
||||
CommandUseTable(DataContainer container) {
|
||||
super(Icon.called("terminal") + " Command", Icon.called("list-ol") + "Times Used");
|
||||
|
||||
Map<String, Integer> commandUse = container.getValue(ServerKeys.COMMAND_USAGE).orElse(new HashMap<>());
|
||||
|
||||
setColor("lime");
|
||||
if (commandUse.isEmpty()) {
|
||||
addRow("No Commands");
|
||||
|
@ -32,17 +31,22 @@ public class CommandUseTable extends TableContainer {
|
|||
}
|
||||
}
|
||||
|
||||
private List<Map.Entry<String, Integer>> sortByValue(Map<String, Integer> map) {
|
||||
return map.entrySet().stream()
|
||||
.sorted((one, two) -> Integer.compare(two.getValue(), one.getValue()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private void addValues(Map<String, Integer> commandUse) {
|
||||
List<String[]> sorted = MapComparator.sortByValue(commandUse);
|
||||
Collections.reverse(sorted);
|
||||
List<Map.Entry<String, Integer>> sorted = sortByValue(commandUse);
|
||||
|
||||
int i = 0;
|
||||
for (String[] values : sorted) {
|
||||
for (Map.Entry<String, Integer> entry : sorted) {
|
||||
if (i >= 500) {
|
||||
break;
|
||||
}
|
||||
String command = HtmlUtils.removeXSS(values[1]);
|
||||
addRow(command, values[0]);
|
||||
String command = HtmlUtils.removeXSS(entry.getKey());
|
||||
addRow(command, entry.getValue());
|
||||
|
||||
i++;
|
||||
}
|
||||
|
|
|
@ -13,15 +13,17 @@ import com.djrapitops.plan.utilities.html.icon.Icon;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Html table that displays Deaths of a single player.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class DeathsTable extends TableContainer {
|
||||
class DeathsTable extends TableContainer {
|
||||
|
||||
// TODO
|
||||
private Formatter<DateHolder> yearFormatter;
|
||||
private final Formatter<DateHolder> yearFormatter;
|
||||
|
||||
public DeathsTable(List<PlayerDeath> playerPlayerDeaths) {
|
||||
DeathsTable(List<PlayerDeath> playerPlayerDeaths, Formatter<DateHolder> yearFormatter) {
|
||||
super(Icon.called("clock").of(Family.REGULAR) + " Time", "Killed by", "With");
|
||||
this.yearFormatter = yearFormatter;
|
||||
setColor("red");
|
||||
|
||||
if (playerPlayerDeaths.isEmpty()) {
|
||||
|
|
|
@ -17,14 +17,15 @@ import java.util.List;
|
|||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class GeoInfoTable extends TableContainer {
|
||||
class GeoInfoTable extends TableContainer {
|
||||
|
||||
// TODO
|
||||
private boolean displayIP;
|
||||
private Formatter<DateHolder> yearFormatter;
|
||||
private final boolean displayIP;
|
||||
private final Formatter<DateHolder> yearFormatter;
|
||||
|
||||
public GeoInfoTable(List<GeoInfo> geoInfo) {
|
||||
GeoInfoTable(List<GeoInfo> geoInfo, boolean displayIP, Formatter<DateHolder> yearFormatter) {
|
||||
super("IP", "Geolocation", "Last Used");
|
||||
this.displayIP = displayIP;
|
||||
this.yearFormatter = yearFormatter;
|
||||
|
||||
if (geoInfo.isEmpty()) {
|
||||
addRow("No Connections");
|
||||
|
|
|
@ -0,0 +1,167 @@
|
|||
package com.djrapitops.plan.utilities.html.tables;
|
||||
|
||||
import com.djrapitops.plan.data.container.*;
|
||||
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.data.store.containers.DataContainer;
|
||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
||||
import com.djrapitops.plan.data.store.objects.Nickname;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Factory class for objects that represent HTML tables.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class HtmlTables {
|
||||
|
||||
private final PlanConfig config;
|
||||
private final Formatters formatters;
|
||||
|
||||
@Inject
|
||||
public HtmlTables(
|
||||
PlanConfig config,
|
||||
Formatters formatters
|
||||
) {
|
||||
this.config = config;
|
||||
this.formatters = formatters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Command usage table.
|
||||
*
|
||||
* @param container Container that supports ServerKeys.COMMAND_USAGE.
|
||||
* @return a new {@link CommandUseTable}.
|
||||
*/
|
||||
public TableContainer commandUseTable(DataContainer container) {
|
||||
return new CommandUseTable(container);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Deaths table.
|
||||
*
|
||||
* @param deaths List of {@link PlayerDeath}s to be added to the table.
|
||||
* @return a new {@link DeathsTable}.
|
||||
*/
|
||||
public TableContainer deathsTable(List<PlayerDeath> deaths) {
|
||||
return new DeathsTable(deaths, formatters.year());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new GeoInfo table.
|
||||
*
|
||||
* @param geoInfo List of {@link GeoInfo} to be added to the table.
|
||||
* @return a new {@link GeoInfoTable}.
|
||||
*/
|
||||
public TableContainer geoInfoTable(List<GeoInfo> geoInfo) {
|
||||
return new GeoInfoTable(geoInfo, config.isTrue(Settings.DISPLAY_PLAYER_IPS), formatters.year());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Kill table.
|
||||
*
|
||||
* @param kills List of {@link PlayerKill]s to be added to the table.
|
||||
* @param color Color the table header should be.
|
||||
* @return a new {@link KillsTable}.
|
||||
*/
|
||||
public TableContainer killsTable(List<PlayerKill> kills, String color) {
|
||||
return new KillsTable(kills, color, formatters.year());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Nickname table.
|
||||
*
|
||||
* @param nicknames List of {@link Nickname}s to be added to the table.
|
||||
* @param serverNames Names of the servers, for the server column. // TODO Move Server names to Nickname object.
|
||||
* @return a new {@link NicknameTable}.
|
||||
*/
|
||||
public TableContainer nicknameTable(List<Nickname> nicknames, Map<UUID, String> serverNames) {
|
||||
return new NicknameTable(nicknames, serverNames, formatters.year());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Country - Ping table.
|
||||
*
|
||||
* @param pingPerCountry Map of {@link Ping}s sorted by country names.
|
||||
* @return a new {@link PingTable}.
|
||||
*/
|
||||
public TableContainer pingTable(Map<String, List<Ping>> pingPerCountry) {
|
||||
return new PingTable(pingPerCountry, formatters.decimals());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Session table for a player.
|
||||
*
|
||||
* @param playerName Name of the player.
|
||||
* @param sessions List of {@link Session}s the player has.
|
||||
* @return a new {@link PlayerSessionTable}.
|
||||
*/
|
||||
public TableContainer playerSessionTable(String playerName, List<Session> sessions) {
|
||||
return new PlayerSessionTable(
|
||||
playerName, sessions,
|
||||
config.getNumber(Settings.MAX_SESSIONS), formatters.year(), formatters.timeAmount()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Session table for a server.
|
||||
*
|
||||
* @param playerNames Map of UUID - Name pairs of the players. // TODO Move Player names to Session object.
|
||||
* @param sessions List of {@link Session}s that occurred on the server.
|
||||
* @return a new {@link ServerSessionTable}.
|
||||
*/
|
||||
public TableContainer serverSessionTable(Map<UUID, String> playerNames, List<Session> sessions) {
|
||||
return new ServerSessionTable(
|
||||
playerNames, sessions,
|
||||
config.getNumber(Settings.MAX_SESSIONS), formatters.year(), formatters.timeAmount()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Player table for a server.
|
||||
*
|
||||
* @param players List of {@link PlayerContainer}s of players who have played on the server.
|
||||
* @return a new {@link PlayersTable}.
|
||||
*/
|
||||
public TableContainer playerTableForServerPage(List<PlayerContainer> players) {
|
||||
return new PlayersTable(
|
||||
players, config.getNumber(Settings.MAX_PLAYERS),
|
||||
formatters.timeAmount(), formatters.yearLong()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Player table for a players page.
|
||||
*
|
||||
* @param players List of {@link PlayerContainer}s of players.
|
||||
* @return a new {@link PlayersTable}.
|
||||
*/
|
||||
public TableContainer playerTableForPlayersPage(List<PlayerContainer> players) {
|
||||
return new PlayersTable(
|
||||
players, config.getNumber(Settings.MAX_PLAYERS_PLAYERS_PAGE),
|
||||
formatters.timeAmount(), formatters.yearLong()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Player table that contains Plugin Data.
|
||||
*
|
||||
* @param containers PluginData AnalysisContainers.
|
||||
* @param players List of {@link PlayerContainer}s of players.
|
||||
* @return a new {@link PluginPlayersTable}.
|
||||
*/
|
||||
public TableContainer pluginPlayersTable(Map<PluginData, AnalysisContainer> containers, Collection<PlayerContainer> players) {
|
||||
return new PluginPlayersTable(containers, players, config.getNumber(Settings.MAX_PLAYERS));
|
||||
}
|
||||
}
|
|
@ -13,21 +13,20 @@ import com.djrapitops.plan.utilities.html.icon.Icon;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Html table that displays kills Player has performed.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class KillsTable extends TableContainer {
|
||||
class KillsTable extends TableContainer {
|
||||
|
||||
// TODO
|
||||
private Formatter<DateHolder> yearFormatter;
|
||||
private final Formatter<DateHolder> yearFormatter;
|
||||
|
||||
public KillsTable(List<PlayerKill> playerKills) {
|
||||
this(playerKills, "red");
|
||||
}
|
||||
|
||||
public KillsTable(List<PlayerKill> playerKills, String color) {
|
||||
KillsTable(List<PlayerKill> playerKills, String color, Formatter<DateHolder> yearFormatter) {
|
||||
super(Icon.called("clock").of(Family.REGULAR) + " Time", "Killed", "With");
|
||||
setColor(color);
|
||||
|
||||
this.yearFormatter = yearFormatter;
|
||||
|
||||
if (playerKills.isEmpty()) {
|
||||
addRow("No Kills");
|
||||
} else {
|
||||
|
|
|
@ -16,17 +16,17 @@ import java.util.Map;
|
|||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Utility Class for creating Nicknames Table for inspect page.
|
||||
* Html table that displays player's nicknames and where they were seen.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class NicknameTable extends TableContainer {
|
||||
class NicknameTable extends TableContainer {
|
||||
|
||||
// TODO
|
||||
private Formatter<DateHolder> yearFormatter;
|
||||
private final Formatter<DateHolder> yearFormatter;
|
||||
|
||||
public NicknameTable(List<Nickname> nicknames, Map<UUID, String> serverNames) {
|
||||
NicknameTable(List<Nickname> nicknames, Map<UUID, String> serverNames, Formatter<DateHolder> yearFormatter) {
|
||||
super("Nickname", "Server", "Last Seen");
|
||||
this.yearFormatter = yearFormatter;
|
||||
|
||||
if (nicknames.isEmpty()) {
|
||||
addRow("No Nicknames");
|
||||
|
|
|
@ -8,18 +8,23 @@ import com.djrapitops.plan.utilities.html.icon.Icon;
|
|||
|
||||
import java.util.*;
|
||||
|
||||
public class PingTable extends TableContainer {
|
||||
/**
|
||||
* Html table that displays countries and their average, worst and best pings.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
class PingTable extends TableContainer {
|
||||
|
||||
// TODO
|
||||
private Formatter<Double> decimalFormatter;
|
||||
private final Formatter<Double> decimalFormatter;
|
||||
|
||||
public PingTable(Map<String, List<Ping>> pingPerCountry) {
|
||||
PingTable(Map<String, List<Ping>> pingPerCountry, Formatter<Double> decimalFormatter) {
|
||||
super(
|
||||
Icon.called("globe") + " Country",
|
||||
Icon.called("signal") + " Average Ping",
|
||||
Icon.called("signal") + " Worst Ping",
|
||||
Icon.called("signal") + " Best Ping"
|
||||
);
|
||||
this.decimalFormatter = decimalFormatter;
|
||||
setColor("amber");
|
||||
|
||||
addRows(pingPerCountry);
|
||||
|
|
|
@ -3,42 +3,38 @@ package com.djrapitops.plan.utilities.html.tables;
|
|||
import com.djrapitops.plan.api.PlanAPI;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.element.TableContainer;
|
||||
import com.djrapitops.plan.data.store.containers.DataContainer;
|
||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||
import com.djrapitops.plan.data.store.keys.SessionKeys;
|
||||
import com.djrapitops.plan.data.store.objects.DateHolder;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.html.Html;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* TableContainer for a Session table for a single player.
|
||||
* Html table that can be used to replace a {@link com.djrapitops.plan.utilities.html.structure.SessionAccordion}.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PlayerSessionTable extends TableContainer {
|
||||
class PlayerSessionTable extends TableContainer {
|
||||
|
||||
// TODO
|
||||
private int maxSessions; // Should be over 0, default 50
|
||||
private Formatter<DateHolder> yearFormatter;
|
||||
private Formatter<Long> timeAmountFormatter;
|
||||
private final int maxSessions;
|
||||
private final Formatter<DateHolder> yearFormatter;
|
||||
private final Formatter<Long> timeAmountFormatter;
|
||||
|
||||
private final String playerName;
|
||||
private final List<Session> sessions;
|
||||
|
||||
public static PlayerSessionTable forContainer(DataContainer container) {
|
||||
return new PlayerSessionTable(
|
||||
container.getValue(PlayerKeys.NAME).orElse("Unknown"),
|
||||
container.getValue(PlayerKeys.SESSIONS).orElse(new ArrayList<>())
|
||||
);
|
||||
}
|
||||
|
||||
public PlayerSessionTable(String playerName, List<Session> sessions) {
|
||||
PlayerSessionTable(String playerName, List<Session> sessions,
|
||||
int maxSessions,
|
||||
Formatter<DateHolder> yearFormatter,
|
||||
Formatter<Long> timeAmountFormatter
|
||||
) {
|
||||
super("Player", "Start", "Length", "World");
|
||||
this.playerName = playerName;
|
||||
this.sessions = sessions;
|
||||
this.maxSessions = maxSessions;
|
||||
this.yearFormatter = yearFormatter;
|
||||
this.timeAmountFormatter = timeAmountFormatter;
|
||||
|
||||
addRows();
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
|||
import com.djrapitops.plan.data.store.mutators.ActivityIndex;
|
||||
import com.djrapitops.plan.data.store.mutators.GeoInfoMutator;
|
||||
import com.djrapitops.plan.data.store.mutators.SessionsMutator;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.utilities.comparators.PlayerContainerLastPlayedComparator;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.html.Html;
|
||||
|
@ -18,20 +17,20 @@ import com.djrapitops.plan.utilities.html.icon.Icon;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Utility for creating Players table html.
|
||||
* Html table that displays a lot of information about players.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PlayersTable extends TableContainer {
|
||||
|
||||
// TODO
|
||||
private Formatter<Long> timeAmountFormatter;
|
||||
private Formatter<Long> yearLongFormatter;
|
||||
class PlayersTable extends TableContainer {
|
||||
|
||||
private final List<PlayerContainer> players;
|
||||
private final int maxPlayers;
|
||||
|
||||
private PlayersTable(List<PlayerContainer> players, int maxPlayers) {
|
||||
PlayersTable(List<PlayerContainer> players,
|
||||
int maxPlayers,
|
||||
Formatter<Long> timeAmountFormatter,
|
||||
Formatter<Long> yearLongFormatter
|
||||
) {
|
||||
super(
|
||||
Icon.called("user") + " Name",
|
||||
Icon.called("check") + " Activity Index",
|
||||
|
@ -51,16 +50,6 @@ public class PlayersTable extends TableContainer {
|
|||
addRows();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static PlayersTable forServerPage(List<PlayerContainer> players) {
|
||||
return new PlayersTable(players, Settings.MAX_PLAYERS.getNumber());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static PlayersTable forPlayersPage(List<PlayerContainer> players) {
|
||||
return new PlayersTable(players, Settings.MAX_PLAYERS_PLAYERS_PAGE.getNumber());
|
||||
}
|
||||
|
||||
private void addRows() {
|
||||
PlanAPI planAPI = PlanAPI.getInstance();
|
||||
long now = System.currentTimeMillis();
|
||||
|
|
|
@ -6,7 +6,6 @@ import com.djrapitops.plan.data.element.TableContainer;
|
|||
import com.djrapitops.plan.data.plugin.PluginData;
|
||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.utilities.html.Html;
|
||||
import com.djrapitops.plugin.utilities.ArrayUtil;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
@ -15,22 +14,33 @@ import java.io.Serializable;
|
|||
import java.util.*;
|
||||
|
||||
/**
|
||||
* TableContainer that creates the html table for per player plugins values.
|
||||
* Html table that displays players data in various plugins.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PluginPlayersTable extends TableContainer {
|
||||
class PluginPlayersTable extends TableContainer {
|
||||
|
||||
private Collection<PlayerContainer> players;
|
||||
|
||||
public PluginPlayersTable(Map<PluginData, AnalysisContainer> containers, Collection<PlayerContainer> players) {
|
||||
this(getPluginDataSet(containers), players);
|
||||
private final int maxPlayers;
|
||||
|
||||
PluginPlayersTable(
|
||||
Map<PluginData, AnalysisContainer> containers,
|
||||
Collection<PlayerContainer> players,
|
||||
int maxPlayers
|
||||
) {
|
||||
this(getPluginDataSet(containers), players, maxPlayers);
|
||||
}
|
||||
|
||||
private PluginPlayersTable(TreeMap<String, Map<UUID, ? extends Serializable>> pluginDataSet, Collection<PlayerContainer> players) {
|
||||
private PluginPlayersTable(
|
||||
TreeMap<String, Map<UUID, ? extends Serializable>> pluginDataSet,
|
||||
Collection<PlayerContainer> players,
|
||||
int maxPlayers
|
||||
) {
|
||||
super(true, getHeaders(pluginDataSet.keySet()));
|
||||
|
||||
this.players = players;
|
||||
this.maxPlayers = maxPlayers;
|
||||
|
||||
useJqueryDataTables("player-plugin-table");
|
||||
|
||||
|
@ -61,10 +71,6 @@ public class PluginPlayersTable extends TableContainer {
|
|||
|
||||
private void addValues(Map<UUID, String[]> rows) {
|
||||
int i = 0;
|
||||
int maxPlayers = Settings.MAX_PLAYERS.getNumber();
|
||||
if (maxPlayers <= 0) {
|
||||
maxPlayers = 2000;
|
||||
}
|
||||
for (PlayerContainer profile : players) {
|
||||
if (i >= maxPlayers) {
|
||||
break;
|
||||
|
|
|
@ -13,24 +13,31 @@ import java.util.Map;
|
|||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* TableContainer for a Session table for a single player.
|
||||
* Html table that can be used to replace a {@link com.djrapitops.plan.utilities.html.structure.SessionAccordion}.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class ServerSessionTable extends TableContainer {
|
||||
class ServerSessionTable extends TableContainer {
|
||||
|
||||
// TODO
|
||||
private int maxSessions; // Should be over 0, default 50
|
||||
private Formatter<DateHolder> yearFormatter;
|
||||
private Formatter<Long> timeAmountFormatter;
|
||||
private final int maxSessions;
|
||||
private final Formatter<DateHolder> yearFormatter;
|
||||
private final Formatter<Long> timeAmountFormatter;
|
||||
|
||||
private final List<Session> sessions;
|
||||
private Map<UUID, String> playerNames;
|
||||
|
||||
public ServerSessionTable(Map<UUID, String> playerNames, List<Session> sessions) {
|
||||
ServerSessionTable(
|
||||
Map<UUID, String> playerNames, List<Session> sessions,
|
||||
int maxSessions,
|
||||
Formatter<DateHolder> yearFormatter,
|
||||
Formatter<Long> timeAmountFormatter
|
||||
) {
|
||||
super("Player", "Start", "Length", "World");
|
||||
this.playerNames = playerNames;
|
||||
this.sessions = sessions;
|
||||
this.maxSessions = maxSessions;
|
||||
this.yearFormatter = yearFormatter;
|
||||
this.timeAmountFormatter = timeAmountFormatter;
|
||||
|
||||
addRows();
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public class PlayersTableTest {
|
|||
PlayerContainer container = new PlayerContainer();
|
||||
container.putRawData(PlayerKeys.SESSIONS, new ArrayList<>());
|
||||
List<PlayerContainer> players = Collections.singletonList(container);
|
||||
String html = PlayersTable.forServerPage(players).parseHtml();
|
||||
String html = new PlayersTable(players, 50, l -> "", l -> "").parseHtml();
|
||||
|
||||
testHtmlValidity(html);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user