Skip to content

Latest commit

 

History

History
28 lines (22 loc) · 932 Bytes

File metadata and controls

28 lines (22 loc) · 932 Bytes

Bukkit Implementation

Usage

Using our custom packet MyPacket created in the main README. In the below example, we are going to pretend that we send a message using a command and can also receive replies, displaying them to the player.

public ServerGateway<Player> gateway = BukkitGatewayProvider.getGateway("MyChannelName", this);

public void onEnable() {
    gateway.registerListener(this);
}

public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof Player) {
        Player player = (Player) sender;
        gateway.sendPacket(player, new MyPacket(StringUtils.join(args, " "))); // send a packet containing the arguments used in the command
    }
}

@PacketHandler
public void onMyPacket(Player player, MyPacket myPacket) {
    player.sendMessage("Received message: " + myPacket.getMessage());
}