ID пакетов в Bungee

MrTrojan

Активный участник
Пользователь
Баллы
98
Имя в Minecraft
BlackTrojan
Здравствуйте, использую библиотеку BungeePackets, для кое-каких целей, и столкнулся с проблемой, чтобы слушать пакеты, нужно их зарегистрировать, а аргументы брать я так не понял откуда.

With this library you can register your own packets! This is just in-case I forget to add one that you need. All of the packets that are in normal minecraft have not been added yet. But soon they will be. To add your own packet, extend the org.spawl.bungeepackets.Packet class. This is an abstract class so you will get 3 methods to start with. Read, write, and handle. Read is called when the BungeeCord recieves the packet, write is called when the Bungee is writing the packet to a pipeline, and handle is called after it is read. Below is an example of how you can register your own packet!

BungeePackets.registerPacket(Protocol.DirectionData.TO_SERVER, <ID>, <CLASS EXTENDING PACKET>);
 
BungeePackets adds in one simple event to manage packets. PacketEvent. The packet event is used to manage all incoming and outgoing packets. With ever incoming and outgoing packet there is a player assigned with it somewhere in the pipe. Using this system we can differentiate whether a server is sending a packet to Bungee, or a player is, vice-versa.

In the example below, we are listening for an incoming packet coming from the client to the BungeeCord. We can check who is sending/receiving packets by checking if they are an instance of a commection. To check if the sender is a palyer, check if the sender is an instanceof a ProxiedPlayer. To check if the sender is Bungee, check if the sender is an instance of a BungeeConnection. To check if the sender is a server, check if the sender is an instanceof a ServerConnection.
Java:
@EventHandler
public void onPacket(PacketEvent event) {
    if(event.getSender() instanceof ProxiedPlayer && event.getReciever() instanceof BungeeConnection) {
        if(event.getPacket() instanceof InFlying) {
            InFlying packet = (InFlying) event.getPacket();
        }
    }
}

Если нужно слушать собственный пакет, то его собсна нужно создать. Айди придумать самому.
 
BungeePackets adds in one simple event to manage packets. PacketEvent. The packet event is used to manage all incoming and outgoing packets. With ever incoming and outgoing packet there is a player assigned with it somewhere in the pipe. Using this system we can differentiate whether a server is sending a packet to Bungee, or a player is, vice-versa.

In the example below, we are listening for an incoming packet coming from the client to the BungeeCord. We can check who is sending/receiving packets by checking if they are an instance of a commection. To check if the sender is a palyer, check if the sender is an instanceof a ProxiedPlayer. To check if the sender is Bungee, check if the sender is an instance of a BungeeConnection. To check if the sender is a server, check if the sender is an instanceof a ServerConnection.
Java:
@EventHandler
public void onPacket(PacketEvent event) {
    if(event.getSender() instanceof ProxiedPlayer && event.getReciever() instanceof BungeeConnection) {
        if(event.getPacket() instanceof InFlying) {
            InFlying packet = (InFlying) event.getPacket();
        }
    }
}

Если нужно слушать собственный пакет, то его собсна нужно создать. Айди придумать самому.
Тогда какие аргументы (первое и третье) задавать?
 
Полагаю Protocol.DirectionData.TO_SERVER - направление(куда отсылается пакет): TO_SERVER или TO_CLIENT.
Третье - сам класс.
public class MyPacket extends Packet{}
Вроде все ясно написано)
 
Последнее редактирование:
Назад
Верх