mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-10-16 00:15:08 +02:00
Command cost api update: Can now set fallback costs.
Repair command addition: ontop of 'repair' and 'repair-<itemname>' you can now charge for 'repair-all' to charge more for /repair all or 'repair-item' to charge per item repaired.
This commit is contained in:
parent
37370f722c
commit
d0f3fb4417
@ -20,6 +20,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
public class Trade
|
public class Trade
|
||||||
{
|
{
|
||||||
private final transient String command;
|
private final transient String command;
|
||||||
|
private final transient String fallbackCommand;
|
||||||
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 Integer exp;
|
||||||
@ -27,27 +28,33 @@ public class Trade
|
|||||||
|
|
||||||
public Trade(final String command, final IEssentials ess)
|
public Trade(final String command, final IEssentials ess)
|
||||||
{
|
{
|
||||||
this(command, null, null, null, ess);
|
this(command, null, null, null, null, ess);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Trade(final String command, final String fallback, final IEssentials ess)
|
||||||
|
{
|
||||||
|
this(command, fallback, null, null, null, ess);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Trade(final double money, final IEssentials ess)
|
public Trade(final double money, final IEssentials ess)
|
||||||
{
|
{
|
||||||
this(null, money, null, null, ess);
|
this(null, 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, null, ess);
|
this(null, null, null, items, null, ess);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Trade(final int exp, final IEssentials ess)
|
public Trade(final int exp, final IEssentials ess)
|
||||||
{
|
{
|
||||||
this(null, null, null, exp, ess);
|
this(null, null, null, null, exp, ess);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Trade(final String command, final Double money, final ItemStack item, final Integer exp, final IEssentials ess)
|
private Trade(final String command, final String fallback, final Double money, final ItemStack item, final Integer exp, final IEssentials ess)
|
||||||
{
|
{
|
||||||
this.command = command;
|
this.command = command;
|
||||||
|
this.fallbackCommand = fallback;
|
||||||
this.money = money;
|
this.money = money;
|
||||||
this.itemStack = item;
|
this.itemStack = item;
|
||||||
this.exp = exp;
|
this.exp = exp;
|
||||||
@ -197,6 +204,10 @@ public class Trade
|
|||||||
&& !user.isAuthorized("essentials.nocommandcost." + command))
|
&& !user.isAuthorized("essentials.nocommandcost." + command))
|
||||||
{
|
{
|
||||||
cost = ess.getSettings().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command);
|
cost = ess.getSettings().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command);
|
||||||
|
if (cost == 0.0 && fallbackCommand != null && !fallbackCommand.isEmpty())
|
||||||
|
{
|
||||||
|
cost = ess.getSettings().getCommandCost(fallbackCommand.charAt(0) == '/' ? fallbackCommand.substring(1) : fallbackCommand);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return cost;
|
return cost;
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,8 @@ public class Commandrepair extends EssentialsCommand
|
|||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("all"))
|
else if (args[0].equalsIgnoreCase("all"))
|
||||||
{
|
{
|
||||||
|
final Trade charge = new Trade("repair-all", ess);
|
||||||
|
charge.isAffordableFor(user);
|
||||||
final List<String> repaired = new ArrayList<String>();
|
final List<String> repaired = new ArrayList<String>();
|
||||||
repairItems(user.getInventory().getContents(), user, repaired);
|
repairItems(user.getInventory().getContents(), user, repaired);
|
||||||
|
|
||||||
@ -69,6 +71,7 @@ public class Commandrepair extends EssentialsCommand
|
|||||||
{
|
{
|
||||||
user.sendMessage(_("repair", Util.joinList(repaired)));
|
user.sendMessage(_("repair", Util.joinList(repaired)));
|
||||||
}
|
}
|
||||||
|
charge.charge(user);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -102,7 +105,7 @@ public class Commandrepair extends EssentialsCommand
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final String itemName = item.getType().toString().toLowerCase(Locale.ENGLISH);
|
final String itemName = item.getType().toString().toLowerCase(Locale.ENGLISH);
|
||||||
final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), ess);
|
final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), "repair-item", ess);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
charge.isAffordableFor(user);
|
charge.isAffordableFor(user);
|
||||||
|
Loading…
Reference in New Issue
Block a user