SHARE
TWEET

Untitled

a guest Aug 13th, 2017 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Npc {
  2.    
  3.     private MinecraftServer nmsServer;
  4.     private WorldServer nmsWorld;
  5.     private GameProfile gp;
  6.    
  7.     public EntityPlayer npc;
  8.     private Player npcPlayer;
  9.     private String name;
  10.    
  11.     public Npc(String name) {
  12.         this.name = name;
  13.        
  14.         nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
  15.         nmsWorld = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
  16.         gp = new GameProfile(UUID.fromString(Files.getUuidFetcher().getUuid(name)), "ยง3" + this.name);
  17.        
  18.         npc = new EntityPlayer(nmsServer, nmsWorld, gp, new PlayerInteractManager(nmsWorld));
  19.         npcPlayer = npc.getBukkitEntity().getPlayer();
  20.         npcPlayer.setPlayerListName("");
  21.     }
  22.  
  23.     public void spawn(Player p) {
  24.         npc.setLocation(p.getLocation().getX(), p.getLocation().getY(), p.getLocation().getZ(), 0F, 0F);
  25.  
  26.         PlayerConnection connection = ((CraftPlayer) p).getHandle().playerConnection;
  27.         connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, npc));
  28.         connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
  29.     }
  30.    
  31.     public void teleport(Player p) {
  32.         PlayerConnection connection = ((CraftPlayer) p).getHandle().playerConnection;
  33.         PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(npc.getId());
  34.         connection.sendPacket(packet);
  35.        
  36.         npc.setLocation(p.getLocation().getX(), p.getLocation().getY(), p.getLocation().getZ(), 0F, 0F);
  37.  
  38.         connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, npc));
  39.         connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
  40.     }
  41. }
RAW Paste Data
Top