Transmission

Reliable bungeecord

The transmission api allows you to communicate across the bungeecord proxy with ease and simplicity. Here are some benefits to using the Transmission API

  • If the Source and Destination servers dont have at least one player, it will be queued to send until the conditions are met for a safe transmission
  • Transmission packets use packet compression
  • Transmission packets are data clusters. You can store vast types of data in them.
  • Transmission packets store several identifiers
    • A Destination of where to go
    • A Source of where it came from
    • A Timestamp for when it was sent
    • A TYPE which is used for parsing the data on the destination server

Transmitting Packets

Sending packets are the simplest, and have the most "will it actually go through" security since the destination ends are checked.

//Creates a transmission to be sent to ALL servers
Transmission t = new Transmission("packet-type");

//You can also set the specific destination
t = new Transmission("packet-type", "specific-server");

//Add some data
t.set("some.boolean", false);
t.set("some.string", "FooBar");
t.set("some.list", Phantom.instance().onlinePlayers().toString(", "));        

//Transmit it!
try
{
    t.transmit();
}
catch(IOException e)
{
    e.printStackTrace();
}

Receiving Transmissions

Receiving transmitters are simple aswell. Just ensure you

  • Implement Transmitter
  • Register it
  • Listen on the Transmit method
package org.phantomapi.example;

import java.util.List;
import org.phantomapi.Phantom;
import org.phantomapi.construct.Controllable;
import org.phantomapi.construct.Controller;
import org.phantomapi.lang.GList;
import org.phantomapi.transmit.Transmission;
import org.phantomapi.transmit.Transmitter;

public class ExampleController extends Controller implements Transmitter
{
    public ExampleController(Controllable parentController)
    {
        super(parentController);
    }

    @Override
    public void onStart()
    {
        //Register the Transmitter
        Phantom.registerTransmitter(this);
    }

    @Override
    public void onStop()
    {

    }

    @Override
    public void onTransmissionReceived(Transmission t)
    {
        //Check if the type is correct
        if(t.getType().equals("packet-type"))
        {
            //Who sent it?
            t.getSource();

            //When did they send it?
            t.getTimeStamp();

            //Get the data we sent
            Boolean someBoolean = t.getBoolean("some.boolean");
            String fooBar = t.getString("some.string");
            List<String> list = t.getStringList("some.list");
        }
    }
}

results matching ""

    No results matching ""