Why are you using a HashMap to represent zero-based integer-keyed contiguous data?
Why is this synchronized? Why does this class require thread safety? You don't write thread-safe code because other people are incapable of understanding thread safety, you write it because you actually need to share it between multiple threads: I'm not convinced this is the case.
Code:
public class ItemDiscardedException extends RuntimeException {
private static final long serialVersionUID = 7130393044046415032L;
}
Useless, add the constructors. I don't know what the idea behind the 'disposed' field is, but that seems pointless.
Code:
long destAmount = this.amount + amount; // use long to prevent overflow
Who knows what's wrong with this?
Code:
public static GamePacket buildResetContainerPacket(int interfaceID) {
GamePacketBuilder bldr = new GamePacketBuilder(72, GamePacket.Type.FIXED);
bldr.putShort(interfaceID);
return bldr.toPacket();
}
public static GamePacket buildContainerItemPacket(int interfaceID, Container container) {
GamePacketBuilder bldr = new GamePacketBuilder(53, GamePacket.Type.VARIABLE_SHORT);
bldr.putShort(interfaceID);
bldr.putShort(container.maximum());
synchronized (container.items) {
for (int i = 0; i < container.maximum(); i++) {
if (container.items.containsKey(i)) {
Item item = container.items.get(i);
if (item.amount() >= 255) {
bldr.put((byte)-1);
bldr.putInt2(item.amount());
}
else {
bldr.put((byte)item.amount());
}
}
else {
bldr.put((byte)0);
bldr.putLEShortA(-1);
}
}
}
Should be somewhere else
Code:
public Container(int maximum, boolean acceptsNotes, boolean forcedItemStacks) {
this.maximumContained = maximum;
this.acceptsNotes = acceptsNotes;
this.forcedStack = forcedItemStacks;
}
Use enums or static constructors, not boolean parameters. Is there actually a container that doesn't allow noted items?
Code:
// stil don't know why we subtract 1
ItemInfo info = ItemInfo.forID(id - 1);
Code:
// we don't sync on other object's items because we don't want a deadlock.
// unfortunately, the only possibility of deadlock is in this method itself.
// if you transfer items between the same two containers in parallel, there's a possibility for deadlock.
// thankfully, i can't see the reason there would be transfers between the same two containers at the same time.
Code:
items.put((Integer)existingSlot, end);
Code:
items.put((Integer)slot, new Item(id, 1));
Code:
items.put((Integer)slot, new Item(id, amount));