Solved How to get Sign Redstone Power

Discussion in 'Plugin Development' started by B3N909, May 17, 2015.

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

    B3N909

    How can I get whenever I change the redstone power going into a sign? RedstoneBlockEvent only gets when redstone or redstone related items get updated and not blocks that they are powering? Thanks!
     
  2. Here you go:
    Code:
    @EventHandler
    public void onBlockEvent(BlockEvent e){
             Block b = e.getBlock();
             if(b.getType() == Material.SIGN || b.getType() == Material.SIGN_POST){
                     if(b.isBlockPowered()){
                            // Block is powered
                     }else{
                            // Block is not powered
                     }
             }
    }
    
     
  3. Offline

    B3N909

    Weird. I am getting a "Unabke to find handler list for event org.bukkit.event.block.BlockEvent"?
     
  4. Offline

    I Al Istannen

    @B3N909 The BlockEvent is abstract. I don't think you can use it. Afaik you have to use the subclasses.
     
  5. Maybe this will work:
    Code:
    @Override
    public void onEnable(){
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){      
                public void run(){
                    for(World w : Bukkit.getWorlds()){
                        for(Chunk c : w.getLoadedChunks()){
                            for(BlockState b : c.getTileEntities()){
                                if(b.isPlaced()){
                                    Block block = (Block) b;
                                    if((block.getType() == Material.SIGN) || (block.getType() == Material.SIGN_POST)){
                                        if(block.isBlockPowered()){
                                            // Powered
                                        }else{
                                            // Not powered
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
               
            }, 5L, 5L);
    }
       
    
     
  6. @loslobos1234 Please stop spoon-feeding code, especially when it's wrong :)


    @B3N909 You can use BlockRedstoneEvent - simply get the redstone that changes, and then check around it to see if it's going into a sign.
     
  7. Man, im just trying to help.
     
    MaTaMoR_ likes this.
  8. @loslobos1234 I know, but spoon-feeding is not helpful. See this post if you want more info on that.
     
  9. Offline

    RingOfStorms

    It is also not helpful when you're providing really bad practices that also don't really work at all. Scanning every single chunk every 5 ticks is going to be an incredibly long and expensive task, and your method doesn't really act as a one time event, but rather will cause whatever code to run every single frame, which is not what the intended behavior is.

    And I don't want to be horribly rude and harsh, but the fact that you used "BlockEvent" means that you don't have the basics or a general understanding of the Bukkit API, which can only mean that you have more work yourself when it comes to learning. And since that is the case, you should lay off of the spoon feed tutorials because people who can't write good code should not be sharing their code for other people to learn from.
     
    NathanWolf likes this.
  10. I know what spoon-feeding is, i speak english you know im not that dumb.
    I'll stop doing that then.

    Okay then, if i dont have a good understanding of the bukkit api, then why do i have 7 plugins?
    If i dont know how to do a couple things yet, that means i just dont know how to utilize those methods in the api yet
    Do i give a sh*t? no!
     
    MaTaMoR_ likes this.
  11. Don't stop, fight them, we can win .
     
    loslobos1234 likes this.
  12. Lol
     
    MaTaMoR_ likes this.
  13. Offline

    B3N909

    I was able to do a BlockPyhsicsEvent which basically runs every block update to check if the block has a current passing through it. If you don't know block updates happen on redstone. Thread Closed.
     
    loslobos1234 likes this.
Thread Status:
Not open for further replies.

Share This Page