Get EntityPlayer Name from PacketType.Play.Client.USE_ENTITY

Discussion in 'Spigot Plugin Development' started by _zMattyPower_, Aug 7, 2018.

  1. Hi, I created a Entity Player, and for this the only method to get that you right click or click a fake player is with packets, and i used ProtocolLib, but i don't know how to get only the fake player and not all the players that you right click. This is the code:

    Code (Java):
        public static void npcInteract() {
            ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(Main.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.USE_ENTITY) {
                public void onPacketReceiving(PacketEvent e) {
                    if (e.getPacketType() == PacketType.Play.Client.USE_ENTITY) {
                        try {
                            PacketContainer packet = e.getPacket();
                            Player p = e.getPlayer();
                            if (!interactCooldown.contains(p)) {
                                Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable() {
                                    public void run() {
                                }, 40L);
                        } catch (Exception ex) {

    And i have another problem, sometimes I get this error, I think is ProtocolLib, but i'm not sure.

    Code (Text):
    [16:16:34 FATAL]: Handling task
    java.util.concurrent.ExecutionException: java.lang.NullPointerException
            at Source) ~[?:1.8.0_162]
            at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_162]
            at net.minecraft.server.v1_8_R1.MinecraftServer.z( [spigot-1.8.jar:git-Spigot-550ebace-7019900e]
            at net.minecraft.server.v1_8_R1.DedicatedServer.z( [spigot-1.8.jar:git-Spigot-550ebace-7019900e]
            at net.minecraft.server.v1_8_R1.MinecraftServer.y( [spigot-1.8.jar:git-Spigot-550ebace-7019900e]
            at [spigot-1.8.jar:git-Spigot-550ebace-7019900e]
            at Source) [?:1.8.0_162]
    Caused by: java.lang.NullPointerException
            at net.minecraft.server.v1_8_R1.WorldServer.sendParticles( ~[spigot-1.8.jar:git-Spigot-550ebace-7019900e]
            at net.minecraft.server.v1_8_R1.EntityLiving.a( ~[spigot-1.8.jar:git-Spigot-550ebace-7019900e]
            at net.minecraft.server.v1_8_R1.EntityPlayer.a( ~[spigot-1.8.jar:git-Spigot-550ebace-7019900e]
            at net.minecraft.server.v1_8_R1.PlayerConnection.a( ~[spigot-1.8.jar:git-Spigot-550ebace-7019900e]
            at net.minecraft.server.v1_8_R1.PacketPlayInFlying.a(SourceFile:126) ~[spigot-1.8.jar:git-Spigot-550ebace-7019900e]
            at net.minecraft.server.v1_8_R1.PacketPlayInPositionLook.a(SourceFile:18) ~[spigot-1.8.jar:git-Spigot-550ebace-7019900e]
            at ~[spigot-1.8.jar:git-Spigot-550ebace-7019900e]
            at java.util.concurrent.Executors$ Source) ~[?:1.8.0_162]
            at Source) ~[?:1.8.0_162]
            at net.minecraft.server.v1_8_R1.MinecraftServer.z( ~[spigot-1.8.jar:git-Spigot-550ebace-7019900e]
            ... 4 more
  2. 1. Save the entityID of the fake player
    2. When receiving the packet check if the entityID is equal to the saved one
  3. How I can get the entityID of the fake player? I'm new to packets/ProtocolLib
  4. Ok, I got this to work, but every time a player joins the id will change, and It will not work anymore. (only for the new player)
  5. The id is a temporary value that depends on the current instance and is incremented by one for each new entity (Players included). You would need to get the UUID and save that.
  6. How i can get the fake player uuid from packets?
  7. ↑.
    You would need some way to save them in some way for getting them back later. If they are not created by your plugin, maybe there is an API available for that plugin?