mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-02 14:37:45 +01:00
Nickname table to Inspect page
This commit is contained in:
parent
f2ce10738c
commit
a4d8965b28
@ -46,7 +46,7 @@ public class PlayerProfile implements OfflinePlayer {
|
|||||||
private Map<UUID, WorldTimes> worldTimesMap;
|
private Map<UUID, WorldTimes> worldTimesMap;
|
||||||
|
|
||||||
// Extra information
|
// Extra information
|
||||||
private List<String> nicknames;
|
private Map<UUID, List<String>> nicknames;
|
||||||
private List<GeoInfo> geoInformation;
|
private List<GeoInfo> geoInformation;
|
||||||
|
|
||||||
// Plugin data
|
// Plugin data
|
||||||
@ -68,6 +68,9 @@ public class PlayerProfile implements OfflinePlayer {
|
|||||||
actions = new ArrayList<>();
|
actions = new ArrayList<>();
|
||||||
worldTimesMap = new HashMap<>();
|
worldTimesMap = new HashMap<>();
|
||||||
|
|
||||||
|
nicknames = new HashMap<>();
|
||||||
|
geoInformation = new ArrayList<>();
|
||||||
|
|
||||||
pluginReplaceMap = new HashMap<>();
|
pluginReplaceMap = new HashMap<>();
|
||||||
activityIndex = new HashMap<>();
|
activityIndex = new HashMap<>();
|
||||||
}
|
}
|
||||||
@ -439,7 +442,7 @@ public class PlayerProfile implements OfflinePlayer {
|
|||||||
this.actions = actions;
|
this.actions = actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNicknames(List<String> nicknames) {
|
public void setNicknames(Map<UUID, List<String>> nicknames) {
|
||||||
this.nicknames = nicknames;
|
this.nicknames = nicknames;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -457,7 +460,7 @@ public class PlayerProfile implements OfflinePlayer {
|
|||||||
return timesKicked;
|
return timesKicked;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getNicknames() {
|
public Map<UUID, List<String>> getNicknames() {
|
||||||
return nicknames;
|
return nicknames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,37 +56,44 @@ public class NicknamesTable extends UserIDTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get ALL nicknames of the user.
|
* Get ALL nicknames of the user by Server UUID.
|
||||||
* <p>
|
* <p>
|
||||||
* Get's nicknames from other servers as well.
|
* Get's nicknames from other servers as well.
|
||||||
*
|
*
|
||||||
* @param uuid UUID of the Player
|
* @param uuid UUID of the Player
|
||||||
* @return The nicknames of the User
|
* @return The nicknames of the User in a map by ServerUUID
|
||||||
* @throws SQLException when an error at retrieval happens
|
* @throws SQLException when an error at retrieval happens
|
||||||
*/
|
*/
|
||||||
public List<String> getAllNicknames(UUID uuid) throws SQLException {
|
public Map<UUID, List<String>> getAllNicknames(UUID uuid) throws SQLException {
|
||||||
String sql = "SELECT " + columnNick + " FROM " + tableName +
|
String serverIDColumn = serverTable + "." + serverTable.getColumnID();
|
||||||
|
String serverUUIDColumn = serverTable + "." + serverTable.getColumnUUID() + " as s_uuid";
|
||||||
|
String sql = "SELECT " +
|
||||||
|
columnNick + ", " +
|
||||||
|
serverUUIDColumn +
|
||||||
|
" FROM " + tableName +
|
||||||
|
" JOIN " + serverTable + " on " + serverIDColumn + "=" + columnServerID +
|
||||||
" WHERE (" + columnUserID + "=" + usersTable.statementSelectID + ")";
|
" WHERE (" + columnUserID + "=" + usersTable.statementSelectID + ")";
|
||||||
|
|
||||||
return query(new QueryStatement<List<String>>(sql, 1000) {
|
return query(new QueryStatement<Map<UUID, List<String>>>(sql, 5000) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void prepare(PreparedStatement statement) throws SQLException {
|
public void prepare(PreparedStatement statement) throws SQLException {
|
||||||
statement.setString(1, uuid.toString());
|
statement.setString(1, uuid.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> processResults(ResultSet set) throws SQLException {
|
public Map<UUID, List<String>> processResults(ResultSet set) throws SQLException {
|
||||||
List<String> nicknames = new ArrayList<>();
|
Map<UUID, List<String>> map = new HashMap<>();
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
String nickname = set.getString(columnNick);
|
UUID serverUUID = UUID.fromString(set.getString("s_uuid"));
|
||||||
if (nickname.isEmpty()) {
|
|
||||||
continue;
|
List<String> nicknames = map.getOrDefault(serverUUID, new ArrayList<>());
|
||||||
}
|
|
||||||
if (!nicknames.contains(nickname)) {
|
nicknames.add(set.getString(columnNick));
|
||||||
nicknames.add(nickname);
|
|
||||||
}
|
map.put(serverUUID, nicknames);
|
||||||
}
|
}
|
||||||
return nicknames;
|
return map;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ import main.java.com.djrapitops.plan.utilities.html.graphs.ServerPreferencePieCr
|
|||||||
import main.java.com.djrapitops.plan.utilities.html.graphs.WorldPieCreator;
|
import main.java.com.djrapitops.plan.utilities.html.graphs.WorldPieCreator;
|
||||||
import main.java.com.djrapitops.plan.utilities.html.tables.ActionsTableCreator;
|
import main.java.com.djrapitops.plan.utilities.html.tables.ActionsTableCreator;
|
||||||
import main.java.com.djrapitops.plan.utilities.html.tables.IpTableCreator;
|
import main.java.com.djrapitops.plan.utilities.html.tables.IpTableCreator;
|
||||||
|
import main.java.com.djrapitops.plan.utilities.html.tables.NicknameTableCreator;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -99,20 +100,21 @@ public class InspectPageParser extends PageParser {
|
|||||||
String favoriteServer = serverNames.get(profile.getFavoriteServer());
|
String favoriteServer = serverNames.get(profile.getFavoriteServer());
|
||||||
addValue("favoriteServer", favoriteServer != null ? favoriteServer : "Unknown");
|
addValue("favoriteServer", favoriteServer != null ? favoriteServer : "Unknown");
|
||||||
|
|
||||||
// TODO IP Timestamp table
|
addValue("tableBodyNicknames", NicknameTableCreator.createTable(profile.getNicknames(), serverNames));
|
||||||
List<String> nicknames = profile.getNicknames().stream()
|
|
||||||
.map(HtmlUtils::swapColorsToSpan)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
addValue("tableBodyIPs", IpTableCreator.createTable(profile.getGeoInformation()));
|
addValue("tableBodyIPs", IpTableCreator.createTable(profile.getGeoInformation()));
|
||||||
|
|
||||||
|
// TODO REMOVE after 4.1.0
|
||||||
|
List<String> nicknames = profile.getNicknames().values().stream()
|
||||||
|
.flatMap(Collection::stream)
|
||||||
|
.distinct()
|
||||||
|
.map(HtmlUtils::swapColorsToSpan)
|
||||||
|
.collect(Collectors.toList());
|
||||||
List<String> geoLocations = profile.getGeoInformation().stream()
|
List<String> geoLocations = profile.getGeoInformation().stream()
|
||||||
.map(GeoInfo::getGeolocation)
|
.map(GeoInfo::getGeolocation)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
// TODO REMOVE after 4.1.0
|
|
||||||
addValue("nicknames", HtmlStructure.createDotList(nicknames.toArray(new String[nicknames.size()])));
|
addValue("nicknames", HtmlStructure.createDotList(nicknames.toArray(new String[nicknames.size()])));
|
||||||
addValue("geolocations", HtmlStructure.createDotList(geoLocations.toArray(new String[geoLocations.size()])));
|
addValue("geolocations", HtmlStructure.createDotList(geoLocations.toArray(new String[geoLocations.size()])));
|
||||||
|
//
|
||||||
|
|
||||||
Map<UUID, List<Session>> sessions = profile.getSessions();
|
Map<UUID, List<Session>> sessions = profile.getSessions();
|
||||||
Map<String, List<Session>> sessionsByServerName = sessions.entrySet().stream()
|
Map<String, List<Session>> sessionsByServerName = sessions.entrySet().stream()
|
||||||
@ -223,7 +225,7 @@ public class InspectPageParser extends PageParser {
|
|||||||
double activityIndex = profile.getActivityIndex(now);
|
double activityIndex = profile.getActivityIndex(now);
|
||||||
String[] activityIndexFormat = FormatUtils.readableActivityIndex(activityIndex);
|
String[] activityIndexFormat = FormatUtils.readableActivityIndex(activityIndex);
|
||||||
|
|
||||||
addValue("activityIndexNumber", /*FormatUtils.cutDecimals(*/activityIndex);
|
addValue("activityIndexNumber", FormatUtils.cutDecimals(activityIndex));
|
||||||
addValue("activityIndexColor", activityIndexFormat[0]);
|
addValue("activityIndexColor", activityIndexFormat[0]);
|
||||||
addValue("activityIndex", activityIndexFormat[1]);
|
addValue("activityIndex", activityIndexFormat[1]);
|
||||||
|
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Licence is provided in the jar as license.yml also here:
|
||||||
|
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||||
|
*/
|
||||||
|
package main.java.com.djrapitops.plan.utilities.html.tables;
|
||||||
|
|
||||||
|
import main.java.com.djrapitops.plan.utilities.html.Html;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility Class for creating Actions Table for inspect page.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public class NicknameTableCreator {
|
||||||
|
|
||||||
|
|
||||||
|
public NicknameTableCreator() {
|
||||||
|
throw new IllegalStateException("Utility class");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String createTable(Map<UUID, List<String>> nicknames, Map<UUID, String> serverNames) {
|
||||||
|
StringBuilder html = new StringBuilder();
|
||||||
|
if (nicknames.isEmpty()) {
|
||||||
|
html.append(Html.TABLELINE_2.parse("No Nicknames", "-"));
|
||||||
|
} else {
|
||||||
|
for (Map.Entry<UUID, List<String>> entry : nicknames.entrySet()) {
|
||||||
|
String serverName = serverNames.getOrDefault(entry.getKey(), "Unknown");
|
||||||
|
for (String nick : entry.getValue()) {
|
||||||
|
html.append(Html.TABLELINE_2.parse(nick, serverName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return html.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -391,7 +391,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th><i class="fa fa-wifi"></i> IP-address</th>
|
<th><i class="fa fa-wifi"></i> IP-address</th>
|
||||||
<th><i class="fa fa-globe"></i> Geolocation</th>
|
<th><i class="fa fa-globe"></i> Geolocation</th>
|
||||||
<th><i class="fa fa-clock-o"></i> Last Used</th>
|
<th><i class="fa fa-clock-o"></i> Last Connected</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -310,8 +310,8 @@ public class DatabaseTest {
|
|||||||
assertEquals(1, nicknames.size());
|
assertEquals(1, nicknames.size());
|
||||||
assertEquals(expected, nicknames.get(0));
|
assertEquals(expected, nicknames.get(0));
|
||||||
|
|
||||||
List<String> allNicknames = nickTable.getAllNicknames(uuid);
|
Map<UUID, List<String>> allNicknames = nickTable.getAllNicknames(uuid);
|
||||||
assertEquals(nicknames, allNicknames);
|
assertEquals(nicknames, allNicknames.get(Plan.getServerUUID()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user