Why doesn't this block change work? o_o

Discussion in 'Plugin Development' started by DrAgonmoray, Jun 13, 2012.

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

    DrAgonmoray

    Take this code. I've trimmed all the non-related stuff out:
    Code:java
    1.  
    2. public void playerInteract(PlayerInteractEvent event) {
    3. Player player = event.getPlayer();
    4. if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
    5. player.sendBlockChange(event.getClickedBlock().getLocation(), Material.GLASS, (byte) 0);
    6. } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    7. player.sendBlockChange(event.getClickedBlock().getLocation(), Material.BEDROCK, (byte) 0);
    8. }
    9. event.setCancelled(true);
    10. }
    11. }
    12.  

    The first if block (Action.LEFT_CLICK_BLOCK section) sends the block change as expected.
    However the else-if block doesn't send the block change (or atleast it isn't rendered).
    If I left click, it changes the clicked block to glass.
    if I right click, nothing happens.

    Why is this? :confused:
     
  2. But if you change bedrock to obsidian it does work? or generally the else-if doesn't work?
     
  3. Offline

    DrAgonmoray

    In general. The material is pretty much irrelevant.
     
  4. but you're sure that you get inside the else-if (just to make sure)?
     
  5. Offline

    DrAgonmoray

    Yep. 100% positive that it gets there every time. ( I had it send the player messages and print to console)
     
  6. you remeber an chunk error, and when you where sneaking to the enge of it, and pressed right click on the side of the block, and sying the blocks to pop up, that is saying to my that the server is sending its own block chances when you right click, after the ones from you
     
  7. Offline

    DrAgonmoray

    thats what I was thinking, but why, and how do I stop it?
     
  8. Offline

    ZeusAllMighty11

    Why do you set the event to cancelled?
     
  9. because that doesn't change the block to something?
     
  10. Offline

    DrAgonmoray

    I don't want thhe normal action (block placement, block breaking, etc) to happen.
     
  11. Offline

    Wolvereness Bukkit Team Member

    Clients get a block update when right-clicking. Waiting a tick after the interact should solve this.
     
  12. Offline

    DrAgonmoray

    I was afraid I would have to do that :S
    it just seems messy, but ok
     
  13. Offline

    IanM_56

    For one thing a right-click with the hand is not sent to the server, only if you use a material it is.
     
  14. This thread is over 1 year old, absolute no need to necro bump.
     
  15. Offline

    IanM_56

    Are you saying my post means I'm a forum Necromancer? (This is a joke)
     
Thread Status:
Not open for further replies.

Share This Page