Check if sign is on block

Discussion in 'Plugin Development' started by ko47374737, Jul 26, 2014.

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


    Hello i am making a crates plugin and its a chest
    i need to check if a sign is on the back of the chest and it has a curtain text and they right click with a curtain item it performs something!
  2. Offline


    ko47374737 I believe if it's on a chest, it would be a wall sign, therefore this code would check if it's on a chest.
    if(e.getBlock().getType() == Material.WALL_SIGN){ // Sign is on a chest.
  3. Offline


    Niknea But it doesnt check for a chest? How would i check if its on a chest
  4. Offline


    ko47374737 You'd then need to do some math, to get the block behind the sign, then check if the block is a chest.
  5. Offline


    Niknea Sorry not to be rude, but this doesn't help
  6. Offline


    Niknea likes this.
  7. Offline


  8. Offline


  9. Offline


    xTigerRebornx Thank you

    I couldnt find it, the method it said isnt actually in there. anyone else

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 9, 2016
  10. Offline


  11. Offline


    dsouzamatt How would i get it when they click a chest check if a sign is on the chest?
  12. Offline


    Check around the chest, find a sign and see if its built on the chest. All the methods you need are presented above.
  13. Offline


    ko47374737 just to clear some confusion, the sign dsouzamatt and xTigerRebornx are talking about is org.bukkit.material.Sign, and you are most likely using org.bukkit.block. Sign.

    The material package is for the MaterialData, which you get from calling BlockState#getData() (BlockStates can be retrieves through Block#getState()).

    The block package is used for so called tile entities, blocks with special properties that can change without changing the type or datavalue. Typical examples are chests and signs. These can be retrieved from casting the BlockState to the appropriate subclass (all tile entities have (or should have) their own special subclass, the rest of the blocks have a 'simple' BlockState instance).

    After casting, you can get the lines (signs) or the inventory (chest), or whatever the subclass provides (for more, check the link below).

    In your case, none of this is needed up to the point where you know if there is a sign around. First loop over all blocks around the block (there are 6 BlockFaces, where two can be sign posts and 4 can be wall signs attached to the chest. You should be able to figure out which ;)). Then simply check if the opposite of the BlockFace used in getRelative() equals the attached face (this is retrieved with the material package, org.bukkit.material.Sign) (there is a method for getting the opposing face, documentation is the key ;))

    If so, you get the lines of the sign (this time, we use the org.bukkit.block.Sign one).

    Lastly, you check if the lines match whatever you wanted, to verify if it is your chest
Thread Status:
Not open for further replies.

Share This Page