cleaned up code

This commit is contained in:
alisolarflare 2016-11-19 12:21:30 -05:00
parent 18c8080951
commit 5570c06cdb

View file

@ -8,35 +8,40 @@ import alisolarflare.components.ModCommand;
import alisolarflare.components.insurance.Insurance.InsuranceType; import alisolarflare.components.insurance.Insurance.InsuranceType;
public class getInsurance extends ModCommand { public class getInsurance extends ModCommand {
private final int defaultAmount = 1;
private final InsuranceType defaultInsuranceType = InsuranceType.Block;
@Override @Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) { public boolean OnCommand(CommandSender sender, String alias, String[] args) {
Player player = (Player) sender; Player player = (Player) sender;
if (args.length == 0){
player.getInventory().addItem(Insurance.getInsurance(InsuranceType.Block)); int amount = defaultAmount;
return true; InsuranceType insuranceType = defaultInsuranceType;
}else if(args.length == 1){
switch(args.length){
case 0:
break;
case 1:
if (StringUtils.isNumeric(args[0])){ if (StringUtils.isNumeric(args[0])){
int amount = Integer.parseInt(args[0]); amount = Integer.parseInt(args[0]);
player.getInventory().addItem(Insurance.getInsurance(InsuranceType.Block, amount)); break;
return true; }else if (Insurance.isInsuranceType(args[0])){
insuranceType = InsuranceType.valueOf(args[0]);
break;
}else{ }else{
if (Insurance.isInsuranceType(args[0])){ return false;
player.getInventory().addItem((Insurance.getInsurance(InsuranceType.valueOf(args[0]))));
return true;
}else{
return false;
}
} }
}else if (args.length >=2){ default:
if (StringUtils.isNumeric(args[0]) && Insurance.isInsuranceType(args[1])){ if (StringUtils.isNumeric(args[0]) && Insurance.isInsuranceType(args[1])){
player.getInventory().addItem((Insurance.getInsurance(InsuranceType.valueOf(args[1]), Integer.parseInt(args[0])))); amount = Integer.parseInt(args[0]);
return true; insuranceType = InsuranceType.valueOf(args[0]);
break;
}else{ }else{
return false; return false;
} }
} }
return false;
player.getInventory().addItem(Insurance.getInsurance(insuranceType, amount));
return true;
} }
@Override @Override
public String[] GetHelpText(String alias){ public String[] GetHelpText(String alias){