something like onPacket. Is this possible?

Discussion in 'Plugin Development' started by Murderscene, Sep 22, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Murderscene

    Looking around the forums, I can see how to send a packet from the server to the client but how would I intercept a packet sent from the client to the server so that I can trigger methods each time it happens.

    Just looking at getting started on this if anyone has anywhere they can point me
     
  2. Offline

    Comphenix

    You have to override the static packet lists in net.minecraft.server.Packet. You can get a more readable version with MCP:
    Code:java
    1. public abstract class Packet
    2. {
    3. /** Maps packet id to packet class */
    4. public static IntHashMap packetIdToClassMap = new IntHashMap();
    5.  
    6. /** Maps packet class to packet id */
    7. private static Map packetClassToIdMap = new HashMap();
    8.  
    9. /** List of the client's packet IDs. */
    10. private static Set clientPacketIdList = new HashSet();
    11.  
    12. /** List of the server's packet IDs. */
    13. private static Set serverPacketIdList = new HashSet();
    14. //..

    Essentially, you have to add your own packet class to the first two lists.

    But of course, you don't have to reinvent the wheel. I wrote a packet interception library that does it for you. All you need to do is register a client packet listener:
    Code:java
    1. // Listen for the Click Window packet
    2. protocolManager.addPacketListener(
    3. new PacketAdapter(this, ConnectionSide.CLIENT_SIDE, ListenerPriority.NORMAL, 102) {
    4. @Override
    5. public void onPacketSending(PacketEvent event) {
    6. // Item packets
    7. if (event.getPacketID() == 102) {
    8. // ect.
    9. }
    10. }
    11. });
     
Thread Status:
Not open for further replies.

Share This Page