Browse files

Rename MaterialAndData to ItemType

  • Loading branch information...
1 parent b5ae1a9 commit d3648395c2d3b6271120a04d2e6fc44a80714bb2 @aumgn committed May 26, 2012
View
16 command/src/main/java/fr/aumgn/bukkitutils/command/CommandArgs.java
@@ -18,7 +18,7 @@
import fr.aumgn.bukkitutils.command.messages.Messages;
import fr.aumgn.bukkitutils.geom.Vector;
import fr.aumgn.bukkitutils.geom.Vector2D;
-import fr.aumgn.bukkitutils.util.MaterialAndData;
+import fr.aumgn.bukkitutils.itemtype.ItemType;
import fr.aumgn.bukkitutils.util.Util;
public class CommandArgs extends CommandArgsBase {
@@ -231,7 +231,7 @@ public Material getMaterial(int index, Material def) {
return def;
}
- public MaterialAndData getMaterialAndData(int index) {
+ public ItemType getItemType(int index) {
String[] splitted = get(index).split(":");
if (splitted.length > 2) {
throw new InvalidMaterialAndDataFormat(local, get(index));
@@ -247,22 +247,22 @@ public MaterialAndData getMaterialAndData(int index) {
}
Material material = getMaterial(splitted[0]);
- return new MaterialAndData(material, data);
+ return new ItemType(material, data);
}
- public MaterialAndData getMaterialAndData(int index, MaterialAndData def) {
+ public ItemType getItemType(int index, ItemType def) {
if (hasIndex(index)) {
- return getMaterialAndData(index);
+ return getItemType(index);
}
return def;
}
- public MaterialAndData getMaterialAndData(int index, Material def) {
+ public ItemType getItemType(int index, Material def) {
if (hasIndex(index)) {
- return getMaterialAndData(index);
+ return getItemType(index);
}
- return new MaterialAndData(def);
+ return new ItemType(def);
}
}
View
18 command/src/test/java/fr/aumgn/bukkitutils/command/CommandArgsTest.java
@@ -10,7 +10,7 @@
import fr.aumgn.bukkitutils.command.exception.NoSuchMaterial;
import fr.aumgn.bukkitutils.geom.Vector;
import fr.aumgn.bukkitutils.geom.Vector2D;
-import fr.aumgn.bukkitutils.util.MaterialAndData;
+import fr.aumgn.bukkitutils.itemtype.ItemType;
public class CommandArgsTest {
@@ -109,34 +109,34 @@ public void testInvalidMaterialId() {
}
@Test
- public void testMaterialAndData() {
+ public void testItemType() {
CommandArgs args = CommandArgsUtil.parse("stone:3");
- MaterialAndData materialAndData = args.getMaterialAndData(0);
+ ItemType materialAndData = args.getItemType(0);
assertEquals(Material.STONE, materialAndData.getMaterial());
assertEquals(3, materialAndData.getData());
}
@Test
- public void testMaterialAndDataWithoutData() {
+ public void testItemTypeWithoutData() {
CommandArgs args = CommandArgsUtil.parse("stone");
- MaterialAndData materialAndData = args.getMaterialAndData(0);
+ ItemType materialAndData = args.getItemType(0);
assertEquals(Material.STONE, materialAndData.getMaterial());
assertEquals(0, materialAndData.getData());
}
@Test(expected = InvalidMaterialAndDataFormat.class)
- public void testInvalidMaterialAndDataFormat() {
+ public void testInvalidItemTypeFormat() {
CommandArgs args = CommandArgsUtil.parse("stone:4:5");
- args.getMaterialAndData(0);
+ args.getItemType(0);
}
@Test(expected = InvalidMaterialAndDataFormat.class)
- public void testInvalidMaterialAndDataData() {
+ public void testInvalidItemTypeData() {
CommandArgs args = CommandArgsUtil.parse("stone:invaliddata");
- args.getMaterialAndData(0);
+ args.getItemType(0);
}
}
View
26 ...mgn/bukkitutils/util/MaterialAndData.java → .../aumgn/bukkitutils/itemtype/ItemType.java
@@ -1,23 +1,23 @@
-package fr.aumgn.bukkitutils.util;
+package fr.aumgn.bukkitutils.itemtype;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
-public class MaterialAndData {
+public class ItemType {
private final Material material;
private final byte data;
- public MaterialAndData(Material material) {
+ public ItemType(Material material) {
this(material, 0);
}
- public MaterialAndData(Material material, int data) {
+ public ItemType(Material material, int data) {
this(material, (byte) data);
}
- public MaterialAndData(Material material, byte data) {
+ public ItemType(Material material, byte data) {
if (material == null) {
throw new IllegalArgumentException("Material can't be null.");
}
@@ -26,28 +26,28 @@ public MaterialAndData(Material material, byte data) {
this.data = data;
}
- public MaterialAndData(ItemStack stack) {
+ public ItemType(ItemStack stack) {
this(stack.getType(), stack.getData().getData());
}
- public MaterialAndData(Block block) {
+ public ItemType(Block block) {
this(block.getType(), block.getData());
}
public Material getMaterial() {
return material;
}
- public MaterialAndData setMaterial(Material material) {
- return new MaterialAndData(material, data);
+ public ItemType setMaterial(Material material) {
+ return new ItemType(material, data);
}
public byte getData() {
return data;
}
- public MaterialAndData setData(byte data) {
- return new MaterialAndData(material, data);
+ public ItemType setData(byte data) {
+ return new ItemType(material, data);
}
public int getMaxStackSize() {
@@ -93,11 +93,11 @@ public boolean equals(Object obj) {
return true;
}
- if (!(obj instanceof MaterialAndData)) {
+ if (!(obj instanceof ItemType)) {
return false;
}
- MaterialAndData other = (MaterialAndData) obj;
+ ItemType other = (ItemType) obj;
if (data != other.data || material != other.material) {
return false;
}

0 comments on commit d364839

Please sign in to comment.