@Override
  public ItemStack decrStackSize(int i, int j) {
    if (contents[i] != null) {
      int max = StoreUtil.instance().maxPurchase(credits, contents[i].itemID);
      if (max == 0) {
        return null;
      }
      if (max < j) {
        j = max;
      }
      if (contents[i].stackSize <= j) {
        ItemStack itemstack = contents[i];
        int cost = StoreUtil.instance().getCost(itemstack);
        if (credits >= cost) {
          contents[i] = null;
          onInventoryChanged();
          return itemstack;
        }

        return null;
      }
      ItemStack itemstack1 = contents[i].splitStack(j);
      int cost = StoreUtil.instance().getCost(itemstack1);
      if (credits >= cost) {
        if (contents[i].stackSize == 0) {
          contents[i] = null;
        }
        onInventoryChanged();
        return itemstack1;
      }
    }
    return null;
  }
 // Calculates the entire value of the contents of the store
 public int calcValue() {
   int total = 0;
   for (int i = 0; i < getSizeInventory(); ++i) {
     total += StoreUtil.instance().getCost(contents[i]);
   }
   return total;
 }
Ejemplo n.º 3
0
  public int store(OutputStream out) throws IOException {

    if (symbol != null) {
      r_symndx = elf.getIndexOfSymbol(symbol);
    }

    final long info;
    if (elf.isClass32()) {
      info = (r_type & 0xFF) | (r_symndx << 8);
    } else {
      info = ((long) r_type) | (((long) r_symndx) << 32);
    }
    int cnt = 0;
    cnt += StoreUtil.storeAddr(out, elf.e_ident, r_address);
    cnt += StoreUtil.storeXword(out, elf.e_ident, info);
    return cnt;
  }
 public void _saveSettings() { // public for testing purposes
   if (mySaveSettingsIsInProgress.compareAndSet(false, true)) {
     try {
       StoreUtil.doSave(getStateStore());
     } catch (final Throwable ex) {
       if (isUnitTestMode()) {
         System.out.println("Saving application settings failed");
         ex.printStackTrace();
       } else {
         LOG.info("Saving application settings failed", ex);
         invokeLater(
             new Runnable() {
               public void run() {
                 if (ex instanceof PluginException) {
                   final PluginException pluginException = (PluginException) ex;
                   PluginManager.disablePlugin(pluginException.getPluginId().getIdString());
                   Messages.showMessageDialog(
                       "The plugin "
                           + pluginException.getPluginId()
                           + " failed to save settings and has been disabled. Please restart "
                           + ApplicationNamesInfo.getInstance().getFullProductName(),
                       CommonBundle.getErrorTitle(),
                       Messages.getErrorIcon());
                 } else {
                   Messages.showMessageDialog(
                       ApplicationBundle.message(
                           "application.save.settings.error", ex.getLocalizedMessage()),
                       CommonBundle.getErrorTitle(),
                       Messages.getErrorIcon());
                 }
               }
             });
       }
     } finally {
       mySaveSettingsIsInProgress.set(false);
     }
   }
 }
Ejemplo n.º 5
0
 public int store(OutputStream out) throws IOException {
   int cnt = 0;
   if (elf.isClass32()) {
     cnt += StoreUtil.little32(out, st_name);
     cnt += StoreUtil.storeAddr(out, elf.e_ident, st_value);
     cnt += StoreUtil.storeXword(out, elf.e_ident, st_size);
     cnt += StoreUtil.little8(out, st_info);
     cnt += StoreUtil.little8(out, st_other);
     cnt += StoreUtil.little16(out, st_shndx);
   } else {
     cnt += StoreUtil.little32(out, st_name);
     cnt += StoreUtil.little8(out, st_info);
     cnt += StoreUtil.little8(out, st_other);
     cnt += StoreUtil.little16(out, st_shndx);
     cnt += StoreUtil.storeAddr(out, elf.e_ident, st_value);
     cnt += StoreUtil.storeXword(out, elf.e_ident, st_size);
   }
   return cnt;
 }