[Protocol lib] How to make players disguise as a villager

Discussion in 'Plugin Development' started by rb2750, Aug 29, 2013.

Thread Status:
Not open for further replies.
  1. Hi, I have been trying the past 3 days to get my code to work, which should disguise players as villagers, but all that seems to be happening so far, is it is making a fake-player which doesn't move around when the actual player does.

    My current code is this:

    Code:java
    1. final ProtocolManager manager = ProtocolLibrary.getProtocolManager();
    2.  
    3. manager.addPacketListener(new PacketAdapter(this, ConnectionSide.SERVER_SIDE, ListenerPriority.NORMAL, 20)
    4. {
    5. @Override
    6. public void onPacketSending(PacketEvent event)
    7. {
    8. switch (event.getPacketID())
    9. {
    10. case 20:
    11. try
    12. {
    13. PacketContainer pc = event.getPacket();
    14. pc.getIntegers().write(0, 120).write(4, 0);
    15. Field watcherField = net.minecraft.server.v1_6_R2.Entity.class.getDeclaredField("datawatcher");
    16. watcherField.setAccessible(true);
    17. Object villager = net.minecraft.server.v1_6_R2.EntityVillager.class.getConstructor(new Class[]
    18. {
    19. net.minecraft.server.v1_6_R2.World.class
    20. }).newInstance(new Object[]
    21. {
    22. ((CraftWorld) getServer().getWorlds().get(0)).getHandle() //<--- Could potentially cause a problem, if anyone knows how to get the world from the packet, please tell me :)
    23. });
    24. pc.getDataWatcherModifier().write(0, new WrappedDataWatcher((DataWatcher) watcherField.get(villager)));
    25. event.setPacket(pc);
    26. }
    27. {
    28. e.printStackTrace();
    29. }
    30. break;
    31. }
    32. }
    33. });
     
  2. Offline

    phips99

    rb2750-snip- (This won't work)
     


  3. Thanks I'll check this out, and yeah I know you need another player to see the disguise, but yeah anyway thanks :p

    phips99
    Could you possibly do that download in a bukkit-dev download please? Aparently I can't download from that website for an unknown reason:l (Drag and drop into send-message box). Thanks

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  4. Offline

    phips99

    rb2750 I don't have ownership of this plugin os I can't upload it. And if I would it'd take about 3 days that they approve it... I'll upload it on mediafire soon.
     
  5. Offline

    phips99

    Mang0eZPvP As I said before you'll need packet wrapper. Here is the code with packet wrapper:
    Code:java
    1. Packet14SpawnNamedEntity spawned = new Packet14SpawnNamedEntity(); //The packet
    2. spawned.setEntityID(12345); // This id has to be unique
    3. spawned.setPosition(location.toVector()); //Location where the fake player spawns
    4. spawned.setPlayerName(name); //From this player the skin will be renderer!
    5. spawned.setYaw(yaw);
    6. spawned.setPitch(pitch);
    7. //This is very basic, you can set a bunch of more settings, if you want to know, you can tag me
    8. try {
    9. for (Player players : Bukkit.getOnlinePlayers()) {
    10. ProtocolLibrary.getProtocolManager().sendServerPacket(players, spawned.getHandle());
    11. }
    12. e.printStackTrace();
    13. }
    14.  
     
  6. Offline

    Mang0eZPvP

    I think that would do
     
Thread Status:
Not open for further replies.

Share This Page