Esempio n. 1
0
  Importprices(String args[], CommandSender sender) {
    HyperConomy hc = HyperConomy.hc;
    LanguageFile L = hc.getLanguageFile();
    DataHandler sf = hc.getDataFunctions();

    try {
      if (args.length == 1) {
        String economy = args[0];
        if (sf.testEconomy(economy)) {
          new Backup();
          FileConfiguration itemsyaml = hc.getYaml().getItems();
          Iterator<String> it = itemsyaml.getKeys(false).iterator();
          while (it.hasNext()) {
            String name = it.next().toString();
            double value = itemsyaml.getDouble(name + ".value");
            double staticprice = itemsyaml.getDouble(name + ".price.staticprice");
            double startprice = itemsyaml.getDouble(name + ".initiation.startprice");
            HyperObject ho = sf.getHyperObject(name, economy);
            ho.setValue(value);
            ho.setStartprice(startprice);
            ho.setStaticprice(staticprice);
          }
          FileConfiguration enchantsyaml = hc.getYaml().getEnchants();
          Iterator<String> it2 = enchantsyaml.getKeys(false).iterator();
          while (it2.hasNext()) {
            String name = it2.next().toString();
            double value = enchantsyaml.getDouble(name + ".value");
            double staticprice = enchantsyaml.getDouble(name + ".price.staticprice");
            double startprice = enchantsyaml.getDouble(name + ".initiation.startprice");
            HyperObject ho = sf.getHyperObject(name, economy);
            ho.setValue(value);
            ho.setStartprice(startprice);
            ho.setStaticprice(staticprice);
          }
          sender.sendMessage(L.get("PRICES_IMPORTED"));
        } else {
          sender.sendMessage(L.get("ECONOMY_NOT_EXIST"));
          return;
        }
      } else {
        sender.sendMessage(L.get("IMPORTPRICES_INVALID"));
      }
    } catch (Exception e) {
      sender.sendMessage(L.get("IMPORTPRICES_INVALID"));
    }
  }
Esempio n. 2
0
 Sellall(String args[], Player p) {
   hc = HyperConomy.hc;
   s = hc.getShop();
   calc = hc.getCalculation();
   tran = hc.getTransaction();
   ench = hc.getETransaction();
   player = p;
   try {
     s.setinShop(player);
     if (s.inShop() != -1) {
       if (!hc.getYaml().getConfig().getBoolean("config.use-shop-permissions")
           || player.hasPermission("hyperconomy.shop.*")
           || player.hasPermission("hyperconomy.shop." + s.getShop(player))
           || player.hasPermission("hyperconomy.shop." + s.getShop(player) + ".sell")) {
         if (args.length == 0) {
           int slotn = 0;
           Inventory invent = player.getInventory();
           int heldslot = player.getInventory().getHeldItemSlot();
           int itd = 0;
           // Sells the held item slot first.
           if (invent.getItem(heldslot) != null) {
             itd = invent.getItem(heldslot).getTypeId();
           }
           if (itd != 0) {
             int da = calc.getpotionDV(invent.getItem(heldslot));
             int newdat = calc.newData(itd, da);
             String ke = itd + ":" + newdat;
             String nam = hc.getnameData(ke);
             int amount = tran.countInvitems(itd, newdat, player);
             if (nam != null) {
               if (s.has(s.getShop(player), nam)) {
                 tran.sell(nam, itd, newdat, amount, player);
               } else {
                 sendMessage("§9Sorry, one or more of those items cannot be traded at this shop.");
               }
             }
           }
           // Sells remaining items after the held slot.
           while (slotn < 36) {
             if (invent.getItem(slotn) == null) {
               itd = 0;
             } else {
               itd = invent.getItem(slotn).getTypeId();
             }
             if (itd != 0) {
               ItemStack itemn = invent.getItem(slotn);
               if (ench.hasenchants(itemn) == false) {
                 int da = calc.getpotionDV(invent.getItem(slotn));
                 int newdat = calc.newData(itd, da);
                 String ke = itd + ":" + newdat;
                 String nam = hc.getnameData(ke);
                 if (nam != null) {
                   int amount = tran.countInvitems(itd, newdat, player);
                   if (s.has(s.getShop(player), nam)) {
                     tran.sell(nam, itd, newdat, amount, player);
                   } else {
                     sendMessage(
                         "§9Sorry, one or more of those items cannot be traded at this shop.");
                   }
                 }
               } else {
                 sendMessage("§9You cannot buy or sell enchanted items!");
               }
             }
             slotn++;
           }
         } else {
           player.sendMessage("§4Invalid Parameters. Use /sellall");
           return;
         }
       } else {
         player.sendMessage("§9Sorry, you don't have permission to trade here.");
         return;
       }
     } else {
       player.sendMessage("§4You must be in a shop to buy or sell!");
       return;
     }
   } catch (Exception e) {
     player.sendMessage("§4Invalid Parameters. Use /sellall");
     return;
   }
 }