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()), KIT(new SignKit()),
MAIL(new SignMail()), MAIL(new SignMail()),
PROTECTION(new SignProtection()), PROTECTION(new SignProtection()),
REPAIR(new SignRepair()),
SELL(new SignSell()), SELL(new SignSell()),
SPAWNMOB(new SignSpawnmob()), SPAWNMOB(new SignSpawnmob()),
TIME(new SignTime()), TIME(new SignTime()),

View file

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