Fixed InternalStateException Player profile was null when a new player registers #446

This commit is contained in:
Rsl1122 2017-12-03 09:47:51 +02:00
parent 7f580bffe9
commit 65db632874
4 changed files with 25 additions and 10 deletions

View File

@ -2,6 +2,7 @@ package main.java.com.djrapitops.plan.api;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Plan; 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.AnalysisData;
import main.java.com.djrapitops.plan.data.plugin.PluginData; import main.java.com.djrapitops.plan.data.plugin.PluginData;
import main.java.com.djrapitops.plan.systems.info.BukkitInformationManager; import main.java.com.djrapitops.plan.systems.info.BukkitInformationManager;
@ -142,7 +143,7 @@ public class API {
* @param uuid UUID of the player. * @param uuid UUID of the player.
* @return player.html with all placeholders replaced. * @return player.html with all placeholders replaced.
*/ */
public String getPlayerHtmlAsString(UUID uuid) { public String getPlayerHtmlAsString(UUID uuid) throws ParseException {
return plugin.getInfoManager().getPlayerHtml(uuid); return plugin.getInfoManager().getPlayerHtml(uuid);
} }

View File

@ -108,9 +108,25 @@ public class BukkitInformationManager extends InformationManager {
} catch (WebAPIException e) { } catch (WebAPIException e) {
attemptConnection(); attemptConnection();
cachePlayer(uuid); cachePlayer(uuid);
} catch (ParseException e) {
if (!(e.getCause() instanceof IllegalStateException)) {
Log.toLog(this.getClass().getName(), e);
}
} }
} else { } 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 <player>"
);
}
return new InternalErrorResponse(e, this.getClass().getName());
}
});
if (Settings.ANALYSIS_EXPORT.isTrue()) { if (Settings.ANALYSIS_EXPORT.isTrue()) {
HtmlExport.exportPlayer(plugin, uuid); HtmlExport.exportPlayer(plugin, uuid);
} }
@ -246,12 +262,8 @@ public class BukkitInformationManager extends InformationManager {
} }
@Override @Override
public String getPlayerHtml(UUID uuid) { public String getPlayerHtml(UUID uuid) throws ParseException {
try {
return Theme.replaceColors(new InspectPageParser(uuid, plugin).parse()); return Theme.replaceColors(new InspectPageParser(uuid, plugin).parse());
} catch (ParseException e) {
return new InternalErrorResponse(e, this.getClass().getSimpleName()).getContent();
}
} }
@Override @Override

View File

@ -5,6 +5,7 @@
package main.java.com.djrapitops.plan.systems.info; package main.java.com.djrapitops.plan.systems.info;
import com.djrapitops.plugin.command.ISender; 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.DataCache;
import main.java.com.djrapitops.plan.systems.cache.SessionCache; import main.java.com.djrapitops.plan.systems.cache.SessionCache;
import main.java.com.djrapitops.plan.systems.webserver.PageCache; import main.java.com.djrapitops.plan.systems.webserver.PageCache;
@ -48,7 +49,7 @@ public abstract class InformationManager {
return PageCache.isCached("inspectPage: " + uuid); 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 * Used for /server on Bukkit and /network on Bungee

View File

@ -1,5 +1,6 @@
package main.java.com.djrapitops.plan.systems.webserver.response; 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.settings.theme.Theme;
import main.java.com.djrapitops.plan.systems.info.InformationManager; import main.java.com.djrapitops.plan.systems.info.InformationManager;
import org.apache.commons.lang3.text.StrSubstitutor; import org.apache.commons.lang3.text.StrSubstitutor;
@ -16,7 +17,7 @@ public class InspectPageResponse extends Response {
private final UUID uuid; private final UUID uuid;
public InspectPageResponse(InformationManager infoManager, UUID uuid) { public InspectPageResponse(InformationManager infoManager, UUID uuid) throws ParseException {
this.uuid = uuid; this.uuid = uuid;
super.setHeader("HTTP/1.1 200 OK"); super.setHeader("HTTP/1.1 200 OK");
super.setContent(infoManager.getPlayerHtml(uuid)); super.setContent(infoManager.getPlayerHtml(uuid));