ProtocolLib

3M Downloads

1.21 - Error with PacketConstructor.withPacket()

TheCalypso opened this issue ยท 1 comments

commented
  • This issue is not solved in a development build

Describe the bug
This is my code

public static PacketContainer createPacketSEL(int entityID, Entity entity) {
		PacketType packetType = PacketType.Play.Server.SPAWN_ENTITY;
		var nesPacket = ProtocolLibrary.getProtocolManager()
				.createPacketConstructor(packetType, entity).createPacket(entity);

        nesPacket.getIntegers().write(0, entityID);

        return nesPacket;
    }

Version Info
https://pastebin.com/y1vWWC4F

Additional context
Error in console :

[11:11:53 WARN]: [GaspeziaNPCs] Plugin GaspeziaNPCs v1.10.0 generated an exception while executing task 392
java.lang.IllegalArgumentException: No suitable constructor could be found.
        at ProtocolLib.jar/com.comphenix.protocol.injector.PacketConstructor.withPacket(PacketConstructor.java:204) ~[ProtocolLib.jar:?]
        at ProtocolLib.jar/com.comphenix.protocol.injector.PacketFilterManager.createPacketConstructor(PacketFilterManager.java:372) ~[ProtocolLib.jar:?]
        at GNPCs-1.10.0.jar/fr.hotmail.regisgaia.gnpcs.packets.NPCsPC.createPacketSEL(NPCsPC.java:163) ~[GNPCs-1.10.0.jar:?]
        at GNPCs-1.10.0.jar/fr.hotmail.regisgaia.gnpcs.packets.SenderPacketsEntity.sendSpawnPacketsAsync(SenderPacketsEntity.java:21) ~[GNPCs-1.10.0.jar:?]
        at GNPCs-1.10.0.jar/fr.hotmail.regisgaia.gnpcs.packets.SenderPacketsEntity.lambda$sendSpawnPackets$0(SenderPacketsEntity.java:17) ~[GNPCs-1.10.0.jar:?]
        at org.bukkit.craftbukkit.scheduler.CraftTask.run(CraftTask.java:86) ~[paper-1.21.jar:1.21-127-4e6a2a1]
        at org.bukkit.craftbukkit.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:57) ~[paper-1.21.jar:1.21-127-4e6a2a1]
        at com.destroystokyo.paper.ServerSchedulerReportingWrapper.run(ServerSchedulerReportingWrapper.java:22) ~[paper-1.21.jar:?]
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) ~[?:?]
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) ~[?:?]
        at java.base/java.lang.Thread.run(Thread.java:1583) ~[?:?]
commented

Update :
My last code worked in 1.20.6, I tested this and it is work in 1.21.

public static PacketContainer createPacketSEL(int entityID, Entity entity) {
		PacketContainer nesPacket = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
		nesPacket.getModifier().writeDefaults();
		var spawnPacketModifier = nesPacket.getModifier();
		nesPacket.getEntityTypeModifier().write(0, entity.getType());
		spawnPacketModifier.write(0, entityID);
		spawnPacketModifier.write(3, entity.getLocation().getX());
		spawnPacketModifier.write(4, entity.getLocation().getY());
		spawnPacketModifier.write(5, entity.getLocation().getZ());
		spawnPacketModifier.write(6, getCompressedAngle(entity.getLocation().getYaw()));
		spawnPacketModifier.write(7, getCompressedAngle(entity.getLocation().getPitch()));
		return nesPacket;
	}

It is normal that last code (ProtocolLibrary.getProtocolManager().createPacketConstructor(packetType, entity).createPacket(entity)) don't work in 1.21 ?

Thanks a lot !