Moved packages and fixed logging

Moved packages in a more logical order.
Fixed TransactionLogger using only event.getStock()[0] while logging the
transaction.
Also, TransactionLogger uses string formatter now, instead of a
StringBuilder.
This commit is contained in:
Acrobot 2012-08-10 21:44:32 +02:00
parent aa60c7caab
commit 30fa329645
15 changed files with 34 additions and 41 deletions

View File

@ -15,12 +15,12 @@ import com.Acrobot.ChestShop.Listeners.ItemInfoListener;
import com.Acrobot.ChestShop.Listeners.Player.PlayerConnect; import com.Acrobot.ChestShop.Listeners.Player.PlayerConnect;
import com.Acrobot.ChestShop.Listeners.Player.PlayerInteract; import com.Acrobot.ChestShop.Listeners.Player.PlayerInteract;
import com.Acrobot.ChestShop.Listeners.Player.ShortNameSaver; import com.Acrobot.ChestShop.Listeners.Player.ShortNameSaver;
import com.Acrobot.ChestShop.Listeners.Shop.PostTransaction.EconomicModule; import com.Acrobot.ChestShop.Listeners.PostTransaction.EconomicModule;
import com.Acrobot.ChestShop.Listeners.Shop.PostTransaction.ItemManager; import com.Acrobot.ChestShop.Listeners.PostTransaction.ItemManager;
import com.Acrobot.ChestShop.Listeners.Shop.PreTransaction.*; import com.Acrobot.ChestShop.Listeners.PreTransaction.*;
import com.Acrobot.ChestShop.Listeners.Shop.PostTransaction.EmptyShopDeleter; import com.Acrobot.ChestShop.Listeners.PostTransaction.EmptyShopDeleter;
import com.Acrobot.ChestShop.Listeners.Shop.PostTransaction.TransactionLogger; import com.Acrobot.ChestShop.Listeners.PostTransaction.TransactionLogger;
import com.Acrobot.ChestShop.Listeners.Shop.PostTransaction.TransactionMessageSender; import com.Acrobot.ChestShop.Listeners.PostTransaction.TransactionMessageSender;
import com.Acrobot.ChestShop.Logging.FileFormatter; import com.Acrobot.ChestShop.Logging.FileFormatter;
import com.Acrobot.ChestShop.Signs.RestrictedSign; import com.Acrobot.ChestShop.Signs.RestrictedSign;
import com.avaje.ebean.EbeanServer; import com.avaje.ebean.EbeanServer;

View File

@ -1,4 +1,4 @@
package com.Acrobot.ChestShop.Listeners.Shop.PostTransaction; package com.Acrobot.ChestShop.Listeners.PostTransaction;
import com.Acrobot.ChestShop.Economy.Economy; import com.Acrobot.ChestShop.Economy.Economy;
import com.Acrobot.ChestShop.Events.TransactionEvent; import com.Acrobot.ChestShop.Events.TransactionEvent;

View File

@ -1,4 +1,4 @@
package com.Acrobot.ChestShop.Listeners.Shop.PostTransaction; package com.Acrobot.ChestShop.Listeners.PostTransaction;
import com.Acrobot.ChestShop.Config.Config; import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Config.Property; import com.Acrobot.ChestShop.Config.Property;

View File

@ -1,4 +1,4 @@
package com.Acrobot.ChestShop.Listeners.Shop.PostTransaction; package com.Acrobot.ChestShop.Listeners.PostTransaction;
import com.Acrobot.Breeze.Utils.InventoryUtil; import com.Acrobot.Breeze.Utils.InventoryUtil;
import com.Acrobot.ChestShop.Events.TransactionEvent; import com.Acrobot.ChestShop.Events.TransactionEvent;

View File

@ -1,4 +1,4 @@
package com.Acrobot.ChestShop.Listeners.Shop.PostTransaction; package com.Acrobot.ChestShop.Listeners.PostTransaction;
import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Config.Config; import com.Acrobot.ChestShop.Config.Config;
@ -19,34 +19,27 @@ import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.BUY;
* @author Acrobot * @author Acrobot
*/ */
public class TransactionLogger implements Listener { 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 @EventHandler
public static void onTransaction(TransactionEvent event) { public static void onTransaction(TransactionEvent event) {
StringBuilder message = new StringBuilder(70); String template = (event.getTransactionType() == BUY ? BUY_MESSAGE : SELL_MESSAGE);
message.append(event.getClient().getName()); StringBuilder items = new StringBuilder(50);
if (event.getTransactionType() == BUY) {
message.append(" bought ");
} else {
message.append(" sold ");
}
for (ItemStack item : event.getStock()) { for (ItemStack item : event.getStock()) {
message.append(item.getAmount()).append(' ').append(getSignName(item)); items.append(item.getAmount()).append(' ').append(getSignName(item));
} }
message.append(" for ").append(event.getPrice()); String message = String.format(template,
event.getClient().getName(),
items.toString(),
event.getPrice(),
event.getOwner().getName(),
locationToString(event.getSign().getLocation()));
if (event.getTransactionType() == BUY) { ChestShop.getBukkitLogger().info(message);
message.append(" from ");
} else {
message.append(" to ");
}
message.append(event.getOwner()).append(' ');
message.append(locationToString(event.getSign().getLocation()));
ChestShop.getBukkitLogger().info(message.toString());
} }
@EventHandler @EventHandler
@ -60,7 +53,7 @@ public class TransactionLogger implements Listener {
for (ItemStack item : event.getStock()) { for (ItemStack item : event.getStock()) {
Transaction transaction = new Transaction(); Transaction transaction = new Transaction();
transaction.setAmount(event.getStock()[0].getAmount()); transaction.setAmount(item.getAmount());
transaction.setItemID(item.getTypeId()); transaction.setItemID(item.getTypeId());
transaction.setItemDurability(item.getDurability()); transaction.setItemDurability(item.getDurability());

View File

@ -1,4 +1,4 @@
package com.Acrobot.ChestShop.Listeners.Shop.PostTransaction; package com.Acrobot.ChestShop.Listeners.PostTransaction;
import com.Acrobot.ChestShop.Config.Config; import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Config.Language; import com.Acrobot.ChestShop.Config.Language;

View File

@ -1,4 +1,4 @@
package com.Acrobot.ChestShop.Listeners.Shop.PreTransaction; package com.Acrobot.ChestShop.Listeners.PreTransaction;
import com.Acrobot.Breeze.Utils.InventoryUtil; import com.Acrobot.Breeze.Utils.InventoryUtil;
import com.Acrobot.ChestShop.Economy.Economy; import com.Acrobot.ChestShop.Economy.Economy;

View File

@ -1,4 +1,4 @@
package com.Acrobot.ChestShop.Listeners.Shop.PreTransaction; package com.Acrobot.ChestShop.Listeners.PreTransaction;
import com.Acrobot.ChestShop.Config.Config; import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Events.PreTransactionEvent; import com.Acrobot.ChestShop.Events.PreTransactionEvent;

View File

@ -1,4 +1,4 @@
package com.Acrobot.ChestShop.Listeners.Shop.PreTransaction; package com.Acrobot.ChestShop.Listeners.PreTransaction;
import com.Acrobot.ChestShop.Config.Config; import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Config.Language; import com.Acrobot.ChestShop.Config.Language;

View File

@ -1,4 +1,4 @@
package com.Acrobot.ChestShop.Listeners.Shop.PreTransaction; package com.Acrobot.ChestShop.Listeners.PreTransaction;
import com.Acrobot.Breeze.Utils.InventoryUtil; import com.Acrobot.Breeze.Utils.InventoryUtil;
import com.Acrobot.Breeze.Utils.MaterialUtil; import com.Acrobot.Breeze.Utils.MaterialUtil;

View File

@ -1,4 +1,4 @@
package com.Acrobot.ChestShop.Listeners.Shop.PreTransaction; package com.Acrobot.ChestShop.Listeners.PreTransaction;
import com.Acrobot.ChestShop.Events.PreTransactionEvent; import com.Acrobot.ChestShop.Events.PreTransactionEvent;
import com.Acrobot.ChestShop.Events.TransactionEvent; import com.Acrobot.ChestShop.Events.TransactionEvent;

View File

@ -1,4 +1,4 @@
package com.Acrobot.ChestShop.Listeners.Shop.PreTransaction; package com.Acrobot.ChestShop.Listeners.PreTransaction;
import com.Acrobot.Breeze.Utils.PriceUtil; import com.Acrobot.Breeze.Utils.PriceUtil;
import com.Acrobot.ChestShop.Events.PreTransactionEvent; import com.Acrobot.ChestShop.Events.PreTransactionEvent;

View File

@ -1,4 +1,4 @@
package com.Acrobot.ChestShop.Listeners.Shop.PreTransaction; package com.Acrobot.ChestShop.Listeners.PreTransaction;
import com.Acrobot.ChestShop.Events.PreTransactionEvent; import com.Acrobot.ChestShop.Events.PreTransactionEvent;
import com.Acrobot.ChestShop.Signs.ChestShopSign; import com.Acrobot.ChestShop.Signs.ChestShopSign;

View File

@ -1,4 +1,4 @@
package com.Acrobot.ChestShop.Listeners.Shop.PreTransaction; package com.Acrobot.ChestShop.Listeners.PreTransaction;
import com.Acrobot.ChestShop.Events.PreTransactionEvent; import com.Acrobot.ChestShop.Events.PreTransactionEvent;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@ -1,4 +1,4 @@
package com.Acrobot.ChestShop.Listeners.Shop.PreTransaction; package com.Acrobot.ChestShop.Listeners.PreTransaction;
import com.Acrobot.Breeze.Utils.InventoryUtil; import com.Acrobot.Breeze.Utils.InventoryUtil;
import com.Acrobot.ChestShop.Events.PreTransactionEvent; import com.Acrobot.ChestShop.Events.PreTransactionEvent;