ProtocolLib

3M Downloads

Any examples on how to modify chunk packet

PedroMPagani opened this issue ยท 1 comments

commented

Make sure you're doing the following

  • [Y] You're using the latest build for your server version
  • [Y] This isn't an issue caused by another plugin
  • [Y] You've checked for duplicate issues
  • [Y] You didn't use /reload

Describe the question
I'm trying to change blocks on a chunk modifying the Map chunk packet, I'm not exactly sure why my current code isn't changing any block type at all.

API method(s) used`

ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(Main.instance, ListenerPriority.MONITOR, PacketType.Play.Server.MAP_CHUNK){
            @Override
            public void onPacketSending(PacketEvent event){
                if (event.getPacketType() != PacketType.Play.Server.MAP_CHUNK){
                    return;
                }
                event.setReadOnly(false);
                PacketContainer packet = event.getPacket();
                PacketContainer clone = packet.shallowClone();
                PacketPlayOutMapChunk.ChunkMap chunkMap = (PacketPlayOutMapChunk.ChunkMap) clone.getModifier().read(2);
                int i = 0;
                Bukkit.broadcastMessage(String.valueOf(chunkMap.a.length));
                IBlockData iblockdata = Block.getById(1).getBlockData();
                chunkMap.a = new byte[4096];
                while (i < 4096){
                    chunkMap.a[i++] = (byte)(Block.d.b(iblockdata) & 255);
                    chunkMap.a[i++] = (byte)(Block.d.b(iblockdata) >> 8 & 255);
                }
                clone.getModifier().write(2,chunkMap);
                event.setPacket(clone);
            }
        });

Expected behavior

At least replace some blocks on the chunks so I can start digging on how im gonna change the blocks based on their location too

Code
This is the packet map chunk from 1.8 obfs:
image

Additional context
Add any other context about the problem here.

commented

Obs: I cant use the multi block change because it currently lags 1.8 clients, trying to get it to work for all clients smoothly.