orikenig Check if the block id type is wool. Then get the item data and compare its data value. A google search will show you which id corresponds to which colour of wool.
The data value is the color. If you want easy colors you can use: Code: DyeColor color = DyeColor.getByWoolData(block.getData()); if(color == DyeColor.RED) { // ... }
I tried to use your code and did it like that: Code: Block b = e.getBlock(); DyeColor Color = DyeColor.getByWoolData(b.getData()); Player p = e.getPlayer(); if(e.getBlock().equals(b)){ if(Color == DyeColor.RED){ p.sendMessage("Hi!"); } } And it doesn't working.
orikenig you want to get the state of that block and then cast it to Material Wool. After that just do a getColor() on that object and see if it has the right color. I would use switch for that as you may want to do different things when getting different colors. Code: @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { Block b = event.getBlock(); if (!b.equals(Material.WOOL)) return; DyeColor woolColor = ((Wool) b.getState()).getColor(); switch (woolColor) { case RED: //red code here break; case GREEN: //green code here break; } }
Ok, the basics then. I hope you know what a listener is if not please checkout the wiki page first and read about it. in that code example you have an event. That event describes the BlockBreakEvent. You can get the affected block with event.getBlock() and the player by event.getPlayer(); Each block has a state. The state of that affected block can be fetched by using event.getBlock().getState(). It holds basic informations like the position of that block and so on. (Have a look at the apidocs http://jd.bukkit.org/apidocs/) Anyways ... my code example wouldn't work i believe as Wool does not implement Metadatable. (didn't checked it just did it from my mind and i assumed it would be the same as when playing with Sings but ....) Sry that i misleaded you.
lycano I don't think you can compare a Block with Material. Perhaps with block.getType() at the very basic level you could do this and it would work until red changes id. Code: @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { Block b = event.getBlock(); if(b.getType() == Material.WOOL && b.getData().getData() == 14) { //do stuff } }
Do a check the block to check if its wool if it is do. Wool wool = (Wool) ev.getBlock().getData(); If(wool.getColor() == DyeColor.RED) { } This code hasn't been tested. I have used it for an item but never blocks I don't know if wool will cast a block you have to check that as well