aboutsummaryrefslogtreecommitdiff
path: root/spark-common/src/main/java/me/lucko/spark/common/CommandSender.java
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2019-06-16 13:30:16 +0100
committerLuck <git@lucko.me>2019-06-16 13:30:16 +0100
commit11db3961055067fcd27b579113af4f6d32b9f6a6 (patch)
treee7846447332f5341a3abbf04a085f6fb66d6f870 /spark-common/src/main/java/me/lucko/spark/common/CommandSender.java
parent35a3bf42fca8bae92780d87b1833cf4217a828f4 (diff)
downloadspark-11db3961055067fcd27b579113af4f6d32b9f6a6.tar.gz
spark-11db3961055067fcd27b579113af4f6d32b9f6a6.tar.bz2
spark-11db3961055067fcd27b579113af4f6d32b9f6a6.zip
Use protobuf to encode data instead of JSON
Diffstat (limited to 'spark-common/src/main/java/me/lucko/spark/common/CommandSender.java')
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/CommandSender.java13
1 files changed, 13 insertions, 0 deletions
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();