mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-12-25 09:27:39 +01:00
Send the transaction message in an async thread
This commit is contained in:
parent
9e1e582d4a
commit
42ca03b780
@ -7,6 +7,7 @@ import com.Acrobot.ChestShop.DB.Transaction;
|
||||
import com.Acrobot.ChestShop.Events.TransactionEvent;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -20,24 +21,28 @@ public class TransactionLogger implements Listener {
|
||||
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";
|
||||
|
||||
@EventHandler
|
||||
public static void onTransaction(TransactionEvent event) {
|
||||
String template = (event.getTransactionType() == BUY ? BUY_MESSAGE : SELL_MESSAGE);
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public static void onTransaction(final TransactionEvent event) {
|
||||
ChestShop.getBukkitServer().getScheduler().runTaskAsynchronously(ChestShop.getPlugin(), new Runnable() {
|
||||
@Override public void run() {
|
||||
String template = (event.getTransactionType() == BUY ? BUY_MESSAGE : SELL_MESSAGE);
|
||||
|
||||
StringBuilder items = new StringBuilder(50);
|
||||
StringBuilder items = new StringBuilder(50);
|
||||
|
||||
for (ItemStack item : event.getStock()) {
|
||||
items.append(item.getAmount()).append(' ').append(getSignName(item));
|
||||
}
|
||||
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()));
|
||||
String message = String.format(template,
|
||||
event.getClient().getName(),
|
||||
items.toString(),
|
||||
event.getPrice(),
|
||||
event.getOwner().getName(),
|
||||
locationToString(event.getSign().getLocation()));
|
||||
|
||||
ChestShop.getBukkitLogger().info(message);
|
||||
ChestShop.getBukkitLogger().info(message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
Loading…
Reference in New Issue
Block a user