2012-08-05 23:33:29 +00:00
|
|
|
package com.earth2me.essentials.signs;
|
|
|
|
|
|
|
|
import com.earth2me.essentials.ChargeException;
|
|
|
|
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;
|
2013-10-11 02:44:41 +00:00
|
|
|
import net.ess3.api.IEssentials;
|
2012-08-05 23:33:29 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
2012-08-05 23:33:29 +00:00
|
|
|
|
2013-05-26 21:00:35 +00:00
|
|
|
|
2015-04-15 04:06:16 +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");
|
|
|
|
} else if (!repairTarget.equalsIgnoreCase("all") && !repairTarget.equalsIgnoreCase("hand")) {
|
|
|
|
sign.setLine(1, "§c<hand|all>");
|
|
|
|
throw new SignException(tl("invalidSignLine", 2));
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
|
|
|
|
Commandrepair command = new Commandrepair();
|
|
|
|
command.setEssentials(ess);
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (sign.getLine(1).equalsIgnoreCase("hand")) {
|
|
|
|
command.repairHand(player);
|
|
|
|
} else if (sign.getLine(1).equalsIgnoreCase("all")) {
|
|
|
|
command.repairAll(player);
|
|
|
|
} else {
|
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
throw new SignException(ex.getMessage(), ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
charge.charge(player);
|
|
|
|
Trade.log("Sign", "Repair", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess);
|
|
|
|
return true;
|
|
|
|
}
|
2012-08-05 23:33:29 +00:00
|
|
|
}
|