From 9904eb0b0d9e53d055f7d7677aceab99e618858a Mon Sep 17 00:00:00 2001 From: GJ Date: Sat, 31 Mar 2012 16:40:06 -0400 Subject: [PATCH] Assorted cleanup. --- .../com/gmail/nossr50/datatypes/ToolType.java | 102 +++++++++--------- .../com/gmail/nossr50/datatypes/Tree.java | 6 +- .../com/gmail/nossr50/datatypes/TreeNode.java | 83 +++++++------- 3 files changed, 99 insertions(+), 92 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/datatypes/ToolType.java b/src/main/java/com/gmail/nossr50/datatypes/ToolType.java index 331abfa61..cf898bba9 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/ToolType.java +++ b/src/main/java/com/gmail/nossr50/datatypes/ToolType.java @@ -6,52 +6,58 @@ import org.bukkit.inventory.ItemStack; import com.gmail.nossr50.ItemChecks; import com.gmail.nossr50.locale.mcLocale; -public enum ToolType -{ - AXE(mcLocale.getString("Skills.LowerAxe"), mcLocale.getString("Skills.ReadyAxe")), - FISTS(mcLocale.getString("Skills.LowerFists"), mcLocale.getString("Skills.ReadyFists")), - HOE(mcLocale.getString("Skills.LowerHoe"), mcLocale.getString("Skills.ReadyHoe")), - PICKAXE(mcLocale.getString("Skills.LowerPickAxe"), mcLocale.getString("Skills.ReadyPickAxe")), - SHOVEL(mcLocale.getString("Skills.LowerShovel"), mcLocale.getString("Skills.ReadyShovel")), - SWORD(mcLocale.getString("Skills.LowerSword"), mcLocale.getString("Skills.ReadySword")); - - private String lowerTool; - private String raiseTool; - - private ToolType(String lowerTool, String raiseTool) - { - this.lowerTool = lowerTool; - this.raiseTool = raiseTool; - } - - public String getLowerTool() - { - return this.lowerTool; - } - - public String getRaiseTool() - { - return this.raiseTool; - } - - public boolean inHand(ItemStack is) - { - switch(this) - { - case AXE: - return ItemChecks.isAxe(is); - case FISTS: - return is.getType().equals(Material.AIR); - case HOE: - return ItemChecks.isHoe(is); - case PICKAXE: - return ItemChecks.isMiningPick(is); - case SHOVEL: - return ItemChecks.isShovel(is); - case SWORD: - return ItemChecks.isSword(is); - } - return false; - } - +public enum ToolType { + AXE(mcLocale.getString("Skills.LowerAxe"), mcLocale.getString("Skills.ReadyAxe")), + FISTS(mcLocale.getString("Skills.LowerFists"), mcLocale.getString("Skills.ReadyFists")), + HOE(mcLocale.getString("Skills.LowerHoe"), mcLocale.getString("Skills.ReadyHoe")), + PICKAXE(mcLocale.getString("Skills.LowerPickAxe"), mcLocale.getString("Skills.ReadyPickAxe")), + SHOVEL(mcLocale.getString("Skills.LowerShovel"), mcLocale.getString("Skills.ReadyShovel")), + SWORD(mcLocale.getString("Skills.LowerSword"), mcLocale.getString("Skills.ReadySword")); + + private String lowerTool; + private String raiseTool; + + private ToolType(String lowerTool, String raiseTool) { + this.lowerTool = lowerTool; + this.raiseTool = raiseTool; + } + + public String getLowerTool() { + return lowerTool; + } + + public String getRaiseTool() { + return raiseTool; + } + + /** + * Check to see if the item is of the appropriate type. + * + * @param is The item to check + * @return true if the item is the right type, false otherwise + */ + public boolean inHand(ItemStack is) { + switch (this) { + case AXE: + return ItemChecks.isAxe(is); + + case FISTS: + return is.getType().equals(Material.AIR); + + case HOE: + return ItemChecks.isHoe(is); + + case PICKAXE: + return ItemChecks.isMiningPick(is); + + case SHOVEL: + return ItemChecks.isShovel(is); + + case SWORD: + return ItemChecks.isSword(is); + + default: + return false; + } + } } diff --git a/src/main/java/com/gmail/nossr50/datatypes/Tree.java b/src/main/java/com/gmail/nossr50/datatypes/Tree.java index 3fe54ea9c..7c70e11c9 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/Tree.java +++ b/src/main/java/com/gmail/nossr50/datatypes/Tree.java @@ -8,8 +8,6 @@ public class Tree { private TreeNode root = null; - public Tree(){} - /** * Add a node to this tree. * @@ -33,12 +31,12 @@ public class Tree { public PlayerStat[] inOrder() { if (root != null) { ArrayList order = root.inOrder(new ArrayList()); - return order.toArray(new PlayerStat[order.size()]); } else { - /* Throw some dummy info in case the users file is empty. + /* + * Throw some dummy info in case the users file is empty. * It's not a good fix but its better than rewriting the whole system. */ ArrayList x = new ArrayList(); diff --git a/src/main/java/com/gmail/nossr50/datatypes/TreeNode.java b/src/main/java/com/gmail/nossr50/datatypes/TreeNode.java index 92223adc0..2744bb4fb 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/TreeNode.java +++ b/src/main/java/com/gmail/nossr50/datatypes/TreeNode.java @@ -4,46 +4,49 @@ import java.util.ArrayList; import com.gmail.nossr50.datatypes.PlayerStat; -public class TreeNode -{ - TreeNode left = null - , right = null; - PlayerStat ps = new PlayerStat(); +public class TreeNode { + TreeNode left = null; + TreeNode right = null; + PlayerStat ps = new PlayerStat(); - public TreeNode(String p, int in) {ps.statVal = in; ps.name = p;} + public TreeNode(String p, int in) { + ps.statVal = in; + ps.name = p; + } - public void add (String p, int in) - { - if (in >= ps.statVal) - { - if (left == null) - left = new TreeNode(p,in); - else - left.add(p, in); - } - else if(in < ps.statVal) - { - if (right == null) - right = new TreeNode(p,in); - else - right.add(p, in); - } - } - - public ArrayList inOrder(ArrayList a) - { - //if left node is not null than assign arrayList(a) to left.inOrder() - - //GOES THROUGH THE ENTIRE LEFT BRANCH AND GRABS THE GREATEST NUMBER - - if(left != null) - a = left.inOrder(a); - - a.add(ps); - - if(right != null) - a = right.inOrder(a); - - return a; - } + public void add (String p, int in) { + if (in >= ps.statVal) { + if (left == null) { + left = new TreeNode(p, in); + } + else { + left.add(p, in); + } + } + else if(in < ps.statVal) { + if (right == null) { + right = new TreeNode(p, in); + } + else { + right.add(p, in); + } + } + } + + public ArrayList inOrder(ArrayList a) { + //if left node is not null than assign arrayList(a) to left.inOrder() + //GOES THROUGH THE ENTIRE LEFT BRANCH AND GRABS THE GREATEST NUMBER + + if (left != null) { + a = left.inOrder(a); + } + + a.add(ps); + + if (right != null) { + a = right.inOrder(a); + } + + return a; + } }