Overview
ECServerAPI is the primary entry point for the Ember Client Server API. It extends JavaPlugin and provides methods to send packets to players using the Ember client and check their connection status.
Class Definition
public final class ECServerAPI extends JavaPlugin
Getting the Instance
getInstance()
Returns the singleton instance of the API.
public static ECServerAPI getInstance()
The singleton instance of ECServerAPI
Example:
ECServerAPI api = ECServerAPI.getInstance();
Constants
CHANNEL_NAME
The plugin messaging channel name used for communication.
public static final String CHANNEL_NAME = "ember:data"
The channel identifier: "ember:data"
Methods
sendPacket()
Sends a packet to a player if they are connected using the Ember client.
public void sendPacket(Player player, Packet packet)
The Bukkit player to send the packet to
Example:
ECServerAPI api = ECServerAPI.getInstance();
Player player = // ... get player
// Request attestation registration
api.sendPacket(player, new OutAttestationRegister());
This method automatically checks if the player is using the Ember client. If they are not, the packet is silently ignored.
isPlayerOnEmber()
Checks whether a player is connected using the Ember client.
public boolean isPlayerOnEmber(UUID uuid)
The unique identifier of the player to check
true if the player is using Ember client, false otherwise
Example:
ECServerAPI api = ECServerAPI.getInstance();
Player player = // ... get player
if (api.isPlayerOnEmber(player.getUniqueId())) {
// Player is using Ember client
api.sendPacket(player, new OutAttestationRegister());
} else {
// Player is using vanilla client
player.sendMessage("You need the Ember client to use this feature.");
}
getPacketManager()
Returns the packet manager for advanced packet handling.
public PacketManager getPacketManager()
The PacketManager instance handling packet serialization and registration
Example:
ECServerAPI api = ECServerAPI.getInstance();
PacketManager packetManager = api.getPacketManager();
Most users will not need to interact with the PacketManager directly. Use sendPacket() for sending packets.
Complete Example
import com.emberclient.serverapi.ECServerAPI;
import com.emberclient.serverapi.packet.impl.attestation.register.OutAttestationRegister;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class MyPlugin implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
ECServerAPI api = ECServerAPI.getInstance();
// Check if player is using Ember
if (api.isPlayerOnEmber(player.getUniqueId())) {
// Request attestation registration
api.sendPacket(player, new OutAttestationRegister());
}
}
}