Ejemplo n.º 1
0
 public int delete(ItemStack template, int amount) {
   Key key = Key.of(template);
   Element e = _elements.get(key);
   log.debug("take", "template", template, "key", key, "e", e);
   if (e == null) return 0;
   int taken = e.take(amount);
   _total = Math.max(0, _total - taken);
   return taken;
 }
Ejemplo n.º 2
0
 public boolean allowed(ItemStack stack) {
   log.trace("allowed", "template", stack, "size", stack == null ? 0 : stack.stackSize);
   Key key = Key.of(stack);
   Element e = _elements.get(key);
   if (e == null || !e.whitelisted()) return false;
   if (e.count() + stack.stackSize > _maxPerKey) return false;
   if (_total + stack.stackSize > _maxTotal) return false;
   return true;
 }
Ejemplo n.º 3
0
 public void deny(ItemStack template) {
   Key key = Key.of(template);
   Element e = _elements.get(key);
   log.debug("deny", "template", template, "key", key, "e", e);
   if (e == null || !e.whitelisted()) return;
   log.debug("deny: whitelisted: removing...", "empty", e.empty());
   e.whitelisted(false);
   _whitelist.remove(key);
   if (e.empty()) _elements.remove(key);
 }
Ejemplo n.º 4
0
 /** Inserts the target stack and returns what didn't fit. */
 public ItemStack put(ItemStack stack) {
   int amount = Math.min(_max - _size, stack.stackSize);
   if (amount <= 0) return stack;
   Key k = Key.of(stack);
   Integer current = _elements.get(k);
   _elements.put(k, current == null ? amount : current + amount);
   _size += amount;
   stack.splitStack(amount);
   return stack.stackSize > 0 ? stack : null;
 }
Ejemplo n.º 5
0
 public ItemStack take(ItemStack template, int amount) {
   Key k = Key.of(template);
   Integer count = _elements.get(k);
   if (count == null) return null;
   ItemStack stack = k.stack().copy();
   stack.stackSize =
       Math.min(stack.getMaxStackSize(), Math.min(SLOT_STACK_LIMIT, Math.min(amount, count)));
   _size -= stack.stackSize;
   if (stack.stackSize >= count) _elements.remove(k);
   else _elements.put(k, count - stack.stackSize);
   return stack;
 }
Ejemplo n.º 6
0
 public ItemStack put(ItemStack stack) {
   log.debug("put", "stack", stack, "size", stack.stackSize);
   if (stack == null) return null;
   Key key = Key.of(stack);
   Element e = _elements.get(key);
   if (e == null) return stack;
   int amount = stack.stackSize;
   amount = Math.min(amount, _maxTotal - _total);
   amount = e.put(amount, _maxPerKey);
   if (amount == 0) return stack;
   _total += amount;
   log.debug("put: done", "amount", amount);
   return stack.splitStack(amount);
 }
Ejemplo n.º 7
0
 public boolean allow(ItemStack template) {
   log.debug("allow", "template", template);
   if (_whitelist.size() >= _maxKeys) return false;
   Key key = Key.of(template);
   Element e = _elements.get(key);
   if (e == null) {
     e = Element.of(key, 0, true);
     _elements.put(key, e);
     _whitelist.add(key);
   } else if (!e.whitelisted()) {
     e.whitelisted(true);
     _whitelist.add(key);
   }
   return true;
 }
Ejemplo n.º 8
0
 public boolean has(ItemStack template) {
   Key key = Key.of(template);
   Element e = _elements.get(key);
   log.debug("has", "template", template, "key", key, "e", e);
   return e != null && !e.empty();
 }
Ejemplo n.º 9
0
 public static Key fromNbt(NBTTagCompound tag) {
   return Key.of(ItemHelper.readItemStackFromNBT(tag));
 }