[Solved] Change the text of a redstonepowered sign

Discussion in 'Plugin Development' started by TheUnnamedDude, Nov 5, 2011.

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

    TheUnnamedDude

    Hello, i want to get a sign powered by redstone to view the time, with the code i made the sign needs power directly, but i want to make it posible to change the text like this:
    [sign][a random block]___[redstonetorch]
    _____ = redstonedust
    Code:
        public void onBlockRedstoneChange(BlockRedstoneEvent event){
            Block block;
            block = event.getBlock();
    
            if(block.getState() instanceof Sign){
                Sign sign = (Sign)block.getState();
                if(sign.getBlock().isBlockPowered()){
                    if(sign.getLine(0).equalsIgnoreCase("Tiden er:")){
                        Date Dato = new Date();
                        SimpleDateFormat Tid;
                        Tid = new SimpleDateFormat("HH:mm:ss");
                        Tid.setTimeZone(TimeZone.getTimeZone("GMT+1"));
                        sign.setLine(1, ChatColor.DARK_BLUE + Tid.format(Dato));
                        sign.update();
                    }
                }
            }
    }
    no one?

    This is what i want to be possible:
    View attachment 7272

    This is possible:
    View attachment 7275

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 21, 2016
  2. Offline

    turt2live

    I personally don't know how to do what I am about to say, but I'm sure it's possible:

    Check the block the sign is attached to if it is powered, I'm sure there is a method in the sign class to allow this to be possible (if not you could always do an area check)
     
  3. Offline

    TheUnnamedDude

    ok, solved, not so tidy but works :)
    Code:
        @Override
        public void onBlockRedstoneChange(BlockRedstoneEvent event){
            Block block;
            block = event.getBlock();
            if(block.isBlockIndirectlyPowered()){
                Location loc = block.getLocation().add(0, 0, 2);
                Block signblock = event.getBlock().getLocation().getWorld().getBlockAt(loc);
                if(signblock.getState() instanceof Sign){
                    Sign sign = (Sign)signblock.getState();
                    if(sign.getLine(0).equalsIgnoreCase("Tiden er:")){
                    Date Dato = new Date();
                    SimpleDateFormat Tid;
                    Tid = new SimpleDateFormat("HH:mm:ss");
                    Tid.setTimeZone(TimeZone.getTimeZone("GMT+1"));
                    sign.setLine(1, ChatColor.DARK_BLUE + Tid.format(Dato));
                    sign.update();
                    }
                }
            }
            if(block.isBlockIndirectlyPowered()){
                Location loc = block.getLocation().add(0, 0, -2);
                Block signblock = event.getBlock().getLocation().getWorld().getBlockAt(loc);
                if(signblock.getState() instanceof Sign){
                    Sign sign = (Sign)signblock.getState();
                    if(sign.getLine(0).equalsIgnoreCase("Tiden er:")){
                    Date Dato = new Date();
                    SimpleDateFormat Tid;
                    Tid = new SimpleDateFormat("HH:mm:ss");
                    Tid.setTimeZone(TimeZone.getTimeZone("GMT+1"));
                    sign.setLine(1, ChatColor.DARK_BLUE + Tid.format(Dato));
                    sign.update();
                    }
                }
            }
            if(block.isBlockIndirectlyPowered()){
                Location loc = block.getLocation().add(2, 0, 0);
                Block signblock = event.getBlock().getLocation().getWorld().getBlockAt(loc);
                if(signblock.getState() instanceof Sign){
                    Sign sign = (Sign)signblock.getState();
                    if(sign.getLine(0).equalsIgnoreCase("Tiden er:")){
                    Date Dato = new Date();
                    SimpleDateFormat Tid;
                    Tid = new SimpleDateFormat("HH:mm:ss");
                    Tid.setTimeZone(TimeZone.getTimeZone("GMT+1"));
                    sign.setLine(1, ChatColor.DARK_BLUE + Tid.format(Dato));
                    sign.update();
                    }
                }
            }
            if(block.isBlockIndirectlyPowered()){
                Location loc = block.getLocation().add(-2, 0, 0);
                Block signblock = event.getBlock().getLocation().getWorld().getBlockAt(loc);
                if(signblock.getState() instanceof Sign){
                    Sign sign = (Sign)signblock.getState();
                    if(sign.getLine(0).equalsIgnoreCase("Tiden er:")){
                    Date Dato = new Date();
                    SimpleDateFormat Tid;
                    Tid = new SimpleDateFormat("HH:mm:ss");
                    Tid.setTimeZone(TimeZone.getTimeZone("GMT+1"));
                    sign.setLine(1, ChatColor.DARK_BLUE + Tid.format(Dato));
                    sign.update();
                    }
                }
            }
            if(block.getState() instanceof Sign){
                Sign sign = (Sign)block.getState();
                if(sign.getBlock().isBlockPowered()){
                    if(sign.getLine(0).equalsIgnoreCase("Tiden er:")){
                        Date Dato = new Date();
                        SimpleDateFormat Tid;
                        Tid = new SimpleDateFormat("HH:mm:ss");
                        Tid.setTimeZone(TimeZone.getTimeZone("GMT+1"));
                        sign.setLine(1, ChatColor.DARK_BLUE + Tid.format(Dato));
                        sign.update();
                    }
                }
            }
        }
     
  4. Offline

    Acrobot

    Auch.
    Do you know about a "for" loop?
    If so, you could just create a method like:

    Code:
    public static BlockFace[] directions = {BlockFace.NORTH, BlockFace.SOUTH, BlockFace.WEST, BlockFace.EAST} 
    
    public static Sign findAttachedSign(Block baseBlock){
        for (BlockFace direction : directions){
            Block block = baseBlock.getRelative(direction);
            if (block.getState() instanceof Sign){
                Sign sign = (Sign) block.getState();
                if (sign.getLine(0).equalsIgnoreCase("Tiden er:")){
                    return sign;
                }
            }
        }
        return null;
    }
    
    Then, just call this function to find the sign if the block is indirectly powered. It returns null if there's no attached sign with that format.
     
Thread Status:
Not open for further replies.

Share This Page