Solved Fake Player throwing error

Discussion in 'Spigot Plugin Development' started by Simagdo, Apr 23, 2017.

  1. Hey there,
    i want to create a Fake Player but iam getting some errors. First, i get an error, when i compile the resource.
    Here is my code:
    Code (Text):

    public class NPC {
        private int entityID;
        private Location location;
        private GameProfile gameprofile;

        public NPC(String name, Location location) {
            entityID = (int) Math.ceil(Math.random() * 1000) + 2000;
            gameprofile = new GameProfile(UUID.randomUUID(), name);
            changeSkin();
            this.location = location.clone();
        }

        public void changeSkin() {
            String value = "eyJ0aW1lc3RhbXAiOjE0NTIwODMxODcyOTUsInByb2ZpbGVJZCI6IjFiZGMzZGE1YmFiMDQyZGRiYWRjMDQ0N2E4NTE0NjA3IiwicHJvZmlsZU5hbWUiOiJLeW94ZSIsInNpZ25hdHVyZVJlcXVpcmVkIjp0cnVlLCJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvY2YxODkzODFhZDU3ODRlNDAyNDkwN2Q4NmUxNDYyOTQzNzY1N2FhMjFkNmJlMTM0ODVjZTc5YWQ3YjdiYWMxIn19fQ==";
            String signature = "vyN2l0rnhtkiuxDK3Tirk3c+rtcwjbGTQBSFzdWggH7y6rMBh0DNDlIRabh3inpM6tzlsP05Jx3JNoC6PaXOJCsMNQKZlkedRQ1YQIZsMKu1yBROmqRLmCZZZXnh3/13Zf6zyBOucUkolTBRoXY8TnVMAS0K1ZX7g95/srVh5bgWz3Yywvc5Mr25V7deDH5LzAB/B0Xl9TdYA674M1awXg3vlWwlUgsyPIJmvWwbxjDrFi00ImT60MI0FT2TTY1PVIwDwu8GFoAqfwiPd2gsaqSFaJhqkYHFCxJRMsN54Q+E+Cs1o1UscASp9r5qVtQeaYnj6rymAXT3qzxNoOSR2OosgucunEcijMl+wWkWigWA3Gxx5dYpj+ab1puHabmGCaEzcsMPd2fn6MQhg1qxni4xoJKeW4kyjT/SLI8j5KwbuDi+rsZmaVfxZ4udoAgSOgfsoT9XCSfFaYyJk7g0uXcqWvL6AAhrVQErI02hVWIAnVvmVbTuEUxDm0MVZ4BNjFth/BgbeFExZySYhqQPIdoQplMvCloIj7htfbj87WRDbnen6Va87VCcm521PmAStcbcSSQgKRsExxd++c3lPfEFjJ11OlwRrVzUT+RPMxrzhoHxDX123CGPE9QJ4rfmRxuZtpDxxK+bL/5IkZg8AkALEhaG/Iy5eWP1J3l37RU=";
            gameprofile.getProperties().put("textures", new Property("textures", value, signature));
        }

        public void changeSkin(String value, String signature) {
            gameprofile.getProperties().put("textures", new Property("textures", value, signature));
        }

        public void spawn() {

            PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn();
            Reflections.setValue(packet, "a", entityID);
            Reflections.setValue(packet, "b", gameprofile.getId());
            Reflections.setValue(packet, "c", getFixLocation(location.getX()));
            Reflections.setValue(packet, "d", getFixLocation(location.getY()));
            Reflections.setValue(packet, "e", getFixLocation(location.getZ()));
            Reflections.setValue(packet, "f", getFixRotation(location.getYaw()));
            Reflections.setValue(packet, "g", getFixRotation(location.getPitch()));
            Reflections.setValue(packet, "f", 2.5);
            Reflections.setValue(packet, "g", -90);
            Reflections.setValue(packet, "h", 0);
            DataWatcher w = new DataWatcher(null);
            w.a();
            w.a();
            Reflections.setValue(packet, "i", w);
            //addToTablist();
            Reflections.sendPacket(packet);
        }

        public void destroy() {
            PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(new int[]{entityID});
            //rmvFromTablist();
            Reflections.sendPacket(packet);
        }

        /*public void addToTablist() {
            PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo();
            PacketPlayOutPlayerInfo.PlayerInfoData data = packet.new PlayerInfoData(gameprofile, 1, EnumGamemode.NOT_SET, CraftChatMessage.fromString(gameprofile.getName())[0]);
            @SuppressWarnings("unchecked") List<PacketPlayOutPlayerInfo.PlayerInfoData> players = (List<PacketPlayOutPlayerInfo.PlayerInfoData>) Reflections.getValue(packet, "b");
            players.add(data);
            Reflections.setValue(packet, "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER);
            Reflections.setValue(packet, "b", players);
            Reflections.sendPacket(packet);
        }

        public void rmvFromTablist() {
            PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo();
            PacketPlayOutPlayerInfo.PlayerInfoData data = packet.new PlayerInfoData(gameprofile, 1, EnumGamemode.NOT_SET, CraftChatMessage.fromString(gameprofile.getName())[0]);
            @SuppressWarnings("unchecked") List<PacketPlayOutPlayerInfo.PlayerInfoData> players = (List<PacketPlayOutPlayerInfo.PlayerInfoData>) Reflections.getValue(packet, "b");
            players.add(data);
            Reflections.setValue(packet, "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER);
            Reflections.setValue(packet, "b", players);
            Reflections.sendPacket(packet);
        }*/

        public int getFixLocation(double pos) {
            return MathHelper.floor(pos * 32.0D);
        }

        public byte getFixRotation(float yawpitch) {
            return (byte) ((int) (yawpitch * 256.0F / 360.0F));
        }
    }
     
    Reflections class:
    Code (Text):

    public class Reflections {
        public static void setValue(Object obj, String name, Object value) {
            try {
                Field field = obj.getClass().getDeclaredField(name);
                field.setAccessible(true);
                field.set(obj, value);
            } catch (Exception e) {
            }
        }

        public static Object getValue(Object obj, String name) {
            try {
                Field field = obj.getClass().getDeclaredField(name);
                field.setAccessible(true);
                return field.get(obj);
            } catch (Exception e) {
            }
            return null;
        }

        public static void sendPacket(Packet<?> packet, Player player) {
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
        }

        public static void sendPacket(Packet<?> packet) {
            for (Player player : Bukkit.getOnlinePlayers()) sendPacket(packet, player);
        }
    }
     
    Error:
    Code (Text):

    Error:(63, 32) java: cannot access net.minecraft.server.v1_11_R1.PacketPlayOutPlayerInfo.PlayerInfoData
      bad class file: C:\Users\Simon\Desktop\Spiele\Minecraft\Libraries\spigot-1.11.2.jar(net/minecraft/server/v1_11_R1/PacketPlayOutPlayerInfo$PlayerInfoData.class)
        bad RuntimeInvisibleParameterAnnotations attribute: PlayerInfoData(com.mojang.authlib.GameProfile,int,net.minecraft.server.v1_11_R1.EnumGamemode,net.minecraft.server.v1_11_R1.IChatBaseComponent)
        Please remove or make sure it appears in the correct subdirectory of the classpath.
     
    The second i get is, when i spawn the fake Player:
    upload_2017-4-23_20-2-47.png
     
  2. Pretty sure the kick is because your client can't display the player, but can't help you with why. Sorry 'bout that, good luck! :p
     
  3. Are you using Intellij to compile? If so, go to Settings > Build, Execution, Deployment > Compiler > Java Compiler then change Use compiler from Javac to Eclipse. This is a bug not with your code, but with the Javac compiler, seemingly only for that variable.

    EDIT: I am pretty sure you need to clear the gameprofile's properties list before you add to it, that error happens when the payload is too long usually.
     
    • Informative Informative x 2
    • Agree Agree x 1
  4. y do u code a fake players plugin?
     
  5. Why are you postfarming? Your question is not relevant to the Topic..
     
  6. First of all, thank you for the result solving the error while compiling. Currently i am trying to spawn the NPC. I tryed to clear the Properties, but it still throws the error. This is my current constructor, where i tryed to clear the values.
    Code (Text):

    public NPC(String name, Location location) {
        entityID = (int) Math.ceil(Math.random() * 1000) + 2000;
        gameprofile = new GameProfile(UUID.randomUUID(), name);
        gameprofile.getProperties().keys().clear();
        gameprofile.getProperties().entries().clear();
        gameprofile.getProperties().keySet().clear();
        changeSkin();
        this.location = location.clone();
    }
     
     
  7. They're trying to unlock premium resources by the looks of it, hence the spam and the one line plugins that they pumped out today.
     
  8. I'm doing some searching of some code I made a while ago that I was able to track and reproduce the error but need to remember how to do it again because I removed part of it, but in the meantime, output before you clear the gameprofile, GameProfile#toString(), which should print out the players uuid, name, and a property list, and see if any properties are doubled up within that list, and if you see they are, make a filter to just remove one of the sets, and stop the clearing of the GameProfile, and see how they goes.

    EDIT: I actually think the way I fixed it was the filtering technique, or maybe just retrying if the packets were over X length. Sorry I couldn't help much, it's a pretty finicky bug from what I experienced.
     
    #9 RubbaBoy, Apr 26, 2017
    Last edited: Apr 26, 2017
  9. When i output the GameProfile, the Propertie List is empty.
     
  10. (Sorry if this is a stupid question and I'm just blind) but I was looking in your code for a bit, and where is the GameProfile added? I only see instances of it being used to get its ID (Were those 2 functions meant to be commented out?)
     
  11. I am setting the GameProfile in the constructor. Here is the code, which i use to spawn the NPC:
    Code (Text):

    NPC npc = new NPC("Simagdo", player.getLocation());
    npc.spawn();
     
     
  12. Yeah, I see you initialize it, but you don't do anything with it. Could that be an issue?
     
  13. I am using the gameprofile for the ID.
    I tryed a little bit to get it working. The Propertie is {textures=[[email protected]]} after i change the skin.
     
  14. Alright, I played around with your code for a while, and I found a fix to it, which involves replacing a chunk of code. I am not much to spoonfeed, but as a low documented bug that I am not 100% sure how to fix, and you never asked for straight up code, I'm not sure how else to give it to you. This is replacing the spawn() method, the rest of your code seems fine.
    Code (Text):
    public void spawn() {
        addToTablist(); // I am pretty sure this has to go here, so the client sees the player log in first
        MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer(); // Gets the server for the packet, using NMS
        WorldServer nmsWorld = ((CraftWorld) location.getWorld()).getHandle(); // Gets the NMS world to spawn the NPC using NMS
        EntityPlayer npc = new EntityPlayer(nmsServer, nmsWorld, gameprofile, new PlayerInteractManager(nmsWorld)); // Creates an NPC player instead of all reflection based value setting, this is more safe, reliable, and easier
        npc.setLocation(location.getX(), location.getY(), location.getZ(), 0, 0); // Sets the location, again, much easier and less server-intensive from reflection
        PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn(npc); // Created the initial PacketPlayOutNamedEntitySpawn you had perviously, except with the 'npc' EntityPlayer we created previously with all the data in it
        Reflections.sendPacket(packet); // Sends the packet, no change in this line
    }
     
    • Winner Winner x 1
    • Friendly Friendly x 1
  15. Thank you for helping. Another question. You are using an EntityPlayer. Is it possible to add a Pathfinder or something like this, so he can walk?
     
  16. I don't think you can do it, because for pathfinding you need a certain type of Entity (I think, I am not too familiar with Pathfinding/custom entities)

    EDIT: You could simulate something like pathfinding with the Entityplayer#move() function probably, might be jittery in moving though