1.16.5 How do i hide the placed block before event cancelled

Discussion in 'Spigot Plugin Development' started by KaboomRoads, Jul 2, 2021.

  1. On Hypixel the block placed is not visible but I can see the head placed before it gets removed,
    how did they do that
     
  2. Listen to BlockPlaceEvent and cancel it
     
  3. This is the first half of the video, he wants to know hypixel did it do the block doesn’t show (second half video)
     
  4. Ohhh!
    Use a Packet listener then - find the Packet that's for placing blocks and use it instead.
    On the other hand, if you want to avoid Packet usage you can listen to PlayerInteractEvent, make the proper checks that it's block placing, then disable it before it even gets to the placing.
     
    • Like Like x 1
  5. i tried the packet listener with protocollib and it made a ghost block each time i placed it and the player interact event did the same as the block place event
    edit: here is my packet listener code
    Code (Java):
    protocolManager.addPacketListener
            (
                      new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.BLOCK_CHANGE)
                      {
                        @Override
                        public void onPacketSending(PacketEvent event) {
                            if (event.getPacketType() == PacketType.Play.Server.BLOCK_CHANGE) {
                                if(event.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.PLAYER_HEAD))
                                    if(event.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName().contains("null"))
                                        if(event.getPlayer().getInventory().getItemInMainHand().getItemMeta().hasLore())
                                            event.setCancelled(true);
                            }
                        }
                    }
            );
    edit 2:
    i changed my code to this and it also doesent work and if i right click the ground with something that cannot be placed it throws an error
    Code (Java):

    protocolManager.addPacketListener
            (
                      new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Client.BLOCK_PLACE)
                      {
                        @Override
                        public void onPacketSending(PacketEvent event) {
                            if (event.getPacketType() == PacketType.Play.Client.BLOCK_PLACE) {
                                if(event.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.PLAYER_HEAD))
                                    if(event.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName().contains("null"))
                                        if(event.getPlayer().getInventory().getItemInMainHand().getItemMeta().hasLore())
                                            event.setCancelled(true);
                            }
                        }
                    }
            );
     
    edit 3:
    the error is IllegalStateException
     
    #5 KaboomRoads, Jul 2, 2021
    Last edited: Jul 2, 2021
  6. Make sure you make the priority of PlayerInteractEvent LOWEST.
    If it still doesn't work, both with PlayerInteractEvent and with Packets you can try setting the block to it's previous value (so it doesn't create ghosts).
     
  7. im not exactly sure how to set the block to its prvious value, but wouldnt that just do the same thing as cancelling BlockPlaceEvent?
    edit again:
    as in showing the block client side before the server responds with the block change
     
  8. So do it with BukkitRunnable so it runs right after.
    On the other hand, you can disable all block placing with GameRule, then place only the blocks you do want by listening to canceled PlayerInteractEvents.
     
  9. yes but wouldnt there still be at least a 1 tick delay?
     
  10. I'm pretty sure Hypixel does the 2nd thing I wrote:
     
  11. what gamerule? i cant find any block place gamerule ingame or in spigot
     
  12. My bad, you need to use your server's server.properties and set the spawn protection value to the maximum value
     
  13. all that does is delete every block i place and the blocks are still visible in the same way as cancelling the event
     
  14. Then you did something wrong - serer.properties is called before even creating the event so if it's disabled there's no way the block will be placed.
    Make sure that you disabled the plugin's listeners or it may cause issues (which is probably why you're getting ghost blocks).
     
  15. the thing is it deletes the block from my hand and also it shows a block for a tick and also i was using stone which has no listeners listening for it
     
  16. Weird... then try Adventure mode.
    If that doesn't work then I have no idea, sry.
     
  17. im sure hypixel does not use adventure mode you can see the block outlines
     
    • Like Like x 1
    • Agree Agree x 1