Best way for sending blockchange?

Discussion in 'Spigot Plugin Development' started by HydroTekZ, Jun 7, 2015.

  1. Let's say I want all water blocks to be seen like lava for some players (just an example, I won't do that). What is the best way of doing this, which event should I use? An example would be very nice.
     
  2. So essentially you want a player to see something that is not there?
     
  3. Exactly.
     
  4. @HydroTekZ basically, you would want something like Orebfuscator, perhaps look at their source code. You could override the chunk packets (but they are compressed, so it should be handled asynchronously) and any block change packets the server sends.
     
    • Like Like x 1
  5. The code is pretty big and advanced, I didn't find anything helpful there.

    I know of that function, but when do you recommend I do it? If I do it on PlayerMoveEvent, maybe that could affect the performance in a bad way.

    Couldn't it be easy as this? D:
    Code (Java):
        @EventHandler
        public void onChunkSend(ChunkSendEvent e){
            Player player = e.getPlayer();
            if (player.isOp()){
                for (Block b : e.getBlocks()){
                    if (b.getType() == Material.WATER){
                        e.changeBlock(b, Material.LAVA);
                    }
                }
            }
        }
     
  6. Blocks are sent to the client in chunks. Find the packet(s) that send the chunk data to the client and override it doing your own thing. May be easier with ProtocolLib.

    Using the player.sendBlockChange() method is definitely not something you want to do on large scale. I have a plugin that does this for 4-6 blocks to be changed at a time, and it actually lags the client for a split second.
     
  7. If you just want to replace specific blocks, you might find the AlternateBlocks API useful: http://www.spigotmc.org/resources/4986/
     
  8. Doesnt this work?
    Looks like the best way.
     
  9. No, it does not work. I don't think that event even exist.