better synchronous call warning

This commit is contained in:
Elias Müller 2024-12-08 22:36:11 +01:00
parent ddedcea8ea
commit 9004609c1b
2 changed files with 9 additions and 3 deletions

View File

@ -74,7 +74,7 @@ public abstract class HttpRepository extends Repository {
private ReqResp<String> sendHttp(HttpRequest request) { private ReqResp<String> sendHttp(HttpRequest request) {
try(HttpClient client = HttpClient.newHttpClient()) { try(HttpClient client = HttpClient.newHttpClient()) {
this.validateThread(); this.validateThread(request.uri().getPath());
HttpResponse<String> httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString()); HttpResponse<String> httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
return new ReqResp<>(httpResponse.statusCode(), httpResponse.body()); return new ReqResp<>(httpResponse.statusCode(), httpResponse.body());
} catch(IOException | InterruptedException e) { } catch(IOException | InterruptedException e) {

View File

@ -15,7 +15,13 @@ public abstract class Repository {
this.gson = new Gson(); this.gson = new Gson();
} }
protected void validateThread() { protected void validateThread(String commandName) {
if(Bukkit.isPrimaryThread()) Main.logger().warning("Repository was called synchronously!"); if(!Bukkit.isPrimaryThread()) return;
Main.logger().warning(String.format(
"Repository '%s' was called synchronously with command '%s'!",
this.getClass().getSimpleName(),
commandName
));
} }
} }