ProtocolLib

3M Downloads

Entity interaction packet

plytki opened this issue ยท 0 comments

commented

Describe the question
I'm sending entities through packets and I want them to be able to interact with them. On 1.8 it worked, but when I switched to 1.19.3 packet listener for USE_ENTITY stopped working and it seems that player don't send USE_ENTITY packets when the entity is clientsided (it should theoretically send the packets, because how would the server then know if it's clicking the entity or not).

API method(s) used
I'm adding new packet adatper for USE_ENTITY packet.

Expected behavior
The packet event should be handled in my packet adapter. (It's not triggering currently)

Code

System.out.println("adding new packet adapter");
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(this.plugin, ListenerPriority.MONITOR, PacketType.Play.Client.USE_ENTITY) {
	@Override
	public void onPacketReceiving(PacketEvent event) {
		Player player = event.getPlayer();
		PacketContainer packet = event.getPacket();
		System.out.println("entity clicked");
		EnumWrappers.EntityUseAction action = event.getPacket().getEntityUseActions().readSafely(0);
		com.comphenix.protocol.wrappers.WrappedEnumEntityUseAction wrappedEnumEntityUseAction = event.getPacket().getEnumEntityUseActions().readSafely(0);
		if (Objects.nonNull(wrappedEnumEntityUseAction)) {
			action = wrappedEnumEntityUseAction.getAction();
		}
		Integer entityId = packet.getIntegers().getValues().get(0);
		System.out.println(action.name());
		FurnitureObject furnitureObject = MCDevLib.getPlugin().getFurnitureRegistry().getFurnitureByElement(entityId);
		if (furnitureObject == null) return;
		System.out.println(2);
		FurnitureInteractEvent newEvent = new FurnitureInteractEvent(furnitureObject, player, player.getEquipment().getItemInMainHand());
		System.out.println(3);
		new BukkitRunnable() {
			@Override
			public void run() {
				Bukkit.getPluginManager().callEvent(newEvent);
				System.out.println("new event called");
			}
		}.runTask(this.plugin);
	}

	@Override
	public void onPacketSending(PacketEvent event) {
		super.onPacketSending(event);
	}
});