From 65db6328748bbc2d236e5100c580674884ef14fc Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sun, 3 Dec 2017 09:47:51 +0200 Subject: [PATCH] Fixed InternalStateException Player profile was null when a new player registers #446 --- .../java/com/djrapitops/plan/api/API.java | 3 ++- .../info/BukkitInformationManager.java | 26 ++++++++++++++----- .../plan/systems/info/InformationManager.java | 3 ++- .../response/InspectPageResponse.java | 3 ++- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/api/API.java b/Plan/src/main/java/com/djrapitops/plan/api/API.java index d026d3929..9107b7427 100644 --- a/Plan/src/main/java/com/djrapitops/plan/api/API.java +++ b/Plan/src/main/java/com/djrapitops/plan/api/API.java @@ -2,6 +2,7 @@ package main.java.com.djrapitops.plan.api; import com.djrapitops.plugin.utilities.Verify; import main.java.com.djrapitops.plan.Plan; +import main.java.com.djrapitops.plan.api.exceptions.ParseException; import main.java.com.djrapitops.plan.data.AnalysisData; import main.java.com.djrapitops.plan.data.plugin.PluginData; import main.java.com.djrapitops.plan.systems.info.BukkitInformationManager; @@ -142,7 +143,7 @@ public class API { * @param uuid UUID of the player. * @return player.html with all placeholders replaced. */ - public String getPlayerHtmlAsString(UUID uuid) { + public String getPlayerHtmlAsString(UUID uuid) throws ParseException { return plugin.getInfoManager().getPlayerHtml(uuid); } diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/BukkitInformationManager.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/BukkitInformationManager.java index ec8803513..84a2caeb8 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/info/BukkitInformationManager.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/BukkitInformationManager.java @@ -108,9 +108,25 @@ public class BukkitInformationManager extends InformationManager { } catch (WebAPIException e) { attemptConnection(); cachePlayer(uuid); + } catch (ParseException e) { + if (!(e.getCause() instanceof IllegalStateException)) { + Log.toLog(this.getClass().getName(), e); + } } } else { - PageCache.cachePage("inspectPage: " + uuid, () -> new InspectPageResponse(this, uuid)); + PageCache.cachePage("inspectPage: " + uuid, () -> { + try { + return new InspectPageResponse(this, uuid); + } catch (ParseException e) { + if (e.getCause() instanceof IllegalStateException) { + return new NotFoundResponse( + "Player just registered, so the data was not yet in the database. " + + "Please wait until they log off or use /plan inspect " + ); + } + return new InternalErrorResponse(e, this.getClass().getName()); + } + }); if (Settings.ANALYSIS_EXPORT.isTrue()) { HtmlExport.exportPlayer(plugin, uuid); } @@ -246,12 +262,8 @@ public class BukkitInformationManager extends InformationManager { } @Override - public String getPlayerHtml(UUID uuid) { - try { - return Theme.replaceColors(new InspectPageParser(uuid, plugin).parse()); - } catch (ParseException e) { - return new InternalErrorResponse(e, this.getClass().getSimpleName()).getContent(); - } + public String getPlayerHtml(UUID uuid) throws ParseException { + return Theme.replaceColors(new InspectPageParser(uuid, plugin).parse()); } @Override diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/InformationManager.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/InformationManager.java index 35e32cb93..ef93e980d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/info/InformationManager.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/InformationManager.java @@ -5,6 +5,7 @@ package main.java.com.djrapitops.plan.systems.info; import com.djrapitops.plugin.command.ISender; +import main.java.com.djrapitops.plan.api.exceptions.ParseException; import main.java.com.djrapitops.plan.systems.cache.DataCache; import main.java.com.djrapitops.plan.systems.cache.SessionCache; import main.java.com.djrapitops.plan.systems.webserver.PageCache; @@ -48,7 +49,7 @@ public abstract class InformationManager { return PageCache.isCached("inspectPage: " + uuid); } - public abstract String getPlayerHtml(UUID uuid); + public abstract String getPlayerHtml(UUID uuid) throws ParseException; /** * Used for /server on Bukkit and /network on Bungee diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/response/InspectPageResponse.java b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/response/InspectPageResponse.java index 78f4183c7..d0de8c86e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/response/InspectPageResponse.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/response/InspectPageResponse.java @@ -1,5 +1,6 @@ package main.java.com.djrapitops.plan.systems.webserver.response; +import main.java.com.djrapitops.plan.api.exceptions.ParseException; import main.java.com.djrapitops.plan.settings.theme.Theme; import main.java.com.djrapitops.plan.systems.info.InformationManager; import org.apache.commons.lang3.text.StrSubstitutor; @@ -16,7 +17,7 @@ public class InspectPageResponse extends Response { private final UUID uuid; - public InspectPageResponse(InformationManager infoManager, UUID uuid) { + public InspectPageResponse(InformationManager infoManager, UUID uuid) throws ParseException { this.uuid = uuid; super.setHeader("HTTP/1.1 200 OK"); super.setContent(infoManager.getPlayerHtml(uuid));