ProtoclLib & Packet

Discussion in 'Plugin Development' started by WiseMango13452, Aug 20, 2022.

Thread Status:
Not open for further replies.
  1. Offline

    WiseMango13452

    Hey guys, I've been trying to make an item in my plugin that scans entities around the user and applies the glow effect to them (entities). However, I only want to let the user see the glow effect so I started learning packets.
    Code:
        @EventHandler
        public void playerInteract(PlayerInteractEvent event) {
            if(event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
                Player player = event.getPlayer();
                if(event.getMaterial() == Material.FIRE_CORAL) {
                    if(!player.hasCooldown(Material.FIRE_CORAL)) {
                        event.setCancelled(true);
                        player.setCooldown(Material.FIRE_CORAL, 20 * 20);
                        for(Entity entity : player.getNearbyEntities(10, 10, 10)) {
                            ProtocolManager manager = ProtocolLibrary.getProtocolManager();
                            player.sendMessage(manager + " manager");
                            PacketContainer packet = manager.createPacket(PacketType.Play.Server.ENTITY_METADATA);
                            player.sendMessage(packet + " packet");
                            WrappedDataWatcher watcher = new WrappedDataWatcher();
                            packet.getIntegers().write(0, entity.getEntityId()); //Set packet's entity id
                            packet.getWatchableCollectionModifier().write(1, watcher.getWatchableObjects());
                            WrappedDataWatcher.Registry.get(byte.class);
                            watcher.setObject(
                                    new WrappedDataWatcher.WrappedDataWatcherObject(1, WrappedDataWatcher.Registry.get(byte.class)),
                                    0x40
                            );
                            packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());
                            try {
                                manager.sendServerPacket(player, packet);
                            } catch (InvocationTargetException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
            }
        }
    The problem is with the packet creation itself. As you can see i added #sendMessage to both the PacketContainer and ProtocolManager. I dont know if it's supposed to do this, but ProtocolManager sends "null" and PacketContainer doesnt send at all which leads me to assume theres a problem with the packet creation that stops the lines after from running. Ive checked other forums so please dont send any links to those. Ive tried to google the problem and still nothing. There arent any errors in the console. Any and all help will be appreciated :)
     
Thread Status:
Not open for further replies.

Share This Page