How to Get the Axis a sign faces!

Discussion in 'Plugin Development' started by McLuke500, Jul 24, 2012.

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

    McLuke500

    http://pastebin.com/CrHca1e4

    Im making a plugin that allows you to rate a person build using signs but the first problem I have run into is finding the direction the sign faces to I know where to place the other two.

    I also want it to work if its a wall sign but not sure if the way I have in mind would work.

    How would I get the correct location to put the signs so there in a line of 3 and all face the same way.

    Thanks in advance :D
     
  2. Offline

    lololmaker

    I just yesterday figured the whole thing out:

    Code:java
    1. //Get the signs into Block type sign.getBlock() etc.
    2. MaterialData face = new MaterialData(OriginalSignBlock.getType(), OriginalSignBlock.getData())
    3. //Spawn a sign (set location block type to sign)
    4. NewSignBlock.setData(face);
    5. NewSignBlock.update();


    Something like that, customize by your needs.
     
  3. Offline

    Crast

    One problem is there's two classes named Sign:
    org.bukkit.block.Sign
    org.bukkit.material.Sign

    The former is a Block, and lets you manipulate the text, the latter is a MaterialData subclass, and lets you manipulate the integer "Data Value" through a cleaner API.

    To reconcile it in code which needs both, you need to import one, and reference the other by the full classname.
    Let's say you have a Block and you know it's already a sign (like you checked getType == Material.SIGN or the like). Then you can do:
    Code:
    org.bukkit.material.Sign signData = (org.bukkit.material.Sign) block.getData();
    BlockFace face = signData.getFacing();
    
    Because I find I'm doing this a lot in my plugins, turning blocks into Signs (to get lines) or getting the direction they face, I've got a utility class with these two methods on it:
    Code:
     
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockFace;
    import org.bukkit.block.Sign;
     
    public final class SignUtils {
            public static BlockFace signFacing(Sign sign) {
                    org.bukkit.material.Sign signData = (org.bukkit.material.Sign) sign.getData();
                    return signData.getFacing();
            }
           
            public static Sign signFromBlock(Block block) {
                    return (Sign) block.getState();
            }
    }
    
     
    SchulziHD likes this.
Thread Status:
Not open for further replies.

Share This Page