General Sign questions

Discussion in 'Plugin Development' started by Gopaintman, Sep 11, 2013.

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

    Gopaintman

    Hi,
    So I have this
    Code:java
    1. Location loc = e.getBlock().getLocation();
    2. Block mainBlock = e.getBlock();
    3.  
    4. int mainX = mainBlock.getX();
    5. int mainY = mainBlock.getY();
    6.  
    7. Location[] targLoc = { loc, loc, loc, loc };
    8. targLoc[1].setX(mainX + 1);
    9. targLoc[2].setX(mainX - 1);
    10. targLoc[3].setY(mainY + 1);
    11. targLoc[4].setY(mainY - 1);
    12. Material Sign = Material.SIGN;
    13.  
    14. if (targLoc[1].getBlock().getType() == Sign) {
    15. Sign targSign = (Sign)targLoc[1].getBlock();
    16.  
    17. } else if (targLoc[2].getBlock().getTypeId() == Sign.getId()) {
    18.  
    19. } else if (targLoc[3].getBlock().getTypeId() == Sign.getId()) {
    20.  
    21. } else if (targLoc[4].getBlock().getTypeId() == Sign.getId()) {
    22.  
    23. } else {
    24.  
    25. }

    However I'm wondering if: 1.There is a more efficient way of doing this; 2.I can't seem to get the sign methods from "Sign targSign = (Sign)targLoc[1].getBlock();" such as .setLine();
     
  2. Offline

    xBlackLightx

    So you're trying to get their target block, check if its a sign, and the access the sign methods?
    Gopaintman
     
  3. Offline

    Gopaintman

    Exactly
     
  4. Offline

    xBlackLightx

    Ignore everything that was in this post before. Gimme a minute, I'll get you working code.
    Gopaintman
     
  5. Offline

    Chinwe

    Cast block.getState() to Sign, instead of just the block ;)
     
  6. Offline

    xBlackLightx

    Here is better code. Thanks Chinwe, just realized that right as you posted. Here's some code that should work.

    Code:java
    1. Block targetBlock = e.getPlayer().getTargetBlock(null, 7);
    2. if(targetBlock.getType().equals(Material.SIGN) || (targetBlock.getType().equals(Material.WALL_SIGN))){
    3. Sign targetSign = (Sign) targetBlock.getState();
    4. targetSign.setLine(1, "Hey");
    5. }
     
    Gopaintman likes this.
Thread Status:
Not open for further replies.

Share This Page