1.15.2 sendBlockChange doesn't seem to work? [SOLVED]

Discussion in 'Spigot Plugin Development' started by Strainj1, Mar 24, 2020.

Thread Status:
Not open for further replies.
  1. Hi guys - I'm having a bit of an issue with getting sendBlockChange to work. Everything I've read tells me that it will temporarily change the block appearance (client side appearance only) - I've also seen other plugins do this effect fine, so i know it's possible.

    it's part of a larger codebase, but I've simplified the code for this thread below. The listener is most certainly working because my sendMessage fires totally fine.

    If anyone has any insight it would be wonderful - most of the help on google seems refer to the deprecated method.

    Code (Text):
        //LISTENERS
        @EventHandler(priority=EventPriority.HIGH)
        public void onPlayerRightclick(PlayerInteractEvent event){
            if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)&&event.getHand().equals(EquipmentSlot.HAND)){
                Location clicked_location = event.getClickedBlock().getLocation();
                BlockData block_data_test = Material.DIAMOND_BLOCK.createBlockData();
                event.getPlayer().sendBlockChange(clicked_location,block_data_test);
                event.getPlayer().sendMessage("this line fires fine, but nothing about the block I clicked changes");
             }
         }
     
    • Like Like x 1
  2. I managed to figure it out myself - I needed to make it a delayed task - I have no idea why it required that, but at least I can proceed.

    For future people with the issue - this is what i did.

    Code (Text):

        @EventHandler(priority=EventPriority.HIGH)
        public void onPlayerRightclick(PlayerInteractEvent event){
            if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)&&event.getHand().equals(EquipmentSlot.HAND)){
               
                       
                Location clicked_location = event.getClickedBlock().getLocation();
                Block clicked_block = event.getClickedBlock();
                BlockData block_data_test = Material.DIAMOND_BLOCK.createBlockData();
                Bukkit.getServer().getScheduler().runTaskLater(plugin, () -> {
                    event.getPlayer().sendBlockChange(clicked_location,block_data_test);
                }, 10);
            }
        }
     
    That takes half a tick to change the block, so i'm going to tweak it.

    If anyone feels like explaining to me how I was meant to know that this function required a delay, it would be appreciated :)
     
  3. I believe this was due to the server sending an update for the right-click too, overriding yours since the event is called before the actual interaction happens (Which is why you can cancel it). Also, you only need to delay by 1L, right now you delay for 10L which is half a second, not half a tick. (You can't delay by less than a tick, at least not in the context of Minecraft)
     
    • Informative Informative x 1
  4. Oh of course, yes I meant one second :)

    That makes sense, I appreciate the explanation :)
     
Thread Status:
Not open for further replies.