Advertisement
Guest User

Untitled

a guest
Mar 20th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. package org.arios.net.packet.out;
  2.  
  3. import org.arios.game.container.ContainerEvent;
  4. import org.arios.game.node.item.Item;
  5. import org.arios.net.packet.IoBuffer;
  6. import org.arios.net.packet.OutgoingPacket;
  7. import org.arios.net.packet.PacketHeader;
  8. import org.arios.net.packet.context.ContainerContext;
  9.  
  10. /**
  11.  * Represents the outgoing container packet.
  12.  * @author Emperor
  13.  */
  14. public final class ContainerPacket implements OutgoingPacket<ContainerContext> {
  15.  
  16.     @Override
  17.     public void send(ContainerContext context) {
  18.         IoBuffer buffer = null;
  19.         if (context.isClear()) {
  20.             buffer = new IoBuffer(144);
  21.             buffer.putIntB(context.getInterfaceId() << 16 | context.getChildId());
  22.         } else {
  23.             boolean slotBased = context.getSlots() != null;
  24.             buffer = new IoBuffer(slotBased ? 22 : 105, PacketHeader.SHORT);
  25.             buffer.putShort(context.getInterfaceId());
  26.             buffer.putShort(context.getChildId());
  27.             buffer.putShort(context.getType());
  28.             if (slotBased) {
  29.                 for (int slot : context.getSlots()) {
  30.                     buffer.putSmart(slot);
  31.                     Item item = context.getItems()[slot];
  32.                     if (item != null && !item.equals(ContainerEvent.NULL_ITEM)) {
  33.                         buffer.putShort(item.getId() + 1);
  34.                         int amount = item.getAmount();
  35.                         if (amount < 0 || amount > 254) {
  36.                             buffer.put(255).putInt(amount);
  37.                         } else {
  38.                             buffer.put(amount);
  39.                         }
  40.                     } else {
  41.                         buffer.putShort(0);
  42.                     }
  43.                 }
  44.             } else {
  45.                 buffer.putShort(context.getItems().length);
  46.                 for (Item item : context.getItems())
  47.                     if (item != null) {
  48.                         int amount = item.getAmount();
  49.                         if (amount < 0 || amount > 254) {
  50.                             buffer.putS(255).putInt(amount);
  51.                         } else {
  52.                             buffer.putS(amount);
  53.                         }
  54.                         buffer.putShort(item.getId() + 1);
  55.                     } else {
  56.                         buffer.putS(0).putShort(0);
  57.                     }
  58.             }
  59.         }
  60.         context.getPlayer().getSession().write(buffer);
  61.     }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement