2012-08-10 21:44:32 +02:00
|
|
|
package com.Acrobot.ChestShop.Listeners.PostTransaction;
|
2012-06-08 15:28:36 +02:00
|
|
|
|
2013-08-07 02:03:09 +02:00
|
|
|
import com.Acrobot.Breeze.Utils.LocationUtil;
|
2012-06-08 15:28:36 +02:00
|
|
|
import com.Acrobot.ChestShop.ChestShop;
|
|
|
|
import com.Acrobot.ChestShop.Events.TransactionEvent;
|
|
|
|
import org.bukkit.event.EventHandler;
|
2013-08-05 02:06:01 +02:00
|
|
|
import org.bukkit.event.EventPriority;
|
2012-06-08 15:28:36 +02:00
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
2018-01-03 17:28:31 +01:00
|
|
|
import static com.Acrobot.Breeze.Utils.InventoryUtil.mergeSimilarStacks;
|
2021-01-03 01:55:01 +01:00
|
|
|
import static com.Acrobot.ChestShop.Utils.ItemUtil.getName;
|
2012-08-10 18:56:16 +02:00
|
|
|
import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.BUY;
|
2012-06-08 15:28:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Acrobot
|
|
|
|
*/
|
|
|
|
public class TransactionLogger implements Listener {
|
2012-08-10 21:44:32 +02:00
|
|
|
private static final String BUY_MESSAGE = "%1$s bought %2$s for %3$.2f from %4$s at %5$s";
|
|
|
|
private static final String SELL_MESSAGE = "%1$s sold %2$s for %3$.2f to %4$s at %5$s";
|
|
|
|
|
2018-08-22 01:21:34 +02:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
2013-08-05 02:06:01 +02:00
|
|
|
public static void onTransaction(final TransactionEvent event) {
|
2018-01-22 01:00:24 +01:00
|
|
|
String template = (event.getTransactionType() == BUY ? BUY_MESSAGE : SELL_MESSAGE);
|
|
|
|
|
|
|
|
StringBuilder items = new StringBuilder(50);
|
|
|
|
|
|
|
|
for (ItemStack item : mergeSimilarStacks(event.getStock())) {
|
2018-03-12 21:01:28 +01:00
|
|
|
items.append(item.getAmount()).append(' ').append(getName(item));
|
2018-01-22 01:00:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
String message = String.format(template,
|
|
|
|
event.getClient().getName(),
|
|
|
|
items.toString(),
|
2019-04-25 19:44:22 +02:00
|
|
|
event.getExactPrice(),
|
2018-01-22 01:00:24 +01:00
|
|
|
event.getOwnerAccount().getName(),
|
|
|
|
LocationUtil.locationToString(event.getSign().getLocation()));
|
|
|
|
|
|
|
|
ChestShop.getBukkitLogger().info(message);
|
2012-06-08 15:28:36 +02:00
|
|
|
}
|
|
|
|
}
|