2011-05-22 18:53:23 +00:00
|
|
|
package com.earth2me.essentials;
|
|
|
|
|
2012-09-08 13:55:37 +00:00
|
|
|
import static com.earth2me.essentials.I18n._;
|
2011-12-06 16:42:55 +00:00
|
|
|
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
|
2011-12-13 07:38:15 +00:00
|
|
|
import com.earth2me.essentials.craftbukkit.SetExpFix;
|
2011-07-06 00:58:59 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileWriter;
|
|
|
|
import java.io.IOException;
|
2013-05-05 03:13:17 +00:00
|
|
|
import java.math.BigDecimal;
|
2011-07-06 00:58:59 +00:00
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.util.Date;
|
2011-11-21 01:55:26 +00:00
|
|
|
import java.util.Locale;
|
2011-06-13 13:05:31 +00:00
|
|
|
import java.util.Map;
|
2011-07-06 00:58:59 +00:00
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
2011-07-18 02:49:38 +00:00
|
|
|
import org.bukkit.Location;
|
2012-02-15 06:18:12 +00:00
|
|
|
import org.bukkit.entity.Item;
|
2011-05-22 18:53:23 +00:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
|
2011-06-13 13:05:31 +00:00
|
|
|
public class Trade
|
2011-05-22 18:53:23 +00:00
|
|
|
{
|
2011-06-08 01:18:33 +00:00
|
|
|
private final transient String command;
|
2012-08-31 16:47:35 +00:00
|
|
|
private final transient Trade fallbackTrade;
|
2013-05-05 03:13:17 +00:00
|
|
|
private final transient BigDecimal money;
|
2011-06-13 13:05:31 +00:00
|
|
|
private final transient ItemStack itemStack;
|
2011-12-07 09:31:18 +00:00
|
|
|
private final transient Integer exp;
|
2011-06-08 01:18:33 +00:00
|
|
|
private final transient IEssentials ess;
|
2013-05-05 07:03:06 +00:00
|
|
|
|
|
|
|
|
2013-03-07 02:42:19 +00:00
|
|
|
public enum TradeType
|
|
|
|
{
|
|
|
|
MONEY,
|
|
|
|
EXP,
|
|
|
|
ITEM
|
|
|
|
}
|
2013-05-05 07:03:06 +00:00
|
|
|
|
2013-05-06 05:40:22 +00:00
|
|
|
|
|
|
|
public enum OverflowType
|
|
|
|
{
|
|
|
|
ABORT,
|
|
|
|
DROP,
|
|
|
|
RETURN
|
|
|
|
}
|
|
|
|
|
2011-06-13 13:05:31 +00:00
|
|
|
public Trade(final String command, final IEssentials ess)
|
2011-05-22 18:53:23 +00:00
|
|
|
{
|
2012-04-03 14:35:13 +00:00
|
|
|
this(command, null, null, null, null, ess);
|
|
|
|
}
|
|
|
|
|
2012-08-31 16:47:35 +00:00
|
|
|
public Trade(final String command, final Trade fallback, final IEssentials ess)
|
2012-04-03 14:35:13 +00:00
|
|
|
{
|
|
|
|
this(command, fallback, null, null, null, ess);
|
2011-05-22 18:53:23 +00:00
|
|
|
}
|
2011-10-25 21:18:28 +00:00
|
|
|
|
2013-05-05 16:00:21 +00:00
|
|
|
@Deprecated
|
|
|
|
public Trade(final double money, final IEssentials ess)
|
|
|
|
{
|
|
|
|
this(null, null, BigDecimal.valueOf(money), null, null, ess);
|
|
|
|
}
|
|
|
|
|
2013-05-05 03:13:17 +00:00
|
|
|
public Trade(final BigDecimal money, final IEssentials ess)
|
2011-05-22 18:53:23 +00:00
|
|
|
{
|
2012-04-03 14:35:13 +00:00
|
|
|
this(null, null, money, null, null, ess);
|
2011-05-22 18:53:23 +00:00
|
|
|
}
|
2011-10-25 21:18:28 +00:00
|
|
|
|
2011-06-13 13:05:31 +00:00
|
|
|
public Trade(final ItemStack items, final IEssentials ess)
|
2011-05-22 18:53:23 +00:00
|
|
|
{
|
2012-04-03 14:35:13 +00:00
|
|
|
this(null, null, null, items, null, ess);
|
2011-12-07 09:31:18 +00:00
|
|
|
}
|
2012-02-15 06:18:12 +00:00
|
|
|
|
2011-12-07 09:31:18 +00:00
|
|
|
public Trade(final int exp, final IEssentials ess)
|
|
|
|
{
|
2012-04-03 14:35:13 +00:00
|
|
|
this(null, null, null, null, exp, ess);
|
2011-05-22 18:53:23 +00:00
|
|
|
}
|
2011-10-25 21:18:28 +00:00
|
|
|
|
2013-05-05 03:13:17 +00:00
|
|
|
private Trade(final String command, final Trade fallback, final BigDecimal money, final ItemStack item, final Integer exp, final IEssentials ess)
|
2011-05-22 18:53:23 +00:00
|
|
|
{
|
2011-06-01 10:40:12 +00:00
|
|
|
this.command = command;
|
2012-08-31 16:47:35 +00:00
|
|
|
this.fallbackTrade = fallback;
|
2011-06-13 13:05:31 +00:00
|
|
|
this.money = money;
|
|
|
|
this.itemStack = item;
|
2011-12-07 09:31:18 +00:00
|
|
|
this.exp = exp;
|
2011-06-01 10:40:12 +00:00
|
|
|
this.ess = ess;
|
2011-05-22 18:53:23 +00:00
|
|
|
}
|
2011-10-25 21:18:28 +00:00
|
|
|
|
2011-06-08 01:18:33 +00:00
|
|
|
public void isAffordableFor(final IUser user) throws ChargeException
|
2011-05-22 18:53:23 +00:00
|
|
|
{
|
2012-08-19 02:38:09 +00:00
|
|
|
|
|
|
|
if (ess.getSettings().isDebug())
|
|
|
|
{
|
|
|
|
ess.getLogger().log(Level.INFO, "checking if " + user.getName() + " can afford charge.");
|
|
|
|
}
|
|
|
|
|
2011-06-13 13:05:31 +00:00
|
|
|
if (getMoney() != null
|
2013-05-05 09:41:19 +00:00
|
|
|
&& getMoney().signum() > 0
|
2012-03-28 09:21:31 +00:00
|
|
|
&& !user.canAfford(getMoney()))
|
2011-05-22 18:53:23 +00:00
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
throw new ChargeException(_("notEnoughMoney"));
|
2011-05-22 18:53:23 +00:00
|
|
|
}
|
2011-10-25 21:18:28 +00:00
|
|
|
|
2011-06-13 13:05:31 +00:00
|
|
|
if (getItemStack() != null
|
2013-07-07 11:11:57 +00:00
|
|
|
&& !user.getBase().getInventory().containsAtLeast(itemStack, itemStack.getAmount()))
|
2011-05-22 18:53:23 +00:00
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
throw new ChargeException(_("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " ")));
|
2011-05-22 18:53:23 +00:00
|
|
|
}
|
2011-10-25 21:18:28 +00:00
|
|
|
|
2013-05-05 03:13:17 +00:00
|
|
|
BigDecimal money;
|
2011-06-08 01:18:33 +00:00
|
|
|
if (command != null && !command.isEmpty()
|
2013-05-05 09:41:19 +00:00
|
|
|
&& (money = getCommandCost(user)).signum() > 0
|
2012-03-28 09:21:31 +00:00
|
|
|
&& !user.canAfford(money))
|
2011-05-22 18:53:23 +00:00
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
throw new ChargeException(_("notEnoughMoney"));
|
2011-05-22 18:53:23 +00:00
|
|
|
}
|
2012-02-15 06:18:12 +00:00
|
|
|
|
|
|
|
if (exp != null && exp > 0
|
2013-07-07 11:11:57 +00:00
|
|
|
&& SetExpFix.getTotalExperience(user.getBase()) < exp)
|
2012-02-15 06:18:12 +00:00
|
|
|
{
|
2011-12-07 09:31:18 +00:00
|
|
|
throw new ChargeException(_("notEnoughExperience"));
|
|
|
|
}
|
2011-05-22 18:53:23 +00:00
|
|
|
}
|
2011-10-25 21:18:28 +00:00
|
|
|
|
2013-05-06 05:40:22 +00:00
|
|
|
public boolean pay(final IUser user)
|
2011-06-13 13:05:31 +00:00
|
|
|
{
|
2013-05-06 05:40:22 +00:00
|
|
|
return pay(user, OverflowType.ABORT) == null;
|
2011-10-09 20:25:15 +00:00
|
|
|
}
|
2011-10-25 21:18:28 +00:00
|
|
|
|
2013-05-06 05:40:22 +00:00
|
|
|
public Map<Integer, ItemStack> pay(final IUser user, final OverflowType type)
|
2011-10-09 20:25:15 +00:00
|
|
|
{
|
2013-05-05 09:41:19 +00:00
|
|
|
if (getMoney() != null && getMoney().signum() > 0)
|
2011-06-13 13:05:31 +00:00
|
|
|
{
|
2013-05-05 21:37:28 +00:00
|
|
|
if (ess.getSettings().isDebug())
|
|
|
|
{
|
|
|
|
ess.getLogger().log(Level.INFO, "paying user " + user.getName() + " via trade " + getMoney().toPlainString());
|
|
|
|
}
|
2011-06-13 13:05:31 +00:00
|
|
|
user.giveMoney(getMoney());
|
|
|
|
}
|
|
|
|
if (getItemStack() != null)
|
|
|
|
{
|
2013-05-06 05:40:22 +00:00
|
|
|
// This stores the would be overflow
|
2013-07-07 11:11:57 +00:00
|
|
|
Map<Integer, ItemStack> overFlow = InventoryWorkaround.addAllItems(user.getBase().getInventory(), getItemStack());
|
2013-05-06 05:40:22 +00:00
|
|
|
|
|
|
|
if (overFlow != null)
|
2011-10-09 20:25:15 +00:00
|
|
|
{
|
2013-05-06 05:40:22 +00:00
|
|
|
switch (type)
|
2011-10-09 20:25:15 +00:00
|
|
|
{
|
2013-05-06 05:40:22 +00:00
|
|
|
case ABORT:
|
|
|
|
if (ess.getSettings().isDebug())
|
|
|
|
{
|
|
|
|
ess.getLogger().log(Level.INFO, "abort paying " + user.getName() + " itemstack " + getItemStack().toString() + " due to lack of inventory space ");
|
|
|
|
}
|
|
|
|
|
|
|
|
return overFlow;
|
|
|
|
|
|
|
|
case RETURN:
|
|
|
|
// Pay the user the items, and return overflow
|
2013-07-07 11:11:57 +00:00
|
|
|
final Map<Integer, ItemStack> returnStack = InventoryWorkaround.addItems(user.getBase().getInventory(), getItemStack());
|
|
|
|
user.getBase().updateInventory();
|
2013-05-06 05:40:22 +00:00
|
|
|
|
|
|
|
if (ess.getSettings().isDebug())
|
|
|
|
{
|
|
|
|
ess.getLogger().log(Level.INFO, "paying " + user.getName() + " partial itemstack " + getItemStack().toString() + " with overflow " + returnStack.get(0).toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnStack;
|
|
|
|
|
|
|
|
case DROP:
|
|
|
|
// Pay the users the items directly, and drop the rest, will always return no overflow.
|
2013-07-07 11:11:57 +00:00
|
|
|
final Map<Integer, ItemStack> leftOver = InventoryWorkaround.addItems(user.getBase().getInventory(), getItemStack());
|
|
|
|
final Location loc = user.getBase().getLocation();
|
2013-05-06 05:40:22 +00:00
|
|
|
for (ItemStack loStack : leftOver.values())
|
2012-02-15 06:18:12 +00:00
|
|
|
{
|
2013-05-06 05:40:22 +00:00
|
|
|
final int maxStackSize = loStack.getType().getMaxStackSize();
|
|
|
|
final int stacks = loStack.getAmount() / maxStackSize;
|
|
|
|
final int leftover = loStack.getAmount() % maxStackSize;
|
|
|
|
final Item[] itemStacks = new Item[stacks + (leftover > 0 ? 1 : 0)];
|
|
|
|
for (int i = 0; i < stacks; i++)
|
|
|
|
{
|
|
|
|
final ItemStack stack = loStack.clone();
|
|
|
|
stack.setAmount(maxStackSize);
|
|
|
|
itemStacks[i] = loc.getWorld().dropItem(loc, stack);
|
|
|
|
}
|
|
|
|
if (leftover > 0)
|
|
|
|
{
|
|
|
|
final ItemStack stack = loStack.clone();
|
|
|
|
stack.setAmount(leftover);
|
|
|
|
itemStacks[stacks] = loc.getWorld().dropItem(loc, stack);
|
|
|
|
}
|
2012-02-15 06:18:12 +00:00
|
|
|
}
|
2013-05-06 05:40:22 +00:00
|
|
|
if (ess.getSettings().isDebug())
|
2012-02-15 06:18:12 +00:00
|
|
|
{
|
2013-05-06 05:40:22 +00:00
|
|
|
ess.getLogger().log(Level.INFO, "paying " + user.getName() + " partial itemstack " + getItemStack().toString() + " and dropping overflow " + leftOver.get(0).toString());
|
2012-02-15 06:18:12 +00:00
|
|
|
}
|
2011-10-09 20:25:15 +00:00
|
|
|
}
|
|
|
|
}
|
2013-05-06 05:40:22 +00:00
|
|
|
else if (ess.getSettings().isDebug())
|
2011-06-13 13:05:31 +00:00
|
|
|
{
|
2013-05-06 05:40:22 +00:00
|
|
|
ess.getLogger().log(Level.INFO, "paying " + user.getName() + " itemstack " + getItemStack().toString());
|
2011-06-13 13:05:31 +00:00
|
|
|
}
|
2013-07-07 11:11:57 +00:00
|
|
|
user.getBase().updateInventory();
|
2011-06-13 13:05:31 +00:00
|
|
|
}
|
2011-12-07 09:31:18 +00:00
|
|
|
if (getExperience() != null)
|
|
|
|
{
|
2013-07-07 11:11:57 +00:00
|
|
|
SetExpFix.setTotalExperience(user.getBase(), SetExpFix.getTotalExperience(user.getBase()) + getExperience());
|
2011-12-07 09:31:18 +00:00
|
|
|
}
|
2013-05-06 05:40:22 +00:00
|
|
|
return null;
|
2011-06-13 13:05:31 +00:00
|
|
|
}
|
2011-10-25 21:18:28 +00:00
|
|
|
|
2011-06-08 01:18:33 +00:00
|
|
|
public void charge(final IUser user) throws ChargeException
|
2011-05-22 18:53:23 +00:00
|
|
|
{
|
2012-08-31 16:47:35 +00:00
|
|
|
if (ess.getSettings().isDebug())
|
|
|
|
{
|
2013-05-05 21:37:28 +00:00
|
|
|
ess.getLogger().log(Level.INFO, "attempting to charge user " + user.getName());
|
2012-08-31 16:47:35 +00:00
|
|
|
}
|
2011-06-13 13:05:31 +00:00
|
|
|
if (getMoney() != null)
|
2011-05-22 18:53:23 +00:00
|
|
|
{
|
2013-05-05 21:37:28 +00:00
|
|
|
if (ess.getSettings().isDebug())
|
|
|
|
{
|
|
|
|
ess.getLogger().log(Level.INFO, "charging user " + user.getName() + " money " + getMoney().toPlainString());
|
|
|
|
}
|
2013-05-05 09:41:19 +00:00
|
|
|
if (!user.canAfford(getMoney()) && getMoney().signum() > 0)
|
2011-05-22 18:53:23 +00:00
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
throw new ChargeException(_("notEnoughMoney"));
|
2011-05-22 18:53:23 +00:00
|
|
|
}
|
2011-06-13 13:05:31 +00:00
|
|
|
user.takeMoney(getMoney());
|
2011-05-22 18:53:23 +00:00
|
|
|
}
|
2011-06-13 13:05:31 +00:00
|
|
|
if (getItemStack() != null)
|
2011-05-22 18:53:23 +00:00
|
|
|
{
|
2013-05-05 21:37:28 +00:00
|
|
|
if (ess.getSettings().isDebug())
|
|
|
|
{
|
|
|
|
ess.getLogger().log(Level.INFO, "charging user " + user.getName() + " itemstack " + getItemStack().toString());
|
|
|
|
}
|
2013-07-07 11:11:57 +00:00
|
|
|
if (!user.getBase().getInventory().containsAtLeast(getItemStack(), getItemStack().getAmount()))
|
2011-05-22 18:53:23 +00:00
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
throw new ChargeException(_("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " ")));
|
2011-05-22 18:53:23 +00:00
|
|
|
}
|
2013-07-07 11:11:57 +00:00
|
|
|
user.getBase().getInventory().removeItem(getItemStack());
|
|
|
|
user.getBase().updateInventory();
|
2011-05-22 18:53:23 +00:00
|
|
|
}
|
2012-03-13 16:15:01 +00:00
|
|
|
if (command != null)
|
2011-05-22 18:53:23 +00:00
|
|
|
{
|
2013-05-05 03:13:17 +00:00
|
|
|
final BigDecimal cost = getCommandCost(user);
|
2013-05-05 09:55:39 +00:00
|
|
|
if (!user.canAfford(cost) && cost.signum() > 0)
|
2011-05-22 18:53:23 +00:00
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
throw new ChargeException(_("notEnoughMoney"));
|
2011-05-22 18:53:23 +00:00
|
|
|
}
|
2011-05-23 09:55:23 +00:00
|
|
|
user.takeMoney(cost);
|
2011-05-22 18:53:23 +00:00
|
|
|
}
|
2011-12-07 09:31:18 +00:00
|
|
|
if (getExperience() != null)
|
|
|
|
{
|
2013-05-05 21:37:28 +00:00
|
|
|
if (ess.getSettings().isDebug())
|
|
|
|
{
|
|
|
|
ess.getLogger().log(Level.INFO, "charging user " + user.getName() + " exp " + getExperience());
|
|
|
|
}
|
2013-07-07 11:11:57 +00:00
|
|
|
final int experience = SetExpFix.getTotalExperience(user.getBase());
|
2011-12-07 09:31:18 +00:00
|
|
|
if (experience < getExperience() && getExperience() > 0)
|
|
|
|
{
|
|
|
|
throw new ChargeException(_("notEnoughExperience"));
|
|
|
|
}
|
2013-07-07 11:11:57 +00:00
|
|
|
SetExpFix.setTotalExperience(user.getBase(), experience - getExperience());
|
2011-12-07 09:31:18 +00:00
|
|
|
}
|
2013-05-05 21:37:28 +00:00
|
|
|
if (ess.getSettings().isDebug())
|
|
|
|
{
|
|
|
|
ess.getLogger().log(Level.INFO, "charge user " + user.getName() + " completed");
|
|
|
|
}
|
2011-05-22 18:53:23 +00:00
|
|
|
}
|
2011-10-25 21:18:28 +00:00
|
|
|
|
2013-05-05 03:13:17 +00:00
|
|
|
public BigDecimal getMoney()
|
2011-06-13 13:05:31 +00:00
|
|
|
{
|
|
|
|
return money;
|
|
|
|
}
|
2011-10-25 21:18:28 +00:00
|
|
|
|
2011-06-13 13:05:31 +00:00
|
|
|
public ItemStack getItemStack()
|
|
|
|
{
|
|
|
|
return itemStack;
|
|
|
|
}
|
2012-02-15 06:18:12 +00:00
|
|
|
|
2011-12-07 09:31:18 +00:00
|
|
|
public Integer getExperience()
|
|
|
|
{
|
|
|
|
return exp;
|
|
|
|
}
|
2013-05-05 07:03:06 +00:00
|
|
|
|
2013-03-07 02:42:19 +00:00
|
|
|
public TradeType getType()
|
|
|
|
{
|
2013-05-05 07:03:06 +00:00
|
|
|
if (getExperience() != null)
|
|
|
|
{
|
2013-03-08 22:04:54 +00:00
|
|
|
return TradeType.EXP;
|
2013-03-07 02:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (getItemStack() != null)
|
|
|
|
{
|
|
|
|
return TradeType.ITEM;
|
|
|
|
}
|
|
|
|
|
2013-05-05 07:03:06 +00:00
|
|
|
return TradeType.MONEY;
|
2013-03-07 02:42:19 +00:00
|
|
|
}
|
2012-03-13 16:15:01 +00:00
|
|
|
|
2013-05-05 03:13:17 +00:00
|
|
|
public BigDecimal getCommandCost(final IUser user)
|
2012-03-13 16:15:01 +00:00
|
|
|
{
|
2013-05-05 03:13:17 +00:00
|
|
|
BigDecimal cost = BigDecimal.ZERO;
|
2012-08-31 16:47:35 +00:00
|
|
|
if (command != null && !command.isEmpty())
|
2012-03-13 16:15:01 +00:00
|
|
|
{
|
|
|
|
cost = ess.getSettings().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command);
|
2013-05-05 19:05:28 +00:00
|
|
|
if (cost.signum() == 0 && fallbackTrade != null)
|
2012-04-03 14:35:13 +00:00
|
|
|
{
|
2012-08-31 16:47:35 +00:00
|
|
|
cost = fallbackTrade.getCommandCost(user);
|
2012-04-03 14:35:13 +00:00
|
|
|
}
|
2012-08-19 02:38:09 +00:00
|
|
|
|
|
|
|
if (ess.getSettings().isDebug())
|
|
|
|
{
|
|
|
|
ess.getLogger().log(Level.INFO, "calculated command (" + command + ") cost for " + user.getName() + " as " + cost);
|
|
|
|
}
|
2012-03-13 16:15:01 +00:00
|
|
|
}
|
2013-05-05 19:05:28 +00:00
|
|
|
if (cost.signum() != 0 && (user.isAuthorized("essentials.nocommandcost.all")
|
2013-05-05 21:37:28 +00:00
|
|
|
|| user.isAuthorized("essentials.nocommandcost." + command)))
|
2012-08-31 16:47:35 +00:00
|
|
|
{
|
2013-05-05 03:13:17 +00:00
|
|
|
return BigDecimal.ZERO;
|
2012-08-31 16:47:35 +00:00
|
|
|
}
|
2012-03-13 16:15:01 +00:00
|
|
|
return cost;
|
|
|
|
}
|
2011-07-06 00:58:59 +00:00
|
|
|
private static FileWriter fw = null;
|
2011-10-25 21:18:28 +00:00
|
|
|
|
2011-07-18 02:49:38 +00:00
|
|
|
public static void log(String type, String subtype, String event, String sender, Trade charge, String receiver, Trade pay, Location loc, IEssentials ess)
|
2011-07-06 00:58:59 +00:00
|
|
|
{
|
2012-10-06 02:31:34 +00:00
|
|
|
//isEcoLogUpdateEnabled() - This refers to log entries with no location, ie API updates #EasterEgg
|
|
|
|
//isEcoLogEnabled() - This refers to log entries with with location, ie /pay /sell and eco signs.
|
2013-05-05 07:03:06 +00:00
|
|
|
|
2012-02-27 15:31:43 +00:00
|
|
|
if ((loc == null && !ess.getSettings().isEcoLogUpdateEnabled())
|
|
|
|
|| (loc != null && !ess.getSettings().isEcoLogEnabled()))
|
2011-07-06 00:58:59 +00:00
|
|
|
{
|
|
|
|
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();
|
2011-07-18 02:58:55 +00:00
|
|
|
sb.append(type).append(",").append(subtype).append(",").append(event).append(",\"");
|
2011-07-06 00:58:59 +00:00
|
|
|
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());
|
|
|
|
}
|
2011-12-07 09:31:18 +00:00
|
|
|
if (charge.getExperience() != null)
|
|
|
|
{
|
|
|
|
sb.append(charge.getExperience()).append(",");
|
|
|
|
sb.append("exp").append(",");
|
|
|
|
sb.append("\"\"");
|
|
|
|
}
|
2011-07-06 00:58:59 +00:00
|
|
|
}
|
|
|
|
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());
|
|
|
|
}
|
2011-12-07 09:31:18 +00:00
|
|
|
if (pay.getExperience() != null)
|
|
|
|
{
|
|
|
|
sb.append(pay.getExperience()).append(",");
|
|
|
|
sb.append("exp").append(",");
|
|
|
|
sb.append("\"\"");
|
|
|
|
}
|
2011-07-06 00:58:59 +00:00
|
|
|
}
|
2011-07-18 02:49:38 +00:00
|
|
|
if (loc == null)
|
|
|
|
{
|
|
|
|
sb.append(",\"\",\"\",\"\",\"\"");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sb.append(",\"");
|
|
|
|
sb.append(loc.getWorld().getName()).append("\",");
|
|
|
|
sb.append(loc.getBlockX()).append(",");
|
|
|
|
sb.append(loc.getBlockY()).append(",");
|
|
|
|
sb.append(loc.getBlockZ()).append(",");
|
|
|
|
}
|
2011-07-06 00:58:59 +00:00
|
|
|
sb.append("\n");
|
|
|
|
try
|
|
|
|
{
|
|
|
|
fw.write(sb.toString());
|
|
|
|
fw.flush();
|
|
|
|
}
|
|
|
|
catch (IOException ex)
|
|
|
|
{
|
|
|
|
Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
|
|
|
|
}
|
|
|
|
}
|
2011-10-25 21:18:28 +00:00
|
|
|
|
2011-07-06 00:58:59 +00:00
|
|
|
public static void closeLog()
|
|
|
|
{
|
2011-10-09 20:25:15 +00:00
|
|
|
if (fw != null)
|
|
|
|
{
|
2011-07-06 00:58:59 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
fw.close();
|
|
|
|
}
|
|
|
|
catch (IOException ex)
|
|
|
|
{
|
|
|
|
Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
|
|
|
|
}
|
|
|
|
fw = null;
|
|
|
|
}
|
|
|
|
}
|
2011-05-22 18:53:23 +00:00
|
|
|
}
|