Now using name cache in a few places.

This commit is contained in:
Rsl1122 2017-09-08 20:43:40 +03:00
parent 8b391a31cf
commit 013f01ccff
4 changed files with 16 additions and 8 deletions

View File

@ -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

View File

@ -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;
}
/**

View File

@ -145,7 +145,6 @@ public class InspectPageParser extends PageParser {
addValue("worldPieSeries", worldPieData[0]);
addValue("gmSeries", worldPieData[1]);
addValue("punchCardSeries", punchCardData);
List<Session> 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);

View File

@ -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),