mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-12 04:20:41 +00:00
Support for experience as trading goods on signs. This will not work until experience is fixed in Bukkit.
This commit is contained in:
parent
67a3a55f5a
commit
fdd8fffbb3
4 changed files with 114 additions and 25 deletions
|
@ -64,4 +64,8 @@ public interface IUser
|
||||||
Teleport getTeleport();
|
Teleport getTeleport();
|
||||||
|
|
||||||
void setJail(String jail);
|
void setJail(String jail);
|
||||||
|
|
||||||
|
public int getTotalExperience();
|
||||||
|
|
||||||
|
public void setTotalExperience(int l);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,28 +20,35 @@ public class Trade
|
||||||
private final transient String command;
|
private final transient String command;
|
||||||
private final transient Double money;
|
private final transient Double money;
|
||||||
private final transient ItemStack itemStack;
|
private final transient ItemStack itemStack;
|
||||||
|
private final transient Integer exp;
|
||||||
private final transient IEssentials ess;
|
private final transient IEssentials ess;
|
||||||
|
|
||||||
public Trade(final String command, final IEssentials ess)
|
public Trade(final String command, final IEssentials ess)
|
||||||
{
|
{
|
||||||
this(command, null, null, ess);
|
this(command, null, null, null, ess);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Trade(final double money, final IEssentials ess)
|
public Trade(final double money, final IEssentials ess)
|
||||||
{
|
{
|
||||||
this(null, money, null, ess);
|
this(null, money, null, null, ess);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Trade(final ItemStack items, final IEssentials ess)
|
public Trade(final ItemStack items, final IEssentials ess)
|
||||||
{
|
{
|
||||||
this(null, null, items, ess);
|
this(null, null, items, null, ess);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Trade(final int exp, final IEssentials ess)
|
||||||
|
{
|
||||||
|
this(null, null, null, exp, ess);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Trade(final String command, final Double money, final ItemStack item, final IEssentials ess)
|
private Trade(final String command, final Double money, final ItemStack item, final Integer exp, final IEssentials ess)
|
||||||
{
|
{
|
||||||
this.command = command;
|
this.command = command;
|
||||||
this.money = money;
|
this.money = money;
|
||||||
this.itemStack = item;
|
this.itemStack = item;
|
||||||
|
this.exp = exp;
|
||||||
this.ess = ess;
|
this.ess = ess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +78,11 @@ public class Trade
|
||||||
{
|
{
|
||||||
throw new ChargeException(_("notEnoughMoney"));
|
throw new ChargeException(_("notEnoughMoney"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (exp != null && exp > 0
|
||||||
|
&& user.getTotalExperience() < exp) {
|
||||||
|
throw new ChargeException(_("notEnoughExperience"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pay(final IUser user)
|
public void pay(final IUser user)
|
||||||
|
@ -101,6 +113,10 @@ public class Trade
|
||||||
}
|
}
|
||||||
user.updateInventory();
|
user.updateInventory();
|
||||||
}
|
}
|
||||||
|
if (getExperience() != null)
|
||||||
|
{
|
||||||
|
user.setTotalExperience(user.getTotalExperience() + getExperience());
|
||||||
|
}
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,6 +152,15 @@ public class Trade
|
||||||
}
|
}
|
||||||
user.takeMoney(cost);
|
user.takeMoney(cost);
|
||||||
}
|
}
|
||||||
|
if (getExperience() != null)
|
||||||
|
{
|
||||||
|
final int experience = user.getTotalExperience();
|
||||||
|
if (experience < getExperience() && getExperience() > 0)
|
||||||
|
{
|
||||||
|
throw new ChargeException(_("notEnoughExperience"));
|
||||||
|
}
|
||||||
|
user.setTotalExperience(experience - getExperience());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double getMoney()
|
public Double getMoney()
|
||||||
|
@ -147,6 +172,11 @@ public class Trade
|
||||||
{
|
{
|
||||||
return itemStack;
|
return itemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getExperience()
|
||||||
|
{
|
||||||
|
return exp;
|
||||||
|
}
|
||||||
private static FileWriter fw = null;
|
private static FileWriter fw = null;
|
||||||
|
|
||||||
public static void log(String type, String subtype, String event, String sender, Trade charge, String receiver, Trade pay, Location loc, IEssentials ess)
|
public static void log(String type, String subtype, String event, String sender, Trade charge, String receiver, Trade pay, Location loc, IEssentials ess)
|
||||||
|
@ -193,6 +223,12 @@ public class Trade
|
||||||
sb.append("money").append(",");
|
sb.append("money").append(",");
|
||||||
sb.append(ess.getSettings().getCurrencySymbol());
|
sb.append(ess.getSettings().getCurrencySymbol());
|
||||||
}
|
}
|
||||||
|
if (charge.getExperience() != null)
|
||||||
|
{
|
||||||
|
sb.append(charge.getExperience()).append(",");
|
||||||
|
sb.append("exp").append(",");
|
||||||
|
sb.append("\"\"");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sb.append(",\"");
|
sb.append(",\"");
|
||||||
if (receiver != null)
|
if (receiver != null)
|
||||||
|
@ -218,6 +254,12 @@ public class Trade
|
||||||
sb.append("money").append(",");
|
sb.append("money").append(",");
|
||||||
sb.append(ess.getSettings().getCurrencySymbol());
|
sb.append(ess.getSettings().getCurrencySymbol());
|
||||||
}
|
}
|
||||||
|
if (pay.getExperience() != null)
|
||||||
|
{
|
||||||
|
sb.append(pay.getExperience()).append(",");
|
||||||
|
sb.append("exp").append(",");
|
||||||
|
sb.append("\"\"");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (loc == null)
|
if (loc == null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -399,6 +399,11 @@ public class EssentialsSign
|
||||||
sign.setLine(index, (quantity - decrement) + " times");
|
sign.setLine(index, (quantity - decrement) + " times");
|
||||||
return new Trade(signName.toLowerCase(Locale.ENGLISH) + "sign", ess);
|
return new Trade(signName.toLowerCase(Locale.ENGLISH) + "sign", ess);
|
||||||
}
|
}
|
||||||
|
else if (item.equalsIgnoreCase("exp") || item.equalsIgnoreCase("xp"))
|
||||||
|
{
|
||||||
|
sign.setLine(index, quantity + " exp");
|
||||||
|
return new Trade(quantity, ess);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
final ItemStack stack = getItemStack(item, quantity, ess);
|
final ItemStack stack = getItemStack(item, quantity, ess);
|
||||||
|
|
|
@ -160,8 +160,13 @@ public class SignTrade extends EssentialsSign
|
||||||
if (split.length == 2 && !amountNeeded)
|
if (split.length == 2 && !amountNeeded)
|
||||||
{
|
{
|
||||||
final int amount = getIntegerPositive(split[0]);
|
final int amount = getIntegerPositive(split[0]);
|
||||||
final ItemStack item = getItemStack(split[1], amount, ess);
|
|
||||||
if (amount < 1 || item.getTypeId() == 0)
|
if (amount < 1)
|
||||||
|
{
|
||||||
|
throw new SignException(_("moreThanZero"));
|
||||||
|
}
|
||||||
|
if (!(split[1].equalsIgnoreCase("exp") || split[1].equalsIgnoreCase("xp"))
|
||||||
|
&& getItemStack(split[1], amount, ess).getTypeId() == 0)
|
||||||
{
|
{
|
||||||
throw new SignException(_("moreThanZero"));
|
throw new SignException(_("moreThanZero"));
|
||||||
}
|
}
|
||||||
|
@ -177,10 +182,14 @@ public class SignTrade extends EssentialsSign
|
||||||
if (split.length == 3 && amountNeeded)
|
if (split.length == 3 && amountNeeded)
|
||||||
{
|
{
|
||||||
final int stackamount = getIntegerPositive(split[0]);
|
final int stackamount = getIntegerPositive(split[0]);
|
||||||
final ItemStack item = getItemStack(split[1], stackamount, ess);
|
|
||||||
int amount = getIntegerPositive(split[2]);
|
int amount = getIntegerPositive(split[2]);
|
||||||
amount -= amount % stackamount;
|
amount -= amount % stackamount;
|
||||||
if (amount < 1 || stackamount < 1 || item.getTypeId() == 0)
|
if (amount < 1 || stackamount < 1)
|
||||||
|
{
|
||||||
|
throw new SignException(_("moreThanZero"));
|
||||||
|
}
|
||||||
|
if (!(split[1].equalsIgnoreCase("exp") || split[1].equalsIgnoreCase("xp"))
|
||||||
|
&& getItemStack(split[1], stackamount, ess).getTypeId() == 0)
|
||||||
{
|
{
|
||||||
throw new SignException(_("moreThanZero"));
|
throw new SignException(_("moreThanZero"));
|
||||||
}
|
}
|
||||||
|
@ -218,16 +227,30 @@ public class SignTrade extends EssentialsSign
|
||||||
|
|
||||||
if (split.length == 3)
|
if (split.length == 3)
|
||||||
{
|
{
|
||||||
final int stackamount = getIntegerPositive(split[0]);
|
if (split[1].equalsIgnoreCase("exp") || split[1].equalsIgnoreCase("xp"))
|
||||||
final ItemStack item = getItemStack(split[1], stackamount, ess);
|
|
||||||
int amount = getInteger(split[2]);
|
|
||||||
amount -= amount % stackamount;
|
|
||||||
if (notEmpty && (amount < 1 || stackamount < 1 || item.getTypeId() == 0))
|
|
||||||
{
|
{
|
||||||
throw new SignException(_("tradeSignEmpty"));
|
final int stackamount = getIntegerPositive(split[0]);
|
||||||
|
int amount = getInteger(split[2]);
|
||||||
|
amount -= amount % stackamount;
|
||||||
|
if (notEmpty && (amount < 1 || stackamount < 1))
|
||||||
|
{
|
||||||
|
throw new SignException(_("tradeSignEmpty"));
|
||||||
|
}
|
||||||
|
return new Trade(fullAmount ? amount : stackamount, ess);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
final int stackamount = getIntegerPositive(split[0]);
|
||||||
|
final ItemStack item = getItemStack(split[1], stackamount, ess);
|
||||||
|
int amount = getInteger(split[2]);
|
||||||
|
amount -= amount % stackamount;
|
||||||
|
if (notEmpty && (amount < 1 || stackamount < 1 || item.getTypeId() == 0))
|
||||||
|
{
|
||||||
|
throw new SignException(_("tradeSignEmpty"));
|
||||||
|
}
|
||||||
|
item.setAmount(fullAmount ? amount : stackamount);
|
||||||
|
return new Trade(item, ess);
|
||||||
}
|
}
|
||||||
item.setAmount(fullAmount ? amount : stackamount);
|
|
||||||
return new Trade(item, ess);
|
|
||||||
}
|
}
|
||||||
throw new SignException(_("invalidSignLine", index + 1));
|
throw new SignException(_("invalidSignLine", index + 1));
|
||||||
}
|
}
|
||||||
|
@ -287,17 +310,32 @@ public class SignTrade extends EssentialsSign
|
||||||
|
|
||||||
if (split.length == 3)
|
if (split.length == 3)
|
||||||
{
|
{
|
||||||
final int stackamount = getIntegerPositive(split[0]);
|
if (split[1].equalsIgnoreCase("exp") || split[1].equalsIgnoreCase("xp"))
|
||||||
//TODO: Unused local variable
|
|
||||||
final ItemStack item = getItemStack(split[1], stackamount, ess);
|
|
||||||
final int amount = getInteger(split[2]);
|
|
||||||
final String newline = stackamount + " " + split[1] + ":" + (amount + Math.round(value));
|
|
||||||
if (newline.length() > 15)
|
|
||||||
{
|
{
|
||||||
throw new SignException("Line too long!");
|
final int stackamount = getIntegerPositive(split[0]);
|
||||||
|
final int amount = getInteger(split[2]);
|
||||||
|
final String newline = stackamount + " " + split[1] + ":" + (amount + Math.round(value));
|
||||||
|
if (newline.length() > 15)
|
||||||
|
{
|
||||||
|
throw new SignException("Line too long!");
|
||||||
|
}
|
||||||
|
sign.setLine(index, newline);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
final int stackamount = getIntegerPositive(split[0]);
|
||||||
|
//TODO: Unused local variable
|
||||||
|
final ItemStack item = getItemStack(split[1], stackamount, ess);
|
||||||
|
final int amount = getInteger(split[2]);
|
||||||
|
final String newline = stackamount + " " + split[1] + ":" + (amount + Math.round(value));
|
||||||
|
if (newline.length() > 15)
|
||||||
|
{
|
||||||
|
throw new SignException("Line too long!");
|
||||||
|
}
|
||||||
|
sign.setLine(index, newline);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
sign.setLine(index, newline);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
throw new SignException(_("invalidSignLine", index + 1));
|
throw new SignException(_("invalidSignLine", index + 1));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue