Nickname table to Inspect page

This commit is contained in:
Rsl1122 2017-11-22 10:20:53 +02:00
parent f2ce10738c
commit a4d8965b28
6 changed files with 80 additions and 29 deletions

View File

@ -46,7 +46,7 @@ public class PlayerProfile implements OfflinePlayer {
private Map<UUID, WorldTimes> worldTimesMap;
// Extra information
private List<String> nicknames;
private Map<UUID, List<String>> nicknames;
private List<GeoInfo> geoInformation;
// Plugin data
@ -68,6 +68,9 @@ public class PlayerProfile implements OfflinePlayer {
actions = new ArrayList<>();
worldTimesMap = new HashMap<>();
nicknames = new HashMap<>();
geoInformation = new ArrayList<>();
pluginReplaceMap = new HashMap<>();
activityIndex = new HashMap<>();
}
@ -439,7 +442,7 @@ public class PlayerProfile implements OfflinePlayer {
this.actions = actions;
}
public void setNicknames(List<String> nicknames) {
public void setNicknames(Map<UUID, List<String>> nicknames) {
this.nicknames = nicknames;
}
@ -457,7 +460,7 @@ public class PlayerProfile implements OfflinePlayer {
return timesKicked;
}
public List<String> getNicknames() {
public Map<UUID, List<String>> getNicknames() {
return nicknames;
}

View File

@ -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>
* Get's nicknames from other servers as well.
*
* @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
*/
public List<String> getAllNicknames(UUID uuid) throws SQLException {
String sql = "SELECT " + columnNick + " FROM " + tableName +
public Map<UUID, List<String>> getAllNicknames(UUID uuid) throws SQLException {
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 + ")";
return query(new QueryStatement<List<String>>(sql, 1000) {
return query(new QueryStatement<Map<UUID, List<String>>>(sql, 5000) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, uuid.toString());
}
@Override
public List<String> processResults(ResultSet set) throws SQLException {
List<String> nicknames = new ArrayList<>();
public Map<UUID, List<String>> processResults(ResultSet set) throws SQLException {
Map<UUID, List<String>> map = new HashMap<>();
while (set.next()) {
String nickname = set.getString(columnNick);
if (nickname.isEmpty()) {
continue;
}
if (!nicknames.contains(nickname)) {
nicknames.add(nickname);
}
UUID serverUUID = UUID.fromString(set.getString("s_uuid"));
List<String> nicknames = map.getOrDefault(serverUUID, new ArrayList<>());
nicknames.add(set.getString(columnNick));
map.put(serverUUID, nicknames);
}
return nicknames;
return map;
}
});
}

View File

@ -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.tables.ActionsTableCreator;
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.stream.Collectors;
@ -99,20 +100,21 @@ public class InspectPageParser extends PageParser {
String favoriteServer = serverNames.get(profile.getFavoriteServer());
addValue("favoriteServer", favoriteServer != null ? favoriteServer : "Unknown");
// TODO IP Timestamp table
List<String> nicknames = profile.getNicknames().stream()
.map(HtmlUtils::swapColorsToSpan)
.collect(Collectors.toList());
addValue("tableBodyNicknames", NicknameTableCreator.createTable(profile.getNicknames(), serverNames));
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()
.map(GeoInfo::getGeolocation)
.collect(Collectors.toList());
// TODO REMOVE after 4.1.0
addValue("nicknames", HtmlStructure.createDotList(nicknames.toArray(new String[nicknames.size()])));
addValue("geolocations", HtmlStructure.createDotList(geoLocations.toArray(new String[geoLocations.size()])));
//
Map<UUID, List<Session>> sessions = profile.getSessions();
Map<String, List<Session>> sessionsByServerName = sessions.entrySet().stream()
@ -223,7 +225,7 @@ public class InspectPageParser extends PageParser {
double activityIndex = profile.getActivityIndex(now);
String[] activityIndexFormat = FormatUtils.readableActivityIndex(activityIndex);
addValue("activityIndexNumber", /*FormatUtils.cutDecimals(*/activityIndex);
addValue("activityIndexNumber", FormatUtils.cutDecimals(activityIndex));
addValue("activityIndexColor", activityIndexFormat[0]);
addValue("activityIndex", activityIndexFormat[1]);

View File

@ -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();
}
}

View File

@ -391,7 +391,7 @@
<tr>
<th><i class="fa fa-wifi"></i> IP-address</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>
</thead>
<tbody>

View File

@ -310,8 +310,8 @@ public class DatabaseTest {
assertEquals(1, nicknames.size());
assertEquals(expected, nicknames.get(0));
List<String> allNicknames = nickTable.getAllNicknames(uuid);
assertEquals(nicknames, allNicknames);
Map<UUID, List<String>> allNicknames = nickTable.getAllNicknames(uuid);
assertEquals(nicknames, allNicknames.get(Plan.getServerUUID()));
}
@Test