mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-02 11:21:15 +01:00
Added RawJsonMessage constructor taking a json object as a string to reduce boilerplate code
This commit is contained in:
parent
e8e8022ec6
commit
882720c822
@ -2,6 +2,7 @@ package net.minestom.server.chat;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
@ -109,6 +110,10 @@ public abstract class JsonMessage {
|
||||
this.jsonObject = jsonObject;
|
||||
}
|
||||
|
||||
public RawJsonMessage(@NotNull String jsonObject) {
|
||||
this.jsonObject = JsonParser.parseString(jsonObject).getAsJsonObject();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JsonObject getJsonObject() {
|
||||
|
@ -1,7 +1,5 @@
|
||||
package net.minestom.server.utils.binary;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
@ -152,8 +150,7 @@ public class BinaryReader extends InputStream {
|
||||
}
|
||||
|
||||
public JsonMessage readJsonMessage(int maxLength) {
|
||||
final String string = readSizedString(maxLength);
|
||||
final JsonObject jsonObject = JsonParser.parseString(string).getAsJsonObject();
|
||||
final String jsonObject = readSizedString(maxLength);
|
||||
return new JsonMessage.RawJsonMessage(jsonObject);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user