Vinetos

[Packets Bukkit] NPCs ou Fake Players (#02) - FakePlayers

Oct 26th, 2015
1,045
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import com.mojang.authlib.GameProfile;
  2. import net.minecraft.server.v1_8_R3.*;
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.Location;
  5. import org.bukkit.craftbukkit.v1_8_R3.CraftServer;
  6. import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
  7. import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
  8. import org.bukkit.entity.Player;
  9.  
  10. /**
  11. * @author VINETOS on 26/10/2015.
  12. */
  13. public class FakePlayer {
  14.  
  15. private String name;
  16. private EntityPlayer ep;
  17.  
  18. public FakePlayer(String name){
  19. this.name = name;
  20. }
  21.  
  22. public void spawn(Player p){
  23. MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
  24. WorldServer world = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
  25. EntityPlayer npc = new EntityPlayer(server, world, new GameProfile(p.getUniqueId(), name), new PlayerInteractManager(world));
  26. Location loc = p.getLocation();
  27. npc.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
  28.  
  29. for(Player pls : Bukkit.getOnlinePlayers()){
  30. PlayerConnection connection = ((CraftPlayer)pls).getHandle().playerConnection;
  31. connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, npc));
  32. connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
  33. }
  34. ep = npc;
  35. }
  36.  
  37. public void dispawn(){
  38. for(Player pls : Bukkit.getOnlinePlayers()){
  39. PlayerConnection connection = ((CraftPlayer)pls).getHandle().playerConnection;
  40. connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, ep));
  41. connection.sendPacket(new PacketPlayOutEntityDestroy(new int[]{ep.getId()}));
  42. }
  43. }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment