package io.luna.net.msg.out;

import io.luna.game.model.item.Item;
import io.luna.game.model.mob.Player;
import io.luna.net.codec.ByteMessage;
import io.luna.net.codec.ByteOrder;
import io.luna.net.codec.ByteTransform;
import io.luna.net.codec.MessageType;
import io.luna.net.msg.GameMessageWriter;

/**
 * A {@link GameMessageWriter} implementation that displays a group of items on a widget.
 *
 * @author lare96 <http://github.org/lare96>
 */
public final class WidgetItemsMessageWriter extends GameMessageWriter {

    /**
     * The widget identifier.
     */
    private final int id;

    /**
     * The items.
     */
    private final Item[] items;

    /**
     * Creates a new {@link WidgetItemsMessageWriter}.
     *
     * @param id The widget identifier.
     * @param items The items.
     */
    public WidgetItemsMessageWriter(int id, Item[] items) {
        this.id = id;
        this.items = items;
    }

    @Override
    public ByteMessage write(Player player) {
        ByteMessage msg = ByteMessage.message(53, MessageType.VAR_SHORT);
        msg.putShort(id);
        msg.putShort(items.length);

        for (Item item : items) {
            if (item == null) {
                msg.put(0);
                msg.putShort(0, ByteTransform.A, ByteOrder.LITTLE);
                continue;
            }

            if (item.getAmount() >= 255) {
                msg.put(255);
                msg.putInt(item.getAmount(), ByteOrder.INVERSE_MIDDLE);
            } else {
                msg.put(item.getAmount());
            }
            msg.putShort(item.getId() + 1, ByteTransform.A, ByteOrder.LITTLE);
        }
        return msg;
    }
}

@@ -293,16 +293,71 @@
 riter;%0A%0A
+import java.util.Arrays;%0Aimport java.util.Collection;%0A%0A
 /**%0A * A
@@ -692,22 +692,32 @@
 e final 
+Collection%3C
 Item
-%5B%5D
+%3E
  items;%0A
@@ -918,32 +918,298 @@
 Item%5B%5D items) %7B%0A
+        this(id, Arrays.asList(items));%0A    %7D%0A%0A    /**%0A     * Creates a new %7B@link WidgetItemsMessageWriter%7D.%0A     *%0A     * @param id The widget identifier.%0A     * @param items The items.%0A     */%0A    public WidgetItemsMessageWriter(int id, Collection%3CItem%3E items) %7B%0A
         this.id 
@@ -1440,14 +1440,14 @@
 ems.
-length
+size()
 );%0A%0A

Rename outbound packet 53