コード例 #1
0
  @EventHandler
  public static void onTransactionLogToDB(TransactionEvent event) {
    if (!Config.getBoolean(LOG_TO_DATABASE) && !Config.getBoolean(GENERATE_STATISTICS_PAGE)) {
      return;
    }

    double pricePerStack = event.getPrice() / event.getStock().length;

    for (ItemStack item : event.getStock()) {
      Transaction transaction = new Transaction();

      transaction.setAmount(item.getAmount());

      transaction.setItemID(item.getTypeId());
      transaction.setItemDurability(item.getDurability());

      transaction.setPrice((float) pricePerStack);

      transaction.setShopOwner(event.getOwner().getName());
      transaction.setShopUser(event.getClient().getName());

      transaction.setSec(System.currentTimeMillis() / 1000);
      transaction.setBuy(event.getTransactionType() == BUY);

      Queue.addToQueue(transaction);
    }
  }
コード例 #2
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);
  }