From 94137252a8ff99cbbf26c9a0bdd78f9f41584fd7 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Mon, 2 Oct 2017 17:31:27 +0300 Subject: [PATCH] Fixed NPE related to InspectPageParser and UserInfo #312 --- .../plan/database/tables/UsersTable.java | 16 ++++++++++ .../info/parsing/InspectPageParser.java | 29 ++++++++++--------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/UsersTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/UsersTable.java index b8d2f1229..d9ac2bb53 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/UsersTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/UsersTable.java @@ -439,4 +439,20 @@ public class UsersTable extends UserIDTable { close(set, statement); } } + + public Optional getRegisterDate(UUID uuid) throws SQLException { + PreparedStatement statement = null; + ResultSet set = null; + try (Connection connection = getConnection()) { + statement = connection.prepareStatement(Select.from(tableName, columnRegistered).where(columnUUID + "=?").toString()); + statement.setString(1, uuid.toString()); + set = statement.executeQuery(); + if (set.next()) { + Optional.of(set.getLong(columnRegistered)); + } + return Optional.empty(); + } finally { + close(set, statement); + } + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPageParser.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPageParser.java index 840582cce..46bd10ffa 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPageParser.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPageParser.java @@ -15,6 +15,7 @@ import main.java.com.djrapitops.plan.data.Session; import main.java.com.djrapitops.plan.data.UserInfo; import main.java.com.djrapitops.plan.database.Database; import main.java.com.djrapitops.plan.database.tables.SessionsTable; +import main.java.com.djrapitops.plan.database.tables.UsersTable; import main.java.com.djrapitops.plan.utilities.Benchmark; import main.java.com.djrapitops.plan.utilities.FormatUtils; import main.java.com.djrapitops.plan.utilities.MiscUtils; @@ -30,10 +31,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 java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; import java.util.stream.Collectors; /** @@ -60,18 +58,21 @@ public class InspectPageParser extends PageParser { SessionsTable sessionsTable = db.getSessionsTable(); UserInfo userInfo = db.getUserInfoTable().getUserInfo(uuid); - int timesKicked = db.getUsersTable().getTimesKicked(uuid); + UsersTable usersTable = db.getUsersTable(); + String playerName = usersTable.getPlayerName(uuid); + Optional registerDate = usersTable.getRegisterDate(uuid); + if (registerDate.isPresent()) { + addValue("registered", FormatUtils.formatTimeStampYear(registerDate.get())); + } else { + addValue("registered", "-"); + } + + addValue("playerName", playerName); + int timesKicked = usersTable.getTimesKicked(uuid); addValue("version", MiscUtils.getPlanVersion()); addValue("timeZone", MiscUtils.getTimeZoneOffsetHours()); - if (userInfo != null) { - addValue("playerName", userInfo.getName()); - addValue("registered", FormatUtils.formatTimeStampYear(userInfo.getRegistered())); - } else { - addValue("playerName", "Error occurred."); - addValue("registered", "Error occurred."); - } long lastSeen = sessionsTable.getLastSeen(uuid); if (lastSeen != 0) { addValue("lastSeen", FormatUtils.formatTimeStampYear(lastSeen)); @@ -177,7 +178,9 @@ public class InspectPageParser extends PageParser { addValue("mobKillCount", mobKillCount); addValue("deathCount", deathCount); - playerClassification(userInfo, lastSeen, playTime, sessionCount); + if (userInfo != null) { + playerClassification(userInfo, lastSeen, playTime, sessionCount); + } return HtmlUtils.replacePlaceholders(FileUtil.getStringFromResource("player.html"), placeHolders); } catch (Exception e) {