Reverting Packet29DestroyEntity

Discussion in 'Plugin Development' started by xTrollxDudex, Aug 9, 2013.

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

    xTrollxDudex

    Hey guys, I working with packets a bit and I came to realize that Packet29DestroyEntity completely removes my mob, how would I make the mob come back/stop sending it?
     
  2. Offline

    pope_on_dope

    can't you use ProtocolLib to stop the packet..?
     
  3. Offline

    chasechocolate

    I believe the opposite of that is the spawn mob packet. Maybe send that to the player? I am not a packet master, maybe Comphenix knows.
     
  4. Offline

    Comphenix

    There might be other ways, but your safest bet is probably to intercept and remove it from the packet queue, like what ProtocolLib does when you cancel a PacketEvent:
    Code:java
    1. final int ENTITY_TO_PRESERVE = 10;
    2.  
    3. ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(this, ConnectionSide.SERVER_SIDE, Packets.Server.DESTROY_ENTITY) {
    4. @Override
    5. public void onPacketSending(PacketEvent event) {
    6. // Check for entity ID
    7. int[] entities = event.getPacket().getIntegerArrays().read(0);
    8. List<Integer> list = Lists.newArrayList(Ints.asList(entities));
    9. list.remove(ENTITY_TO_PRESERVE);
    10.  
    11. if (list.size() > 0) {
    12. event.getPacket().getIntegerArrays().write(0, Ints.toArray(list));
    13. } else {
    14. event.setCancelled(true);
    15. }
    16. }
    17. });


    If requiring ProtocolLib is a problem, I recommend using it only when present (soft-depend), and use your on interception method otherwise.
     
  5. Offline

    xTrollxDudex

    Comphenix
    Oh I haven't thought about that :p
    Thanks!
     
Thread Status:
Not open for further replies.

Share This Page