Created the JSONBuilder.java

This commit is contained in:
Mathias Wagner 2024-02-13 18:39:51 +01:00
parent 17dd784e1f
commit 650605c8d7
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

View File

@ -0,0 +1,38 @@
package de.gnmyt.mcdash.http;
import java.util.HashMap;
public class JSONBuilder {
private final HashMap<String, Object> json = new HashMap<>();
private final ResponseController response;
/**
* Constructor of the {@link JSONBuilder}
*
* @param response The response controller
*/
public JSONBuilder(ResponseController response) {
this.response = response;
}
/**
* Adds a new value to the JSON
*
* @param key The key of the value
* @param value The value you want to add
* @return the current {@link JSONBuilder} instance
*/
public JSONBuilder add(String key, Object value) {
json.put(key, value);
return this;
}
/**
* Finishes the JSON and sends it to the client
*/
public void finish() {
response.json(json);
}
}