Solved How to disguise player as an animal/mob ?

Discussion in 'Spigot Plugin Development' started by J-B, Jan 15, 2020.

  1. J-B

    J-B

    Good morning, sir,
    The reason I come here is because I haven't found any answers.

    I'm trying to disguise a player as an animal but it doesn't work.
    At one point I managed to create a sheep but it didn't move and when you interacted with it it made a lot of mistakes.
    So I'm looking for methods to disguise myself as an animal.

    I don't want to use protocollib or a plugin I already have.

    Thank you for your precious help
     
    #1 J-B, Jan 15, 2020
    Last edited: Jan 15, 2020
  2. 1. How dare you assume that there is only one gentlemen to be found in here?
    2. Well... if you don't want to use protocollib, you can only use your own packets. I do not believe, there is a "nice" method that can set the entity type of a player or any entity for that matter.
    The only thing you could do is catch-all outgoing packets that say "Hey, I'm a player" and replace them by a similar packet, that says "Hey, I'm a sheep"
     
    #2 Schottky, Jan 15, 2020
    Last edited: Jan 17, 2020
    • Agree Agree x 1
    • Funny Funny x 1
  3. Yeah thats a lot of work. You need to listen for a ton of packets.
    The to go library for this is LisDisguises. Doesnt look free at first but it is.
    Its literally one method to disguise a player as an animal or other player.
     
  4. J-B

    J-B

    Sorry, my translator put "sir" in. I'm so bad at English ^^
     
  5. J-B

    J-B

    Exactly, I've tried a lot of methods and I haven't been able to...
     
  6. LibsDisguises does work, show us some code.
     
  7. J-B

    J-B

    Code (Text):
        public static void disguisePlayer(Player p) {
            EntitySheep eh = new EntitySheep(((CraftPlayer) p).getHandle().world);
            PacketPlayOutEntityDestroy p29 = new PacketPlayOutEntityDestroy(new int[]{p.getEntityId()});
            PacketPlayOutSpawnEntity p20 = new PacketPlayOutSpawnEntity(eh, 1);
            new java.util.Timer().schedule(
                    new java.util.TimerTask() {
                        @Override
                        public void run() {
                            try {
                                java.lang.reflect.Field profileField = p20.getClass().getDeclaredField("b");
                                profileField.setAccessible(true);
                                profileField.set(p20, new GameProfile(p.getUniqueId(), "mouton"));
                                //profileField.set(eh, new GameProfile(p.getUniqueId(), "mouton"));
                                p.sendMessage("§aVous êtes devenus un mouton");
                            } catch (Exception e) {
                                System.out.println(e.getMessage());
                            }
                            for(Player o : Bukkit.getOnlinePlayers()){
                                if(!o.getName().equals(p.getName())){
                                    ((CraftPlayer)o).getHandle().playerConnection.sendPacket(p29);
                                    ((CraftPlayer)o).getHandle().playerConnection.sendPacket(p20);
                                }
                            }
                        }
                    },
                    500
            );
        }
     
  8. J-B

    J-B

    this code doesn't work, it seems to me it's the one where the sheep don't follow us.
     
  9. I mean... you are sending an Entity-destroy packet and Entity-spawn packet. However, players can move, so why don't you try to send another packet updating the position of the entity according to that of the player?
    You could make a Set of hidden players and (either at discrete timesteps or on an event) you send a new packet to the players telling them how the sheep has moved
     
  10. J-B

    J-B

    how do you do that?
     
  11. Just look at some of the PacketPlayOutEntity packets, especially PacketPlayOutRelEntityMoveLook. I suppose that's the one that is responsible for where an Entity is. Other options are PacketPlayOutEntityVelocity in combination with PacketPlayOutEntityHeadRotation. Set the values for these packets according to what you get from the player
     
  12. J-B

    J-B

    Won't that be too much of a bug ?
     
  13. Since you're trying to avoid using a lib that already optimized all of this and don'twanna use protocollib, yeah it may not be the best performance wise but hey at least it'll work
     
  14. If you’re unsure of how to approach this problem, I suggest you look at the source for the various disguise plugins out there and figure it out based on that. You can find the 1.15 version of LibsDisguises here and work your way back.
     
  15. J-B

    J-B

    I want use for 1.8 version and I've already searched this side unsuccessfully...
     
  16. J-B

    J-B

  17. How so? It is a disguise plugin that works in 1.8 and doesn’t even use ProtocolLib. What do you even need help with? All the plugin does was described in the first reply to your question:
    You’re going to need to be more specific on why the linked repo doesn’t help you. You can copy and paste everything into your plugin and it will work basically exactly how you want.
     
  18. J-B

    J-B

    Thank you for your help,
    I've just been going through the codes and I can't find a single trace of any packets sent.
    So I'm looking for, if anyone has it, methods that would allow me to disguise myself as a sheep.
     
  19. You can’t disguise yourself by sending a packet, you need to intercept the packets spawning the a player and replace the information with that of a sheep, look at the disguise API and figure out how that modifies the packet manager