Packet filters for the API?

As you may (or may not) know, you can use FileFilters from to only list files that fit certain specs. I thought it would be good to have a similar functionality in the API, but for packets that are sent to the clients. This would make it easier to intercept chat-, entity-, etc. packets, maybe modify their data, before they’re sent to the the client.

For example (this is just an idea):

Server.addPacketFilter(typeOfPacket, new PacketFilter() {
    @Override public boolean filter(Packet pck) {
        if (((Player)"Player"))
            return false;
            return true;

Would cancel all packets of type “typeOfpacket” that are sent to the player named “Player”.

What do you think? Would sth like this be helpful (or possible)?


This seems an awful lot like GitHub - aadnk/ProtocolLib: Provides read and write access to the Minecraft protocol with Bukkit.. While I don’t think it will be included in the API(at least in the first few versions), someone will eventually port ProtocolLib to a Sponge plugin, I’m sure.

1 Like

Wouldn’t it better to make this a event?

  • PacketSendEvent
  • PacketRecieveEvent

I’d love to see that.

I also would love to see that. I only see 1 problem. All these packets :worried:. Will give a class explosion in the API. I don’t know if it is possible to generalize every packet in 1 packet class.

1 Like

That might be a problem… But there are classes for every Packet in the Vanilla server too…

Well thats just the problem. If we have to make an interface for every packet … . I guess @gratimax is right. We will need a sponge addon mod for this. I say mod because a plugin can’t solve the problem. On the positive sight. That addon won’t need to do reflection or other hacky stuff in order to get things done.

Packets are implementation details, much like NBT. :frowning:

Comphenix has suggested that ProtocolLib for Sponge is a possibility:

Packet filtering is definitely something that should be in a plugin, not a properly-abstracted API.

1 Like