summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2011-07-06 02:58:59 +0200
committersnowleo <schneeleo@gmail.com>2011-07-06 02:58:59 +0200
commitb2723740726631caa837dcf3d2695720eb170dcc (patch)
treed79b1cf04de9f0ad5ddb039e50b2b1a1a1f2cbb6
parent8afde1ccc0aaf089940c879fcbe3efb65e07a88f (diff)
downloadEssentials-b2723740726631caa837dcf3d2695720eb170dcc.tar
Essentials-b2723740726631caa837dcf3d2695720eb170dcc.tar.gz
Essentials-b2723740726631caa837dcf3d2695720eb170dcc.tar.lz
Essentials-b2723740726631caa837dcf3d2695720eb170dcc.tar.xz
Essentials-b2723740726631caa837dcf3d2695720eb170dcc.zip
Basic logging of trade/buy/sell signs and sell command
-rw-r--r--Essentials/src/com/earth2me/essentials/Essentials.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/Settings.java5
-rw-r--r--Essentials/src/com/earth2me/essentials/Trade.java105
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandsell.java5
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/SignBuy.java1
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/SignSell.java1
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/SignTrade.java4
7 files changed, 122 insertions, 1 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java
index d75c13a73..27dc46409 100644
--- a/Essentials/src/com/earth2me/essentials/Essentials.java
+++ b/Essentials/src/com/earth2me/essentials/Essentials.java
@@ -241,11 +241,13 @@ public class Essentials extends JavaPlugin implements IEssentials
public void onDisable()
{
instance = null;
+ Trade.closeLog();
logger.removeHandler(errorHandler);
}
public void reload()
{
+ Trade.closeLog();
loadBanList();
for (IConf iConf : confList)
diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java
index 4622bbe46..7f4328d1b 100644
--- a/Essentials/src/com/earth2me/essentials/Settings.java
+++ b/Essentials/src/com/earth2me/essentials/Settings.java
@@ -385,4 +385,9 @@ public class Settings implements IConf
}
return max;
}
+
+ boolean isEcoLogEnabled()
+ {
+ return config.getBoolean("economy-log-enabled", false);
+ }
}
diff --git a/Essentials/src/com/earth2me/essentials/Trade.java b/Essentials/src/com/earth2me/essentials/Trade.java
index 93d73acde..0be445032 100644
--- a/Essentials/src/com/earth2me/essentials/Trade.java
+++ b/Essentials/src/com/earth2me/essentials/Trade.java
@@ -1,6 +1,13 @@
package com.earth2me.essentials;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.text.DateFormat;
+import java.util.Date;
import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.bukkit.inventory.ItemStack;
@@ -122,4 +129,102 @@ public class Trade
{
return itemStack;
}
+ private static FileWriter fw = null;
+
+ public static void log(String type, String subtype, String event, String sender, Trade charge, String receiver, Trade pay, IEssentials ess)
+ {
+ if (!ess.getSettings().isEcoLogEnabled())
+ {
+ return;
+ }
+ if (fw == null)
+ {
+ try
+ {
+ fw = new FileWriter(new File(ess.getDataFolder(), "trade.log"), true);
+ }
+ catch (IOException ex)
+ {
+ Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
+ }
+ }
+ StringBuilder sb = new StringBuilder();
+ sb.append(type).append(",").append(subtype).append(",").append("event").append(",\"");
+ sb.append(DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(new Date()));
+ sb.append("\",\"");
+ if (sender != null)
+ {
+ sb.append(sender);
+ }
+ sb.append("\",");
+ if (charge == null)
+ {
+ sb.append("\"\",\"\",\"\"");
+ }
+ else
+ {
+ if (charge.getItemStack() != null)
+ {
+ sb.append(charge.getItemStack().getAmount()).append(",");
+ sb.append(charge.getItemStack().getType().toString()).append(",");
+ sb.append(charge.getItemStack().getDurability());
+ }
+ if (charge.getMoney() != null)
+ {
+ sb.append(charge.getMoney()).append(",");
+ sb.append("money").append(",");
+ sb.append(ess.getSettings().getCurrencySymbol());
+ }
+ }
+ sb.append(",\"");
+ if (receiver != null)
+ {
+ sb.append(receiver);
+ }
+ sb.append("\",");
+ if (pay == null)
+ {
+ sb.append("\"\",\"\",\"\"");
+ }
+ else
+ {
+ if (pay.getItemStack() != null)
+ {
+ sb.append(pay.getItemStack().getAmount()).append(",");
+ sb.append(pay.getItemStack().getType().toString()).append(",");
+ sb.append(pay.getItemStack().getDurability());
+ }
+ if (pay.getMoney() != null)
+ {
+ sb.append(pay.getMoney()).append(",");
+ sb.append("money").append(",");
+ sb.append(ess.getSettings().getCurrencySymbol());
+ }
+ }
+ sb.append("\n");
+ try
+ {
+ fw.write(sb.toString());
+ fw.flush();
+ }
+ catch (IOException ex)
+ {
+ Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
+ }
+ }
+
+ public static void closeLog()
+ {
+ if (fw != null) {
+ try
+ {
+ fw.close();
+ }
+ catch (IOException ex)
+ {
+ Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
+ }
+ fw = null;
+ }
+ }
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java
index 155ee695c..4a20968b7 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java
@@ -4,6 +4,7 @@ import org.bukkit.Server;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.InventoryWorkaround;
import com.earth2me.essentials.ItemDb;
+import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import java.util.logging.Level;
@@ -151,8 +152,10 @@ public class Commandsell extends EssentialsCommand
}
charge(user);
- InventoryWorkaround.removeItem(user.getInventory(), true, new ItemStack(is.getType(), amount, is.getDurability()));
+ final ItemStack ris = new ItemStack(is.getType(), amount, is.getDurability());
+ InventoryWorkaround.removeItem(user.getInventory(), true, ris);
user.updateInventory();
+ Trade.log("Command", "Sell", "Item", user.getName(), new Trade(ris, ess), user.getName(), new Trade(worth*amount, ess), ess);
user.giveMoney(worth * amount);
user.sendMessage(Util.format("itemSold", Util.formatCurrency(worth * amount), amount, Util.formatCurrency(worth)));
logger.log(Level.INFO, Util.format("itemSoldConsole", user.getDisplayName(), is.getType().toString().toLowerCase(), Util.formatCurrency(worth * amount), amount, Util.formatCurrency(worth)));
diff --git a/Essentials/src/com/earth2me/essentials/signs/SignBuy.java b/Essentials/src/com/earth2me/essentials/signs/SignBuy.java
index 21dc7683e..4249342e1 100644
--- a/Essentials/src/com/earth2me/essentials/signs/SignBuy.java
+++ b/Essentials/src/com/earth2me/essentials/signs/SignBuy.java
@@ -29,6 +29,7 @@ public class SignBuy extends EssentialsSign
charge.isAffordableFor(player);
items.pay(player);
charge.charge(player);
+ Trade.log("Sign", "Buy", "Interact", username, charge, username, items, ess);
return true;
}
}
diff --git a/Essentials/src/com/earth2me/essentials/signs/SignSell.java b/Essentials/src/com/earth2me/essentials/signs/SignSell.java
index d35a83518..9df1ec874 100644
--- a/Essentials/src/com/earth2me/essentials/signs/SignSell.java
+++ b/Essentials/src/com/earth2me/essentials/signs/SignSell.java
@@ -29,6 +29,7 @@ public class SignSell extends EssentialsSign
charge.isAffordableFor(player);
money.pay(player);
charge.charge(player);
+ Trade.log("Sign", "Sell", "Interact", username, charge, username, money, ess);
return true;
}
}
diff --git a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java
index c7515a2fb..8f7b0f8c2 100644
--- a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java
+++ b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java
@@ -24,6 +24,7 @@ public class SignTrade extends EssentialsSign
charge.isAffordableFor(player);
sign.setLine(3, "ยง8" + username);
charge.charge(player);
+ Trade.log("Sign", "Trade", "Create", username, charge, username, null, ess);
return true;
}
@@ -35,6 +36,7 @@ public class SignTrade extends EssentialsSign
final Trade stored = getTrade(sign, 1, true, true, ess);
substractAmount(sign, 1, stored);
stored.pay(player);
+ Trade.log("Sign", "Trade", "OwnerInteract", username, null, username, stored, ess);
}
else
{
@@ -45,6 +47,7 @@ public class SignTrade extends EssentialsSign
trade.pay(player);
addAmount(sign, 1, charge);
charge.charge(player);
+ Trade.log("Sign", "Trade", "Interact", sign.getLine(3), charge, username, trade, ess);
}
return true;
}
@@ -58,6 +61,7 @@ public class SignTrade extends EssentialsSign
final Trade stored2 = getTrade(sign, 2, true, false, ess);
stored1.pay(player);
stored2.pay(player);
+ Trade.log("Sign", "Trade", "Break", username, stored2, username, stored1, ess);
return true;
}
else