ProtocolLib

3M Downloads

Chunks are invisible when you register the map chunk packet

Anarchick opened this issue ยท 1 comments

commented

Make sure you're doing the following

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

Describe the question
Tested on paper 1.16.4 and 1.16.5 with ProtocolLib v4.6.0
If you register the packettype for map chunk and do nothing with him (= no field write or read) + no registration of the packet into a variable, then the player join, chunks load with a small delay. If the player log out then join another time all chunks are invisible or sometimes take + 10 seconds to load.

When chunks are visible for the player, there is no problem to keep editing other chunk map packet, I can display fake biomes.

Expected behavior
Chunks should be visible for the player. I don't know if the problem is my code or ProtocolLib. I can't find a solution and I'm a begginer in Java. I have no problem with other packettypes, I can manipulate them without problems :/

Code

...
if (!addToListener.isEmpty()) PacketManager.onPacketEvent(addToListener.toArray(new PacketType[0]), priority, packetEvent -> {
            SkriptPacket.pluginManager.callEvent(new BukkitPacketEvent(packetEvent, priority));
        });
    public static void onPacketEvent(PacketType[] packetTypes, ListenerPriority priority, Consumer<PacketEvent> handler) {
        ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(new PacketAdapter(SkriptPacket.getInstance(), priority, packetTypes) {
            @Override
            public void onPacketReceiving(PacketEvent event) {
                handler.accept(event);
            }

            @Override
            public void onPacketSending(PacketEvent event) {
                handler.accept(event);
            }
        }).syncStart();
    }

Additional context
If you reload or stop the server, all chunks appears = the queue of packets is send.

I use a dev test server without a lot of plugins

commented

Not up to date but same code :
https://github.com/Anarchick/skript-packet/tree/1.0/src/main/java/fr/anarchick/skriptpacket/packets

EDIT : Chunks are visible after some seconds or instant in my up to date code (branch=MAIN)
I changed :

	public static void onPacketEvent(PacketType[] packetTypes, ListenerPriority priority, Consumer<PacketEvent> handler) {
        ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(new PacketAdapter(SkriptPacket.getInstance(), priority, packetTypes) {
            @Override
            public void onPacketReceiving(PacketEvent event) {
                handler.accept(event);
            }

            @Override
            public void onPacketSending(PacketEvent event) {
                handler.accept(event);
            }
        }).syncStart();
    }

to

    public static void onPacketEvent(PacketType[] packetTypes, ListenerPriority priority, Plugin plugin) {
        for (PacketType packetType : packetTypes) {
            if (packetType.isServer()) {
                ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(new PacketAdapter(plugin, priority, packetType) {
                    @Override
                    public void onPacketSending(PacketEvent event) {
                        SkriptPacket.pluginManager.callEvent(new BukkitPacketEvent(event, priority));
                    }
                }).syncStart();
            } else {
                ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(new PacketAdapter(plugin, priority, packetType) {
                    @Override
                    public void onPacketReceiving(PacketEvent event) {
                        SkriptPacket.pluginManager.callEvent(new BukkitPacketEvent(event, priority));
                    }
                }).syncStart();
            }
        }
    }