New Sign: Repair

Syntax: [repair] / <hand|all> / [cost]
This commit is contained in:
KHobbits 2012-08-06 00:33:29 +01:00
parent 9e975568be
commit ee608d944a
3 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,57 @@
package com.earth2me.essentials.signs;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
import com.earth2me.essentials.commands.Commandrepair;
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") )
{
throw new SignException(_("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);
String[] args = new String[]
{
sign.getLine(1)
};
try
{
command.run(ess.getServer(), player, "repair", args);
}
catch (Exception ex)
{
throw new SignException(ex.getMessage(), ex);
}
charge.charge(player);
return true;
}
}

View File

@ -13,6 +13,7 @@ public enum Signs
KIT(new SignKit()),
MAIL(new SignMail()),
PROTECTION(new SignProtection()),
REPAIR(new SignRepair()),
SELL(new SignSell()),
SPAWNMOB(new SignSpawnmob()),
TIME(new SignTime()),

View File

@ -219,6 +219,7 @@ enabledSigns:
#- gamemode
#- heal
#- spawnmob
#- repair
#- time
#- weather
#- protection