ChestShop-3/com/Acrobot/ChestShop/Logging/Logging.java

55 lines
1.8 KiB
Java
Raw Normal View History

2011-05-15 19:33:03 +02:00
package com.Acrobot.ChestShop.Logging;
2011-06-09 22:54:01 +02:00
import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Config.Property;
2011-05-29 13:25:25 +02:00
import com.Acrobot.ChestShop.DB.Queue;
import com.Acrobot.ChestShop.DB.Transaction;
import com.Acrobot.ChestShop.Shop.Shop;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
2011-05-15 19:33:03 +02:00
/**
* @author Acrobot
*/
public class Logging {
2011-05-29 13:25:25 +02:00
private static DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
public static String getDateAndTime() {
Date date = new Date();
return dateFormat.format(date);
}
2011-06-09 22:54:01 +02:00
2011-05-29 13:25:25 +02:00
public static void log(String string) {
if (Config.getBoolean(Property.LOG_TO_CONSOLE)) {
2011-06-09 22:54:01 +02:00
System.out.println("[ChestShop] " + string);
}
2011-05-29 13:25:25 +02:00
FileWriterQueue.addToQueue(getDateAndTime() + ' ' + string);
}
2011-06-09 22:54:01 +02:00
public static void logTransaction(boolean isBuying, Shop shop, Player player) {
2011-05-29 13:25:25 +02:00
log(player.getName() + (isBuying ? " bought " : " sold ") + shop.stockAmount + ' ' + shop.stock.getType() + " for " + (isBuying ? shop.buyPrice + " from " : shop.sellPrice + " to ") + shop.owner);
if (!Config.getBoolean(Property.USE_DATABASE)) {
2011-05-29 13:25:25 +02:00
return;
}
Transaction transaction = new Transaction();
transaction.setAmount(shop.stockAmount);
transaction.setBuy(isBuying);
ItemStack stock = shop.stock;
transaction.setItemDurability(stock.getDurability());
transaction.setItemID(stock.getTypeId());
transaction.setPrice((isBuying ? shop.buyPrice : shop.sellPrice));
2011-06-09 22:54:01 +02:00
transaction.setSec(System.currentTimeMillis() / 1000);
2011-05-29 13:25:25 +02:00
transaction.setShopOwner(shop.owner);
transaction.setShopUser(player.getName());
Queue.addToQueue(transaction);
2011-05-15 19:33:03 +02:00
}
}