From 5570c06cdbf6dcb1b53940def00581c1c786c9e9 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Sat, 19 Nov 2016 12:21:30 -0500 Subject: [PATCH] cleaned up code --- .../components/insurance/getInsurance.java | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/alisolarflare/components/insurance/getInsurance.java b/src/alisolarflare/components/insurance/getInsurance.java index 382a572..f5ed916 100644 --- a/src/alisolarflare/components/insurance/getInsurance.java +++ b/src/alisolarflare/components/insurance/getInsurance.java @@ -8,35 +8,40 @@ import alisolarflare.components.ModCommand; import alisolarflare.components.insurance.Insurance.InsuranceType; public class getInsurance extends ModCommand { - + private final int defaultAmount = 1; + private final InsuranceType defaultInsuranceType = InsuranceType.Block; @Override public boolean OnCommand(CommandSender sender, String alias, String[] args) { Player player = (Player) sender; - if (args.length == 0){ - player.getInventory().addItem(Insurance.getInsurance(InsuranceType.Block)); - return true; - }else if(args.length == 1){ + + int amount = defaultAmount; + InsuranceType insuranceType = defaultInsuranceType; + + switch(args.length){ + case 0: + break; + case 1: if (StringUtils.isNumeric(args[0])){ - int amount = Integer.parseInt(args[0]); - player.getInventory().addItem(Insurance.getInsurance(InsuranceType.Block, amount)); - return true; + amount = Integer.parseInt(args[0]); + break; + }else if (Insurance.isInsuranceType(args[0])){ + insuranceType = InsuranceType.valueOf(args[0]); + break; }else{ - if (Insurance.isInsuranceType(args[0])){ - player.getInventory().addItem((Insurance.getInsurance(InsuranceType.valueOf(args[0])))); - return true; - }else{ - return false; - } + return false; } - }else if (args.length >=2){ + default: if (StringUtils.isNumeric(args[0]) && Insurance.isInsuranceType(args[1])){ - player.getInventory().addItem((Insurance.getInsurance(InsuranceType.valueOf(args[1]), Integer.parseInt(args[0])))); - return true; + amount = Integer.parseInt(args[0]); + insuranceType = InsuranceType.valueOf(args[0]); + break; }else{ return false; } } - return false; + + player.getInventory().addItem(Insurance.getInsurance(insuranceType, amount)); + return true; } @Override public String[] GetHelpText(String alias){