2012-08-05 23:33:29 +00:00
|
|
|
package com.earth2me.essentials.signs;
|
|
|
|
|
|
|
|
import com.earth2me.essentials.ChargeException;
|
2012-09-08 13:55:37 +00:00
|
|
|
import static com.earth2me.essentials.I18n._;
|
2013-07-13 15:14:39 +00:00
|
|
|
import net.ess3.api.IEssentials;
|
2012-08-05 23:33:29 +00:00
|
|
|
import com.earth2me.essentials.Trade;
|
|
|
|
import com.earth2me.essentials.User;
|
|
|
|
import com.earth2me.essentials.commands.Commandrepair;
|
2013-05-26 21:00:35 +00:00
|
|
|
import com.earth2me.essentials.commands.NotEnoughArgumentsException;
|
2012-08-05 23:33:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
public class SignRepair extends EssentialsSign
|
|
|
|
{
|
|
|
|
public SignRepair()
|
|
|
|
{
|
|
|
|
super("Repair");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
|
|
|
|
{
|
|
|
|
final String repairTarget = sign.getLine(1);
|
|
|
|
if (repairTarget.isEmpty())
|
|
|
|
{
|
|
|
|
sign.setLine(1, "Hand");
|
|
|
|
}
|
2013-02-28 03:15:21 +00:00
|
|
|
else if (!repairTarget.equalsIgnoreCase("all") && !repairTarget.equalsIgnoreCase("hand"))
|
2012-08-05 23:33:29 +00:00
|
|
|
{
|
2012-09-23 23:19:39 +00:00
|
|
|
sign.setLine(1, "§c<hand|all>");
|
2012-08-05 23:33:29 +00:00
|
|
|
throw new SignException(_("invalidSignLine", 2));
|
2013-02-28 03:15:21 +00:00
|
|
|
}
|
2012-08-05 23:33:29 +00:00
|
|
|
validateTrade(sign, 2, ess);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
|
|
|
|
{
|
|
|
|
final Trade charge = getTrade(sign, 2, ess);
|
|
|
|
charge.isAffordableFor(player);
|
2013-02-28 03:15:21 +00:00
|
|
|
|
2012-08-05 23:33:29 +00:00
|
|
|
Commandrepair command = new Commandrepair();
|
|
|
|
command.setEssentials(ess);
|
2013-05-26 21:00:35 +00:00
|
|
|
|
2012-08-05 23:33:29 +00:00
|
|
|
try
|
|
|
|
{
|
2013-05-26 21:00:35 +00:00
|
|
|
if (sign.getLine(1).equalsIgnoreCase("hand"))
|
|
|
|
{
|
|
|
|
command.repairHand(player);
|
|
|
|
}
|
|
|
|
else if (sign.getLine(1).equalsIgnoreCase("all"))
|
|
|
|
{
|
|
|
|
command.repairAll(player);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
|
|
|
|
2012-08-05 23:33:29 +00:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
throw new SignException(ex.getMessage(), ex);
|
|
|
|
}
|
2013-05-26 21:00:35 +00:00
|
|
|
|
2013-02-28 03:15:21 +00:00
|
|
|
charge.charge(player);
|
|
|
|
Trade.log("Sign", "Repair", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess);
|
2012-08-05 23:33:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|