예제 #1
0
 private static float generateAveragePrice(int itemID) {
   float price = 0;
   List<Transaction> prices =
       ChestShop.getDB()
           .find(Transaction.class)
           .where()
           .eq("itemID", itemID)
           .eq("buy", true)
           .findList();
   for (Transaction t : prices) price += t.getAveragePricePerItem();
   float toReturn = price / prices.size();
   return (!Float.isNaN(toReturn) ? toReturn : 0);
 }
예제 #2
0
  private static double generateItemTotal(int itemID, boolean bought, boolean sold) {
    double amount = 0;
    List<Transaction> list;
    if (bought)
      list =
          ChestShop.getDB()
              .find(Transaction.class)
              .where()
              .eq("buy", 1)
              .eq("itemID", itemID)
              .findList();
    else if (sold)
      list =
          ChestShop.getDB()
              .find(Transaction.class)
              .where()
              .eq("buy", 0)
              .eq("itemID", itemID)
              .findList();
    else list = ChestShop.getDB().find(Transaction.class).where().eq("itemID", itemID).findList();

    for (Transaction t : list) amount += t.getAmount();
    return amount;
  }
예제 #3
0
  @EventHandler
  public static void onTransaction(TransactionEvent event) {
    String template = (event.getTransactionType() == BUY ? BUY_MESSAGE : SELL_MESSAGE);

    StringBuilder items = new StringBuilder(50);

    for (ItemStack item : event.getStock()) {
      items.append(item.getAmount()).append(' ').append(getSignName(item));
    }

    String message =
        String.format(
            template,
            event.getClient().getName(),
            items.toString(),
            event.getPrice(),
            event.getOwner().getName(),
            locationToString(event.getSign().getLocation()));

    ChestShop.getBukkitLogger().info(message);
  }