BlockPlaceEvent

Discussion in 'Plugin Development' started by Snowl, Jan 23, 2011.

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

    Snowl

    I swear to god, my plugin hates me or something... nothing is working properly...
    anyway,
    PHP:
        public void onBlockPlace(BlockPlaceEvent event){
         
    System.out.println("TEST PLEASE WORK");
        }
    doesn't work! I swear to god... I have searched, probed the javadocs, tried everything. No. It doesn't want to trigger.

    Please help a noob :D
     
  2. Offline

    MadMichi

    Unfortunately i can't help you, i can only say my test plugin doesn't get the event either.
    In the roadmap the event is marked as "done", but in the java docs it still says "not implemented yet".[​IMG]
     
  3. Offline

    Archelaus

    It works.

    Code:
    public void onBlockPlace(BlockPlaceEvent event)
        {
            Block block = event.getBlockPlaced();
            event.getPlayer().sendMessage(block.getType().name());
            event.setCancelled(false);
     
          if (event.getBlockPlaced().getType().equals(Material.TNT)) {
            event.getBlockPlaced().setType(Material.AIR);
            event.setCancelled(true);
          }
     
  4. Offline

    MadMichi

    Okay, i found an error in my code after looking into RightLegRed's example.
    I wrote onBlockPlaced().
    Now that i changed it to onBlockPlace() it works for me too.

    Could you paste more of your code David? The error must be somewhere else.
     
  5. Offline

    eisental

    Maybe you forgot to register the event?
    Code:
     pm.registerEvent(Type.BLOCK_PLACED, blockListener, Priority.Normal, this);
     
  6. Offline

    Snowl

    -.- I looked at my event code and I retyped BLOCK_PLACED (even though it was that in the first place and valid) and it works now... Thanks :D
     
  7. Offline

    paletas

    To avoid such mistakes try using the annotation @Override before the method to ensure your using a method from the base listener.
     
  8. Offline

    MadMichi

    I will try that, thanks for the hint.
     
  9. Offline

    mjmr89

    Sorry to resurrect a bit of a dead topic, but I think it would be better than making a new one on the same sort of topic. I'm having trouble getting my onBlockPlace to work. Heres my function in my block listener:

    public void onBlockPlace(BlockPlaceEvent be){
    Block b = be.getBlock();
    be.getPlayer().sendMessage("Block placed: " + b.getType().name());
    if(isSign(b)){
    plugin.getServer().broadcastMessage("Sign placed.");
    if(isBlockIndirectlyPowered(b)){
    plugin.getServer().broadcastMessage("Sign placed, powered, outside of onSignPowered");
    onSignPowered(b);
    }
    }
    }

    And my register line:
    pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal, this);

    Now it doesn't matter what my functions mean (isSign, the others - one which I borrowed from Afforess :) ), that first sendMessage() should work, but that message only seems to show up if its not a sign/signpost, or redstone dust. It makes no sense to me. I'm guessing it just doesn't work for signs or redstone yet?
     
  10. Offline

    void420

    Signs and redstone dust can only be intercepted using onPlayerItem (at the moment?).
     
Thread Status:
Not open for further replies.

Share This Page