ProtocolLib

3M Downloads

FieldAccessException: Error when writting to array.

Binjabin opened this issue ยท 4 comments

commented

I get this error when I try to write to the entity id.

[11:46:22 INFO]: [Skript] method StructureModifier#write called with (0 (Long), [10231] (int[])) threw a FieldAccessException: Field index 0 is out of bounds for length 0

Expect this to write to the entity ID array of the packet.

The code is in skript, which if you don't understand I get it. It's quite similar tp java.


effect destroy clientside npc with id %num% for %players%:
    parse:
        set {_deletePlayer} to new play_server_player_info_remove packet
        set {_deleteEntity} to new play_server_entity_destroy packet
        continue
    trigger:
        set {_uuid} to {npc.uuidfromid.%expression-1%}
        clear {npc.uuidfromid.%expression-1%}
        {_deletePlayer}.getUUIDLists().write(0, Collections.singletonList({_uuid}))

        set {_int} to "%expression-1%" parsed as int
        set {_array} to new int[1]
        set {_array}[0] to {_int}
        broadcast "%{_array}%"
        {_deleteEntity}.setEntityIds({_array})

        send expression-3 packet {_deletePlayer}
        send expression-3 packet {_deleteEntity}
commented

This actually gives me a slightly different error.
[Skript] No matching non-static method: PacketContainer#setEntityIds called with ([10231] (int[]))

The one that gives me the old error is the same code but with the line {_deleteEntity}.getIntegerArrays.write(0, {_array}) instead.

commented

You need getIntLists() in recent minecraft versions.

In Java it would be packet.getIntLists().write(0, ...)

commented

You need getIntLists() in recent minecraft versions.

In Java it would be packet.getIntLists().write(0, ...)

I am now getting a different error, but this definitely helped thank you.

set {_int} to "%expression-1%" parsed as int
{_deleteEntity}.getIntLists().write(0, Collections.singletonList({_int}))

[Skript] method StructureModifier#write called with (0 (Long), [10231] (SingletonList)) threw a ClassCastException: class java.lang.Long cannot be cast to class java.lang.Integer (java.lang.Long and java.lang.Integer are in module java.base of loader 'bootstrap')

commented

I managed to solve this error by changing to the type intlist. It doesn't actually work yet thought. No errors but it isn't deleting any entities.

Is there perhaps a more updated packet wrapper to use, since this one is apparently outdated?