2011-06-13 00:59:10 +02:00
|
|
|
package com.Acrobot.ChestShop.Items;
|
|
|
|
|
|
|
|
import org.bukkit.CoalType;
|
|
|
|
import org.bukkit.DyeColor;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.TreeSpecies;
|
2011-12-20 21:39:45 +01:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2011-06-13 00:59:10 +02:00
|
|
|
import org.bukkit.material.*;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Acrobot
|
|
|
|
*/
|
2011-08-13 12:08:34 +02:00
|
|
|
public class DataValue {
|
|
|
|
public static byte get(String type, Material material) {
|
2011-07-23 21:00:47 +02:00
|
|
|
if (material == null) return 0;
|
2011-07-02 20:34:14 +02:00
|
|
|
|
2011-08-13 12:08:34 +02:00
|
|
|
type = type.toUpperCase().replace(" ", "_");
|
2011-06-13 00:59:10 +02:00
|
|
|
MaterialData materialData = null;
|
|
|
|
|
2011-07-15 21:45:26 +02:00
|
|
|
try {
|
|
|
|
switch (material) {
|
|
|
|
case SAPLING:
|
|
|
|
case LOG:
|
2011-08-13 12:08:34 +02:00
|
|
|
materialData = new Tree(TreeSpecies.valueOf(type));
|
2011-07-15 21:45:26 +02:00
|
|
|
break;
|
|
|
|
case STEP:
|
|
|
|
case DOUBLE_STEP:
|
2011-08-13 12:08:34 +02:00
|
|
|
materialData = new Step(Items.getMaterial(type));
|
2011-07-15 21:45:26 +02:00
|
|
|
break;
|
|
|
|
case WOOL:
|
2011-08-13 12:08:34 +02:00
|
|
|
materialData = new Wool(DyeColor.valueOf(type));
|
2011-07-15 21:45:26 +02:00
|
|
|
break;
|
2011-12-20 21:39:45 +01:00
|
|
|
case INK_SACK:
|
2012-01-09 22:39:38 +01:00
|
|
|
byte data = (byte) (15 - DyeColor.valueOf(type).getData());
|
|
|
|
materialData = new Wool(DyeColor.getByData(data));
|
2011-12-20 21:39:45 +01:00
|
|
|
break;
|
2011-07-15 21:45:26 +02:00
|
|
|
case COAL:
|
2011-08-13 12:08:34 +02:00
|
|
|
materialData = new Coal(CoalType.valueOf(type));
|
2011-07-15 21:45:26 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-03-17 15:00:25 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
return 0;
|
|
|
|
}
|
2011-06-13 00:59:10 +02:00
|
|
|
|
|
|
|
return (materialData == null ? 0 : materialData.getData());
|
|
|
|
}
|
2012-03-17 15:00:25 +01:00
|
|
|
|
|
|
|
public static String getName(ItemStack is) {
|
2011-12-20 21:39:45 +01:00
|
|
|
short dur = is.getDurability();
|
|
|
|
if (dur == 0) return null;
|
2012-03-17 15:00:25 +01:00
|
|
|
|
2011-12-20 21:39:45 +01:00
|
|
|
Material material = is.getType();
|
|
|
|
|
|
|
|
String name = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
switch (material) {
|
|
|
|
case SAPLING:
|
|
|
|
case LOG:
|
|
|
|
name = TreeSpecies.getByData((byte) dur).name();
|
|
|
|
break;
|
|
|
|
case STEP:
|
|
|
|
case DOUBLE_STEP:
|
|
|
|
name = new Step(Material.getMaterial(dur)).getMaterial().name();
|
|
|
|
break;
|
|
|
|
case WOOL:
|
|
|
|
name = DyeColor.getByData((byte) dur).name();
|
|
|
|
break;
|
|
|
|
case INK_SACK:
|
|
|
|
name = DyeColor.getByData((byte) (15 - dur)).name();
|
|
|
|
break;
|
|
|
|
case COAL:
|
|
|
|
name = CoalType.getByData((byte) dur).name();
|
|
|
|
break;
|
|
|
|
}
|
2012-03-17 15:00:25 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-12-20 21:39:45 +01:00
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
2011-06-13 00:59:10 +02:00
|
|
|
}
|