ProtocolLib

3M Downloads

FieldAccessException - ProtocolLib 5.0.0 - spigot-api 1.20.1-R0.1-SNAPSHOT

SadShrimpyy opened this issue ยท 6 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
I'm trying to send a packet to update the player's location at the execution of a command.
The onCommand method Overrided works fine, but the packet creation or sending din't works... The player remain in his exact location...

API method(s) used
getProtocolManager(), createPacket(), write() and sendServerPacket().

Expected behavior
Not the error...

Code
If applicable, add relevant code from your project

Additional context

ProtocolManager manager = ProtocolLibrary.getProtocolManager();
Player p = event.getPlayer();
Location l =  p.getLocation();

container.getIntegers().write(0, p.getEntityId());
container.getShorts().write(0, (short) 5);
container.getShorts().write(1, (short) 5);
container.getShorts().write(2, (short) 5);
container.getBooleans().write(0, !p.isFlying());

manager.sendServerPacket(p, updatedPacket);

And then, nothings happens...

commented

Please share the code calling createPacket().
Also, please share the complete stack trace of the error you get in the console.

And you should be the latest dev build of ProtocolLib (https://ci.dmulloy2.net/job/ProtocolLib/661/) for MC 1.20.1. Version 5.0.0 is not compatible with MC 1.20.1!

commented

Sure!
This is the compile stack trace:

[14:03:15] [Server thread/INFO]: [ProtocolLib] Loading ProtocolLib v5.0.0
[14:03:15] [Server thread/WARN]: [ProtocolLib] Version (MC: 1.20.1) has not yet been tested! Proceed with caution.
[14:03:15] [Server thread/INFO]: [ProtocolLib] Enabling ProtocolLib v5.0.0

This is the complete method:

@Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        ProtocolManager manager = ProtocolLibrary.getProtocolManager();
        Player p = Bukkit.getPlayer(sender.getName());

        PacketContainer container = manager.createPacket(PacketType.Play.Server.REL_ENTITY_MOVE);

        // updatedPacket.getId() return (43 == 0x2B) (Packet ID on the wiki)
        //  -> REL_ENTITY_MOVE is Update_Entity_Position on the wiki (cientbound)

        container.getIntegers().write(0, p.getEntityId());
        container.getShorts().write(0, (short) 5);
        container.getShorts().write(1, (short) 5);
        container.getShorts().write(2, (short) 5);
        container.getBooleans().write(0, !p.isFlying());

        manager.sendServerPacket(p, container);

        return true;
    }

At the execution of that method, nothings show up, and the player executor stay in the same location.
And oh... The latest version is compativile with mc 1.20.1?

commented

Yes, you need the ProtocolLib version I linked for 1.20.1 support.

So you are not getting a "FieldAccessException"? I was curious because you mentioned it in the title.

I actually do not think sending REL_ENTITY_MOVE has an affect on the player. It is used to update the position of another player relatively. If you want to move the player you are sending the packet to to another location, use ENTITY_TELPORT.
This will take absolute coordinates though. Here is an example on how to use this packet in 1.20.1: https://github.com/lukalt/PacketWrapper/blob/master/src/main/java/com/comphenix/packetwrapper/wrappers/play/clientbound/WrapperPlayServerEntityTeleport.java

commented

Ok, I tried to import the version you linked me, and rewrite the method to send the packet...
Here is the method with the PacketType.ENTITY_TELEPORT:

@Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        ProtocolManager manager = sadLibrary.generics().getProtocolManager();
        Player p = Bukkit.getPlayer(sender.getName());
        Location l = p.getLocation();

        PacketContainer container = manager.createPacket(PacketType.Play.Server.ENTITY_TELEPORT);

        // container.getId() return (104 == 0x68) (Packet ID on the wiki)
        //  -> ENTITY_TELEPORT is Teleport_Entity on the wiki (cientbound)

        container.getIntegers().write(0, p.getEntityId());
        container.getDoubles().write(0, l.getX() + 5D);
        container.getDoubles().write(1, l.getY() + 5D);
        container.getDoubles().write(2, l.getZ() + 5D);
        container.getBytes().write(0, (byte) (l.getPitch() * 256.0F / 360.0F));
        container.getBytes().write(1, (byte) (l.getYaw() * 256.0F / 360.0F));
        container.getBooleans().write(0, !p.isFlying());

        manager.sendServerPacket(p, container);

        return true;
    }

By sending the command, running the method, nothing works... Also, in the console no error show up.

I attach also the /protocol dump

ProtocolLib Dump
Timestamp: 07/23/23 14:48:14

ProtocolLib Version: ProtocolLib v5.1.0-SNAPSHOT-661
Bukkit Version: 1.20.1-R0.1-SNAPSHOT
Server Version: 3830-Spigot-0ca4eb6-36b1076 (MC: 1.20.1)
Java Version: 17.0.7

ProtocolLib: com.comphenix.protocol.ProtocolLib@23b5b709[
  statistics=com.comphenix.protocol.metrics.Statistics@399961a
  packetTask=com.comphenix.protocol.scheduler.DefaultTask@592e5671
  tickCounter=202
  configExpectedMod=1
  updater=com.comphenix.protocol.updater.SpigotUpdater@1fe94651
  redirectHandler=com.comphenix.protocol.ProtocolLib$2@11eaa75a
  scheduler=com.comphenix.protocol.scheduler.DefaultScheduler@5e8cda3b
  commandProtocol=com.comphenix.protocol.CommandProtocol@753a8245
  commandPacket=com.comphenix.protocol.CommandPacket@2034897d
  commandFilter=com.comphenix.protocol.CommandFilter@64202a56
  packetLogging=com.comphenix.protocol.PacketLogging@5cc569eb
  skipDisable=false
  isEnabled=true
  loader=org.bukkit.plugin.java.JavaPluginLoader@7dcce09c
  server=CraftServer{serverName=CraftBukkit,serverVersion=3830-Spigot-0ca4eb6-36b1076,minecraftVersion=1.20.1}
  file=plugins\ProtocolLib.jar
  description=org.bukkit.plugin.PluginDescriptionFile@1ca006d3
  dataFolder=plugins\ProtocolLib
  classLoader=org.bukkit.plugin.java.PluginClassLoader@6c9f7ce5
  naggable=true
  newConfig=YamlConfiguration[path='', root='YamlConfiguration']
  configFile=plugins\ProtocolLib\config.yml
  logger=org.bukkit.plugin.PluginLogger@718f7b6a
]
Manager: com.comphenix.protocol.injector.PacketFilterManager@3777f25b[
  plugin=ProtocolLib v5.1.0-SNAPSHOT-661
  server=CraftServer{serverName=CraftBukkit,serverVersion=3830-Spigot-0ca4eb6-36b1076,minecraftVersion=1.20.1}
  reporter=com.comphenix.protocol.ProtocolLib$1@2bfdfcf8
  minecraftVersion=(MC: 1.20.1)
  asyncFilterManager=com.comphenix.protocol.async.AsyncFilterManager@2dd2064c
  pluginVerifier=com.comphenix.protocol.injector.PluginVerifier@278c6cb7
  inboundListeners=com.comphenix.protocol.injector.SortedPacketListenerList@2fe1b737
  outboundListeners=com.comphenix.protocol.injector.SortedPacketListenerList@6b3f940f
  registeredListeners=[]
  packetInjector=com.comphenix.protocol.injector.netty.manager.NetworkManagerPacketInjector@56e20f42
  playerInjectionHandler=com.comphenix.protocol.injector.netty.manager.NetworkManagerPlayerInjector@12cf28fd
  networkManagerInjector=com.comphenix.protocol.injector.netty.manager.NetworkManagerInjector@30b57d9c
  debug=false
  closed=false
  injected=true
]

No listeners

commented

Also, I have tried the same method in 1.19.4 and it didn't work...
Please help...

commented

I also have no clue why it is not working then. But I do not think it is a problem of ProtocolLib.
A assume that you are somehow sending the wrong packet. Maybe check which packets the Minecraft Server sends when it teleports a player