From 013f01ccff5e0b2ed0e2ea85e3c4ac14d6b32d8d Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Fri, 8 Sep 2017 20:43:40 +0300 Subject: [PATCH] Now using name cache in a few places. --- .../java/com/djrapitops/plan/data/PlayerKill.java | 4 +++- .../com/djrapitops/plan/systems/cache/DataCache.java | 12 +++++++++++- .../plan/systems/info/parsing/InspectPageParser.java | 2 -- .../utilities/html/tables/KillsTableCreator.java | 6 ++---- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/data/PlayerKill.java b/Plan/src/main/java/com/djrapitops/plan/data/PlayerKill.java index ab5c6453f..251f351ef 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/PlayerKill.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/PlayerKill.java @@ -1,5 +1,6 @@ package main.java.com.djrapitops.plan.data; +import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.database.tables.Actions; import org.apache.commons.lang3.builder.ToStringBuilder; @@ -59,7 +60,8 @@ public class PlayerKill { } public Action convertToAction() { - return new Action(time, Actions.KILLED, "name with " + weapon); // TODO Name Cache. + String name = Plan.getInstance().getDataCache().getName(victim); + return new Action(time, Actions.KILLED, name + " with " + weapon); } @Override diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/cache/DataCache.java b/Plan/src/main/java/com/djrapitops/plan/systems/cache/DataCache.java index c8eb62c25..ebe8de4cd 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/cache/DataCache.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/cache/DataCache.java @@ -67,7 +67,17 @@ public class DataCache extends SessionCache { * @return name or null if not cached. */ public String getName(UUID uuid) { - return playerNames.get(uuid); + String name = playerNames.get(uuid); + if (name == null) { + try { + name = db.getUsersTable().getPlayerName(uuid); + playerNames.put(uuid, name); + } catch (SQLException e) { + Log.toLog(this.getClass().getName(), e); + name = "Error occurred"; + } + } + return name; } /** 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 1cf3f57e9..1c64e4f95 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 @@ -145,7 +145,6 @@ public class InspectPageParser extends PageParser { addValue("worldPieSeries", worldPieData[0]); addValue("gmSeries", worldPieData[1]); - addValue("punchCardSeries", punchCardData); List sessionsInLengthOrder = allSessions.stream() @@ -168,7 +167,6 @@ public class InspectPageParser extends PageParser { addValue("mobKillCount", mobKillCount); addValue("deathCount", deathCount); - playerClassification(userInfo, lastSeen, playTime, sessionCount); return HtmlUtils.replacePlaceholders(FileUtil.getStringFromResource("player.html"), placeHolders); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/KillsTableCreator.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/KillsTableCreator.java index 7bbd19231..58ba01b00 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/KillsTableCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/KillsTableCreator.java @@ -1,7 +1,6 @@ package main.java.com.djrapitops.plan.utilities.html.tables; -import com.djrapitops.plugin.utilities.player.Fetch; -import com.djrapitops.plugin.utilities.player.IOfflinePlayer; +import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.data.PlayerKill; import main.java.com.djrapitops.plan.locale.Locale; import main.java.com.djrapitops.plan.locale.Msg; @@ -46,8 +45,7 @@ public class KillsTableCreator { long date = kill.getTime(); - IOfflinePlayer victim = Fetch.getIOfflinePlayer(kill.getVictim()); - String name = victim.getName(); + String name = Plan.getInstance().getDataCache().getName(kill.getVictim()); html.append(Html.TABLELINE_3_CUSTOMKEY_1.parse( String.valueOf(date), FormatUtils.formatTimeStamp(date), Html.LINK.parse(HtmlUtils.getInspectUrl(name), name),