use of com.floweytf.utils.stdstreams.StandardByteReader in project scripted-quests by TeamMonumenta.
the class ClientChatProtocol method onPluginMessageReceived.
@Override
public void onPluginMessageReceived(String s, Player player, byte[] bytes) {
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
IStandardByteReader out = new StandardByteReader(stream);
try {
String mode = out.readString();
JsonObject request = GSON.fromJson(mode, JsonElement.class).getAsJsonObject();
// implements `C->S 'version'` and `C->S 'mode'`
switch(request.get("type").getAsString()) {
case "version":
// implements `S->C 'version'`
sendJson(player, JsonObjectBuilder.get().add("type", "version").add("version", VERSION).build());
break;
case "mode":
boolean newMode = request.get("send").getAsJsonPrimitive().getAsBoolean();
if (newMode) {
mShouldSendMessage.add(player.getUniqueId());
} else {
mShouldSendMessage.remove(player.getUniqueId());
}
break;
default:
// Silently ignore other type requests
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations