Exemplo n.º 1
0
  public static Sheep spawn(Location location) {

    MinecraftServer server = MinecraftServer.getServer();
    WorldServer world = server.getWorldServer(0);
    for (WorldServer ws : server.worlds) {
      if (ws.getWorld().getName().equals(location.getWorld().getName())) {
        world = ws;
        break;
      }
    }
    World mcWorld = (World) ((CraftWorld) location.getWorld()).getHandle();
    final SheepNPC customEntity = new SheepNPC(world);
    customEntity.setLocation(
        location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    ((CraftLivingEntity) customEntity.getBukkitEntity()).setRemoveWhenFarAway(false);
    mcWorld.addEntity(customEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
    return (CraftSheep) customEntity.getBukkitEntity();
  }
Exemplo n.º 2
0
  public static NpcPlayer valueOf(Player player) {
    MinecraftServer minecraftServer = MinecraftServer.getServer();
    WorldServer worldServer = minecraftServer.getWorldServer(0);
    PlayerInteractManager playerInteractManager = new PlayerInteractManager(worldServer);
    GameProfile gameProfile =
        new GameProfile(
            UUID.randomUUID(), NpcNameGeneratorFactory.getNameGenerator().generate(player));

    for (Map.Entry<String, Property> entry :
        ((CraftPlayer) player).getProfile().getProperties().entries()) {
      gameProfile.getProperties().put(entry.getKey(), entry.getValue());
    }

    NpcPlayer npcPlayer =
        new NpcPlayer(minecraftServer, worldServer, gameProfile, playerInteractManager);
    npcPlayer.identity = new NpcIdentity(player);

    new NpcPlayerConnection(npcPlayer);

    return npcPlayer;
  }