Skip to content

Conversation

@Rubenicos
Copy link
Contributor

@Rubenicos Rubenicos commented Nov 19, 2023

Packet listening

Unified packet event class

Now PacketReceiveEvent and PacketSendEvent extends a common AbstractPacketEvent class with the new method AbstractPacketListener#packetEvent(), this is useful if you want to detect a packet that can be generated by the server and proxy.

Functional listeners

Instead of making this:

private MyPacketListener listener;

public void register() {
  listener = new MyPacketListener();
  Protocolize.listenerProvider().registerListener(listener);
}

public void unregister() {
  Protocolize.listenerProvider().unregisterListener(listener);
}

public class MyPacketListener extends AbstractPacketListener<Packet> {  
 
  public MyPacketListener() {  
    super(Packet.class, Direction.DOWNSTREAM, 0);  
  }  
 
  @Override  
  public void packetReceive(PacketReceiveEvent<Packet> event) {  
    // do something
    }  
  }  
}

Now you can make this:

private AbstractPacketListener<Packet> listener;

public void register() {
  listener = Protocolize.listenerProvider().register(Packet.class, Direction.DOWNSTREAM).onReceive(event -> {
    // do something
  });
}

public void unregister() {
  Protocolize.listenerProvider().unregister(listener);
}

Protocolize player

Packet sending

Now ProtocolizePlayer instance can be used to send packets with different protocols, since CONFIGURATION protocol was added this is quite useful.

ProtocolizePlayer player;
Object packet;
player.sendPacket(packet);
player.sendPacket(packet, Protocol.CONFIGURATION);

Protocol information

Get current player protocol from MinecraftDecoder and MinecraftEncoder.

ProtocolizePlayer player;
Protocol decoderProtocol = player.decoderProtocol();
Protocol encoderProtocol = player.encoderProtocol();

@Exceptionflug
Copy link
Owner

Hey, sorry for the late response. I did take a look at this PR and I found it quite useful. But I would like you to check a few things before this can get merged. At first I want you to ensure that there are no API breaking changes here and everything is still binary compatible with already compiled code from an earlier api version.

@Reddishye
Copy link

yo @Exceptionflug, are there any news about this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants