How do I check what color a wool block is?

Discussion in 'Plugin Development' started by HawkIngot, Dec 16, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    HawkIngot

    I need it so my plugin checks what color wool block was placed or destroyed. This is what I have so far:

    Code:
    @EventHandler
    public void blockPlace(BlockPlaceEvent e) {
        if(playersInGame.contains(e.getPlayer())) {
     
          //players in game is a hashmap I use.
     
          Block b = e.getBlock();
          if(b.getType() != Material.WOOL) {
              e.setCancelled(true);
          }
    How do I check if the wool block is like blue?
     
  2. Offline

    gomeow

    b.getData();
    returns a byte.
     
  3. Offline

    HawkIngot

    Can you show me it being used somehow.
     
  4. Offline

    chasechocolate

  5. Offline

    fireblast709

    Code:java
    1. if(b.getState().getData() instanceof Wool)
    2. {
    3. DyeColor color = ((Wool)b.getState().getData()).getColor();
    4. if(color == DyeColor.BLACK)
    5. {
    6. // its black :3
    7. }
    8. }

    Just saying :3
     
  6. Offline

    caseif

    An alternate way to do this:
    Code:java
    1. HashMap<Int, String> hm = new HashMap<Int, String>();
    2. hm.put(0, WHITE);
    3. hm.put(1, ORANGE);
    4. // etc.
    5. String color = hm.get(b.getDurability);

    This could, of course, be easily modified to return a color rather than a string. I would use this code f your goal is to get the color of the wool, rather than check if it is a certain value.
     
Thread Status:
Not open for further replies.

Share This Page