What exactly does sendBlockChange() do?

Discussion in 'Plugin Development' started by killgoblen, Jun 26, 2011.

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

    killgoblen

    Pretty straightforward question. Can someone please explain to me in a way that an idiot (me! =D) could understand? Thanks!
     
  2. Offline

    Shamebot

    It sends a block change to the client which didn't happen, in other words fakes a block change.
     
  3. Offline

    killgoblen

    Then should the client see the block change but no one else will?
     
  4. Offline

    Shamebot

  5. Offline

    MCManager

    That is nice for invisible jails and such :p
     
  6. Offline

    killgoblen

    I tried doing an onPlayerInteract() and an if statement to check if the event was a Block Right-click, then

    event.getPlayer().sendBlockChange(event.getClickedBlock().getLocation, 7, (byte) 0)

    But when I right-clicked a block, nothing happened. Am I just incompetent? :p
     
  7. Offline

    zonedabone

    Did you register the event?
     
  8. Offline

    killgoblen

    Yes, I registered onPlayerInteract()
     
  9. Offline

    zonedabone

    No idea then. Could we check out the source code?
     
  10. Offline

    killgoblen

    Yup, here ya go:
    Code:
    public void onPlayerInteract(PlayerInteractEvent event){
        if(event.getType() == RIGHT_CLICK_BLOCK){
            event.getPlayer().sendBlockChange(event.getClickedBlock().getLocation(), 7, (byte) 0);
        }
    }
    That's it.
     
  11. Offline

    zeff

    As far as I can see, there is no Event.Type of RIGHT_CLICK_BLOCK. I use the same event for a different cause and I determine the players action like this:
    Code:
    @Override
    public void onPlayerInteract(PlayerInteractEvent event){
      if( event.getAction() == Action.RIGHT_CLICK_BLOCK ){
        doSomething();
      }
    }
    
    
    event.getType() will probably return ENTITY_INTERACT.
     
  12. Offline

    zonedabone

    That's it! zeff has definitely got the answer there. The type will return Event.Type.PLAYER_INTERACT.
     
  13. Offline

    killgoblen

    Sorry, I meant to type Action.RIGHT_CLICK_BLOCK after event.getType(). I typed that outside of an IDE, so I messed that one up.

    Anyway, it still doesn't work. Should I be sending it a Block instead of a Location?
     
  14. Offline

    nisovin

    Can you post your entire source? Are you sure you registered your event with the PluginManager?
     
  15. It's because you are using event.getType(), which does return an Event.Type-constant (PLAYER_INTERACT) and NOT the action of the PlayerInteract-event. Test Action.RIGHT_CLICK_BLOCK against event.getAction().
     
  16. Offline

    killgoblen

    That is what I did. I messed up when I typed that code, so here it is again:

    Code:
        public void onPlayerInteract(PlayerInteractEvent event){
            if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
                event.getPlayer().sendBlockChange(event.getClickedBlock().getLocation(), 7, (byte) 0);
            }
        }
    And inside the main class:
    Code:
        private final NPCTestPL pl = new NPCTestPL(this);
        public void onEnable(){
            PluginManager pm = this.getServer().getPluginManager();
            pm.registerEvent(Event.Type.PLAYER_INTERACT, pl, Event.Priority.Normal, this);
        }
    It's called NPCTest because that was the original point of that project for about 5 minutes, then I decided to try this. :p
     
  17. Offline

    codename_B

    If you want to see this in action check out the plugin BananaCube
     
Thread Status:
Not open for further replies.

Share This Page