How to test if a wall sign is on a dispencer

Discussion in 'Plugin Development' started by dan14941, May 18, 2014.

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

    dan14941

    Im trying to test if the sign was placed on a dispencer here is my code:

    Code:
    @EventHandler
        public void onSignCreate(SignChangeEvent e)
        {
            if(e.getLine(0).equalsIgnoreCase("[Ladder Bomb]"))
            {
                e.setLine(0, "§2[Ladder Bomb]");
                e.setLine(1, " ");
                e.setLine(3, "§4OFF");
                e.setLine(2, " ");
            }
           
            if(e.getBlock().getType() == Material.WALL_SIGN)
            {
                Sign s = (Sign) e.getBlock().getState().getData();
                if(!e.getBlock().getRelative(e.i would get block attached to but i cant?()).getType().equals(Material.DISPENSER))
                {
                    e.getBlock().breakNaturally();
                }
                else e.setLine(1, "§1DISPENCER");
            }
            else
            {
                e.getBlock().breakNaturally();
            }
        }
    and im using the import org.bukkit.block.Sign; not import org.bukkit.material.Sign;

    so if anyone can help it would be appreciated!
     
  2. Offline

    Devra

    You need to get the Material of the sign. then you can get the Block it is attached to with:
    Code:
    org.bukkit.material.Sign signMat = (org.bukkit.material.Sign) e.getBlock().getState().getData();
    Block oppositeBlock = e.getBlock().gerRelative(signMat.getAttachedFace());
    
     
  3. Offline

    tommyhoogstra

    Devra
    You dont need all the other stuff like org.bukkit.material, since its imported.
    Code:java
    1. Sign signMat = (Sign) e.getBlock().getState().getData();
    2. Block oppositeBlock = e.getBlock().gerRelative(signMat.getAttachedFace());
    3. if(oppositeBlock().getType() == Material.DISPENSER){
    4. //STUFF
    5. }
     
  4. Offline

    Devra

    tommyhoogstra: Well, you need it if you are using both, the Material Sign and the Block Sign. Then you need to specify wich one you use...but you might be right, because Eclipse sometimes gives the oppertunety to handle it by itselve, even though I am not shure how that works...
     
Thread Status:
Not open for further replies.

Share This Page