-
Notifications
You must be signed in to change notification settings - Fork 1
Usage
This page goes over how to use SubData.
You may want to use Maven to handle the dependency for you. If so, here's the code you need to make it happen.
<repositories>
<repository>
<id>ME1312.net</id>
<url>https://dev.ME1312.net/maven</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>net.ME1312.SubData</groupId>
<artifactId>ServerAPI</artifactId>
<version>00w00a</version>
</dependency>
</dependencies>artifactId can be replaced with the location and access level you choose.
version can be replaced with the build version of your choice.
Access Level: ServerAPI, ClientAPI
Documentation (Server): https://dev.me1312.net/jenkins/job/SubData/javadoc/ServerAPI/
Documentation (Client): https://dev.me1312.net/jenkins/job/SubData/javadoc/ClientAPI/
Packets vs. Messages:
The first thing to do when working with Packets and Messages is to decide which one to use: a packet or a message. If you're the app developer and you need speed, then the more efficient packet is for you. Otherwise, if you're a plugin/mod developer who needs compatibility with other plugins/mods, the more versatile message is for you.
Sending different types of data:
Luckily, Packets and Messages both have a similar API style despite their differences, but the next choice is a little tougher: Which type of packet/message should you be using? Well, that depends on what you're looking to send.
MessageOut: Sends no data (but still performs an action when received)
MessageStreamOut: Sends raw data byte by byte (good for sending custom and/or large data types)
MessageObjectOut<Key>: Sends a Galaxi ObjectMap<> via MessagePack (best choice in most scenarios)
For ObjectMap<>, the following types are supported as keys:
-> String (easiest to use)
-> Double
-> Integer (recommended)
-> Boolean (limit: 2 values)
In this exercise we will be sending a message containing a string from the client to the server. This process can also be reversed to send the message from the server to the client. Once you wrap your head around this concept, you can pretty much send anything over SubData.
Client-side:
First, you have to define the message:
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.SubData.Client.Protocol.MessageObjectOut;
import net.ME1312.SubData.Client.DataSender;
public class ExampleMessageOut implements MessageObjectOut<String> {
private final ObjectMap<String> data = new ObjectMap<>();
public ExampleMessageOut(String message) {
data.set("message", message);
}
@Override
public ObjectMap<String> send(DataSender sender) {
return data;
}
}The purpose of this class is to define what to send once your message comes up in the queue. From here, you can register your message with the protocol and begin sending messages over the network.
Server-side:
Before a message can be received, though, you have to define it on the other side:
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.SubData.Server.Protocol.MessageObjectIn;
import net.ME1312.SubData.Server.DataClient;
public class ExampleMessageIn implements MessageObjectIn<String> {
@Override
public void receive(DataClient client, ObjectMap<String> data) {
System.out.println(data.getRawString("message"));
}
}The purpose of this class is to define how to process any incoming data. Register your message handler with the protocol using the same settings, and you're ready to start receiving messages.
Access Level: Server, Client
Documentation (Server): https://dev.me1312.net/jenkins/job/SubData/javadoc/Server/
Documentation (Client): https://dev.me1312.net/jenkins/job/SubData/javadoc/Client/
// We're still writing this part of the docs
// Sorry about that!