New materials, changed material names per style guidelines + correct names

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
Bukkit/Spigot 2011-01-13 23:33:10 +00:00
parent 0a677497d4
commit 2fab54ae7b
2 changed files with 224 additions and 174 deletions

View file

@ -1,199 +1,249 @@
package org.bukkit;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.material.MaterialData;
/**
* An enum of all material IDs accepted by the official server + client
*/
public enum Material {
Air(0),
Stone(1),
Grass(2),
Dirt(3),
Cobblestone(4),
Wood(5),
Sapling(6),
Bedrock(7),
Water(8),
StationaryWater(9),
Lava(10),
StationaryLava(11),
Sand(12),
Gravel(13),
GoldOre(14),
IronOre(15),
CoalOre(16),
Log(17),
Leaves(18),
Sponge(19),
Glass(20),
Cloth(35),
YellowFlower(37),
RedRose(38),
BrownMushroom(39),
RedMushroom(40),
GoldBlock(41),
IronBlock(42),
DoubleStep(43),
Step(44),
Brick(45),
AIR(0),
STONE(1),
GRASS(2),
DIRT(3),
COBBLESTONE(4),
WOOD(5),
SAPLING(6),
BEDROCK(7),
WATER(8),
STATIONARY_WATER(9),
LAVA(10),
STATIONARY_LAVA(11),
SAND(12),
GRAVEL(13),
GOLD_ORE(14),
IRON_ORE(15),
COAL_ORE(16),
LOG(17),
LEAVES(18),
SPONGE(19),
GLASS(20),
LAPIS_ORE(21),
LAPIS_BLOCK(22),
DISPENSER(23),
SANDSTONE(24),
NOTE_BLOCK(25),
CLOTH(35),
YELLOW_FLOWER(37),
RED_ROSE(38),
BROWN_MUSHROOM(39),
RED_MUSHROOM(40),
GOLD_BLOCK(41),
IRON_BLOCK(42),
DOUBLE_STEP(43),
STEP(44),
BRICK(45),
TNT(46),
BookShelf(47),
MossyCobblestone(48),
Obsidian(49),
Torch(50),
Fire(51),
MobSpawner(52),
WoodStairs(53),
Chest(54),
RedstoneWire(55),
DiamondOre(56),
DiamondBlock(57),
Workbench(58),
Crops(59),
Soil(60),
Furnace(61),
BurningFurnace(62),
SignPost(63),
WoodenDoor(64),
Ladder(65),
Rails(66),
CobblestoneStairs(67),
WallSign(68),
Lever(69),
StonePlate(70),
IronDoorBlock(71),
WoodPlate(72),
RedstoneOre(73),
GlowingRedstoneOre(74),
RedstoneTorchOff(75),
RedstoneTorchOn(76),
StoneButton(77),
Snow(78),
Ice(79),
SnowBlock(80),
Cactus(81),
Clay(82),
ReedBlock(83),
Jukebox(84),
Fence(85),
Pumpkin(86),
Netherstone(87),
SlowSand(88),
LightStone(89),
Portal(90),
JackOLantern(91),
IronSpade(256),
IronPickaxe(257),
IronAxe(258),
FlintAndSteel(259),
Apple(260),
Bow(261),
Arrow(262),
Coal(263),
Diamond(264),
IronIngot(265),
GoldIngot(266),
IronSword(267),
WoodSword(268),
WoodSpade(269),
WoodPickaxe(270),
WoodAxe(271),
StoneSword(272),
StoneSpade(273),
StonePickaxe(274),
StoneAxe(275),
DiamondSword(276),
DiamondSpade(277),
DiamondPickaxe(278),
DiamondAxe(279),
Stick(280),
Bowl(281),
MushroomSoup(282),
GoldSword(283),
GoldSpade(284),
GoldPickaxe(285),
GoldAxe(286),
String(287),
Feather(288),
Gunpowder(289),
WoodHoe(290),
StoneHoe(291),
IronHoe(292),
DiamondHoe(293),
GoldHoe(294),
Seeds(295),
Wheat(296),
Bread(297),
LeatherHelmet(298),
LeatherChestplate(299),
LeatherLeggings(300),
LeatherBoots(301),
ChainmailHelmet(302),
ChainmailChestplate(303),
ChainmailLeggings(304),
ChainmailBoots(305),
IronHelmet(306),
IronChestplate(307),
IronLeggings(308),
IronBoots(309),
DiamondHelmet(310),
DiamondChestplate(311),
DiamondLeggings(312),
DiamondBoots(313),
GoldHelmet(314),
GoldChestplate(315),
GoldLeggings(316),
GoldBoots(317),
Flint(318),
Pork(319),
GrilledPork(320),
Painting(321),
GoldenApple(322),
Sign(323),
WoodDoor(324),
Bucket(325),
WaterBucket(326),
LavaBucket(327),
Minecart(328),
Saddle(329),
IronDoor(330),
RedStone(331),
SnowBall(332),
Boat(333),
Leather(334),
MilkBucket(335),
ClayBrick(336),
ClayBall(337),
Reed(338),
Paper(339),
Book(340),
SlimeBall(341),
StorageMinecart(342),
PoweredMinecart(343),
Egg(344),
Compass(345),
FishingRod(346),
Watch(347),
LightstoneDust(348),
RawFish(349),
CookedFish(350),
GoldRecord(2256),
GreenRecord(2257);
BOOKSHELF(47),
MOSSY_COBBLESTONE(48),
OBSIDIAN(49),
TORCH(50),
FIRE(51),
MOB_SPAWNER(52),
WOOD_STAIRS(53),
CHEST(54),
REDSTONE_WIRE(55),
DIAMOND_ORE(56),
DIAMOND_BLOCK(57),
WORKBENCH(58),
CROPS(59),
SOIL(60),
FURNACE(61),
BURNING_FURNACE(62),
SIGN_POST(63),
WOODEN_DOOR(64),
LADDER(65),
RAILS(66),
COBBLESTONE_STAIRS(67),
WALL_SIGN(68),
LEVER(69),
STONE_PLATE(70),
IRON_DOOR_BLOCK(71),
WOOD_PLATE(72),
REDSTONE_ORE(73),
GLOWING_REDSTONE_ORE(74),
REDSTONE_TORCH_OFF(75),
REDSTONE_TORCH_ON(76),
STONE_BUTTON(77),
SNOW(78),
ICE(79),
SNOW_BLOCK(80),
CACTUS(81),
CLAY(82),
SUGAR_CANE_BLOCK(83),
JUKEBOX(84),
FENCE(85),
PUMPKIN(86),
NETHERRACK(87),
SOUL_SAND(88),
GLOWSTONE(89),
PORTAL(90),
JACK_O_LANTERN(91),
CAKE_BLOCK(92),
IRON_SPADE(256),
IRON_PICKAXE(257),
IRON_AXE(258),
FLINT_AND_STEEL(259),
APPLE(260),
BOW(261),
ARROW(262),
COAL(263),
DIAMOND(264),
IRON_INGOT(265),
GOLD_INGOT(266),
IRON_SWORD(267),
WOOD_SWORD(268),
WOOD_SPADE(269),
WOOD_PICKAXE(270),
WOOD_AXE(271),
STONE_SWORD(272),
STONE_SPADE(273),
STONE_PICKAXE(274),
STONE_AXE(275),
DIAMOND_SWORD(276),
DIAMOND_SPADE(277),
DIAMOND_PICKAXE(278),
DIAMOND_AXE(279),
STICK(280),
BOWL(281),
MUSHROOM_SOUP(282),
GOLD_SWORD(283),
GOLD_SPADE(284),
GOLD_PICKAXE(285),
GOLD_AXE(286),
STRING(287),
FEATHER(288),
SULPHUR(289),
WOOD_HOE(290),
STONE_HOE(291),
IRON_HOE(292),
DIAMOND_HOE(293),
GOLD_HOE(294),
SEEDS(295),
WHEAT(296),
BREAD(297),
LEATHER_HELMET(298),
LEATHER_CHESTPLATE(299),
LEATHER_LEGGINGS(300),
LEATHER_BOOTS(301),
CHAINMAIL_HELMET(302),
CHAINMAIL_CHESTPLATE(303),
CHAINMAIL_LEGGINGS(304),
CHAINMAIL_BOOTS(305),
IRON_HELMET(306),
IRON_CHESTPLATE(307),
IRON_LEGGINGS(308),
IRON_BOOTS(309),
DIAMOND_HELMET(310),
DIAMOND_CHESTPLATE(311),
DIAMOND_LEGGINGS(312),
DIAMOND_BOOTS(313),
GOLD_HELMET(314),
GOLD_CHESTPLATE(315),
GOLD_LEGGINGS(316),
GOLD_BOOTS(317),
FLINT(318),
PORK(319),
GRILLED_PORK(320),
PAINTING(321),
GOLDEN_APPLE(322),
SIGN(323),
WOOD_DOOR(324),
BUCKET(325),
WATER_BUCKET(326),
LAVA_BUCKET(327),
MINECART(328),
SADDLE(329),
IRON_DOOR(330),
REDSTONE(331),
SNOW_BALL(332),
BOAT(333),
LEATHER(334),
MILK_BUCKET(335),
CLAY_BRICK(336),
CLAY_BALL(337),
SUGAR_CANE(338),
PAPER(339),
BOOK(340),
SLIME_BALL(341),
STORAGE_MINECART(342),
POWERED_MINECART(343),
EGG(344),
COMPASS(345),
FISHING_ROD(346),
WATCH(347),
GLOWSTONE_DUST(348),
RAW_FISH(349),
COOKED_FISH(350),
INK_SACK(351),
BONE(352),
SUGAR(353),
CAKE(354),
GOLD_RECORD(2256),
GREEN_RECORD(2257);
private final int id;
private final Class<MaterialData> data;
private static final Map<Integer, Material> lookupId = new HashMap<Integer, Material>();
private static final Map<String, Material> lookupName = new HashMap<String, Material>();
private Material(final int id) {
this(id, null);
}
private Material(final int id, final Class<MaterialData> data) {
this.id = id;
this.data = data;
}
public int getID() {
return id;
}
public Class<MaterialData> getData() {
return data;
}
public MaterialData getNewData(final byte raw) {
if (data == null) {
return null;
}
try {
Constructor<MaterialData> ctor = data.getConstructor(int.class, byte.class);
return ctor.newInstance(id, raw);
} catch (InstantiationException ex) {
Logger.getLogger(Material.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(Material.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalArgumentException ex) {
Logger.getLogger(Material.class.getName()).log(Level.SEVERE, null, ex);
} catch (InvocationTargetException ex) {
Logger.getLogger(Material.class.getName()).log(Level.SEVERE, null, ex);
} catch (NoSuchMethodException ex) {
Logger.getLogger(Material.class.getName()).log(Level.SEVERE, null, ex);
} catch (SecurityException ex) {
Logger.getLogger(Material.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
public boolean isBlock() {
return id < 256;
}

View file

@ -66,7 +66,7 @@ public class PlayerItemEvent extends PlayerEvent implements Cancellable {
* @return Material the material of the item used
*/
public Material getMaterial() {
if (this.item == null) return Material.Air;
if (this.item == null) return Material.AIR;
return item.getType();
}