Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
0
 public void dump() {
   log.debug("DUMP", "total", _total);
   for (Element e : _elements.values())
     log.debug(
         "DUMP: element",
         "key",
         e.key().stack(),
         "whitelisted",
         e.whitelisted(),
         "count",
         e.count());
 }
Ejemplo n.º 5
0
 public void fromNbt(NBTTagCompound tag) {
   clear();
   NBTTagList elements = tag.getTagList("elements", Constants.NBT.TAG_COMPOUND);
   for (int i = 0; i < elements.tagCount(); ++i) {
     NBTTagCompound element = elements.getCompoundTagAt(i);
     Key k = Key.fromNbt(element.getCompoundTag("key"));
     Element e = Element.fromNbt(element.getCompoundTag("element"));
     _elements.put(k, e);
     if (e.whitelisted()) _whitelist.add(k);
   }
   _exportable.fromNbt(tag.getCompoundTag("exportable"));
   if (tag.hasKey("export"))
     _export = ItemHelper.readItemStackFromNBT(tag.getCompoundTag("export"));
   _total = tag.getInteger("total");
 }