Skip to content

Docs: API

Alemiz edited this page Aug 31, 2019 · 3 revisions

🔧API

You can access StarGate API using class GateAPI. Every methods are static.

Avalibe Functions:

  • getGateServer() Returns instance of Server(alemiz.stargate.gate.Server) class.
  • RegisterPacket(StarGatePacket packet) This function we use to register new custom packets.
  • putPacket(String client, StarGatePacket packet) Send packet to client specifying his CHEVRON/name and packet.
  • ping(String client) Pings specified client. It can cause early disconnection. Maybe soon will return ping.
  • pingAll() Exactly same as ping() but this will ping all connected clients.
  • setResponse(String client, String uuid, String response) We use this function to set response of packet based on UUID. Response is then send to client that sent our packet.

If you want to know more consider looking here.

📦Packet Handling

Received Packets are handled by CustomPacketEvent. Official Packets are handled automaticly.

Accessing Custom Packet from Event:

public StarGatePacket getPacket() {
  return packet;
}

See full CustomPacketEvent class.

⚙️Creating Own Packets

For better understanding please read StarGatePacket and WelcomePacket.

Convertor

Convertor is used for encoding and decoding packets. We can use it for static and nonstatic usage Functions:

  • packetStringData(String packetString) Exports packetString to data array

  • putInt(int integer) Pushes Integer to array

  • putString(String string) Pushes String to array

  • getString(int key) Returns String from array by key value

  • getPacketString() Returns packetString from array data

  • static getInt(String string) Returns Integer from String

  • static getPacketString(String[] strings) Returns packetString from given array

  • static getPacketStringData(String packetString) Returns array data from given string

Example (nonstatic):

Convertor convertor = new Convertor(getID());

convertor.putString(server);
convertor.putInt(tps);
convertor.putInt(players);

this.encoded = convertor.getPacketString();

Example (static):

String[] data = Convertor.getPacketStringData(packetString);
int PacketId = Convertor.getInt(data[0]);

Clone this wiki locally