From 11db3961055067fcd27b579113af4f6d32b9f6a6 Mon Sep 17 00:00:00 2001 From: Luck Date: Sun, 16 Jun 2019 13:30:16 +0100 Subject: Use protobuf to encode data instead of JSON --- .../src/main/java/me/lucko/spark/common/CommandSender.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'spark-common/src/main/java/me/lucko/spark/common/CommandSender.java') diff --git a/spark-common/src/main/java/me/lucko/spark/common/CommandSender.java b/spark-common/src/main/java/me/lucko/spark/common/CommandSender.java index aca5fba..198bd79 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/CommandSender.java +++ b/spark-common/src/main/java/me/lucko/spark/common/CommandSender.java @@ -23,6 +23,7 @@ package me.lucko.spark.common; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; +import me.lucko.spark.proto.SparkProtos.CommandSenderData; import net.kyori.text.Component; import java.util.UUID; @@ -72,6 +73,18 @@ public interface CommandSender { return user; } + public CommandSenderData toProto() { + CommandSenderData.Builder proto = CommandSenderData.newBuilder() + .setType(isPlayer() ? CommandSenderData.Type.PLAYER : CommandSenderData.Type.OTHER) + .setName(this.name); + + if (this.uniqueId != null) { + proto.setUniqueId(this.uniqueId.toString()); + } + + return proto.build(); + } + public static CommandSender.Data deserialize(JsonElement element) { JsonObject userObject = element.getAsJsonObject(); String user = userObject.get("name").getAsJsonPrimitive().getAsString(); -- cgit