How do I check the color of the block under me

Discussion in 'Plugin Development' started by Johan_Wolf, Aug 29, 2014.

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

    Johan_Wolf

    I want to check if I'm under a red stained clay block, but i don't know how :c

    Code:java
    1. public void bewegung(PlayerMoveEvent e){
    2. if(plugin.imSpiel.contains(e.getPlayer().getName())){
    3. Player p=e.getPlayer();
    4. Block b=p.getLocation().subtract(0.0D, 1.0D, 0.0D).getBlock();
    5.  
    6. if(b.getType() == Material.STAINED_CLAY && DyeColor.CYAN){ //dont work :(
    7. p.sendMessage("debug");
    8. }
    9. }
    10. }


    Thank you.
     
  2. Offline

    _Filip

    DyeColor.CYAN does not return a Boolean, but an enum value of "DyeColor", you should learn the basics of if statements, and understanding what values you must input into said if statement.
     
    FerusGrim likes this.
  3. Offline

    Jimfutsu

    That is not how to check the color of stained clay, in order to check it, you need to get the data of the block.
    Code:
    b.getType().getData() == DyeColor.RED.getDyeData()
    Also, checking with the player move event happens very fast, if you don't add a cool down for the check, then this will cause a lot of lag.
     
  4. Offline

    FerusGrim

    Jimfutsu

    Are you... sure that would work? I mean, the statement wouldn't know the difference, as they're the same type. But somehow I feel as though Material#getData would return something different than DyeColor#getDyeData...
     
  5. Offline

    Jimfutsu

    FerusGrim
    I'm positive this works, this returns a Boolean, the code essentially gets the data of the block, in this case, stained clay. Then, it checks if it is equal to the data of a RED colored stained clay. If this is true, then the if statement continues.
     
  6. Offline

    FerusGrim

    Mhm, of course. I wasn't in doubt that the statement would work. Just that the two data types were relevant to each other. But, yeah, I looked as well, and confirmed it.
     
Thread Status:
Not open for further replies.

Share This Page