Assorted cleanup.

This commit is contained in:
GJ 2012-03-31 16:40:06 -04:00
parent f89f215813
commit 9904eb0b0d
3 changed files with 99 additions and 92 deletions

View File

@ -6,52 +6,58 @@ import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.ItemChecks; import com.gmail.nossr50.ItemChecks;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;
public enum ToolType public enum ToolType {
{ AXE(mcLocale.getString("Skills.LowerAxe"), mcLocale.getString("Skills.ReadyAxe")),
AXE(mcLocale.getString("Skills.LowerAxe"), mcLocale.getString("Skills.ReadyAxe")), FISTS(mcLocale.getString("Skills.LowerFists"), mcLocale.getString("Skills.ReadyFists")),
FISTS(mcLocale.getString("Skills.LowerFists"), mcLocale.getString("Skills.ReadyFists")), HOE(mcLocale.getString("Skills.LowerHoe"), mcLocale.getString("Skills.ReadyHoe")),
HOE(mcLocale.getString("Skills.LowerHoe"), mcLocale.getString("Skills.ReadyHoe")), PICKAXE(mcLocale.getString("Skills.LowerPickAxe"), mcLocale.getString("Skills.ReadyPickAxe")),
PICKAXE(mcLocale.getString("Skills.LowerPickAxe"), mcLocale.getString("Skills.ReadyPickAxe")), SHOVEL(mcLocale.getString("Skills.LowerShovel"), mcLocale.getString("Skills.ReadyShovel")),
SHOVEL(mcLocale.getString("Skills.LowerShovel"), mcLocale.getString("Skills.ReadyShovel")), SWORD(mcLocale.getString("Skills.LowerSword"), mcLocale.getString("Skills.ReadySword"));
SWORD(mcLocale.getString("Skills.LowerSword"), mcLocale.getString("Skills.ReadySword"));
private String lowerTool;
private String lowerTool; private String raiseTool;
private String raiseTool;
private ToolType(String lowerTool, String raiseTool) {
private ToolType(String lowerTool, String raiseTool) this.lowerTool = lowerTool;
{ this.raiseTool = raiseTool;
this.lowerTool = lowerTool; }
this.raiseTool = raiseTool;
} public String getLowerTool() {
return lowerTool;
public String getLowerTool() }
{
return this.lowerTool; public String getRaiseTool() {
} return raiseTool;
}
public String getRaiseTool()
{ /**
return this.raiseTool; * Check to see if the item is of the appropriate type.
} *
* @param is The item to check
public boolean inHand(ItemStack is) * @return true if the item is the right type, false otherwise
{ */
switch(this) public boolean inHand(ItemStack is) {
{ switch (this) {
case AXE: case AXE:
return ItemChecks.isAxe(is); return ItemChecks.isAxe(is);
case FISTS:
return is.getType().equals(Material.AIR); case FISTS:
case HOE: return is.getType().equals(Material.AIR);
return ItemChecks.isHoe(is);
case PICKAXE: case HOE:
return ItemChecks.isMiningPick(is); return ItemChecks.isHoe(is);
case SHOVEL:
return ItemChecks.isShovel(is); case PICKAXE:
case SWORD: return ItemChecks.isMiningPick(is);
return ItemChecks.isSword(is);
} case SHOVEL:
return false; return ItemChecks.isShovel(is);
}
case SWORD:
return ItemChecks.isSword(is);
default:
return false;
}
}
} }

View File

@ -8,8 +8,6 @@ public class Tree {
private TreeNode root = null; private TreeNode root = null;
public Tree(){}
/** /**
* Add a node to this tree. * Add a node to this tree.
* *
@ -33,12 +31,12 @@ public class Tree {
public PlayerStat[] inOrder() { public PlayerStat[] inOrder() {
if (root != null) { if (root != null) {
ArrayList<PlayerStat> order = root.inOrder(new ArrayList<PlayerStat>()); ArrayList<PlayerStat> order = root.inOrder(new ArrayList<PlayerStat>());
return order.toArray(new PlayerStat[order.size()]); return order.toArray(new PlayerStat[order.size()]);
} }
else { 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. * It's not a good fix but its better than rewriting the whole system.
*/ */
ArrayList<PlayerStat> x = new ArrayList<PlayerStat>(); ArrayList<PlayerStat> x = new ArrayList<PlayerStat>();

View File

@ -4,46 +4,49 @@ import java.util.ArrayList;
import com.gmail.nossr50.datatypes.PlayerStat; import com.gmail.nossr50.datatypes.PlayerStat;
public class TreeNode public class TreeNode {
{ TreeNode left = null;
TreeNode left = null TreeNode right = null;
, right = null; PlayerStat ps = new PlayerStat();
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) public void add (String p, int in) {
{ if (in >= ps.statVal) {
if (in >= ps.statVal) if (left == null) {
{ left = new TreeNode(p, in);
if (left == null) }
left = new TreeNode(p,in); else {
else left.add(p, in);
left.add(p, in); }
} }
else if(in < ps.statVal) else if(in < ps.statVal) {
{ if (right == null) {
if (right == null) right = new TreeNode(p, in);
right = new TreeNode(p,in); }
else else {
right.add(p, in); right.add(p, in);
} }
} }
}
public ArrayList<PlayerStat> inOrder(ArrayList<PlayerStat> a)
{ public ArrayList<PlayerStat> inOrder(ArrayList<PlayerStat> a) {
//if left node is not null than assign arrayList(a) to left.inOrder() //if left node is not null than assign arrayList(a) to left.inOrder()
//GOES THROUGH THE ENTIRE LEFT BRANCH AND GRABS THE GREATEST NUMBER
//GOES THROUGH THE ENTIRE LEFT BRANCH AND GRABS THE GREATEST NUMBER
if (left != null) {
if(left != null) a = left.inOrder(a);
a = left.inOrder(a); }
a.add(ps); a.add(ps);
if(right != null) if (right != null) {
a = right.inOrder(a); a = right.inOrder(a);
}
return a;
} return a;
}
} }